Advertisement
Guest User

Untitled

a guest
May 14th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.52 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package atfali;
  7.  
  8. //import static com.sun.org.apache.xalan.internal.lib.ExsltDatetime.date;
  9. import java.io.File;
  10. import java.io.FileInputStream;
  11. import java.io.FileNotFoundException;
  12. import java.io.InputStream;
  13. import java.sql.Blob;
  14. import java.sql.Connection;
  15. import java.sql.DriverManager;
  16. import java.sql.PreparedStatement;
  17. import java.sql.ResultSet;
  18. import java.sql.SQLException;
  19. import java.sql.Statement;
  20. import java.text.ParseException;
  21. import java.text.SimpleDateFormat;
  22. import java.util.ArrayList;
  23. import java.util.Date;
  24. import java.util.logging.Level;
  25. import java.util.logging.Logger;
  26. import javax.sql.rowset.serial.SerialBlob;
  27. import javax.swing.JOptionPane;
  28.  
  29. /**
  30. *
  31. * @author Farida Adham
  32. */
  33. public class Patient {
  34.  
  35. public int patientID;
  36. public String fname, lname, phone, parents, dReferred, notes;
  37. public boolean sex;
  38. public Date dob = new Date();
  39. public Date admissionDate = new Date();
  40. public long months, years;
  41. public Blob photo, pedegree;
  42. public String extraNotes;
  43.  
  44.  
  45. public void setExtraNotes(String extraNotes) {
  46. this.extraNotes = extraNotes;
  47. }
  48.  
  49. public boolean isSex() {
  50. return sex;
  51. }
  52.  
  53. public String getExtraNotes() {
  54. return extraNotes;
  55. }
  56.  
  57. public void setPedegree(Blob pedegree) {
  58. this.pedegree = pedegree;
  59. }
  60.  
  61. public int getPatientID() {
  62. return patientID;
  63. }
  64.  
  65. public String getFname() {
  66. return fname;
  67. }
  68.  
  69. public String getLname() {
  70. return lname;
  71. }
  72.  
  73. public boolean getSex() {
  74. return sex;
  75. }
  76.  
  77. public String getPhone() {
  78. return phone;
  79. }
  80.  
  81. public String getParents() {
  82. return parents;
  83. }
  84.  
  85. public String getdReferred() {
  86. return dReferred;
  87. }
  88.  
  89. public Date getDob() {
  90. return dob;
  91. }
  92.  
  93. public Date getAdmissionDate() {
  94. return admissionDate;
  95. }
  96.  
  97. public Blob getPedegree() {
  98. return pedegree;
  99. }
  100.  
  101. public String getNotes() {
  102. return notes;
  103. }
  104.  
  105. public long getMonths() {
  106. return months;
  107. }
  108.  
  109. public long getYears() {
  110. return years;
  111. }
  112.  
  113. public Blob getPhoto() {
  114. return photo;
  115. }
  116.  
  117. public void setPatientID(int patientID) {
  118. this.patientID = patientID;
  119. }
  120.  
  121. public void setFname(String fname) {
  122. this.fname = fname;
  123. }
  124.  
  125. public void setLname(String lname) {
  126. this.lname = lname;
  127. }
  128.  
  129. public void setSex(boolean sex) {
  130. this.sex = sex;
  131. }
  132.  
  133. public void setPhone(String phone) {
  134. this.phone = phone;
  135. }
  136.  
  137. public void setParents(String parents) {
  138. this.parents = parents;
  139. }
  140.  
  141. public void setdReferred(String dReferred) {
  142. this.dReferred = dReferred;
  143. }
  144.  
  145. public void setNotes(String notes) {
  146. this.notes = notes;
  147. }
  148.  
  149. public void setMonths(long months) {
  150. this.months = months;
  151. }
  152.  
  153. public void setYears(long years) {
  154. this.years = years;
  155. }
  156.  
  157. public void setPhoto(Blob photo) {
  158. this.photo = photo;
  159. }
  160.  
  161. public void setDob(Date dob) {
  162. this.dob = dob;
  163. }
  164.  
  165. public void setAdmissionDate(Date admissionDate) {
  166. this.admissionDate = admissionDate;
  167. }
  168.  
  169. public void addPatient(Patient patient , ArrayList diagnosis) throws FileNotFoundException, ParseException {
  170. int no_of_rows = 0;
  171.  
  172. try {
  173. Connection con = DriverManager.getConnection(
  174. "jdbc:derby://localhost:1527/Atfali", "root", "root");
  175. Statement stmt = con.createStatement();
  176. ResultSet rs = stmt.executeQuery("SELECT * FROM patients");
  177. while (rs.next()) {
  178. no_of_rows++;
  179. }
  180. System.out.println("There are " + no_of_rows + " record in the table");
  181.  
  182. Statement stmt2 = con.createStatement();
  183. InputStream is = new FileInputStream(new File(Home.s));
  184. InputStream is1 = new FileInputStream(new File(Home.s1));
  185.  
  186. PreparedStatement addnew = con.prepareStatement("INSERT INTO PATIENTS(PATIENTID, FNAME, LNAME, DOB, YEARS, MONTHS, SEX, PHONE, PARENTS,"
  187. + "DREFERRED, ADMISSIONDATE, NOTES, PEDEGREE, PHOTO) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
  188.  
  189. SimpleDateFormat parser = new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy");
  190. Date datedob = null;
  191. Date dateadmission = null;
  192. try {
  193. datedob = parser.parse(patient.getDob().toString());
  194. } catch (ParseException ex) {
  195. Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
  196. }
  197. try {
  198. dateadmission = parser.parse(patient.getAdmissionDate().toString());
  199. } catch (ParseException ex) {
  200. Logger.getLogger(Home.class.getName()).log(Level.SEVERE, null, ex);
  201. }
  202. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
  203. String dob = formatter.format(datedob);
  204. Date date = formatter.parse(dob);
  205. String admission = formatter.format(dateadmission);
  206. Date admissiondate = formatter.parse(admission);
  207.  
  208. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
  209. Date parsed = format.parse(dob);
  210. java.sql.Date sqldob = new java.sql.Date(parsed.getTime());
  211. Date parsed1 = format.parse(admission);
  212. java.sql.Date sqladmission = new java.sql.Date(parsed.getTime());
  213.  
  214. addnew.setInt(1, (no_of_rows + 1));
  215. addnew.setString(2, patient.getFname());
  216. addnew.setString(3, patient.getLname());
  217. addnew.setDate(4, sqldob);
  218. addnew.setInt(5, (int) patient.getYears());
  219. addnew.setInt(6, (int) patient.getMonths());
  220. addnew.setBoolean(7, patient.getSex());
  221. addnew.setString(8, patient.getPhone());
  222. addnew.setString(9, patient.getParents());
  223. addnew.setString(10, patient.getdReferred());
  224. addnew.setDate(11, sqladmission);
  225. addnew.setString(12, patient.getNotes());
  226. addnew.setBlob(13, is1);
  227. addnew.setBlob(14, is);
  228. System.out.println(addnew);
  229. addnew.executeUpdate();
  230. DiagnosedPatient dp = new DiagnosedPatient();
  231. dp.addDiagnosedPatient((no_of_rows + 1), diagnosis);
  232. Home.openedPatient.setPatientID((no_of_rows + 1));
  233. //JOptionPane.showMessageDialog(null, "Data inserted", "mabroook", JOptionPane.INFORMATION_MESSAGE);
  234. } catch (SQLException e) {
  235. System.out.println("SQL exception occured" + e);
  236. }
  237. }
  238.  
  239.  
  240. public void addNotes(String ExtraNotes){
  241. //int patientID = Admin.patientID;
  242. int patientID = Home.openedPatient.getPatientID();
  243. try{
  244. Connection con = DriverManager.getConnection(
  245. "jdbc:derby://localhost:1527/Atfali", "root", "root");
  246. Statement stmt = con.createStatement();
  247. PreparedStatement addExtraNotes = con.prepareStatement("INSERT INTO NOTES(PATIENTID, EXTRANOTES) VALUES (?,?)");
  248. addExtraNotes.setInt(1, patientID);
  249. addExtraNotes.setString(2, ExtraNotes);
  250. addExtraNotes.executeUpdate();
  251.  
  252. }catch(SQLException e){
  253. System.out.println("SQL exception occured" + e);
  254. }
  255. }
  256.  
  257. public void addResults(String path,int id) throws FileNotFoundException{
  258. int patientID = Home.openedPatient.getPatientID();
  259. try{
  260. Connection con = DriverManager.getConnection(
  261. "jdbc:derby://localhost:1527/Atfali", "root", "root");
  262. Statement stmt = con.createStatement();
  263. if(id == 1){
  264. PreparedStatement addphoto = con.prepareStatement("INSERT INTO TESTRESULTS(PATIENTID, PHOTO1) VALUES (?,?)");
  265. InputStream is = new FileInputStream(new File(path));
  266. addphoto.setInt(1, patientID);
  267. addphoto.setBlob(2, is);
  268. }
  269.  
  270.  
  271. }catch(SQLException e){
  272. System.out.println("SQL exception occured" + e);
  273. }
  274. }
  275.  
  276. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement