PatientBean.java
001 package com.bea.medrec.beans;
002 
003 import com.bea.medrec.utils.MedRecWebAppUtils;
004 import com.bea.medrec.value.Patient;
005 import javax.servlet.http.HttpServletRequest;
006 import org.apache.struts.action.ActionErrors;
007 import org.apache.struts.action.ActionMapping;
008 import org.apache.struts.validator.Resources;
009 
010 /**
011  <p>Form bean for the register and patient webapps.
012  * This form has the following fields,
013  * with default values in square brackets:
014  <ul>
015  <li><b>firstName</b> - Entered firstName value
016  <li><b>middleName</b> - Entered firstName value
017  <li><b>lastName</b> - Entered firstName value
018  <li><b>dob</b> - Entered date of birth value
019  <li><b>ssn</b> - Entered social security number value
020  <li><b>email</b> - Entered email value
021  <li><b>phone</b> - Entered phone value
022  </ul>
023  </p>
024  *
025  @author Copyright (c) 2006 by BEA Systems. All Rights Reserved.
026  */
027 public final class PatientBean extends BaseBean {
028   // Gender
029   public static final String MALE = "Male";
030   public static final String FEMALE = "Female";
031 
032   // Instance Variables
033   private String firstName = null;;
034   private String middleName = null;;
035   private String lastName = null;;
036   private String dob = null;;
037   private String gender = null;;
038   private String ssn = null;;
039   private String phone = null;;
040   private String email = null;;
041   private AddressBean address = new AddressBean();
042 
043   // Constructors
044   public PatientBean() {
045   }
046 
047   public PatientBean(Patient patient) {
048     String displayDate =
049         MedRecWebAppUtils.getDisplayDate(patient.getDateOfBirth());
050     super.setId(patient.getId());
051     this.firstName = patient.getFirstName();
052     this.middleName = patient.getMiddleName();
053     this.lastName = patient.getLastName();
054     this.dob = displayDate;
055     this.gender = patient.getGender();
056     this.ssn = patient.getSsn();
057     this.phone = patient.getPhone();
058     this.email = patient.getEmail();
059     this.address = new AddressBean(patient.getAddress());
060   }
061 
062   public PatientBean(String id,
063                      String firstName,
064                      String middleName,
065                      String lastName,
066                      String dob,
067                      String gender,
068                      String ssn,
069                      String phone,
070                      String email,
071                      AddressBean address) {
072     super.setId(id);
073     this.firstName = firstName;
074     this.middleName = middleName;
075     this.lastName = lastName;
076     this.dob = dob;
077     this.gender = gender;
078     this.ssn = ssn;
079     this.phone = phone;
080     this.email = email;
081     this.address = address;
082   }
083 
084   public PatientBean(Integer id,
085                      String firstName,
086                      String middleName,
087                      String lastName,
088                      String dob,
089                      String gender,
090                      String ssn,
091                      String phone,
092                      String email,
093                      AddressBean address) {
094     super.setId(id);
095     this.firstName = firstName;
096     this.middleName = middleName;
097     this.lastName = lastName;
098     this.dob = dob;
099     this.gender = gender;
100     this.ssn = ssn;
101     this.phone = phone;
102     this.email = email;
103     this.address = address;
104   }
105 
106   // Getters
107   public String getFirstName() {
108     return this.firstName;
109   }
110 
111   public String getMiddleName() {
112     return this.middleName;
113   }
114 
115   public String getLastName() {
116     return this.lastName;
117   }
118 
119   public String getDob() {
120     return this.dob;
121   }
122 
123   public String getGender() {
124     return this.gender;
125   }
126 
127   public String getSsn() {
128     return this.ssn;
129   }
130 
131   public String getPhone() {
132     return this.phone;
133   }
134 
135   public String getEmail() {
136     return this.email;
137   }
138 
139   public AddressBean getAddress() {
140     return this.address;
141   }
142 
143   // Setters
144   public void setFirstName(String firstName) {
145     this.firstName = firstName;
146   }
147 
148   public void setMiddleName(String middleName) {
149     this.middleName = middleName;
150   }
151 
152   public void setLastName(String lastName) {
153     this.lastName = lastName;
154   }
155 
156   public void setDob(String dob) {
157     this.dob = setDateStr(dob);
158   }
159 
160   public void setGender(String gender) {
161     this.gender = gender;
162   }
163 
164   public void setSsn(String ssn) {
165     this.ssn = ssn;
166   }
167 
168   public void setPhone(String phone) {
169     this.phone = phone;
170   }
171 
172   public void setEmail(String email) {
173     this.email = email;
174   }
175 
176   public void setAddress(AddressBean address) {
177     this.address = address;
178   }
179 
180   // Public Methods
181   public void reset() {
182     this.firstName = null;
183     this.middleName = null;
184     this.lastName = null;
185     this.dob = null;
186     this.gender = null;
187     this.ssn = null;
188     this.phone = null;
189     this.email = null;
190   }
191 
192   /**
193    <p>Validate patient.</p>
194    *
195    @param mapping
196    @param request
197    *
198    @return ActionErrors
199    */
200   public ActionErrors validate(ActionMapping mapping,
201                                HttpServletRequest request) {
202     ActionErrors errors = new ActionErrors();
203     // only validate if the user has clicked "Login"
204     String loginSubmit = Resources.getMessage(request, "button.Save");
205     if (loginSubmit.equals(request.getParameter("action"))) {
206       errors = super.validate(mapping, request);
207     }
208     return errors;
209   }
210 
211 
212   public String toString() {
213     StringBuffer str = new StringBuffer();
214     str.append("Patient[Id: "+super.getId());
215     str.append(" | Name: "+firstName);
216     str.append(" "+middleName);
217     str.append(" "+lastName);
218     str.append(" | DOB: "+dob);
219     str.append(" | Gender: "+gender);
220     str.append(" | SSN: "+ssn);
221     str.append(" | Phone: "+phone);
222     str.append(" | Email: "+email);
223     str.append(" | "+((address == null"Address: null" : address.toString()));
224     str.append("]");
225 
226     return str.toString();
227   }
228 
229   /**
230    <p>Converts patient presentation bean to patient value object.</p>
231    *
232    @return Patient
233    */
234   public Patient toPatient() {
235     return new Patient(getId(),
236         getFirstName(),
237         getMiddleName(),
238         getLastName(),
239         str2Calendar(getDob()),
240         getGender(),
241         getSsn(),
242         getPhone(),
243         getEmail(),
244         getAddress().toAddress());
245   }
246 }