Skip to content
Snippets Groups Projects
Commit 0bf0d424 authored by xuechen5's avatar xuechen5 Committed by adityab3
Browse files

Implement AddPreRegisterPatientAction when preregister form is submitted

parent 330be7bf
Branches UC91.1
No related tags found
1 merge request!3Uc91.1
......@@ -6,6 +6,10 @@ 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 Pre-registered Patient page (PreRegisterPatient.jsp). This just adds an empty patient, creates an entered password for
......@@ -27,23 +31,33 @@ public class AddPreRegisteredPatientAction {
* @param loggedInMID
*/
public AddPreRegisteredPatientAction(DAOFactory factory, long loggedInMID) {
this.patientDAO = factory.getPatientDAO();
this.loggedInMID = loggedInMID;
this.patientDAO = factory.getPatientDAO();
this.loggedInMID = loggedInMID;
this.authDAO = factory.getAuthDAO();
}
/**
* Creates a new patient, returns the new MID.
* Creates a new patient, returns the new MID. Adds a new user to the table with a
* preRegisteredPatient role
*
* @param p patient to be created
* @return the new MID of the patient
* @throws FormValidationException if the patient is not successfully validated
* @throws ITrustException
*/
public long addPatient(PatientBean p) {
// Add patient to DB
long newMID = 0L;
public long addPatient(PatientBean p) throws FormValidationException, ITrustException {
new AddPatientValidator().validate(p);
long newMID = patientDAO.addEmptyPatient(); // the new added row id in the database
p.setMID(newMID);
String pwd = authDAO.addUser(newMID, Role.PREREGISTEREDPATIENT, p.getPassword());
p.setPassword(pwd);
patientDAO.editPatient(p, loggedInMID);
return newMID;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment