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
package edu.ncsu.csc.itrust.action;
/**
* Used by PHAs to view the reported adverse events
*/
import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import edu.ncsu.csc.itrust.EmailUtil;
import edu.ncsu.csc.itrust.beans.AdverseEventBean;
import edu.ncsu.csc.itrust.beans.Email;
import edu.ncsu.csc.itrust.beans.MessageBean;
import edu.ncsu.csc.itrust.beans.PatientBean;
import edu.ncsu.csc.itrust.dao.DAOFactory;
import edu.ncsu.csc.itrust.dao.mysql.AdverseEventDAO;
import edu.ncsu.csc.itrust.dao.mysql.PatientDAO;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.exception.FormValidationException;
import edu.ncsu.csc.itrust.exception.ITrustException;
public class MonitorAdverseEventAction {
private long loggedInMID;
private EmailUtil emailer;
private PatientDAO patientDAO;
private AdverseEventDAO adverseEventDAO;
private SendMessageAction messenger;
/**
* Constructor
* @param factory
* @param loggedInMID
*/
public MonitorAdverseEventAction(DAOFactory factory, long loggedInMID){
this.loggedInMID = loggedInMID;
this.patientDAO = factory.getPatientDAO();
this.emailer = new EmailUtil(factory);
this.adverseEventDAO = factory.getAdverseEventDAO();
this.messenger = new SendMessageAction(factory, loggedInMID);
}
/**
* Returns a list of reports between specified dates
* @param isPrescription Boolean to return prescriptions or immunizations
* @param start The starting date
* @param end The ending date
* @return the list of events
* @throws ITrustException
* @throws FormValidationException
* @throws SQLException
* @throws ParseException
*/
public List<AdverseEventBean> getReports(boolean isPrescription, String start, String end)throws ITrustException, FormValidationException, SQLException, ParseException {
if(isPrescription) {
return adverseEventDAO.getPerscriptions(start, end);
} else { //is Immunization
return adverseEventDAO.getImmunizations(start, end);
}
}
/**
* Returns the patient's name
* @param MID the MID of the patient to return the name for.
* @return
*/
public String getName(long MID) {
try {
return patientDAO.getName(MID);
} catch(DBException e) {
return "";
} catch(ITrustException e) {
return "Patient no longer exists";
}
}
/**
* Sends an e-mail to a patient requesting more information
* @param patientMID The patient to receive the message
* @param message The message
* @return string for testing purposes
* @throws DBException
*/
public String sendEmail(long patientMID, String message) throws DBException{
String rValue;
List<String> toList = new ArrayList<String>();
PatientBean receiver = patientDAO.getPatient(patientMID);
toList.add(receiver.getEmail());
Email mail = new Email();
mail.setBody(message);
mail.setFrom(loggedInMID + "");
mail.setToList(toList);
emailer.sendEmail(mail);
rValue = "" + mail.getFrom() + " " + mail.getBody();
return rValue;
}
/**
* Method used to remove an adverse event report
*
* @param id the id of the report to be removed
* @throws DBException
* @throws ITrustException
*/
public void remove(int id) throws DBException, ITrustException, FormValidationException{
long HCPMID;
try{
AdverseEventBean aeBean = adverseEventDAO.getReport(id);
adverseEventDAO.removeReport(id);
HCPMID = adverseEventDAO.getHCPMID(id);
MessageBean mBeanTwo = new MessageBean();
MessageBean mBeanOne = new MessageBean();
String body = "An adverse event for " + aeBean.getDrug() + " perscribed to " + patientDAO.getName(Long.parseLong(aeBean.getMID())) +" with description: (" + aeBean.getDescription()+ ") was removed.";
mBeanOne.setTo(Long.parseLong(aeBean.getMID()));
mBeanTwo.setTo(HCPMID);
mBeanOne.setSubject("Subject");
mBeanTwo.setSubject("Subject");
mBeanOne.setBody(body);
mBeanTwo.setBody(body);
mBeanOne.setFrom(loggedInMID);
mBeanTwo.setFrom(loggedInMID);
messenger.sendMessage(mBeanOne);
messenger.sendMessage(mBeanTwo);
}catch(SQLException e){
throw new DBException(e);
}
}
}