i need help to edit the two methods below so that i can have
i need help to edit the two methods below so that i can have them work in the class provided after the two methods.
Insert and Select methods below
Patient class below
then below is what the outcome of the data we add to the file we ill create when we get the two methods above to work will look like
patients.txt A900:1234:Jimmy:Hawkins:Marietta:jhawk@yahoo.com:Cign.a A901:9999:Bill:Smith: Acworth:bsmith@gmail.com: Aetna A902:8888: Teri:Smart:Atlanta:tsm@yahoo.com:BlueCross A903:777:James: Roy:Acworth:jamesray@gmail.com:BlueCross A904:5555: Mary:Wilson: Roswell:mwil@yahoo.com:cigna A905: 1111:Faith: Adams: Roswell:faith@gmail.com: Aetna A906:1111:Jerry: Jones:Dallas:ij@cowboys.com:Cigna A907:9090:Carrie:Slater:Marietta:cslat@gmail.com:Cigna A908:9898:Sara:Jefferson: Dallas:sjeff@gmail.com:Cigna A909:1234:Debbie:Johnson:Marietta:djohn@hotmail.com:Cigna A910:1111:Marth:stewart:Marietta:mstew@gmail.com: Aetna A911:4555: John: Franca:Kennesaw: jfranco@hotmail.com:BlueCrosSolution
package pis;
import java.sql.*;
 import java.util.ArrayList;
 public class Patient {
 private String id,name,dob,complaints,gender,referedby, contactno,mrvid;
 private int age;
 private ArrayList<Visit> visits;
 public Patient() {
 }
public String getId() {
 return id;
 }
public void setId(String id) {
 this.id = id;
 }
public String getName() {
 return name;
 }
public void setName(String name) {
 this.name = name;
 }
public String getDob() {
 return dob;
 }
public void setDob(String dob) {
 this.dob = dob;
 }
public String getComplaints() {
 return complaints;
 }
public void setComplaints(String complaints) {
 this.complaints = complaints;
 }
public String getGender() {
 return gender;
 }
public void setGender(String gender) {
 this.gender = gender;
 }
public String getReferedby() {
 return referedby;
 }
public void setReferedby(String referedby) {
 this.referedby = referedby;
 }
public String getContactno() {
 return contactno;
 }
public void setContactno(String contactno) {
 this.contactno = contactno;
 }
   
 public String add() {
 Connection con = null;
 try {
 con = Database.getConnection();
 Statement st = con.createStatement();
 // get patient id
 ResultSet rs = st.executeQuery(\"select nvl(max(pid),0) + 1 from patients\");
 rs.next();
 id = rs.getString(1);
 rs.close();
   
 PreparedStatement ps = con.prepareStatement(\"insert into patients values(?,?,?,?,?,?,null,?)\");
 ps.setString(1,id);
 ps.setString(2,name);
 ps.setString(3,dob);
 ps.setString(4,gender);
 ps.setString(5,contactno);
 ps.setString(6,complaints);
 ps.setString(7,referedby);
 if ( ps.executeUpdate() == 1)
 return id;
 else
 return null; // error
 }
 catch(Exception ex) {
 System.out.println(ex.getMessage());
 return null;
 }
 finally {
 Database.close(con);
 }
 } // add()
  
 public static boolean update(String pid, String contactno, String complaints) {
 Connection con = null;
 try {
 con = Database.getConnection();
 PreparedStatement ps = con.prepareStatement(\"update patients set contactno =?, complaints = ? where pid = ?\");
 ps.setString(1,contactno);
 ps.setString(2,complaints);
 ps.setString(3,pid);
 if ( ps.executeUpdate() == 1)
 return true;
 else
 return false; // error
 }
 catch(Exception ex) {
 System.out.println(ex.getMessage());
 return false;
 }
 finally {
 Database.close(con);
 }
 } // update()
  
 public int getAge() {
 return age;
 }
public void setAge(int age) {
 this.age = age;
 }
public ArrayList<Visit> getVisits() {
 return visits;
 }
public void setVisits(ArrayList<Visit> visits) {
 this.visits = visits;
 }
   
 public static Patient getAllDetails(String pid) {
 // connect and get all details of the given patient
 Connection con= null;
 try{
 con = Database.getConnection();
 PreparedStatement ps = con.prepareStatement(\"select name,gender, dob, (sysdate - dob) / 365 age, complaints, contactno, referedby from patients where pid = ?\");
 ps.setString(1,pid);
 ResultSet rs = ps.executeQuery();
 if (! rs.next () )
 return null;
 // System.out.println(\"Patient Found\");
 // create Patient object and load data from row to object
 Patient p = new Patient();
 p.setId(pid);
 p.setName( rs.getString(\"name\"));
 p.setContactno( rs.getString(\"contactno\"));
 p.setComplaints( rs.getString(\"complaints\"));
 p.setGender( rs.getString(\"gender\"));
 p.setDob( rs.getString(\"dob\"));
 p.setAge( rs.getInt(\"age\"));
 p.setReferedby( rs.getString(\"referedby\"));
 rs.close();
   
 // Get details of visits of this patient
 ps = con.prepareStatement(\"select vid, to_char(visitdate) vdate,complaint from visits where pid = ? order by visitdate desc\");
 ps.setString(1,pid);
 rs = ps.executeQuery();
 ArrayList<Visit> visits = new ArrayList<Visit>();
 Visit v;
 while ( rs.next()) {
 visits.add(new Visit(rs.getString(\"vid\"), pid,rs.getString(\"complaint\"), rs.getString(\"vdate\")));
 }
 rs.close();
 p.setVisits(visits);
 return p;
 } // end of try
 catch(Exception ex) {
 System.out.println(ex.getMessage());
 return null;
 }
 finally {
 Database.close(con);
 }
 
 } // getAllDetails()
   
   
   
 public static Patient getDetails(String pid) {
 Connection con= null;
 try{
 con = Database.getConnection();
 PreparedStatement ps = con.prepareStatement(\"select name,gender, dob, (sysdate - dob) / 365 age, complaints, contactno, referedby from patients where pid = ?\");
 ps.setString(1,pid);
 ResultSet rs = ps.executeQuery();
 if (! rs.next () )
 return null;
 Patient p = new Patient();
 p.setId(pid);
 p.setName( rs.getString(\"name\"));
 p.setContactno( rs.getString(\"contactno\"));
 p.setComplaints( rs.getString(\"complaints\"));
 p.setGender( rs.getString(\"gender\"));
 p.setDob( rs.getString(\"dob\"));
 p.setAge( rs.getInt(\"age\"));
 p.setReferedby( rs.getString(\"referedby\"));
 rs.close();
 return p;
 } // end of try
 catch(Exception ex) {
 System.out.println(ex.getMessage());
 return null;
 }
 finally {
 Database.close(con);
 }
 
 } // getDetails()
   
 public static ArrayList<Patient> getPatients(String pname,String fromage, String toage, String gender) {
 String cond = \" 1 = 1 \";
 if ( pname.length() > 0 )
 cond += \" and upper(name) like \'%\" + pname.toUpperCase() + \"%\'\";
   
 if ( fromage.length() > 0 )
 cond += \" and (sysdate - dob)/365 >= \" + fromage;
   
 if ( toage.length() > 0 )
 cond += \" and (sysdate - dob)/365 <= \" + toage;
   
 if (! gender.equals(\"a\"))
 cond += \" and gender = \'\" + gender + \"\'\";
 Connection con = null;
 ArrayList<Patient> pl = new ArrayList<Patient>();
 try {
 con = Database.getConnection();
 Statement st = con.createStatement();
 ResultSet rs = st.executeQuery(\"select p.pid,name,decode(gender,\'m\',\'Male\',\'Female\') gender, (sysdate-dob) / 365 age, complaints, to_char(visitdate) visitdate,contactno, referedby from patients p, visits v where p.mrvid = v.vid and \" + cond);
 while ( rs.next()) {
 Patient p = new Patient();
 p.setId( rs.getString(\"pid\"));
 p.setName( rs.getString(\"name\"));
 p.setGender( rs.getString(\"gender\"));
 p.setContactno( rs.getString(\"contactno\"));
 p.setComplaints( rs.getString(\"complaints\"));
 p.setAge( rs.getInt(\"age\"));
 p.setReferedby( rs.getString(\"referedby\"));
 p.setMrvid( rs.getString(\"visitdate\"));
 pl.add(p);
 } // while
 return pl;
 }
 catch(Exception ex) {
 System.out.println(ex.getMessage());
 return pl;
 }
 finally {
 Database.close(con);
 }
 } // getPatients
public String getMrvid() {
 return mrvid;
 }
public void setMrvid(String mrvid) {
 this.mrvid = mrvid;
 }
 } // Patient class
package pis;
import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.Statement;
 import java.util.ArrayList;
 public class Visit {
 private String vid, pid, complaint,visitdate;
 private ArrayList<Drug> drugs;
 private ArrayList<Test> tests;
 public Visit() {}
 public Visit( String vid, String pid, String complaint, String visitdate) {
 this.setVid(vid);
 this.pid = pid;
 this.complaint = complaint;
 this.visitdate = visitdate;
 drugs = new ArrayList<Drug>();
 tests = new ArrayList<Test>();
 }
public String getPid() {
 return pid;
 }
public void setPid(String pid) {
 this.pid = pid;
 }
public String getComplaint() {
 return complaint;
 }
public void setComplaint(String complaint) {
 this.complaint = complaint;
 }
public String getVisitdate() {
 return visitdate;
 }
public void setVisitdate(String visitdate) {
 this.visitdate = visitdate;
 }
public ArrayList<Drug> getDrugs() {
 return drugs;
 }
public void setDrugs(ArrayList drugs) {
 this.drugs = drugs;
 }
public ArrayList<Test> getTests() {
 return tests;
 }
public void setTests(ArrayList tests) {
 this.tests = tests;
 }
public String getVid() {
 return vid;
 }
public void setVid(String vid) {
 this.vid = vid;
 }
   
 public static String add(String pid, String complaint, String drugnames[], String dosage[], String nodays[], String tests[]) {
 Connection con = null;
 String vid;
 try {
 con = Database.getConnection();
 // begin a transaction
 con.setAutoCommit(false);
 Statement st = con.createStatement();
 // get visit id
 ResultSet rs = st.executeQuery(\"select nvl(max(vid),0) + 1 from visits\");
 rs.next();
 vid = rs.getString(1);
 rs.close();
 PreparedStatement ps = con.prepareStatement(\"insert into visits values(?,?,sysdate,?)\");
 ps.setString(1,vid);
 ps.setString(2,pid);
 ps.setString(3,complaint);
 if ( ps.executeUpdate() != 1)
 return null; // error
 System.out.println(\"Visit added\");
 // insert into DRUGS
 ps = con.prepareStatement(\"insert into drugs values(?,?,?,?)\");
 for ( int i = 0; i < 5; i ++) {
 if ( drugnames[i].trim().length() == 0 ) continue;
 ps.setString(1,vid);
 ps.setString(2,drugnames[i]);
 ps.setString(3,dosage[i]);
 ps.setString(4,nodays[i]);
 if ( ps.executeUpdate() == 0 )
 throw new Exception(\"Could not insert drug details\");
 else
 System.out.println(\"drug added\");
 }
 // insert into TESTS
 ps = con.prepareStatement(\"insert into tests values(?,?,null,null)\");
 for (int i = 0 ; i < 5 ; i ++) {
 if ( tests[i].trim().length() == 0 ) continue;
 ps.setString(1,vid);
 ps.setString(2,tests[i]);
 if ( ps.executeUpdate() == 0 )
 throw new Exception(\"Could not insert test details\");
 else
 System.out.println(\"Test added\");
 }
   
 // update patients data
 ps = con.prepareStatement(\"update patients set mrvid = ? where pid = ?\");
 ps.setString(1,vid);
 ps.setString(2,pid);
 ps.executeUpdate();
 con.commit();
 return vid;
 }
 catch(Exception ex) {
 try {
 con.rollback();
 }
 catch(Exception nex) {}
 System.out.println(ex.getMessage());
 return null;
 }
 finally {
 Database.close(con);
 }
 } // add()
   
   
   
 public static boolean updateTests(String vid, String testnames[], String testdates[], String testresults[]) {
 Connection con = null;
 try {
 con = Database.getConnection();
 // begin a transaction
 con.setAutoCommit(false);
 PreparedStatement ps = con.prepareStatement(\"update tests set testdate = ? , result = ? where vid = ? and testname = ?\");
 for ( int i = 0 ; i < testnames.length ; i ++) {
 if ( testdates[i].trim().length() > 0 && testresults[i].trim().length() > 0 ) {
 ps.setString(1,testdates[i]);
 ps.setString(2,testresults[i]);
 ps.setString(3,vid);
 ps.setString(4, testnames[i]);
 if ( ps.executeUpdate() != 1) return false;
 }
 }
 con.commit();
 return true;
 }
 catch(Exception ex) {
 try {
 con.rollback();
 }
 catch(Exception nex) {}
 System.out.println(ex.getMessage());
 return false;
 }
 finally {
 Database.close(con);
 }
 } // add()
   
 public static Visit getAllDetails(String vid) {
 // connect and get all details of the given visit
 Connection con= null;
 try{
 con = Database.getConnection();
 PreparedStatement ps = con.prepareStatement(\"select vid,to_char(visitdate) visitdate, complaint from visits where vid = ?\");
 ps.setString(1,vid);
 ResultSet rs = ps.executeQuery();
 if (! rs.next () )
 return null;
 Visit v = new Visit( );
 v.setVid(vid);
 v.setVisitdate( rs.getString(\"visitdate\"));
 v.setComplaint( rs.getString(\"complaint\"));
   
 // Get details of drugs related to visit
 ps = con.prepareStatement(\"select drugname, dosage, nodays from drugs where vid = ?\");
 ps.setString(1,vid);
 rs = ps.executeQuery();
 ArrayList<Drug> drugs = new ArrayList<Drug>();
 while ( rs.next()) {
 drugs.add(new Drug(vid, rs.getString(\"drugname\"), rs.getString(\"dosage\"), rs.getInt(\"nodays\")));
 }
 rs.close();
 v.setDrugs(drugs);
   
 // Get details of tests related to visit
 ps = con.prepareStatement(\"select testname, nvl(to_char(testdate),\' \') testdate, nvl(result,\' \') result from tests where vid = ?\");
 ps.setString(1,vid);
 rs = ps.executeQuery();
 ArrayList<Test> tests = new ArrayList<Test>();
 while ( rs.next()) {
 tests.add(new Test(vid, rs.getString(\"testname\"), rs.getString(\"testdate\"), rs.getString(\"result\")));
 }
 rs.close();
 v.setTests(tests);
   
 return v;
   
 } // end of try
 catch(Exception ex) {
 System.out.println(ex.getMessage());
 return null;
 }
 finally {
 Database.close(con);
 }
 } // getAllDetails()
   
   
   
 public static ArrayList<Test> getTests(String vid) {
 Connection con= null;
 try{
 con = Database.getConnection();
 // Get details of tests related to visit
 PreparedStatement ps = con.prepareStatement(\"select testname, nvl(to_char(testdate),\' \') testdate, nvl(result,\' \') result from tests where vid = ?\");
 ps.setString(1,vid);
 ResultSet rs = ps.executeQuery();
 ArrayList<Test> tests = new ArrayList<Test>();
 while ( rs.next()) {
 tests.add(new Test(vid, rs.getString(\"testname\"), rs.getString(\"testdate\"), rs.getString(\"result\")));
 }
 rs.close();
 return tests;
 } // end of try
 catch(Exception ex) {
 System.out.println(ex.getMessage());
 return null;
 }
 finally {
 Database.close(con);
 }
 } // getAllDetails()
 }
<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
 <head>
 <title>New Patient</title>
 </head>
 <body>
 <%@include file=\"head.html\"%>
 <h2>New Patient</h2>
 <form action=\"newpatient.jsp\" method=\"post\">
 <table>
 <tr>
 <td>Patient Name :
 <td><input type=\"text\" name=\"name\" size-=\"20\" />
 </tr>
 <tr>
 <td>Date of birth :</td>
 <td><input type=\"text\" name=\"dob\" value=\"\" size=\"10\" /> (dd-mon-yyyy)
 </tr>
 <tr>
 <td>Gender :</td>
 <td><input type=\"radio\" name=\"gender\" value=\"m\" />Male
 <input type=\"radio\" name=\"gender\" value=\"f\" />Female
 </tr>
   
 <tr>
 <td>Contact No. :</td>
 <td><input type=\"text\" name=\"contactno\" value=\"\" size=\"15\" />
 </tr>
<tr>
 <td>Complaints : </td>
 <td><textarea name=\"complaints\" rows=\"4\" cols=\"30\"></textarea>
 </tr>
   
   
 <tr>
 <td>Refered By :</td>
 <td><input type=\"text\" name=\"referedby\" value=\"\" size=\"20\" />
 </tr>
 </table>
 <p/>
 <input type=\"submit\" value=\"Add Patient\" />
 <input type=\"reset\" value=\"Clear All\" />
 </form>
 <%@include file=\"footer.html\"%>
 </body>
 </html>










