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
package edu.ncsu.csc.itrust.action;
import java.util.ArrayList;
import java.util.List;
import edu.ncsu.csc.itrust.EmailUtil;
import edu.ncsu.csc.itrust.beans.Email;
import edu.ncsu.csc.itrust.beans.PatientBean;
import edu.ncsu.csc.itrust.beans.PersonnelBean;
import edu.ncsu.csc.itrust.beans.PrescriptionBean;
import edu.ncsu.csc.itrust.dao.DAOFactory;
import edu.ncsu.csc.itrust.dao.mysql.PatientDAO;
import edu.ncsu.csc.itrust.dao.mysql.PersonnelDAO;
import edu.ncsu.csc.itrust.exception.ITrustException;
/**
* Handles retrieving beans for viewPrescriptionRecords.jsp
*
*
*/
public class ViewExpiredPrescriptionsAction {
private PatientDAO patientDAO;
private PersonnelDAO personnelDAO;
private EmailUtil emailer;
private long loggedInMID;
/**
* Set up defaults
*
* @param factory The DAOFactory used to create the DAOs used in this action.
* @param loggedInMID The MID of the person viewing the expired prescriptions.
*/
public ViewExpiredPrescriptionsAction(DAOFactory factory, long loggedInMID) {
this.emailer = new EmailUtil(factory);
this.patientDAO = factory.getPatientDAO();
this.personnelDAO = factory.getPersonnelDAO();
this.loggedInMID = loggedInMID;
}
/**
* Gets a PatientBean from an MID
*
* @param patientID MID of the patient
* @return PatientBean for the MID given
* @throws ITrustException
*/
public PatientBean getPatient(long patientID) throws ITrustException {
return patientDAO.getPatient(patientID);
}
/**
* Gets the logged in person's representees
*
* @return list of PatientBeans holding the representees
* @throws ITrustException
*/
public List<PatientBean> getRepresentees() throws ITrustException {
return patientDAO.getRepresented(loggedInMID);
}
/**
* Returns the prescribing HCP for a prescription
*
* @param prescription item in question
* @return HCP who prescribed the prescription
* @throws ITrustException
*/
public PersonnelBean getPrescribingDoctor(PrescriptionBean prescription) throws ITrustException {
return personnelDAO.getPrescribingDoctor(prescription);
}
/**
* Returns all the prescriptions for a given patient
*
* @param patientID patient in question
* @return list of all the prescriptions for that patient
* @throws ITrustException
*/
public List<PrescriptionBean> getPrescriptionsForPatient(long patientID) throws ITrustException {
PatientBean patient = patientDAO.getPatient(patientID);
if (loggedInMID == patientID) {
return patientDAO.getExpiredPrescriptions(patientID);
}
List<String> toList = new ArrayList<String>();
toList.add(patient.getEmail());
List<PatientBean> representatives = patientDAO.getRepresenting(patientID);
for(PatientBean representative : representatives) {
if (loggedInMID == representative.getMID()) {
return patientDAO.getExpiredPrescriptions(patientID);
}
toList.add(representative.getEmail());
}
List<PersonnelBean> dlhcps = patientDAO.getDeclaredHCPs(patientID);
for(PersonnelBean dlhcp : dlhcps) {
if (loggedInMID == dlhcp.getMID()) {
return patientDAO.getExpiredPrescriptions(patientID);
}
List<PersonnelBean> uaps = personnelDAO.getUAPsForHCP(dlhcp.getMID());
for(PersonnelBean uap : uaps) {
if (loggedInMID == uap.getMID()) {
return patientDAO.getPrescriptions(patientID);
}
}
}
Email email = new Email();
email.setToList(toList);
email.setFrom("noreply@itrust.com");
email.setSubject("Undesignated Personnel Have Accessed Your Prescription Records");
email.setBody("An undesignated HCP or UAP has accessed your prescription records. For more information, please log in to iTrust.");
emailer.sendEmail(email);
return patientDAO.getPrescriptions(patientID);
}
}