Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package atfali;
- //import static com.sun.org.apache.xalan.internal.lib.ExsltDatetime.date;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.InputStream;
- import java.sql.Blob;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.sql.rowset.serial.SerialBlob;
- import javax.swing.JOptionPane;
- /**
- *
- * @author Farida Adham
- */
- public class Patient {
- public int patientID;
- public String fname, lname, phone, parents, dReferred, notes;
- public boolean sex;
- public Date dob = new Date();
- public Date admissionDate = new Date();
- public long months, years;
- public Blob photo, pedegree;
- public String extraNotes;
- public void setExtraNotes(String extraNotes) {
- this.extraNotes = extraNotes;
- }
- public boolean isSex() {
- return sex;
- }
- public String getExtraNotes() {
- return extraNotes;
- }
- public void setPedegree(Blob pedegree) {
- this.pedegree = pedegree;
- }
- public int getPatientID() {
- return patientID;
- }
- public String getFname() {
- return fname;
- }
- public String getLname() {
- return lname;
- }
- public boolean getSex() {
- return sex;
- }
- public String getPhone() {
- return phone;
- }
- public String getParents() {
- return parents;
- }
- public String getdReferred() {
- return dReferred;
- }
- public Date getDob() {
- return dob;
- }
- public Date getAdmissionDate() {
- return admissionDate;
- }
- public Blob getPedegree() {
- return pedegree;
- }
- public String getNotes() {
- return notes;
- }
- public long getMonths() {
- return months;
- }
- public long getYears() {
- return years;
- }
- public Blob getPhoto() {
- return photo;
- }
- public void setPatientID(int patientID) {
- this.patientID = patientID;
- }
- public void setFname(String fname) {
- this.fname = fname;
- }
- public void setLname(String lname) {
- this.lname = lname;
- }
- public void setSex(boolean sex) {
- this.sex = sex;
- }
- public void setPhone(String phone) {
- this.phone = phone;
- }
- public void setParents(String parents) {
- this.parents = parents;
- }
- public void setdReferred(String dReferred) {
- this.dReferred = dReferred;
- }
- public void setNotes(String notes) {
- this.notes = notes;
- }
- public void setMonths(long months) {
- this.months = months;
- }
- public void setYears(long years) {
- this.years = years;
- }
- public void setPhoto(Blob photo) {
- this.photo = photo;
- }
- public void setDob(Date dob) {
- this.dob = dob;
- }
- public void setAdmissionDate(Date admissionDate) {
- this.admissionDate = admissionDate;
- }
- public void addPatient(Patient patient , ArrayList diagnosis) throws FileNotFoundException, ParseException {
- int no_of_rows = 0;
- try {
- Connection con = DriverManager.getConnection(
- "jdbc:derby://localhost:1527/Atfali", "root", "root");
- Statement stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery("SELECT * FROM patients");
- while (rs.next()) {
- no_of_rows++;
- }
- System.out.println("There are " + no_of_rows + " record in the table");
- Statement stmt2 = con.createStatement();
- InputStream is = new FileInputStream(new File(Home.s));
- InputStream is1 = new FileInputStream(new File(Home.s1));
- PreparedStatement addnew = con.prepareStatement("INSERT INTO PATIENTS(PATIENTID, FNAME, LNAME, DOB, YEARS, MONTHS, SEX, PHONE, PARENTS,"
- + "DREFERRED, ADMISSIONDATE, NOTES, PEDEGREE, PHOTO) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
- SimpleDateFormat parser = new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy");
- Date datedob = null;
- Date dateadmission = null;
- try {
- datedob = parser.parse(patient.getDob().toString());
- } catch (ParseException ex) {
- Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
- }
- try {
- dateadmission = parser.parse(patient.getAdmissionDate().toString());
- } catch (ParseException ex) {
- Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
- }
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
- String dob = formatter.format(datedob);
- Date date = formatter.parse(dob);
- String admission = formatter.format(dateadmission);
- Date admissiondate = formatter.parse(admission);
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
- Date parsed = format.parse(dob);
- java.sql.Date sqldob = new java.sql.Date(parsed.getTime());
- Date parsed1 = format.parse(admission);
- java.sql.Date sqladmission = new java.sql.Date(parsed.getTime());
- addnew.setInt(1, (no_of_rows + 1));
- addnew.setString(2, patient.getFname());
- addnew.setString(3, patient.getLname());
- addnew.setDate(4, sqldob);
- addnew.setInt(5, (int) patient.getYears());
- addnew.setInt(6, (int) patient.getMonths());
- addnew.setBoolean(7, patient.getSex());
- addnew.setString(8, patient.getPhone());
- addnew.setString(9, patient.getParents());
- addnew.setString(10, patient.getdReferred());
- addnew.setDate(11, sqladmission);
- addnew.setString(12, patient.getNotes());
- addnew.setBlob(13, is1);
- addnew.setBlob(14, is);
- System.out.println(addnew);
- addnew.executeUpdate();
- DiagnosedPatient dp = new DiagnosedPatient();
- dp.addDiagnosedPatient((no_of_rows + 1), diagnosis);
- Home.openedPatient.setPatientID((no_of_rows + 1));
- //JOptionPane.showMessageDialog(null, "Data inserted", "mabroook", JOptionPane.INFORMATION_MESSAGE);
- } catch (SQLException e) {
- System.out.println("SQL exception occured" + e);
- }
- }
- public void addNotes(String ExtraNotes){
- //int patientID = Admin.patientID;
- int patientID = Home.openedPatient.getPatientID();
- try{
- Connection con = DriverManager.getConnection(
- "jdbc:derby://localhost:1527/Atfali", "root", "root");
- Statement stmt = con.createStatement();
- PreparedStatement addExtraNotes = con.prepareStatement("INSERT INTO NOTES(PATIENTID, EXTRANOTES) VALUES (?,?)");
- addExtraNotes.setInt(1, patientID);
- addExtraNotes.setString(2, ExtraNotes);
- addExtraNotes.executeUpdate();
- }catch(SQLException e){
- System.out.println("SQL exception occured" + e);
- }
- }
- public void addResults(String path,int id) throws FileNotFoundException{
- int patientID = Home.openedPatient.getPatientID();
- try{
- Connection con = DriverManager.getConnection(
- "jdbc:derby://localhost:1527/Atfali", "root", "root");
- Statement stmt = con.createStatement();
- if(id == 1){
- PreparedStatement addphoto = con.prepareStatement("INSERT INTO TESTRESULTS(PATIENTID, PHOTO1) VALUES (?,?)");
- InputStream is = new FileInputStream(new File(path));
- addphoto.setInt(1, patientID);
- addphoto.setBlob(2, is);
- }
- }catch(SQLException e){
- System.out.println("SQL exception occured" + e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement