PrescriptionEJB.ejb
001 package com.bea.medrec.entities;
002 
003 import com.bea.medrec.utils.MedRecUtils;
004 import com.bea.medrec.value.Prescription;
005 import java.sql.Date;
006 import java.util.Calendar;
007 import javax.ejb.CreateException;
008 import weblogic.ejb.GenericEntityBean;
009 import weblogic.ejbgen.*;
010 
011 /**
012  <p>PrescriptionEJB is an Container Managed EntityBean that
013  * manipulates record persisted data.</p>
014  *
015  @author Copyright (c) 2006 by BEA Systems. All Rights Reserved.
016  */
017 @AutomaticKeyGeneration(name = "PRESCRIPTION_SEQ",
018                         type = AutomaticKeyGeneration.AutomaticKeyGenerationType.SEQUENCE_TABLE,
019                         cacheSize = "10")
020 @CreateDefaultDbmsTables(value = "Disabled")
021 @Entity(maxBeansInCache = "1000",
022         dataSourceName = "jdbc/MedRecTxDataSource",
023         transTimeoutSeconds = "0",
024         ejbName = "PrescriptionEJB",
025         reentrant = Constants.Bool.FALSE,
026         concurrencyStrategy = Constants.ConcurrencyStrategy.DATABASE,
027         delayDatabaseInsertUntil = Entity.DelayDatabaseInsertUntil.EJB_POST_CREATE,
028         tableName = "prescription",
029         readTimeoutSeconds = "600",
030         primKeyClass = "java.lang.Integer",
031         defaultTransaction = Constants.TransactionAttribute.MANDATORY,
032         abstractSchemaName = "PrescriptionEJB")
033 @FileGeneration(localClass = Constants.Bool.TRUE,
034                 localHome = Constants.Bool.TRUE,
035                 valueClass = Constants.Bool.FALSE)
036 @Finders({
037     @Finder(signature = "java.util.Collection findByPatientId(java.lang.Integer n0)",
038             ejbQl = "SELECT OBJECT(o) FROM PrescriptionEJB AS o WHERE o.patientId = ?1 ORDERBY o.datePrescribed",
039             groupName = "liteWeight")
040 })
041 @Relations({
042     @Relation(cascadeDelete = Constants.Bool.FALSE,
043               cmrField = "record",
044               name = "Record-Prescriptions",
045               roleName = "Prescriptions-Has-Record",
046               multiplicity = Relation.Multiplicity.MANY,
047               targetEjb = "RecordEJB",
048               fkColumn = "record_id")
049 })
050 public abstract class PrescriptionEJB extends GenericEntityBean {
051   // Container managed fields
052   @CmpField(column = "id",
053       orderingNumber = "1")
054   @LocalMethod()
055   @PrimkeyField()
056   public abstract Integer getId();
057 
058   @LocalMethod()
059   public abstract void setId(Integer id);
060 
061   @CmpField(column = "pat_id",
062             orderingNumber = "2")
063   @LocalMethod()
064   public abstract Integer getPatientId();
065 
066   @LocalMethod()
067   public abstract void setPatientId(Integer patientId);
068 
069   @CmpField(column = "record_id",
070             orderingNumber = "4")
071   @LocalMethod()
072   public abstract Integer getRecordId();
073 
074   @LocalMethod()
075   public abstract void setRecordId(Integer recordId);
076 
077   @CmpField(column = "date_prescribed",
078             orderingNumber = "5",
079             groupNames = "liteWeight, prescriptions-group")
080   @LocalMethod()
081   public abstract java.sql.Date getDatePrescribed();
082 
083   @LocalMethod()
084   public abstract void setDatePrescribed(java.sql.Date datePrescribed);
085 
086   @CmpField(column = "drug",
087             orderingNumber = "6",
088             groupNames = "liteWeight, prescriptions-group")
089   @LocalMethod()
090   public abstract String getDrug();
091 
092   @LocalMethod()
093   public abstract void setDrug(String drug);
094 
095   @CmpField(column = "dosage",
096             orderingNumber = "7",
097             groupNames = "liteWeight, prescriptions-group")
098   @LocalMethod()
099   public abstract String getDosage();
100 
101   @LocalMethod()
102   public abstract void setDosage(String dosage);
103 
104   @CmpField(column = "frequency",
105             orderingNumber = "8",
106             groupNames = "liteWeight, prescriptions-group")
107   @LocalMethod()
108   public abstract String getFrequency();
109 
110   @LocalMethod()
111   public abstract void setFrequency(String frequency);
112 
113   @CmpField(column = "refills_remaining",
114             orderingNumber = "9",
115             groupNames = "liteWeight, prescriptions-group")
116   @LocalMethod()
117   public abstract Integer getRefillsRemaining();
118 
119   @LocalMethod()
120   public abstract void setRefillsRemaining(Integer refillsRemaining);
121 
122   @CmpField(column = "instructions",
123             orderingNumber = "10",
124             groupNames = "liteWeight, prescriptions-group")
125   @LocalMethod()
126   public abstract String getInstructions();
127 
128   @LocalMethod()
129   public abstract void setInstructions(String instructions);
130 
131 
132   // Container managed relation fields
133   @CmrField(orderingNumber = "11")
134   @LocalMethod()
135   public abstract RecordLocal getRecord();
136 
137   @LocalMethod()
138   public abstract void setRecord(RecordLocal record);
139 
140   /**
141    <p>Returns a value object representation of the bean.</p>
142    *
143    @return Record
144    */
145   @LocalMethod()
146   public Prescription getPrescription() {
147     Prescription prescription = new Prescription();
148     Calendar cal = MedRecUtils.convertSqlDate2Calendar(getDatePrescribed());
149     prescription.setDatePrescribed(cal);
150     prescription.setDrug(getDrug());
151     prescription.setDosage(getDosage());
152     prescription.setFrequency(getFrequency());
153     prescription.setRefillsRemaining(getRefillsRemaining());
154     prescription.setInstructions(getInstructions());
155     return prescription;
156   }
157 
158   /**
159    <p>Returns an abbreviated value object representation of the bean.
160    * Fields returned are:<br>
161    * id<br>
162    * date<br>
163    * symptoms<br>
164    * diagnois</p>
165    *
166    @return Prescription
167    *         <p/>
168    */
169   @LocalMethod()
170   public Prescription getPrescriptionLite() {
171     Prescription prescription = new Prescription();
172     prescription.setId(getId());
173     Calendar cal = MedRecUtils.convertSqlDate2Calendar(getDatePrescribed());
174     prescription.setDatePrescribed(cal);
175     prescription.setDrug(getDrug());
176     prescription.setFrequency(getFrequency());
177     return prescription;
178   }
179 
180   // Home methods
181   /**
182    <p>Prescription create.</p>
183    */
184   public Object ejbCreate(Integer patientId,
185                           Calendar datePrescribed,
186                           String drug,
187                           String dosage,
188                           String frequency,
189                           Integer refillsRemaining,
190                           String instructions,
191                           RecordLocal recordthrows CreateException {
192     setPatientId(patientId);
193     Date sqlDate = MedRecUtils.getDate(datePrescribed);
194     setDatePrescribed(sqlDate);
195     setDrug(drug);
196     setDosage(dosage);
197     setFrequency(frequency);
198     setRefillsRemaining(refillsRemaining);
199     setInstructions(instructions);
200     return null;
201   }
202 
203   public void ejbPostCreate(Integer patientId,
204                             Calendar datePrescribed,
205                             String drug,
206                             String dosage,
207                             String frequency,
208                             Integer refillsRemaining,
209                             String instructions,
210                             RecordLocal recordthrows CreateException {
211     setRecord(record);
212   }
213 
214   /**
215    <p>Prescription create.</p>
216    */
217   public Object ejbCreate(Prescription prescription, RecordLocal record)
218       throws CreateException {
219     setPatientId(prescription.getPatientId());
220     Date sqlDate = MedRecUtils.getDate(prescription.getDatePrescribed());
221     setDatePrescribed(sqlDate);
222     setDrug(prescription.getDrug());
223     setDosage(prescription.getDosage());
224     setFrequency(prescription.getFrequency());
225     setRefillsRemaining(prescription.getRefillsRemaining());
226     setInstructions(prescription.getInstructions());
227     return null;
228   }
229 
230   public void ejbPostCreate(Prescription prescription, RecordLocal record)
231       throws CreateException {
232     /* Delaying the database insert until after ejbPostCreate is required
233       when a cmr-field is mapped to a foreign-key column that doesn't allow
234       null values.  In this case, the cmr-field must be set to a non-null
235       value in ejbPostCreate before the bean is inserted into the database.
236       Note that cmr-fields may not be set during ejbCreate, before the
237       primary key of the bean is known. */
238     setRecord(record);
239   }
240 
241   @LocalMethod()
242   public String toString() {
243     StringBuffer str = new StringBuffer();
244     str.append("PRESCRIPTIONS [Id: "+getId());
245     str.append(" | PatId: " +getPatientId());
246     str.append(" | RecId: "+getRecordId());
247     str.append(" | Calendar: "+getDatePrescribed());
248     str.append(" | Drug: "+getDrug());
249     str.append(" | Dosage: "+getDosage());
250     str.append(" | Freq: "+getFrequency());
251     str.append(" | Refills: "+getRefillsRemaining());
252     str.append(" | Instructions: "+getInstructions());
253     str.append("]");
254     return str.toString();
255   }
256 }