Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

PatientEditor Class Reference

Inheritance diagram for PatientEditor:

Widget List of all members.

Public Member Functions

 PatientEditor (int patient_id, String prefix, Form form)
void loadValues ()
void loadDefaults ()
void display (boolean hidden)

Public Attributes

int patient_id
PolicySelect policy
TextBox name
TextBox address
TextBox phone
ActionButton action
boolean done = false

Static Public Attributes

static final int SAVE = 1
static final int CANCEL = 2

Protected Member Functions

boolean save ()

Detailed Description

Definition at line 4 of file PatientEditor.java.


Constructor & Destructor Documentation

PatientEditor::PatientEditor int  patient_id,
String  prefix,
Form  form
[inline]
 

Definition at line 18 of file PatientEditor.java.

References action, Widget::addChild(), address, Widget::n(), name, phone, and policy.

00019         {
00020           super(prefix, form);
00021           this.patient_id = patient_id;
00022     action = new ActionButton(n("action"), form);
00023     name = new TextBox(0,20,n("name"), form);
00024     phone = new TextBox(0,20,n("phone"), form);
00025     address = new TextBox(2,20,n("address"), form);
00026     policy = new PolicySelect(n("policy"), form);
00027     addChild(action);
00028     addChild(name);
00029     addChild(phone);
00030     addChild(address);
00031     addChild(policy);
00032         }


Member Function Documentation

void PatientEditor::display boolean  hidden  )  [inline]
 

Reimplemented from Widget.

Definition at line 126 of file PatientEditor.java.

References action, address, CANCEL, ActionButton::display(), PolicySelect::display(), TextBox::display(), Widget::modalChild, name, Widget::p(), phone, policy, and SAVE.

00127         {
00128     super.display(hidden);
00129     
00130     if (hidden || modalChild != null) return;
00131     
00132     p(
00133 "<table>\n"+
00134 "<tr>\n"+
00135 "  <td valign=top>Name:</td>\n"+
00136 "  <td>"); name.display(); p("</td>\n"+
00137 "</tr>\n"+
00138 "<tr>\n"+
00139 "  <td valign=top>Phone:</td>\n"+
00140 "  <td>"); phone.display(); p("</td>\n"+
00141 "</tr>\n"+
00142 "<tr>\n"+
00143 "  <td valign=top>Address:</td>\n"+
00144 "  <td>"); address.display(); p("</td>\n"+
00145 "</tr>\n"+
00146 "<tr>\n"+
00147 "  <td valign=top>Insurance Policy:</td>\n"+
00148 "  <td>"); policy.display(); p("</td>\n"+
00149 "</tr>\n"+
00150 "<tr>\n"+
00151 "  <td>&nbsp;</td>\n"+
00152 "  <td>\n"+
00153 "  "); action.display("Save Changes", SAVE); action.display("Cancel", CANCEL); 
00154 p("\n"+
00155 "  </td>\n"+
00156 "</td>\n"+
00157 "</table>\n"+
00158 "");
00159         }

void PatientEditor::loadDefaults  )  [inline]
 

Reimplemented from Widget.

Definition at line 48 of file PatientEditor.java.

References address, Query::close(), Form::connectDb(), Widget::form, SelectBox::id, name, Widget::p(), patient_id, phone, policy, Form::pw, Query::query(), Query::r, and TextBox::text.

00049         {
00050           super.loadDefaults();
00051           Query q = new Query(form.connectDb(), form.pw);
00052           try
00053           {
00054             q.query("SELECT name, phone, address, insurance_policy_id FROM patients WHERE patient_id = " + patient_id);
00055             if (q.r == null || !q.r.next()) return;
00056       name.text = q.r.getString(1);
00057       phone.text = q.r.getString(2);
00058       address.text = q.r.getString(3);
00059       policy.id = new Integer(q.r.getInt(4));
00060           }
00061           catch (SQLException e)
00062           {
00063             p(e);
00064           }
00065           finally
00066           {
00067             q.close();
00068           }
00069         }

void PatientEditor::loadValues  )  [inline]
 

Reimplemented from Widget.

Definition at line 34 of file PatientEditor.java.

References ActionButton::action, action, CANCEL, done, save(), and SAVE.

00035         {
00036     super.loadValues();
00037     
00038     if (action.action == SAVE)
00039     {
00040       if (save()) done = true;
00041     }
00042     else if (action.action == CANCEL)
00043     {
00044       done = true;
00045     }
00046         }

boolean PatientEditor::save  )  [inline, protected]
 

Definition at line 71 of file PatientEditor.java.

References address, Query::close(), Form::conn, Form::connectDb(), Widget::form, SelectBox::id, name, Widget::p(), patient_id, phone, policy, Form::pw, Query::query(), Query::r, and TextBox::text.

00072         {
00073           form.connectDb();
00074           Query q = new Query(form.conn, form.pw);
00075           try
00076           {
00077             PreparedStatement s;
00078             if (patient_id > 0)
00079             {
00080               s = form.conn.prepareStatement("\n"+
00081 "               UPDATE patients SET name = ?, phone = ?, \n"+
00082 "                 address = ?, insurance_policy_id = ?\n"+
00083 "               WHERE patient_id = " + patient_id);
00084             }
00085             else
00086             {
00087               s = form.conn.prepareStatement("\n"+
00088 "               INSERT INTO patients (name, phone, address, insurance_policy_id)\n"+
00089 "               VALUES (?,?,?,?)");
00090             }
00091             try
00092             {
00093               s.setString(1, name.text);
00094               s.setString(2, phone.text);
00095               s.setString(3, address.text);
00096               s.setInt(4, policy.id.intValue());
00097               s.executeUpdate();
00098             }
00099             finally
00100             {
00101               s.close();
00102             }
00103             
00104             if (patient_id <= 0)
00105             {
00106               q.query("SELECT currval('patients_patient_id_seq')");
00107               if (q != null && !q.r.next())
00108                 patient_id = q.r.getInt(1);
00109             }
00110           }
00111           catch (SQLException e)
00112           {
00113             p(e);
00114           }
00115           catch (Throwable e)
00116           {
00117             Query.rethrow(e);
00118           }
00119           finally
00120           {
00121             q.close();
00122           }
00123           return true;
00124         }


Member Data Documentation

ActionButton PatientEditor::action
 

Definition at line 15 of file PatientEditor.java.

TextBox PatientEditor::address
 

Definition at line 12 of file PatientEditor.java.

final int PatientEditor::CANCEL = 2 [static]
 

Definition at line 7 of file PatientEditor.java.

boolean PatientEditor::done = false
 

Definition at line 16 of file PatientEditor.java.

TextBox PatientEditor::name
 

Reimplemented from Widget.

Definition at line 11 of file PatientEditor.java.

int PatientEditor::patient_id
 

Definition at line 9 of file PatientEditor.java.

TextBox PatientEditor::phone
 

Definition at line 13 of file PatientEditor.java.

PolicySelect PatientEditor::policy
 

Definition at line 10 of file PatientEditor.java.

final int PatientEditor::SAVE = 1 [static]
 

Definition at line 6 of file PatientEditor.java.


The documentation for this class was generated from the following file:
Generated on Mon Mar 6 23:34:35 2006 by  doxygen 1.4.4