001 package com.bea.medrec.beans;
002
003 import com.bea.medrec.utils.MedRecWebAppUtils;
004 import com.bea.medrec.value.Prescription;
005 import com.bea.medrec.value.Record;
006 import java.util.ArrayList;
007 import java.util.Collection;
008 import java.util.Iterator;
009 import javax.servlet.http.HttpServletRequest;
010 import org.apache.struts.action.ActionErrors;
011 import org.apache.struts.action.ActionMapping;
012 import org.apache.struts.validator.Resources;
013
014 /**
015 * <p>Form bean for the user record pages.
016 * This form has the following fields,
017 * with default values in square brackets:
018 * <ul>
019 * <li><b>patientId</b> - Hidden patientId value
020 * <li><b>physicianId</b> - Hidden firstName value
021 * <li><b>symptoms</b> - Entered symptoms value
022 * <li><b>diagnosis</b> - Entered diagnosis value
023 * <li><b>notes</b> - Entered notes value
024 * </ul>
025 * </p>
026 *
027 * @author Copyright (c) 2006 by BEA Systems. All Rights Reserved.
028 */
029 public final class RecordBean extends BaseBean {
030 // Instance Variables
031 private String patientId = "";
032 private String physicianName = "";
033 private String date = "";
034 private String symptoms = "";
035 private String diagnosis = "";
036 private String notes = "";
037 private VitalSignsBean vitalSignsBean = new VitalSignsBean();
038 private ArrayList<Object> prescriptionBeans = new ArrayList<Object>();
039
040 // Constuctors
041 public RecordBean() { }
042
043 public RecordBean(Record record) {
044 if (record == null) return;
045 super.setId(record.getId());
046 this.patientId = toStr(record.getPatientId());
047 this.physicianName = record.getPhysicianName();
048 this.date = MedRecWebAppUtils.getDisplayDate(record.getDate());
049 this.symptoms = record.getSymptoms();
050 this.diagnosis = record.getDiagnosis();
051 this.notes = record.getNotes();
052 if (record.getVitalSigns() != null)
053 this.vitalSignsBean = new VitalSignsBean(record.getVitalSigns());
054 this.prescriptionBeans = (ArrayList<Object>)toCollectionBean(
055 record.getPrescriptions(), com.bea.medrec.beans.PrescriptionBean.class);
056 }
057
058 public RecordBean(Integer id,
059 String patientId,
060 String physicianName,
061 String date,
062 String symptoms,
063 String diagnosis,
064 String notes,
065 VitalSignsBean vitalSignsBean,
066 ArrayList<Object> prescriptionBeans) {
067 super.setId(id);
068 this.patientId = patientId;
069 this.physicianName = physicianName;
070 this.date = date;
071 this.symptoms = symptoms;
072 this.diagnosis = diagnosis;
073 this.notes = notes;
074 this.vitalSignsBean = vitalSignsBean;
075 this.prescriptionBeans = prescriptionBeans;
076 }
077
078 public RecordBean(Integer id,
079 Integer patientId,
080 String physicianName,
081 String date,
082 String symptoms,
083 String diagnosis,
084 String notes,
085 VitalSignsBean vitalSignsBean,
086 ArrayList<Object> prescriptionBeans) {
087 super.setId(id);
088 this.patientId = toStr(patientId);
089 this.physicianName = physicianName;
090 this.date = date;
091 this.symptoms = symptoms;
092 this.diagnosis = diagnosis;
093 this.notes = notes;
094 this.vitalSignsBean = vitalSignsBean;
095 this.prescriptionBeans = prescriptionBeans;
096 }
097
098 public RecordBean(String id,
099 String physicianName,
100 String date,
101 String symptoms,
102 String diagnosis) {
103 super.setId(id);
104 this.physicianName = physicianName;
105 this.date = date;
106 this.symptoms = symptoms;
107 this.diagnosis = diagnosis;
108 }
109
110 public RecordBean(Integer id,
111 String physicianName,
112 String date,
113 String symptoms,
114 String diagnosis) {
115 super.setId(id);
116 this.physicianName = physicianName;
117 this.date = date;
118 this.symptoms = symptoms;
119 this.diagnosis = diagnosis;
120 }
121
122 // Getters
123 public String getPatientId() {
124 return this.patientId;
125 }
126
127 public String getPhysicianName() {
128 return "Dr. "+this.physicianName;
129 }
130
131 public String getDate() {
132 return this.date;
133 }
134
135 public String getSymptoms() {
136 return this.symptoms;
137 }
138
139 public String getDiagnosis() {
140 return this.diagnosis;
141 }
142
143 public String getNotes() {
144 return this.notes;
145 }
146
147 public VitalSignsBean getVitalSignsBean() {
148 if (vitalSignsBean == null) vitalSignsBean = new VitalSignsBean();
149 return vitalSignsBean;
150 }
151
152 public Collection getPrescriptionBeans() {
153 return this.prescriptionBeans;
154 }
155
156 // Setters
157 public void setPatientId(String pPatientId) {
158 this.patientId = pPatientId;
159 }
160
161 public void setPhysicianName(String pPhysicianName) {
162 this.physicianName = pPhysicianName;
163 }
164
165 public void setDate(String pDate) {
166 this.date = pDate;
167 }
168
169 public void setSymptoms(String pSymptoms) {
170 this.symptoms = pSymptoms;
171 }
172
173 public void setDiagnosis(String pDiagnosis) {
174 this.diagnosis = pDiagnosis;
175 }
176
177 public void setNotes(String pNotes) {
178 this.notes = pNotes;
179 }
180
181 public void setVitalSignsBean(VitalSignsBean pVitalSignsBean) {
182 this.vitalSignsBean = pVitalSignsBean;
183 }
184
185 public void setPrescriptions(ArrayList<Object> pPrescriptionBeans) {
186 this.prescriptionBeans = pPrescriptionBeans;
187 }
188
189 // Update method
190 public void update(RecordBean recordBean) {
191 this.symptoms = recordBean.getSymptoms();
192 this.diagnosis = recordBean.getDiagnosis();
193 this.notes = recordBean.getNotes();
194 this.vitalSignsBean.update(recordBean.getVitalSignsBean());
195 }
196
197 // utility
198 public int getNumOfPrescriptions() {
199 return (this.prescriptionBeans == null ? 0 : this.prescriptionBeans.size());
200 }
201
202 public void addPrescription(PrescriptionBean pPrescriptionBean) {
203 this.prescriptionBeans.add(pPrescriptionBean);
204 }
205
206 public void removePrescription(String pPrescriptionId) {
207 if (getNumOfPrescriptions() > 1)
208 this.prescriptionBeans.remove(Integer.parseInt(pPrescriptionId));
209 else
210 this.prescriptionBeans.clear();
211 }
212
213 /**
214 * <p>Validate record.</p>
215 *
216 * @param mapping
217 * @param request
218 *
219 * @return ActionErrors
220 */
221 public ActionErrors validate(ActionMapping mapping,
222 HttpServletRequest request) {
223 ActionErrors errors = new ActionErrors();
224 // only validate if the user has clicked "Login"
225 String loginSubmit = Resources.getMessage(request, "button.Save");
226 if (loginSubmit.equals(request.getParameter("action"))) {
227 errors = super.validate(mapping, request);
228 }
229 return errors;
230 }
231
232 /**
233 * <p>Converts record presentation bean to record value object.</p>
234 *
235 * @return Record
236 */
237 public Record toRecord() {
238 return new Record(getPatientId(),
239 str2Calendar(getDate()),
240 getSymptoms(),
241 getDiagnosis(),
242 getNotes(),
243 null, /* FIXME physician */
244 getVitalSignsBean().toVitalSigns(),
245 toPrescriptionArray()
246 );
247 }
248
249 private Prescription[] toPrescriptionArray() {
250 Prescription[] prescriptionVOs = null;
251 if (this.prescriptionBeans != null || this.prescriptionBeans.size() > 0)
252 prescriptionVOs = new Prescription[this.prescriptionBeans.size()];
253 else
254 prescriptionVOs = new Prescription[0];
255
256 int i = 0;
257 for (Iterator iterator = prescriptionBeans.iterator(); iterator.hasNext();
258 i++) {
259 PrescriptionBean prescriptionBean = (PrescriptionBean) iterator.next();
260 prescriptionVOs[i] = prescriptionBean.toPrescription();
261 }
262 return prescriptionVOs;
263 }
264
265 // Utility methods
266 public String toString() {
267 StringBuffer str = new StringBuffer();
268 str.append("Record [");
269 str.append("PatId: "+patientId);
270 str.append(" | PhysName: "+physicianName);
271 str.append(" | DOB: "+date);
272 str.append(" | Syms: "+symptoms);
273 str.append(" | Diag: "+diagnosis);
274 str.append(" | Notes: "+notes);
275 str.append(" | Vitals: "+
276 (vitalSignsBean == null ? "null" : vitalSignsBean.toString()));
277 str.append(" | "+MedRecWebAppUtils.col2Str(prescriptionBeans));
278 str.append("]");
279 return str.toString();
280 }
281
282 }
|