SlideShare a Scribd company logo
1 of 15
Download to read offline
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:BlueCros
Solution
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 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 getVisits() {
return visits;
}
public void setVisits(ArrayList 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 visits = new ArrayList();
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 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 pl = new ArrayList();
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 drugs;
private ArrayList 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();
tests = new ArrayList();
}
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 getDrugs() {
return drugs;
}
public void setDrugs(ArrayList drugs) {
this.drugs = drugs;
}
public ArrayList 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 drugs = new ArrayList();
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 tests = new ArrayList();
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 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 tests = new ArrayList();
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()
}
New Patient
<%@include file="head.html"%>
New PatientPatient Name :
Date of birth : (dd-mon-yyyy)
Gender :Male
Female
Contact No. :Complaints : Refered By :
<%@include file="footer.html"%>

More Related Content

Similar to i need help to edit the two methods below so that i can have them wo.pdf

package com.test;public class Team {    private String teamId;.pdf
package com.test;public class Team {    private String teamId;.pdfpackage com.test;public class Team {    private String teamId;.pdf
package com.test;public class Team {    private String teamId;.pdf
aparnacollection
 
package patienttest;import java.util.Comparator; import java..pdf
 package patienttest;import java.util.Comparator; import java..pdf package patienttest;import java.util.Comparator; import java..pdf
package patienttest;import java.util.Comparator; import java..pdf
annucommunication1
 
Define a class named Doctor whose objects are records for clinic’s d.pdf
Define a class named Doctor whose objects are records for clinic’s d.pdfDefine a class named Doctor whose objects are records for clinic’s d.pdf
Define a class named Doctor whose objects are records for clinic’s d.pdf
MALASADHNANI
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdf
ICADCMLTPC
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdf
NicholasflqStewartl
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdf
aplolomedicalstoremr
 
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdfBasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
ankitmobileshop235
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
kostikjaylonshaewe47
 
Not sure why my program wont run.Programmer S.Villegas helper N.pdf
Not sure why my program wont run.Programmer S.Villegas helper N.pdfNot sure why my program wont run.Programmer S.Villegas helper N.pdf
Not sure why my program wont run.Programmer S.Villegas helper N.pdf
wasemanivytreenrco51
 
Patient.java package A9.toStudents; public class Patient imple.pdf
Patient.java package A9.toStudents; public class Patient imple.pdfPatient.java package A9.toStudents; public class Patient imple.pdf
Patient.java package A9.toStudents; public class Patient imple.pdf
DEEPAKSONI562
 
Ugly code
Ugly codeUgly code
Ugly code
Odd-e
 
public class Patient extends Person {=========== Properties ====.pdf
public class Patient extends Person {=========== Properties ====.pdfpublic class Patient extends Person {=========== Properties ====.pdf
public class Patient extends Person {=========== Properties ====.pdf
arishmarketing21
 
I need help making these adjustments to my class Persons_Informati.pdf
I need help making these adjustments to my class Persons_Informati.pdfI need help making these adjustments to my class Persons_Informati.pdf
I need help making these adjustments to my class Persons_Informati.pdf
omarionmatzmcwill497
 
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdfSorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
akritigallery
 
why will it not display all of the entries-- output -nMenu n-Add Entr.pdf
why will it not display all of the entries--  output -nMenu n-Add Entr.pdfwhy will it not display all of the entries--  output -nMenu n-Add Entr.pdf
why will it not display all of the entries-- output -nMenu n-Add Entr.pdf
abc2232
 

Similar to i need help to edit the two methods below so that i can have them wo.pdf (20)

package com.test;public class Team {    private String teamId;.pdf
package com.test;public class Team {    private String teamId;.pdfpackage com.test;public class Team {    private String teamId;.pdf
package com.test;public class Team {    private String teamId;.pdf
 
package patienttest;import java.util.Comparator; import java..pdf
 package patienttest;import java.util.Comparator; import java..pdf package patienttest;import java.util.Comparator; import java..pdf
package patienttest;import java.util.Comparator; import java..pdf
 
Define a class named Doctor whose objects are records for clinic’s d.pdf
Define a class named Doctor whose objects are records for clinic’s d.pdfDefine a class named Doctor whose objects are records for clinic’s d.pdf
Define a class named Doctor whose objects are records for clinic’s d.pdf
 
Sharable_Java_Python.pdf
Sharable_Java_Python.pdfSharable_Java_Python.pdf
Sharable_Java_Python.pdf
 
TDC2016SP - Código funcional em Java: superando o hype
TDC2016SP - Código funcional em Java: superando o hypeTDC2016SP - Código funcional em Java: superando o hype
TDC2016SP - Código funcional em Java: superando o hype
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdf
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdf
 
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdfBasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
 
JAVA 8 : Migration et enjeux stratégiques en entreprise
JAVA 8 : Migration et enjeux stratégiques en entrepriseJAVA 8 : Migration et enjeux stratégiques en entreprise
JAVA 8 : Migration et enjeux stratégiques en entreprise
 
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
 
Not sure why my program wont run.Programmer S.Villegas helper N.pdf
Not sure why my program wont run.Programmer S.Villegas helper N.pdfNot sure why my program wont run.Programmer S.Villegas helper N.pdf
Not sure why my program wont run.Programmer S.Villegas helper N.pdf
 
Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Domain Driven Design with the F# type System -- F#unctional Londoners 2014Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Domain Driven Design with the F# type System -- F#unctional Londoners 2014
 
Patient.java package A9.toStudents; public class Patient imple.pdf
Patient.java package A9.toStudents; public class Patient imple.pdfPatient.java package A9.toStudents; public class Patient imple.pdf
Patient.java package A9.toStudents; public class Patient imple.pdf
 
Ugly code
Ugly codeUgly code
Ugly code
 
public class Patient extends Person {=========== Properties ====.pdf
public class Patient extends Person {=========== Properties ====.pdfpublic class Patient extends Person {=========== Properties ====.pdf
public class Patient extends Person {=========== Properties ====.pdf
 
I need help making these adjustments to my class Persons_Informati.pdf
I need help making these adjustments to my class Persons_Informati.pdfI need help making these adjustments to my class Persons_Informati.pdf
I need help making these adjustments to my class Persons_Informati.pdf
 
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdfSorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
 
why will it not display all of the entries-- output -nMenu n-Add Entr.pdf
why will it not display all of the entries--  output -nMenu n-Add Entr.pdfwhy will it not display all of the entries--  output -nMenu n-Add Entr.pdf
why will it not display all of the entries-- output -nMenu n-Add Entr.pdf
 
40+ examples of user defined methods in java with explanation
40+ examples of user defined methods in java with explanation40+ examples of user defined methods in java with explanation
40+ examples of user defined methods in java with explanation
 

More from irshadoptical

Help!! Which of the following correctly lists the simple molecules t.pdf
Help!! Which of the following correctly lists the simple molecules t.pdfHelp!! Which of the following correctly lists the simple molecules t.pdf
Help!! Which of the following correctly lists the simple molecules t.pdf
irshadoptical
 
C++ PROGRAMThis program builds on the code below#include iostr.pdf
C++ PROGRAMThis program builds on the code below#include iostr.pdfC++ PROGRAMThis program builds on the code below#include iostr.pdf
C++ PROGRAMThis program builds on the code below#include iostr.pdf
irshadoptical
 
You are in charge of the investigation regarding possible exposur.pdf
You are in charge of the investigation regarding possible exposur.pdfYou are in charge of the investigation regarding possible exposur.pdf
You are in charge of the investigation regarding possible exposur.pdf
irshadoptical
 
Which of the following is not a product of the light reactions of ph.pdf
Which of the following is not a product of the light reactions of ph.pdfWhich of the following is not a product of the light reactions of ph.pdf
Which of the following is not a product of the light reactions of ph.pdf
irshadoptical
 
Write a line of code to create a Print Writer to write to the file .pdf
Write a line of code to create a Print Writer to write to the file .pdfWrite a line of code to create a Print Writer to write to the file .pdf
Write a line of code to create a Print Writer to write to the file .pdf
irshadoptical
 

More from irshadoptical (20)

In practice, a RAM is used to simulate the operation of a stack by m.pdf
In practice, a RAM is used to simulate the operation of a stack by m.pdfIn practice, a RAM is used to simulate the operation of a stack by m.pdf
In practice, a RAM is used to simulate the operation of a stack by m.pdf
 
Help!! Which of the following correctly lists the simple molecules t.pdf
Help!! Which of the following correctly lists the simple molecules t.pdfHelp!! Which of the following correctly lists the simple molecules t.pdf
Help!! Which of the following correctly lists the simple molecules t.pdf
 
How does feasibility differ in an agile environment in comparison to.pdf
How does feasibility differ in an agile environment in comparison to.pdfHow does feasibility differ in an agile environment in comparison to.pdf
How does feasibility differ in an agile environment in comparison to.pdf
 
describe a real-life example of selection against a homozygous reces.pdf
describe a real-life example of selection against a homozygous reces.pdfdescribe a real-life example of selection against a homozygous reces.pdf
describe a real-life example of selection against a homozygous reces.pdf
 
Define a motor unit. What roles do motor units play in graded contrac.pdf
Define a motor unit. What roles do motor units play in graded contrac.pdfDefine a motor unit. What roles do motor units play in graded contrac.pdf
Define a motor unit. What roles do motor units play in graded contrac.pdf
 
An antibody is a protein that has which level of protein structure .pdf
An antibody is a protein that has which level of protein structure  .pdfAn antibody is a protein that has which level of protein structure  .pdf
An antibody is a protein that has which level of protein structure .pdf
 
C++ PROGRAMThis program builds on the code below#include iostr.pdf
C++ PROGRAMThis program builds on the code below#include iostr.pdfC++ PROGRAMThis program builds on the code below#include iostr.pdf
C++ PROGRAMThis program builds on the code below#include iostr.pdf
 
You are in charge of the investigation regarding possible exposur.pdf
You are in charge of the investigation regarding possible exposur.pdfYou are in charge of the investigation regarding possible exposur.pdf
You are in charge of the investigation regarding possible exposur.pdf
 
Which of the following is not a product of the light reactions of ph.pdf
Which of the following is not a product of the light reactions of ph.pdfWhich of the following is not a product of the light reactions of ph.pdf
Which of the following is not a product of the light reactions of ph.pdf
 
Write a line of code to create a Print Writer to write to the file .pdf
Write a line of code to create a Print Writer to write to the file .pdfWrite a line of code to create a Print Writer to write to the file .pdf
Write a line of code to create a Print Writer to write to the file .pdf
 
what is the difference bettween cotranslational import and posttrans.pdf
what is the difference bettween cotranslational import and posttrans.pdfwhat is the difference bettween cotranslational import and posttrans.pdf
what is the difference bettween cotranslational import and posttrans.pdf
 
What is the meaning of critical periods in neonatal development Wha.pdf
What is the meaning of critical periods in neonatal development Wha.pdfWhat is the meaning of critical periods in neonatal development Wha.pdf
What is the meaning of critical periods in neonatal development Wha.pdf
 
What are the major differences between foreign bonds and Eurobonds .pdf
What are the major differences between foreign bonds and Eurobonds .pdfWhat are the major differences between foreign bonds and Eurobonds .pdf
What are the major differences between foreign bonds and Eurobonds .pdf
 
What is meant by ecological fallacySolutionAnswerThe term .pdf
What is meant by ecological fallacySolutionAnswerThe term .pdfWhat is meant by ecological fallacySolutionAnswerThe term .pdf
What is meant by ecological fallacySolutionAnswerThe term .pdf
 
What are the two main branches of Non-Euclidean Geometry What is the.pdf
What are the two main branches of Non-Euclidean Geometry What is the.pdfWhat are the two main branches of Non-Euclidean Geometry What is the.pdf
What are the two main branches of Non-Euclidean Geometry What is the.pdf
 
By what transport method does oxygen enter the blood from the alveol.pdf
By what transport method does oxygen enter the blood from the alveol.pdfBy what transport method does oxygen enter the blood from the alveol.pdf
By what transport method does oxygen enter the blood from the alveol.pdf
 
All of these are examples of evidence used to support the hypothesis.pdf
All of these are examples of evidence used to support the hypothesis.pdfAll of these are examples of evidence used to support the hypothesis.pdf
All of these are examples of evidence used to support the hypothesis.pdf
 
A 28 year-old biologist makes a trip to study life forms in a distan.pdf
A 28 year-old biologist makes a trip to study life forms in a distan.pdfA 28 year-old biologist makes a trip to study life forms in a distan.pdf
A 28 year-old biologist makes a trip to study life forms in a distan.pdf
 
4. Name the following compounds CO2 CH CH3 CH20H CH3COOH 5. Water ha.pdf
4. Name the following compounds CO2 CH CH3 CH20H CH3COOH 5. Water ha.pdf4. Name the following compounds CO2 CH CH3 CH20H CH3COOH 5. Water ha.pdf
4. Name the following compounds CO2 CH CH3 CH20H CH3COOH 5. Water ha.pdf
 
4. When examining whether group differences occur on more than one d.pdf
4. When examining whether group differences occur on more than one d.pdf4. When examining whether group differences occur on more than one d.pdf
4. When examining whether group differences occur on more than one d.pdf
 

Recently uploaded

Recently uploaded (20)

PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptx
 
Scopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsScopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS Publications
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Climbers and Creepers used in landscaping
Climbers and Creepers used in landscapingClimbers and Creepers used in landscaping
Climbers and Creepers used in landscaping
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 

i need help to edit the two methods below so that i can have them wo.pdf

  • 1. 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:BlueCros Solution 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 visits; public Patient() { } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name;
  • 2. } 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() {
  • 3. 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();
  • 4. 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 getVisits() { return visits; } public void setVisits(ArrayList visits) { this.visits = visits; } public static Patient getAllDetails(String pid) { // connect and get all details of the given patient Connection con= null; try{
  • 5. 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 visits = new ArrayList(); 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) {
  • 6. 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;
  • 7. } finally { Database.close(con); } } // getDetails() public static ArrayList 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 pl = new ArrayList(); 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"));
  • 8. 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 drugs; private ArrayList tests; public Visit() {} public Visit( String vid, String pid, String complaint, String visitdate) { this.setVid(vid); this.pid = pid; this.complaint = complaint;
  • 9. this.visitdate = visitdate; drugs = new ArrayList(); tests = new ArrayList(); } 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 getDrugs() { return drugs; } public void setDrugs(ArrayList drugs) { this.drugs = drugs; } public ArrayList getTests() { return tests; } public void setTests(ArrayList tests) { this.tests = tests; } public String getVid() { return vid;
  • 10. } 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");
  • 11. 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()
  • 12. 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()
  • 13. 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 drugs = new ArrayList(); 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 tests = new ArrayList(); while ( rs.next()) { tests.add(new Test(vid, rs.getString("testname"), rs.getString("testdate"),
  • 14. 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 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 tests = new ArrayList(); while ( rs.next()) { tests.add(new Test(vid, rs.getString("testname"), rs.getString("testdate"), rs.getString("result"))); } rs.close(); return tests; } // end of try
  • 15. catch(Exception ex) { System.out.println(ex.getMessage()); return null; } finally { Database.close(con); } } // getAllDetails() } New Patient <%@include file="head.html"%> New PatientPatient Name : Date of birth : (dd-mon-yyyy) Gender :Male Female Contact No. :Complaints : Refered By : <%@include file="footer.html"%>