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
package edu.ncsu.csc.itrust.action;
import java.util.List;
import edu.ncsu.csc.itrust.beans.PersonnelBean;
import edu.ncsu.csc.itrust.dao.DAOFactory;
import edu.ncsu.csc.itrust.dao.mysql.AuthDAO;
import edu.ncsu.csc.itrust.dao.mysql.PatientDAO;
import edu.ncsu.csc.itrust.enums.Role;
import edu.ncsu.csc.itrust.exception.ITrustException;
/**
* Used by the patient to declare HCPs as "designated", in editHCPs.jsp.
*
*
*/
public class DeclareHCPAction {
private PatientDAO patientDAO;
private AuthDAO authDAO;
private long loggedInMID;
/**
* Sets up defaults
*
* @param factory The DAO factory to be used for generating the DAOs for this action.
* @param loggedInMID
* This patient
*/
public DeclareHCPAction(DAOFactory factory, long loggedInMID) {
this.loggedInMID = loggedInMID;
this.patientDAO = factory.getPatientDAO();
this.authDAO = factory.getAuthDAO();
}
/**
* Lists the declared HCPs for this current patient
*
* @return Returns a list of the declared HCPs
* @throws ITrustException
*/
public List<PersonnelBean> getDeclaredHCPS() throws ITrustException {
return patientDAO.getDeclaredHCPs(loggedInMID);
}
/**
* Validate an HCP's MID and declare them, if possible
*
* @param hcpStr
* The MID of an HCP to declare
* @return A status message,
* @throws ITrustException
*/
public String declareHCP(String hcpStr) throws ITrustException {
try {
long hcpID = Long.valueOf(hcpStr);
if (authDAO.getUserRole(hcpID) != Role.HCP)
throw new ITrustException("This user is not a licensed healthcare professional!");
boolean confirm = patientDAO.declareHCP(loggedInMID, hcpID);
if (confirm) {
return "HCP successfully declared";
} else
return "HCP not declared";
} catch (NumberFormatException e) {
throw new ITrustException("HCP's MID not a number");
}
}
/**
* Validate an HCP's MID and undeclare them, if possible
*
* @param input
* The MID of an HCP to undeclare
* @return
* @throws ITrustException
*/
public String undeclareHCP(String input) throws ITrustException {
try {
long hcpID = Long.valueOf(input);
boolean confirm = patientDAO.undeclareHCP(loggedInMID, hcpID);
if (confirm) {
return "HCP successfully undeclared";
} else
return "HCP not undeclared";
} catch (NumberFormatException e) {
throw new ITrustException("HCP's MID not a number");
}
}
}