Question

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

public void insert(String pCode, String pName,String pDesc, double c){
    setProcCode(pCode);
    setProcName(pName);
    setProcDesc(pDesc);
    setCost(c);

    try {
        FileWriter ff=new FileWriter("Procedures.txt",true);
        BufferedWriter b=new BufferedWriter(ff);
        PrintWriter pp=new PrintWriter(b);
        pp.println(pCode+":"+pName+":"+pDesc+":"+c);
        pp.close();
    }
    catch(Exception ep){
        ep.printStackTrace();
    }
}
public void select(String pCode){

    try{
        FileReader ff=new FileReader("Procedures.txt");
        BufferedReader b=new BufferedReader(ff);
        String ll;
        StringTokenizer tt;

        while((ll=b.readLine())!=null){
            tt=new StringTokenizer(ll,":");
            String proCode=tt.nextToken();
            if(proCode.equalsIgnoreCase(pCode)) {
                procCode=proCode;
                procName=tt.nextToken();
                procDesc=tt.nextToken();
                cost = Double.parseDouble(tt.nextToken());
                break;
            }
        }
        b.close();
    }
    catch(Exception ep){
        ep.printStackTrace();
    }
}

Patient class below

public class Patient extends Person {

    /** Properties **/
    private String patId;
    private String passwd;
    private String addr;
    private String insCo;
    private Appointment appoint;

    /** Constructors **/
    public Patient(){
        super();
        setPatId("");
        setPasswd("");
        setAddr("");
        setInsCo("");
        appoint = new Appointment();
    }
    public Patient(String fn, String ln, String em, String pid,
                   String pass, String ad, String ico, Appointment ap){
        super(fn, ln, em);
        setPatId(pid);
        setPasswd(pass);
        setAddr(ad);
        setInsCo(ico);
        appoint = ap;
    }

    /** Behaviors **/
    public void setPatId(String pId){ patId = pId; }
    public String getPatId(){ return patId; }
    public void setPasswd(String pw){ passwd = pw; }
    public String getPasswd(){ return passwd; }
    public void setAddr(String a){ addr = a; }
    public String getAddr(){ return addr; }
    public void setInsCo(String ic){ insCo = ic; }
    public String getInsCo(){ return insCo; }

    public String toString(){
        return super.toString() + "Patient ID:\t" + getPatId() +
                "\nPassword:\t" + getPasswd() +
                "\nAddress:\t" + getAddr() +
                "\nInsurance Company: " + getInsCo() +
                "\n" + appoint.toString();
    }

    public static void main(String[] args){
        Appointment a1;
        a1 = new Appointment("Dec 1, 2013, 9am","A900","D201","P321");
        Patient p1;
        p1 = new Patient("Bill","Smith","[email protected]",
                "A901","9999","Acworth","Aetna",a1);
        System.out.println(p1.toString());
    }
}

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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>

Add a comment
Know the answer?
Add Answer to:
i need help to edit the two methods below so that i can have them work...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help with this code This is what I need to do: Implement the Stack...

    I need help with this code This is what I need to do: Implement the Stack Class with an ArrayList instead of an array, including the following functions: • empty • push • peek • pop • overrided toString( ) function which returns all of the stack’s contents Things to note: • You no longer need a size. • You no longer need to define a constant DEFAULT_CAPACITY. Since ArrayLists grow dynamically. • Whenever possible, use ArrayList functions instead of...

  • I have Majority of the code written but I just need to implement the <,>,and =...

    I have Majority of the code written but I just need to implement the <,>,and = sign in the code. I have posted the instructions for the whole code. I will add what I have at the end. Objectives: Implement basic class concepts in Java Implement inheritance with super and sub-classes Implement basic polymorphism concepts Problem: The TARDIS has been infected by a virus which means it is up to Doctor Who to manually enter calculations into the TARDIS interface....

  • Hello! I have a problem in my code please I need help, I don't know How I can wright precondition, so I need help about assertion of pre_condition of peek. Java OOP Task is! Improve the circular a...

    Hello! I have a problem in my code please I need help, I don't know How I can wright precondition, so I need help about assertion of pre_condition of peek. Java OOP Task is! Improve the circular array implementation of the bounded queue by growing the elements array when the queue is full. Add assertions to check all preconditions of the methods of the bounded queue implementation. My code is! public class MessageQueue{ public MessageQueue(int capacity){ elements = new Message[capacity];...

  • Can someone help me to figure that error I have put below. JAVA ----jGRASP exec: javac...

    Can someone help me to figure that error I have put below. JAVA ----jGRASP exec: javac -g P4Program.java P4Program.java:94: error: package list does not exist Iterator i = new list.iterator(); ^ 1 error ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete. Note: Below there are two different classes that work together. Each class has it's own fuctions/methods. import java.util.*; import java.io.*; public class P4Program{ public void linkedStackFromFile(){ String content = new String(); int count = 1; File...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

  • Can you help me make these two methods listed below work? I have code written but...

    Can you help me make these two methods listed below work? I have code written but it is not working. I would appreciate any advice or help. Function "isAPalidrome" accepts an array of characters and returns an integer. You must use pointer operations only, no arrays. This function should return 1 (true) if the parameter 'string' is a palindrome, or 0 (false) if 'string' is not a palindrome. A palindrome is a sequence of characters which when reversed, is the...

  • Hi. Could you help me with the code below? I need to validate the code below, using expressions that can carry out the actions or that make appropriate changes to the program’s state, using conditiona...

    Hi. Could you help me with the code below? I need to validate the code below, using expressions that can carry out the actions or that make appropriate changes to the program’s state, using conditional and iterative control structures that repeat actions as needed. The unit measurement is missing from the final output and I need it to offer options to lbs, oz, grams, tbsp, tsp, qt, pt, and gal. & fl. oz. Can this be added? The final output...

  • The following are screen grabs of the provided files Thanks so much for your help, and have a n...

    The following are screen grabs of the provided files Thanks so much for your help, and have a nice day! My Java Programming Teacher Gave me this for practice before the exam, butI can't get it to work, and I need a working version to discuss with my teacher ASAP, and I would like to sleep at some point before the exam. Please Help TEST QUESTION 5: Tamagotchi For this question, you will write a number of classes that you...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT