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
package edu.ncsu.csc.itrust.action;
import java.util.Arrays;
import java.util.List;
import edu.ncsu.csc.itrust.EmailUtil;
import edu.ncsu.csc.itrust.beans.Email;
import edu.ncsu.csc.itrust.beans.LabProcedureBean;
import edu.ncsu.csc.itrust.beans.PatientBean;
import edu.ncsu.csc.itrust.dao.DAOFactory;
import edu.ncsu.csc.itrust.dao.mysql.LabProcedureDAO;
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.validate.LabProcedureValidator;
/**
* Class for LabProcUAP.jsp. Handles lab procedures for UAPs
*/
public class LabProcUAPAction {
private LabProcedureDAO lpDAO;
long loggedInMID;
private LabProcedureValidator validator;
private DAOFactory factory;
/**
* Setup
* @param factory The DAOFactory used to create the DAOs used in this action.
* @param loggedInMID UAP who is logged in
*/
public LabProcUAPAction(DAOFactory factory, long loggedInMID) {
factory.getTransactionDAO();
lpDAO = factory.getLabProcedureDAO();
this.loggedInMID = loggedInMID;
validator = new LabProcedureValidator();
this.factory = factory;
}
/**
* Updates a lab procedure
*
* @param b the procedure to update
* @throws DBException
* @throws FormValidationException
*/
public void updateProcedure(LabProcedureBean b) throws DBException, FormValidationException{
validator.validate(b);
//need to check if status is what's being changed - if new status!=old status send email
if(!b.getStatus().equals(lpDAO.getLabProcedure(b.getProcedureID()).getStatus())){
new EmailUtil(factory).sendEmail(makeEmail(b));
}
lpDAO.updateLabProcedure(b);
}
/**
* Sends an e-mail informing the patient that their procedure has been updated
*
* @param b the procedure that was updated
* @return an e-mail to the patient with the notice
* @throws DBException
*/
private Email makeEmail(LabProcedureBean b) throws DBException{
PatientBean p = new PatientDAO(factory).getPatient(b.getPid());
Email email = new Email();
email.setFrom("no-reply@itrust.com");
email.setToList(Arrays.asList(p.getEmail()));
email.setSubject("A Lab Procedure Was Updated");
email.setBody(String.format("Dear %s, %n Your Lab Procedure (%s) has a new updated status of %s. Log on to iTrust to view.", p.getFullName(), b.getLoinc(), b.getStatus()));
return email;
}
/**
* Returns a list of all the lab procedures for a particular patient.
*
* @param id MID of the UAP viewing the procedures
* @return a list of all the lab procedures for that UAP
* @throws DBException
*/
public List<LabProcedureBean> viewProcedures(long id) throws DBException {
return lpDAO.getAllLabProceduresDate(id);
}
/**
* Returns a list of the lab procedures associated with both the HCP and
* the given patient.
*
* @param pid The id of the patient.
* @return A list of lab procedures.
* @throws DBException
*/
public List<LabProcedureBean> viewPatientProcedures(long pid) throws DBException {
return lpDAO.getLabProcedures(loggedInMID, pid);
}
}