Skip to content
Snippets Groups Projects
Commit 689c9fee authored by adityab3's avatar adityab3
Browse files

[backend] added health info logic to preregister action

parent eb974966
No related branches found
No related tags found
1 merge request!6Uc91v2
package edu.ncsu.csc.itrust.action; package edu.ncsu.csc.itrust.action;
import edu.ncsu.csc.itrust.RandomPassword;
import edu.ncsu.csc.itrust.beans.PatientBean; import edu.ncsu.csc.itrust.beans.PatientBean;
import java.io.PrintWriter;
import java.io.StringWriter;
import edu.ncsu.csc.itrust.beans.HealthRecord;
import edu.ncsu.csc.itrust.beans.forms.HealthRecordForm;
import edu.ncsu.csc.itrust.dao.DAOFactory; import edu.ncsu.csc.itrust.dao.DAOFactory;
import edu.ncsu.csc.itrust.dao.mysql.PatientDAO; import edu.ncsu.csc.itrust.dao.mysql.PatientDAO;
import edu.ncsu.csc.itrust.dao.mysql.AuthDAO; import edu.ncsu.csc.itrust.dao.mysql.AuthDAO;
import edu.ncsu.csc.itrust.dao.mysql.HealthRecordsDAO;
import edu.ncsu.csc.itrust.enums.Role; import edu.ncsu.csc.itrust.enums.Role;
import edu.ncsu.csc.itrust.exception.DBException;
import edu.ncsu.csc.itrust.exception.FormValidationException; import edu.ncsu.csc.itrust.exception.FormValidationException;
import edu.ncsu.csc.itrust.exception.ITrustException; import edu.ncsu.csc.itrust.exception.ITrustException;
import edu.ncsu.csc.itrust.validate.AddPatientValidator; import edu.ncsu.csc.itrust.validate.AddPatientValidator;
import edu.ncsu.csc.itrust.validate.HealthRecordFormValidator;
/** /**
* Used for Add Pre-registered Patient page (PreRegisterPatient.jsp). This just adds an empty patient, creates an entered password for * Used for Add Pre-registered Patient page (PreRegisterPatient.jsp). This just adds an empty patient, creates an entered password for
...@@ -22,7 +29,8 @@ import edu.ncsu.csc.itrust.validate.AddPatientValidator; ...@@ -22,7 +29,8 @@ import edu.ncsu.csc.itrust.validate.AddPatientValidator;
public class AddPreRegisteredPatientAction { public class AddPreRegisteredPatientAction {
private PatientDAO patientDAO; private PatientDAO patientDAO;
private AuthDAO authDAO; private AuthDAO authDAO;
private long loggedInMID; private long loggedInMID;
private HealthRecordsDAO healthDAO;
/** /**
* Just the factory and logged in MID * Just the factory and logged in MID
...@@ -33,7 +41,8 @@ public class AddPreRegisteredPatientAction { ...@@ -33,7 +41,8 @@ public class AddPreRegisteredPatientAction {
public AddPreRegisteredPatientAction(DAOFactory factory, long loggedInMID) { public AddPreRegisteredPatientAction(DAOFactory factory, long loggedInMID) {
this.patientDAO = factory.getPatientDAO(); this.patientDAO = factory.getPatientDAO();
this.loggedInMID = loggedInMID; this.loggedInMID = loggedInMID;
this.authDAO = factory.getAuthDAO(); this.authDAO = factory.getAuthDAO();
this.healthDAO = factory.getHealthRecordsDAO();
} }
/** /**
...@@ -47,9 +56,9 @@ public class AddPreRegisteredPatientAction { ...@@ -47,9 +56,9 @@ public class AddPreRegisteredPatientAction {
*/ */
public long addPatient(PatientBean p) throws FormValidationException, ITrustException { public long addPatient(PatientBean p, HealthRecordForm h) throws FormValidationException, ITrustException {
new AddPatientValidator().validate(p); new AddPatientValidator().validate(p);
new HealthRecordFormValidator().validatePreregistration(h);
// Make sure the email is unique // Make sure the email is unique
if (patientDAO.isEmailInUse(p.getEmail())) { if (patientDAO.isEmailInUse(p.getEmail())) {
...@@ -62,7 +71,24 @@ public class AddPreRegisteredPatientAction { ...@@ -62,7 +71,24 @@ public class AddPreRegisteredPatientAction {
String pwd = authDAO.addUser(newMID, Role.PREREGISTEREDPATIENT, p.getPassword()); String pwd = authDAO.addUser(newMID, Role.PREREGISTEREDPATIENT, p.getPassword());
p.setPassword(pwd); p.setPassword(pwd);
patientDAO.editPatient(p, loggedInMID); patientDAO.editPatient(p, loggedInMID);
return newMID;
} // Convert the HealthRecordForm into a HeathRecord
HealthRecord r = formToRecord(h, newMID);
healthDAO.add(r);
return newMID;
}
// TODO: this is taken directly from EditHealthAction.java (DRY)
private HealthRecord formToRecord(HealthRecordForm form, long pid) {
HealthRecord record = new HealthRecord();
record.setPatientID(pid);
if (!"".equals(form.getHeight()))
record.setHeight(Double.parseDouble(form.getHeight()));
if (!"".equals(form.getWeight()))
record.setWeight(Double.parseDouble(form.getWeight()));
record.setSmoker(Integer.parseInt(form.getIsSmoker()));
return record;
}
} }
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