001 package com.bea.medrec.webservices.swing;
002
003 import com.bea.medrec.value.Address;
004 import com.bea.medrec.value.Patient;
005 import com.bea.medrec.webservices.*;
006 import java.awt.*;
007 import java.awt.event.ActionEvent;
008 import java.util.Calendar;
009 import javax.swing.*;
010
011 /**
012 * <p>Edit Patient Profile JFrame. </p>
013 *
014 * @author Copyright (c) 2006 by BEA Systems. All Rights Reserved.
015 */
016 public class EditProfileFrame extends JFrame {
017 private JLabel promptLabel = new JLabel();
018 private JLabel WSDLLabel = new JLabel();
019 private JLabel firstName_label = new JLabel();
020 private JLabel lastName_label = new JLabel();
021 private JLabel middleName_label = new JLabel();
022 private JLabel gender_label = new JLabel();
023 private JLabel dateOfBirth_label = new JLabel();
024 private JLabel ssn_label = new JLabel();
025 private JLabel phone_label = new JLabel();
026 private JLabel email_label = new JLabel();
027 private JLabel address_label = new JLabel();
028
029 private JLabel streetName_label = new JLabel("Street Name");
030 private JLabel city_label = new JLabel("City");
031 private JLabel state_label = new JLabel("State");
032 private JLabel zipcode_label = new JLabel("ZipCode");
033 private JLabel country_label = new JLabel("Country");
034
035
036 private JTextField patientIDTextField = new JTextField(11);
037 private JButton submitButton = new JButton("Submit");
038 private JButton saveButton = new JButton("Save Changes");
039
040 private String wsdl = System.getProperty("wsdl.location");
041 private JTextField WSDLTextField = new JTextField();
042 private JTextField firstName_textfield = new JTextField(15);
043 private JTextField lastName_textfield = new JTextField(15);
044 private JTextField middleName_textfield = new JTextField(15);
045 private JTextField gender_textfield = new JTextField(6);
046 private JTextField dateOfBirth_textfield = new JTextField(9);
047 private JTextField ssn_textfield = new JTextField(9);
048 private JTextField phone_textfield = new JTextField(10);
049 private JTextField email_textfield = new JTextField(20);
050 private JTextField streetName1_textfield = new JTextField(20);
051 private JTextField streetName2_textfield = new JTextField(20);
052 private JTextField city_textfield = new JTextField(15);
053 private JTextField state_textfield = new JTextField(3);
054 private JTextField zipcode_textfield = new JTextField(10);
055 private JTextField country_textfield = new JTextField(15);
056
057 private int width = 675;
058 private int height = 450;
059 private Patient thePatient = null;
060
061 //Construct the frame
062 public EditProfileFrame() {
063 enableEvents(AWTEvent.WINDOW_EVENT_MASK);
064 try {
065 init();
066 this.setSize(width, height);
067 this.setLocation(150, 150);
068 this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
069 this.setDefaultLookAndFeelDecorated(true);
070 this.setVisible(true);
071 }
072 catch(Exception e) {
073 e.printStackTrace();
074 }
075 }
076
077 /**
078 * <p>Map patient data into the textfields</p>
079 */
080 private void mapPatientProfile() {
081 if (this.thePatient != null) {
082 firstName_textfield.setText(this.thePatient.getFirstName());
083 lastName_textfield.setText(this.thePatient.getLastName());
084 middleName_textfield.setText(this.thePatient.getMiddleName());
085 gender_textfield.setText(this.thePatient.getGender());
086 if (this.thePatient.getDateOfBirth() != null) {
087 dateOfBirth_textfield.setText(Utils.getDisplayDate(this.thePatient.getDateOfBirth()));
088 }
089 ssn_textfield.setText(this.thePatient.getSsn());
090 phone_textfield.setText(this.thePatient.getPhone());
091 email_textfield.setText(this.thePatient.getEmail());
092 if (this.thePatient.getAddress() != null) {
093 Address Address = this.thePatient.getAddress();
094 this.streetName1_textfield.setText(Address.getStreetName1());
095 this.streetName2_textfield.setText(Address.getStreetName2());
096 this.city_textfield.setText(Address.getCity());
097 this.state_textfield.setText(Address.getState());
098 this.zipcode_textfield.setText(Address.getZipCode());
099 this.country_textfield.setText(Address.getCountry());
100 }
101 }
102 }
103
104 /**
105 * <p>Address JPanel</p>
106 */
107 private JPanel constructAddressPanel() {
108 JPanel addressPanel = new JPanel();
109 GridBagLayout gridbag = new GridBagLayout();
110 addressPanel.setLayout(gridbag);
111 // addressPanel.setBackground(Color.orange);
112 GridBagConstraints constraints = new GridBagConstraints();
113 address_label.setText("Address");
114 constraints.gridy = 0;
115 constraints.gridx = 0;
116 constraints.anchor = constraints.NORTHWEST;
117 constraints.insets.bottom=10;
118 constraints.insets.right=10;
119 gridbag.setConstraints(address_label, constraints);
120 constraints.gridy = 1;
121 gridbag.setConstraints(this.streetName_label, constraints);
122 constraints.gridx = 1;
123 constraints.gridwidth = 3;
124 gridbag.setConstraints(this.streetName1_textfield, constraints);
125 constraints.gridy = 2;
126 gridbag.setConstraints(this.streetName2_textfield, constraints);
127 constraints.gridwidth = 1;
128 constraints.gridy = 3;
129 constraints.gridx = 0;
130 gridbag.setConstraints(this.city_label, constraints);
131 constraints.gridx = 1;
132 gridbag.setConstraints(this.city_textfield, constraints);
133 constraints.gridy = 4;
134 constraints.gridx = 0;
135 gridbag.setConstraints(this.state_label, constraints);
136 constraints.gridx = 1;
137 gridbag.setConstraints(this.state_textfield, constraints);
138 constraints.gridy = 5;
139 constraints.gridx = 0;
140 gridbag.setConstraints(this.zipcode_label, constraints);
141 constraints.gridx = 1;
142 gridbag.setConstraints(this.zipcode_textfield, constraints);
143 constraints.gridy = 6;
144 constraints.gridx = 0;
145 gridbag.setConstraints(this.country_label, constraints);
146 constraints.gridx = 1;
147 gridbag.setConstraints(this.country_textfield, constraints);
148
149 addressPanel.add(address_label);
150 addressPanel.add(this.streetName_label);
151 addressPanel.add(this.city_label);
152 addressPanel.add(this.state_label);
153 addressPanel.add(this.zipcode_label);
154 addressPanel.add(this.country_label);
155 addressPanel.add(this.streetName1_textfield);
156 addressPanel.add(this.streetName2_textfield);
157 addressPanel.add(this.city_textfield);
158 addressPanel.add(this.state_textfield);
159 addressPanel.add(this.zipcode_textfield);
160 addressPanel.add(this.country_textfield);
161 return addressPanel;
162 }
163
164 /**
165 * <p>Left patient panel</p>
166 */
167 private JPanel constructLeftPatientPanel() {
168 JPanel leftPatientPanel = new JPanel();
169 GridBagLayout gridbag = new GridBagLayout();
170 leftPatientPanel.setLayout(gridbag);
171 // leftPatientPanel.setBackground(Color.pink);
172 GridBagConstraints constraints = new GridBagConstraints();
173
174 firstName_label.setText("First Name");
175 lastName_label.setText("Last Name");
176 middleName_label.setText("Middle Name");
177 gender_label.setText("Gender");
178 dateOfBirth_label.setText("Date of Birth");
179 ssn_label.setText("Social Security");
180 phone_label.setText("Phone");
181 email_label.setText("Email");
182 constraints.anchor = constraints.NORTHWEST;
183 constraints.gridx = 0;
184 constraints.gridy = 0;
185 constraints.insets.bottom=10;
186 constraints.insets.right=10;
187
188 gridbag.setConstraints(firstName_label, constraints);
189 constraints.gridy = 1;
190 gridbag.setConstraints(lastName_label, constraints);
191 constraints.gridy = 2;
192 gridbag.setConstraints(middleName_label, constraints);
193 constraints.gridy = 3;
194 gridbag.setConstraints(gender_label, constraints);
195 constraints.gridy = 4;
196 gridbag.setConstraints(dateOfBirth_label, constraints);
197 constraints.gridy = 5;
198 gridbag.setConstraints(ssn_label, constraints);
199 constraints.gridy = 6;
200 gridbag.setConstraints(phone_label, constraints);
201 constraints.gridy = 7;
202 gridbag.setConstraints(email_label, constraints);
203 constraints.gridx = 1;
204 constraints.gridy = 0;
205 gridbag.setConstraints(firstName_textfield, constraints);
206 constraints.gridy = 1;
207 gridbag.setConstraints(lastName_textfield, constraints);
208 constraints.gridy = 2;
209 gridbag.setConstraints(middleName_textfield, constraints);
210 constraints.gridy = 3;
211 gridbag.setConstraints(gender_textfield, constraints);
212 constraints.gridy = 4;
213 gridbag.setConstraints(dateOfBirth_textfield, constraints);
214 constraints.gridy = 5;
215 ssn_textfield.setToolTipText("Social security number must be 9 digits");
216 gridbag.setConstraints(ssn_textfield, constraints);
217 constraints.gridy = 6;
218 gridbag.setConstraints(phone_textfield, constraints);
219 constraints.gridy = 7;
220 gridbag.setConstraints(email_textfield, constraints);
221
222 leftPatientPanel.add(firstName_label);
223 leftPatientPanel.add(lastName_label);
224 leftPatientPanel.add(middleName_label);
225 leftPatientPanel.add(gender_label);
226 leftPatientPanel.add(dateOfBirth_label);
227 leftPatientPanel.add(ssn_label);
228 leftPatientPanel.add(phone_label);
229 leftPatientPanel.add(email_label);
230 leftPatientPanel.add(firstName_textfield);
231 leftPatientPanel.add(lastName_textfield);
232 leftPatientPanel.add(middleName_textfield);
233 leftPatientPanel.add(gender_textfield);
234 leftPatientPanel.add(dateOfBirth_textfield);
235 leftPatientPanel.add(ssn_textfield);
236 leftPatientPanel.add(phone_textfield);
237 leftPatientPanel.add(email_textfield);
238
239 return leftPatientPanel;
240 }
241
242 /**
243 * <p>JPanel containing all the panels.</p>
244 */
245 private JPanel constructPatientProfile() {
246 JPanel patientProfile = new JPanel();
247 GridBagLayout gridbag = new GridBagLayout();
248 patientProfile.setLayout(gridbag);
249 // patientProfile.setBackground(Color.cyan);
250 GridBagConstraints constraints = new GridBagConstraints();
251 constraints.anchor = constraints.NORTH;
252 constraints.gridy = 3;
253
254 JPanel leftPatientPanel = this.constructLeftPatientPanel();
255 constraints.gridx = 0;
256 constraints.gridy = 0;
257 constraints.gridwidth = 3;
258 gridbag.setConstraints(leftPatientPanel, constraints);
259
260 JPanel addressPanel = this.constructAddressPanel();
261 constraints.gridy = 0;
262 constraints.gridx = 3;
263 constraints.gridwidth = 2;
264 gridbag.setConstraints(addressPanel, constraints);
265 patientProfile.add(leftPatientPanel);
266 patientProfile.add(addressPanel);
267
268 constraints.gridx = 4;
269 constraints.gridy = 11;
270 constraints.gridwidth = 1;
271 constraints.insets.top = 20;
272 gridbag.setConstraints(this.saveButton, constraints);
273 this.saveButton.setFont(new java.awt.Font("Dialog", 1, 12));
274 this.saveButton.setEnabled(false);
275
276 patientProfile.add(this.saveButton);
277
278 this.saveButton.addActionListener(new java.awt.event.ActionListener() {
279 public void actionPerformed(ActionEvent e) {
280 saveButton_actionPerformed(e);
281 }
282 });
283
284 return patientProfile;
285 }
286
287 /**
288 * <p>Search panel. Enter SSN.</p>
289 */
290 private JPanel constructSearchPanel() {
291 JPanel searchPanel = new JPanel();
292 GridBagLayout gridbag = new GridBagLayout();
293 searchPanel.setLayout(gridbag);
294 // searchPanel.setBackground(Color.green);
295 GridBagConstraints constraints = new GridBagConstraints();
296 constraints.anchor = constraints.WEST;
297
298 JPanel wsdlPanel = new JPanel();
299 wsdlPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
300 WSDLTextField.setText(wsdl);
301 WSDLTextField.setFont(new java.awt.Font("Dialog", 0, 10));
302 WSDLLabel.setFont(new java.awt.Font("Dialog", 0, 10));
303 WSDLLabel.setText("wsdl location");
304 wsdlPanel.add(this.WSDLLabel);
305 wsdlPanel.add(this.WSDLTextField);
306
307 constraints.gridx = 0;
308 constraints.gridy = 0;
309 constraints.gridwidth = 2;
310 gridbag.setConstraints(wsdlPanel, constraints);
311 searchPanel.add(wsdlPanel);
312
313
314 constraints.gridwidth = 1;
315 JPanel middlePanel = new JPanel();
316 // middlePanel.setBackground(Color.green);
317 GridBagLayout gridbag2 = new GridBagLayout();
318 middlePanel.setLayout(gridbag2);
319 promptLabel.setFont(new java.awt.Font("Dialog", 1, 14));
320 promptLabel.setText("Enter Patient SSN");
321 this.patientIDTextField.setColumns(9);
322 this.patientIDTextField.setFont(new java.awt.Font("Dialog", 1, 14));
323 constraints.insets.right = 10;
324 gridbag2.setConstraints(promptLabel, constraints);
325 constraints.gridx = 1;
326 gridbag2.setConstraints(patientIDTextField, constraints);
327 middlePanel.add(this.promptLabel);
328 middlePanel.add(this.patientIDTextField);
329
330 constraints.gridx = 0;
331 constraints.gridy = 1;
332 constraints.weighty = 1;
333 gridbag.setConstraints(middlePanel, constraints);
334 searchPanel.add(middlePanel);
335
336 JPanel bottomPanel = new JPanel();
337 bottomPanel.setLayout(new FlowLayout());
338 // bottomPanel.setBackground(Color.red);
339 submitButton.setFont(new java.awt.Font("Dialog", 1, 12));
340 submitButton.addActionListener(new java.awt.event.ActionListener() {
341 public void actionPerformed(ActionEvent e) {
342 submitButton_actionPerformed(e);
343 }
344 });
345 bottomPanel.add(this.submitButton);
346 constraints.gridx = 1;
347 gridbag.setConstraints(bottomPanel, constraints);
348 searchPanel.add(bottomPanel);
349 return searchPanel;
350 }
351
352 /**
353 * <p>Initialize contentPane</p>
354 */
355 private void init() {
356 this.setTitle("Medical Records Swing Client");
357 //this.patientIDTextField
358 Container contentPane = getContentPane();
359 JPanel medrecPane = new JPanel();
360 JPanel searchPanel = this.constructSearchPanel();
361 JPanel patientPanel = this.constructPatientProfile();
362
363 GridBagLayout gridbag = new GridBagLayout();
364 medrecPane.setLayout(gridbag);
365
366 GridBagConstraints constraints = new GridBagConstraints();
367 constraints.anchor = constraints.WEST;
368 constraints.gridx = 0;
369 constraints.gridy = 0;
370 gridbag.setConstraints(searchPanel, constraints);
371 constraints.gridy = 1;
372 constraints.insets.top = 20;
373 gridbag.setConstraints(patientPanel, constraints);
374
375 medrecPane.add(searchPanel);
376 medrecPane.add(patientPanel);
377 contentPane.add(medrecPane);
378 this.patientIDTextField.setDocument(new JTextFieldLimit(9));
379 firstName_textfield.setDocument(new JTextFieldLimit(60));
380 lastName_textfield.setDocument(new JTextFieldLimit(60));
381 middleName_textfield.setDocument(new JTextFieldLimit(60));
382 gender_textfield.setDocument(new JTextFieldLimit(6));
383 dateOfBirth_textfield.setDocument(new JTextFieldLimit(10));
384 ssn_textfield.setDocument(new JTextFieldLimit(9));
385 phone_textfield.setDocument(new JTextFieldLimit(15));
386 email_textfield.setDocument(new JTextFieldLimit(45));
387 email_textfield.setEditable(false);
388 streetName1_textfield.setDocument(new JTextFieldLimit(60));
389 streetName2_textfield.setDocument(new JTextFieldLimit(60));
390 city_textfield.setDocument(new JTextFieldLimit(40));
391 state_textfield.setDocument(new JTextFieldLimit(40));
392 zipcode_textfield.setDocument(new JTextFieldLimit(10));
393 country_textfield.setDocument(new JTextFieldLimit(40));
394
395 this.webServicesInit();
396 }
397
398 /**
399 * <p></p>
400 */
401 private void webServicesInit() {
402 // Setup the global JAXM message factory
403 System.setProperty("javax.xml.soap.MessageFactory",
404 "weblogic.webservice.core.soap.MessageFactoryImpl");
405
406 // Setup the global JAX-RPC service factory
407 System.setProperty( "javax.xml.rpc.ServiceFactory",
408 "weblogic.webservice.core.rpc.ServiceFactoryImpl");
409 }
410
411 /**
412 * <p> Validate Patient ID </p>
413 */
414 boolean validatePatientID() {
415 return (this.patientIDTextField.getText().length() == 9);
416 }
417
418 /**
419 * <p>Handle submit button</p>
420 */
421 void submitButton_actionPerformed(ActionEvent e) {
422 this.resetLabels();
423 this.resetTextFields();
424 if (!validatePatientID()) {
425 JOptionPane.showMessageDialog(this, "Please enter a 9 digit Patient ID",
426 "Entry Error", JOptionPane.ERROR_MESSAGE);
427 return;
428 }
429
430 try {
431 MedRecWebServices ws =
432 new MedRecWebServices_Impl(this.WSDLTextField.getText());
433
434 MedRecWebServicesPortType port = ws.getMedRecWebServicesPort();
435 Patient Patient =
436 (Patient)port.findPatientBySsn(this.patientIDTextField.getText());
437 if (Patient != null) {
438 this.saveButton.setEnabled(true);
439 this.thePatient = Patient;
440 this.mapPatientProfile();
441 this.patientIDTextField.setText("");
442 } else {
443 JOptionPane.showMessageDialog(this, "Invalid Patient ID.",
444 "Search Error", JOptionPane.ERROR_MESSAGE);
445 }
446 } catch (Exception ex) {
447 JOptionPane.showMessageDialog(this, "Could not connect to "+wsdl,
448 "Connection Error", JOptionPane.ERROR_MESSAGE);
449 ex.printStackTrace();
450 }
451 }
452
453 /**
454 * <p> Reset Fields </p>
455 */
456 private void resetLabels() {
457 this.firstName_label.setForeground(Color.black);
458 this.lastName_label.setForeground(Color.black);
459 this.middleName_label.setForeground(Color.black);
460 this.gender_label.setForeground(Color.black);
461 this.dateOfBirth_label.setForeground(Color.black);
462 this.ssn_label.setForeground(Color.black);
463 this.phone_label.setForeground(Color.black);
464 this.email_label.setForeground(Color.black);
465 this.streetName_label.setForeground(Color.black);
466 this.city_label.setForeground(Color.black);
467 this.state_label.setForeground(Color.black);
468 this.zipcode_label.setForeground(Color.black);
469 this.country_label.setForeground(Color.black);
470 }
471
472 /**
473 * <p> Reset TextFields </p>
474 */
475 private void resetTextFields() {
476 this.firstName_textfield.setText("");
477 this.lastName_textfield.setText("");
478 this.middleName_textfield.setText("");
479 this.gender_textfield.setText("");
480 this.dateOfBirth_textfield.setText("");
481 this.ssn_textfield.setText("");
482 this.phone_textfield.setText("");
483 this.email_textfield.setText("");
484 this.streetName1_textfield.setText("");
485 this.streetName2_textfield.setText("");
486 this.city_textfield.setText("");
487 this.state_textfield.setText("");
488 this.zipcode_textfield.setText("");
489 this.country_textfield.setText("");
490 }
491
492 /**
493 * <p> Validate fields </p>
494 *
495 */
496 private boolean validateFields() {
497 boolean result = true;
498 if (this.firstName_textfield.getText().length() == 0) {
499 this.firstName_label.setForeground(Color.red);
500 result = false;
501 }
502 if (this.lastName_textfield.getText().length() == 0) {
503 this.lastName_label.setForeground(Color.red);
504 result = false;
505 }
506 if (this.gender_textfield.getText().length() == 0) {
507 this.gender_label.setForeground(Color.red);
508 result = false;
509 }
510 if (!Utils.isValidDate(this.dateOfBirth_textfield.getText())) {
511 this.dateOfBirth_label.setForeground(Color.red);
512 result = false;
513 }
514 if (this.ssn_textfield.getText().length() != 9) {
515 this.ssn_label.setForeground(Color.red);
516 result = false;
517 }
518 if (this.phone_textfield.getText().length() == 0) {
519 this.phone_label.setForeground(Color.red);
520 result = false;
521 }
522 if (this.email_textfield.getText().length() == 0) {
523 this.email_label.setForeground(Color.red);
524 result = false;
525 }
526 if (this.streetName1_textfield.getText().length() == 0) {
527 this.streetName_label.setForeground(Color.red);
528 result = false;
529 }
530 if (this.city_textfield.getText().length() == 0) {
531 this.city_label.setForeground(Color.red);
532 result = false;
533 }
534 if (this.state_textfield.getText().length() == 0) {
535 this.state_label.setForeground(Color.red);
536 result = false;
537 }
538 if (this.zipcode_textfield.getText().length() == 0) {
539 this.zipcode_label.setForeground(Color.red);
540 result = false;
541 }
542
543 return result;
544 }
545
546
547 /**
548 * <p>Handle save button</p>
549 */
550 void saveButton_actionPerformed(ActionEvent e) {
551 resetLabels();
552 if (!validateFields()) {
553 //Print error message.
554 JOptionPane.showMessageDialog(this, "The following fields are required or have errors that need to be corrected.",
555 "Entry Error", JOptionPane.ERROR_MESSAGE);
556 return;
557 }
558
559 resetLabels();
560
561 try {
562 MedRecWebServices ws =
563 new MedRecWebServices_Impl(this.WSDLTextField.getText());
564
565 MedRecWebServicesPortType port = ws.getMedRecWebServicesPort();
566
567 Address address = new Address();
568 address.setCity(this.city_textfield.getText());
569 address.setCountry(this.country_textfield.getText());
570 address.setId(this.thePatient.getAddress().getId());
571 address.setState(this.state_textfield.getText());
572 address.setStreetName1(this.streetName1_textfield.getText());
573 address.setStreetName2(this.streetName2_textfield.getText());
574 address.setZipCode(this.zipcode_textfield.getText());
575
576 Calendar cal = Utils.str2Calendar(this.dateOfBirth_textfield.getText());
577
578 Patient patient = new Patient();
579 patient.setAddress(address);
580 patient.setDateOfBirth(cal);
581 patient.setEmail(this.email_textfield.getText());
582 patient.setFirstName(this.firstName_textfield.getText());
583 patient.setGender(this.gender_textfield.getText());
584 patient.setId(this.thePatient.getId());
585 patient.setLastName(this.lastName_textfield.getText());
586 patient.setMiddleName(this.middleName_textfield.getText());
587 patient.setPhone(this.phone_textfield.getText());
588 patient.setSsn(this.ssn_textfield.getText());
589
590 port.updatePatient(patient);
591 this.resetTextFields();
592 this.patientIDTextField.requestFocus();
593 } catch (Exception ce) {
594 JOptionPane.showMessageDialog(this, "Could not connect to "+wsdl,
595 "Connection Error", JOptionPane.ERROR_MESSAGE);
596 }
597 }
598
599 }
|