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
package edu.ncsu.csc.itrust.action;
import edu.ncsu.csc.itrust.RandomPassword;
import edu.ncsu.csc.itrust.beans.PatientBean;
import edu.ncsu.csc.itrust.dao.DAOFactory;
import edu.ncsu.csc.itrust.dao.mysql.PatientDAO;
import edu.ncsu.csc.itrust.dao.mysql.AuthDAO;
import edu.ncsu.csc.itrust.enums.Role;
import edu.ncsu.csc.itrust.exception.FormValidationException;
import edu.ncsu.csc.itrust.exception.ITrustException;
import edu.ncsu.csc.itrust.validate.AddPatientValidator;
/**
* Used for Add Patient page (addPatient.jsp). This just adds an empty patient, creates a random password for
* that patient.
*
* Very similar to {@link AddOfficeVisitAction}
*
*
*/
public class AddPatientAction {
private PatientDAO patientDAO;
private AuthDAO authDAO;
private long loggedInMID;
/**
* Just the factory and logged in MID
*
* @param factory
* @param loggedInMID
*/
public AddPatientAction(DAOFactory factory, long loggedInMID) {
this.patientDAO = factory.getPatientDAO();
this.loggedInMID = loggedInMID;
this.authDAO = factory.getAuthDAO();
}
/**
* Creates a new patient, returns the new MID. Adds a new user to the table with a
* specified dependency
*
* @param p patient to be created
* @param isDependent true if the patient is to be a dependent, false otherwise
* @return the new MID of the patient
* @throws FormValidationException if the patient is not successfully validated
* @throws ITrustException
*/
public long addDependentPatient(PatientBean p, long repId) throws FormValidationException, ITrustException {
new AddPatientValidator().validate(p);
long newMID = patientDAO.addEmptyPatient();
boolean isDependent = true;
p.setMID(newMID);
String pwd = authDAO.addUser(newMID, Role.PATIENT, RandomPassword.getRandomPassword());
patientDAO.addRepresentative(repId, newMID);
authDAO.setDependent(newMID, isDependent);
p.setPassword(pwd);
patientDAO.editPatient(p, loggedInMID);
return newMID;
}
public long addPatient(PatientBean p) throws FormValidationException, ITrustException {
new AddPatientValidator().validate(p);
long newMID = patientDAO.addEmptyPatient();
p.setMID(newMID);
String pwd = authDAO.addUser(newMID, Role.PATIENT, RandomPassword.getRandomPassword());
p.setPassword(pwd);
patientDAO.editPatient(p, loggedInMID);
return newMID;
}
}