PrescriptionBean.java
001 package com.bea.medrec.beans;
002 
003 import com.bea.medrec.utils.MedRecWebAppUtils;
004 import com.bea.medrec.value.Prescription;
005 import java.util.Calendar;
006 import javax.servlet.http.HttpServletRequest;
007 import org.apache.struts.action.ActionErrors;
008 import org.apache.struts.action.ActionMapping;
009 import org.apache.struts.validator.Resources;
010 
011 /**
012  <p>Form bean for vital signs.
013  * This form has the following fields,
014  * with default values in square brackets:
015  <ul>
016  <li><b>drug</b> - Entered drug value
017  <li><b>dosage</b> - Entered dosage value
018  <li><b>frequency </b> - Entered frequency value
019  <li><b>refillsRemaining</b> - Entered refills remaining value
020  </ul>
021  </p>
022  *
023  @author Copyright (c) 2006 by BEA Systems. All Rights Reserved.
024  */
025 public final class PrescriptionBean extends BaseBean {
026 
027   // Attributes
028   private String patientId = "";
029   private String recordId = "";
030   private String datePrescribed = "";
031   private String drug = "";
032   private String dosage = "";
033   private String frequency = "";
034   private String refillsRemaining = "";
035   private String instructions = "";
036 
037   // Constructors
038   public PrescriptionBean() {
039   }
040 
041   public PrescriptionBean(Prescription prescription) {
042     String displayDate =
043         MedRecWebAppUtils.getDisplayDate(prescription.getDatePrescribed());
044     super.setId(prescription.getId());
045     this.patientId = String.valueOf(prescription.getPatientId());
046     this.recordId = String.valueOf(prescription.getRecordId());
047     this.datePrescribed = displayDate;
048     this.drug = prescription.getDrug();
049     this.dosage = prescription.getDosage();
050     this.frequency = prescription.getFrequency();
051     this.refillsRemaining = toStr(prescription.getRefillsRemaining());
052     this.instructions = prescription.getInstructions();
053   }
054 
055   public PrescriptionBean(Integer id,
056                           String patientId,
057                           String recordId,
058                           String datePrescribed,
059                           String drug,
060                           String dosage,
061                           String frequency,
062                           Integer refillsRemaining,
063                           String instructions) {
064     super.setId(id);
065     this.patientId = patientId;
066     this.recordId = recordId;
067     this.datePrescribed = datePrescribed;
068     this.drug = drug;
069     this.dosage = dosage;
070     this.frequency = frequency;
071     this.refillsRemaining = toStr(refillsRemaining);
072     this.instructions = instructions;
073   }
074 
075   public PrescriptionBean(String patientId,
076                           String recordId,
077                           String datePrescribed,
078                           String drug,
079                           String dosage,
080                           String frequency,
081                           String refillsRemaining,
082                           String instructions) {
083     this.patientId = patientId;
084     this.recordId = recordId;
085     this.datePrescribed = datePrescribed;
086     this.drug = drug;
087     this.dosage = dosage;
088     this.frequency = frequency;
089     this.refillsRemaining = refillsRemaining;
090     this.instructions = instructions;
091   }
092 
093   // Getters
094   public String getPatientId() {
095     return this.patientId;
096   }
097 
098   public String getRecordId() {
099     return this.recordId;
100   }
101 
102   public String getDatePrescribed() {
103     return this.datePrescribed;
104   }
105 
106   public String getDrug() {
107     return this.drug;
108   }
109 
110   public String getDosage() {
111     return this.dosage;
112   }
113 
114   public String getFrequency() {
115     return this.frequency;
116   }
117 
118   public String getRefillsRemaining() {
119     return this.refillsRemaining;
120   }
121 
122   public String getInstructions() {
123     return this.instructions;
124   }
125 
126   // Setters
127   public void setPatientId(String patientId) {
128     this.patientId = patientId;
129   }
130 
131   public void setRecordId(String recordId) {
132     this.recordId = recordId;
133   }
134 
135   public void setDatePrescribed(String datePrescribed) {
136     this.datePrescribed = datePrescribed;
137   }
138 
139   public void setDrug(String drug) {
140     this.drug = drug;
141   }
142 
143   public void setDosage(String dosage) {
144     this.dosage = dosage;
145   }
146 
147   public void setFrequency(String frequency) {
148     this.frequency = frequency;
149   }
150 
151   public void setRefillsRemaining(String refillsRemaining) {
152     this.refillsRemaining = refillsRemaining;
153   }
154 
155   public void setInstructions(String instructions) {
156     this.instructions = instructions;
157   }
158 
159   // Public Methods
160   public void reset() {
161     this.patientId = "";
162     this.recordId = "";
163     this.datePrescribed = "";
164     this.drug = "";
165     this.dosage = "";
166     this.frequency = "";
167     this.refillsRemaining = "";
168     this.instructions = "";
169   }
170   /**
171    <p>Validate registration.</p>
172    *
173    @param mapping
174    @param request
175    *
176    @return ActionErrors
177    */
178   public ActionErrors validate(ActionMapping mapping,
179                                HttpServletRequest request) {
180     ActionErrors errors = new ActionErrors();
181     // only validate if the user has clicked "Login"
182     String loginSubmit = Resources.getMessage(request, "button.Save");
183     if (loginSubmit.equals(request.getParameter("actionPrescription"))) {
184       errors = super.validate(mapping, request);
185     }
186     return errors;
187   }
188 
189   /**
190    <p>Converts prescription presentation bean to prescription value object.</p>
191    *
192    @return PrescriptionBean
193    */
194   public Prescription toPrescription() {
195     return new Prescription(str2Integer(getPatientId()),
196                             str2Calendar(getDatePrescribed()),
197                             getDrug(),
198                             getDosage(),
199                             getFrequency(),
200                             str2Integer(getRefillsRemaining()),
201                             getInstructions());
202   }
203 
204   // Utility
205   public String toString() {
206     StringBuffer str = new StringBuffer();
207     str.append("PrescriptionBean [");
208     str.append("PatId: "+patientId);
209     str.append(" | Date: "+
210         (datePrescribed == null "null" : datePrescribed.toString()));
211     str.append(" | Drug: "+drug);
212     str.append(" | Dosage: "+dosage);
213     str.append(" | Freq: "+frequency);
214     str.append(" | Refills: "+refillsRemaining);
215     str.append(" | Instructions: "+instructions);
216     str.append("]");
217 
218     return str.toString();
219   }
220  
221 }