"bin" did not exist on "e64fadf34aedb7cb95cd6c5566e525ab4bad79df"
Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
package edu.ncsu.csc.itrust.action;
import java.util.Arrays;
import java.util.List;
import edu.ncsu.csc.itrust.action.base.EditOfficeVisitBaseAction;
import edu.ncsu.csc.itrust.beans.Email;
import edu.ncsu.csc.itrust.beans.HospitalBean;
import edu.ncsu.csc.itrust.beans.OfficeVisitBean;
import edu.ncsu.csc.itrust.beans.PatientBean;
import edu.ncsu.csc.itrust.beans.forms.EditOfficeVisitForm;
import edu.ncsu.csc.itrust.dao.DAOFactory;
import edu.ncsu.csc.itrust.dao.mysql.HospitalsDAO;
import edu.ncsu.csc.itrust.dao.mysql.OfficeVisitDAO;
import edu.ncsu.csc.itrust.dao.mysql.PatientDAO;
import edu.ncsu.csc.itrust.dao.mysql.PersonnelDAO;
import edu.ncsu.csc.itrust.enums.TransactionType;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.exception.FormValidationException;
import edu.ncsu.csc.itrust.exception.ITrustException;
import edu.ncsu.csc.itrust.validate.EditOfficeVisitValidator;
/**
* Edits the office visits of a patient Used by editOfficeVisit.jsp. This
* exists in two states: saved and unsaved. If unsaved, data cannot be saved
* to sub actions (if this is attempted, exceptions will be raised). Once it
* is saved, however, the sub actions can be saved.
*
*
*
*/
public class EditOfficeVisitAction extends EditOfficeVisitBaseAction {
private EditOfficeVisitValidator validator = new EditOfficeVisitValidator();
private PersonnelDAO personnelDAO;
private HospitalsDAO hospitalDAO;
private OfficeVisitDAO ovDAO;
private PatientDAO patDAO;
private EditHealthHistoryAction healthRecordAction;
private EditPrescriptionsAction prescriptionsAction;
private EditProceduresAction proceduresAction;
private EditImmunizationsAction immunizationsAction;
private EditDiagnosesAction diagnosesAction;
private EditLabProceduresAction labProceduresAction;
private EditPatientInstructionsAction patientInstructionsAction;
private EditReferralsAction referralsAction;
private EventLoggingAction loggingAction;
private long loggedInMID;
/**
* Patient id and office visit id validated by super class
*
* @param factory The DAOFactory to be used in creating the DAOs for this action.
* @param loggedInMID The MID of the user who is authorizing this action.
* @param pidString The patient who this action is performed on.
* @param ovIDString The ID of the office visit in play.
* @throws ITrustException
*/
public EditOfficeVisitAction(DAOFactory factory, long loggedInMID, String pidString, String ovIDString)
throws ITrustException {
super(factory, loggedInMID, pidString, ovIDString);
pid = Long.parseLong(pidString);
ovDAO = factory.getOfficeVisitDAO();
this.personnelDAO = factory.getPersonnelDAO();
this.hospitalDAO = factory.getHospitalsDAO();
this.patDAO = factory.getPatientDAO();
this.healthRecordAction = new EditHealthHistoryAction(factory, loggedInMID, pidString, ovIDString);
this.prescriptionsAction = new EditPrescriptionsAction(factory, loggedInMID, pidString, ovIDString);
this.proceduresAction = new EditProceduresAction(factory, loggedInMID, pidString, ovIDString);
this.immunizationsAction = new EditImmunizationsAction(factory, loggedInMID, pidString, ovIDString);
this.diagnosesAction = new EditDiagnosesAction(factory, loggedInMID, pidString, ovIDString);
this.labProceduresAction = new EditLabProceduresAction(factory, loggedInMID, pidString, ovIDString);
this.patientInstructionsAction = new EditPatientInstructionsAction(factory, loggedInMID, pidString, ovIDString);
this.referralsAction = new EditReferralsAction(factory, loggedInMID, pidString, ovIDString);
this.loggingAction = new EventLoggingAction(factory);
this.loggedInMID = loggedInMID;
}
/**
* Create an OfficeVisitAction that is not yet associated with an actual
* office visit. When update() is called, it will be saved. Until then,
* any attempt to save health records, prescriptions, procedures, lab procedures,
* immunizations, or diagnoses will raise an exception.
* @param factory
* @param loggedInMID
* @param pidString
* @throws ITrustException
*/
public EditOfficeVisitAction(DAOFactory factory, long loggedInMID, String pidString)
throws ITrustException {
super(factory, loggedInMID, pidString);
pid = Long.parseLong(pidString);
ovDAO = factory.getOfficeVisitDAO();
this.personnelDAO = factory.getPersonnelDAO();
this.hospitalDAO = factory.getHospitalsDAO();
this.patDAO = factory.getPatientDAO();
this.healthRecordAction = new EditHealthHistoryAction(factory, loggedInMID, pidString);
this.prescriptionsAction = new EditPrescriptionsAction(factory, loggedInMID, pidString);
this.proceduresAction = new EditProceduresAction(factory, loggedInMID, pidString);
this.immunizationsAction = new EditImmunizationsAction(factory, loggedInMID, pidString);
this.diagnosesAction = new EditDiagnosesAction(factory, loggedInMID, pidString);
this.labProceduresAction = new EditLabProceduresAction(factory, loggedInMID, pidString);
this.patientInstructionsAction = new EditPatientInstructionsAction(factory, loggedInMID, pidString);
this.referralsAction = new EditReferralsAction(factory, loggedInMID, pidString);
this.loggingAction = new EventLoggingAction(factory);
this.loggedInMID = loggedInMID;
}
/**
* Used to update the sub actions once a office visit is saved. Until this
* is called, attempting to save sub actions will raise an exception.
* @throws ITrustException
*/
private void reinitializeSubActions() throws ITrustException {
if (isUnsaved()) {
throw new ITrustException("Cannot initalize EditOfficeVisit sub actions. No ovID is present.");
}
DAOFactory factory = getFactory();
String pidString = ""+getPid();
String ovIDString = ""+getOvID();
healthRecordAction = new EditHealthHistoryAction(factory, loggedInMID, pidString, ovIDString);
prescriptionsAction = new EditPrescriptionsAction(factory, loggedInMID, pidString, ovIDString);
proceduresAction = new EditProceduresAction(factory, loggedInMID, pidString, ovIDString);
immunizationsAction = new EditImmunizationsAction(factory, loggedInMID, pidString, ovIDString);
diagnosesAction = new EditDiagnosesAction(factory, loggedInMID, pidString, ovIDString);
labProceduresAction = new EditLabProceduresAction(factory, loggedInMID, pidString, ovIDString);
patientInstructionsAction = new EditPatientInstructionsAction(factory, loggedInMID, pidString, ovIDString);
referralsAction = new EditReferralsAction(factory, loggedInMID, pidString, ovIDString);
}
/**
* Returns the office visit bean for the office visit
*
* @return the OfficeVisitBean of the office visit
* @throws ITrustException
*/
public OfficeVisitBean getOfficeVisit() throws ITrustException {
return getBean();
}
/**
* Gets and returns the associated patient's health history record.
* @return The EditHealthHistoryACtoin sub action associated with this office visit.
* @throws ITrustException
*/
public EditHealthHistoryAction healthRecord() throws ITrustException {
return healthRecordAction;
}
/**
* @return The EditPrescriptionsAction sub action associated with this office visit.
* @throws ITrustException
*/
public EditPrescriptionsAction prescriptions() throws ITrustException {
return prescriptionsAction;
}
/**
* @return The EditProceduresAction sub action associated with this office visit.
* @throws ITrustException
*/
public EditProceduresAction procedures() throws ITrustException {
return proceduresAction;
}
/**
* @return The EditImmunizationsAction sub action associated with this office visit.
* @throws ITrustException
*/
public EditImmunizationsAction immunizations() throws ITrustException {
return immunizationsAction;
}
/**
* @return The EditDiagnosesAction sub action associated with this office visit.
* @throws ITrustException
*/
public EditDiagnosesAction diagnoses() throws ITrustException {
return diagnosesAction;
}
/**
* @return The EditLabProceduresAction sub action associated with this office visit.
* @throws ITrustException
*/
public EditLabProceduresAction labProcedures() throws ITrustException {
return labProceduresAction;
}
public EditPatientInstructionsAction patientInstructions() throws ITrustException {
return patientInstructionsAction;
}
public EditReferralsAction referrals() throws ITrustException {
return referralsAction;
}
/**
* This is a list of all hospitals, ordered by the office visit's hcp FIRST
*
* @param hcpID
* @return
* @throws ITrustException
*/
public List<HospitalBean> getHospitals() throws ITrustException {
List<HospitalBean> hcpsHospitals = personnelDAO.getHospitals(getHcpid());
List<HospitalBean> allHospitals = hospitalDAO.getAllHospitals();
return combineLists(hcpsHospitals, allHospitals);
}
/**
* Combines two lists of hospitals
*
* @param hcpsHospitals hospitals the HCP is assigned to
* @param allHospitals all hospitals
* @return the combined list
*/
private List<HospitalBean> combineLists(List<HospitalBean> hcpsHospitals, List<HospitalBean> allHospitals) {
for (HospitalBean hos : allHospitals) {
if (!hcpsHospitals.contains(hos))
hcpsHospitals.add(hos);
}
return hcpsHospitals;
}
/**
* Updates the office visit with information from the form passed in. If
* the office visit has not yet been saved, calling this method will save
* it as well as make the sub actions able to be saved.
*
* @param form
* information to update
* @return "success" or exception's message
* @throws FormValidationException
*/
public String updateInformation(EditOfficeVisitForm form, boolean isERIncident) throws FormValidationException {
String confirm = "";
try {
updateOv(form, isERIncident);
confirm = "success";
return confirm;
} catch (ITrustException e) {
return e.getMessage();
}
}
/**
* Helper that logs an office visit billing event. The associated patient id, HCP
* id, and office visit id are automatically included.
* added with UC60
* @param trans Transaction type for the log.
* @throws DBException
*/
public void logOfficeVisitBillingEvent(TransactionType trans) throws DBException {
loggingAction.logEvent(trans, loggedInMID, getPid(), "Office visit " + getOvID() + "billed");
}
/**
* Helper that logs an office visit event. The associated patient id, HCP
* id, and office visit id are automatically included.
* @param trans Transaction type for the log.
* @throws DBException
*/
public void logOfficeVisitEvent(TransactionType trans) throws DBException {
loggingAction.logEvent(trans, loggedInMID, getPid(), "Office visit ID: " + getOvID());
}
/**
*
* Sends e-mail regarding the prescribed dangerous drug.
*
* @param hcpID HCP the prescription is made by
* @param patID ID of the patient prescription is for
* @param problem The allergy and/or interaction that is the problem
* @return the sent e-mail
* @throws DBException
*/
public Email makeEmailApp(long hcpID, String patID, String problem) throws DBException, ITrustException {
PatientBean p = patDAO.getPatient(Long.parseLong(patID));
String hcpName = personnelDAO.getName(hcpID);
Email email = new Email();
email.setFrom("no-reply@itrust.com");
email.setToList(Arrays.asList(p.getEmail()));
email.setSubject("HCP has prescribed you a potentially dangerous medication");
email.setBody(String
.format(
"%s has prescribed a medication that you are allergic to or that has a known interaction with a drug you are currently taking. %s",
hcpName, problem));
return email;
}
/**
* Updates the office visit.
*
* @param form form with all the information
* @throws DBException
* @throws FormValidationException
*/
private void updateOv(EditOfficeVisitForm form, boolean isERIncident) throws DBException, FormValidationException, ITrustException {
validator.validate(form);
OfficeVisitBean ov = getBean();
ov.setNotes(form.getNotes());
ov.setVisitDateStr(form.getVisitDate());
ov.setHcpID(Long.valueOf(form.getHcpID()));
ov.setPatientID(Long.valueOf(form.getPatientID()));
ov.setHospitalID(form.getHospitalID());
ov.setERIncident(isERIncident);
ov.setAppointmentType(form.getApptType());
ov.setBilled(form.getIsBilled()); //UC60
updateBean(ov);
}
/**
* @return The OfficeVisitBean associated with this office visit, or if it
* has not been saved, a default OfficeVisitBean with the HCP id and
* patient id filled in.
* @throws DBException
*/
private OfficeVisitBean getBean() throws DBException {
if (isUnsaved()) {
OfficeVisitBean b = new OfficeVisitBean();
b.setHcpID(getHcpid());
b.setPatientID(getPid());
return b;
} else {
return ovDAO.getOfficeVisit(ovID);
}
}
/**
* Update the office visit with the given data. If the office visit has
* not yet been saved, this will save it and reinitialize the sub actions.
* @param bean The data with which to update the office visit.
* @throws DBException
* @throws ITrustException
*/
private void updateBean(OfficeVisitBean bean) throws DBException, ITrustException {
if (isUnsaved()) {
ovID = ovDAO.add(bean);
reinitializeSubActions();
} else {
ovDAO.update(bean);
}
}
}