00001 import java.sql.SQLException; 00002 00003 public class AppointmentList extends Widget 00004 { 00005 public ActionButton action; 00006 public AppointmentEditor editor; 00007 public int appointment_id = 0; 00008 00009 public static final int EDIT = 1; 00010 public static final int DELETE = 2; 00011 00012 public AppointmentList(String prefix, Form form) 00013 { 00014 super(prefix, form); 00015 action = new ActionButton(n("action"), form); 00016 addChild(action); 00017 } 00018 00019 public void loadValues() 00020 { 00021 super.loadValues(); 00022 00023 int a = toInt(loadAttribute("appointment_id"),0); 00024 boolean editing = a != 0; 00025 00026 for(;;) 00027 if (editing) 00028 { 00029 if (a != 0) appointment_id = a; 00030 editor = new AppointmentEditor(appointment_id, n("editor"), form); 00031 addChild(editor); 00032 if (a != 0) editor.loadValues(); else editor.loadDefaults(); 00033 if (editor.done) 00034 appointment_id = 0; 00035 else 00036 { 00037 modalChild = editor; 00038 editor.modal = true; 00039 } 00040 return; 00041 } 00042 else 00043 { 00044 switch (action.action) 00045 { 00046 case EDIT: 00047 editing = true; 00048 appointment_id = action.param; 00049 break; 00050 case DELETE: 00051 deleteAppointment(action.param); 00052 return; 00053 default: 00054 return; 00055 } 00056 } 00057 } 00058 00059 public void deleteAppointment(int id) 00060 { 00061 Query q = new Query(form.connectDb(), form.pw); 00062 try 00063 { 00064 String where = " WHERE appointment_id = " + id + ";\n"; 00065 q.execute( 00066 "DELETE FROM appointment_services" + where + 00067 "DELETE FROM diagnoses" + where + 00068 "DELETE FROM referrals" + where + 00069 "DELETE FROM appointments" + where 00070 ); 00071 } 00072 finally 00073 { 00074 q.close(); 00075 } 00076 } 00077 00078 public void display(boolean hidden) 00079 { 00080 super.display(hidden); 00081 00082 printAttribute("appointment_id", "" + appointment_id); 00083 00084 if (hidden || modalChild != null) return; 00085 00086 p("<p align=center>"); 00087 action.display("Create new appointment...", EDIT, -1); 00088 p("</p>"); 00089 00090 Query q = new Query(form.connectDb(), form.pw); 00091 try 00092 { 00093 q.query("\n"+ 00094 " SELECT to_char(a.begintime, 'DD Mon YYYY HH:MI AM'), \n"+ 00095 " to_char(a.endtime, 'DD Mon YYYY HH:MI AM'), d.name, p.name,\n"+ 00096 " a.appointment_id\n"+ 00097 " FROM appointments AS a\n"+ 00098 " INNER JOIN doctors AS d USING (doctor_id)\n"+ 00099 " INNER JOIN patients AS p USING (patient_id)\n"+ 00100 " ORDER BY a.begintime, a.endtime\n"+ 00101 " "); 00102 00103 if (q.r != null) 00104 { 00105 p("<table border=1>\n"); 00106 p("<tr><td>Begin Time</td><td>End Time</td><td>Patient</td><td>Doctor</td><td> </td></tr>\n"); 00107 while(q.r.next()) 00108 { 00109 p("<tr><td>" + q.r.getString(1) + "</td><td>" + q.r.getString(2) 00110 + "</td><td>" + q.r.getString(3) + "</td><td>" + q.r.getString(4) 00111 + "</td><td>"); 00112 00113 int id = q.r.getInt(5); 00114 00115 action.display("Edit", EDIT, id); 00116 action.display("Delete", DELETE, id); 00117 00118 p("</td></tr>\n"); 00119 } 00120 p("</table>\n"); 00121 } 00122 } 00123 catch(SQLException e) 00124 { 00125 p(e); 00126 } 00127 finally 00128 { 00129 q.close(); 00130 } 00131 } 00132 };