diff --git a/iTrust/src/edu/ncsu/csc/itrust/action/ActivateAndDeactivatePreRegi.java b/iTrust/src/edu/ncsu/csc/itrust/action/ActivateAndDeactivatePreRegi.java new file mode 100644 index 0000000000000000000000000000000000000000..c8eb65899a5ce1b0caad70b187edea6dfef44f24 --- /dev/null +++ b/iTrust/src/edu/ncsu/csc/itrust/action/ActivateAndDeactivatePreRegi.java @@ -0,0 +1,108 @@ +package edu.ncsu.csc.itrust.action; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import edu.ncsu.csc.itrust.action.base.PatientBaseAction; +import edu.ncsu.csc.itrust.beans.Email; +import edu.ncsu.csc.itrust.beans.PatientBean; +import edu.ncsu.csc.itrust.beans.PatientHistoryBean; +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.dao.mysql.PersonnelDAO; +import edu.ncsu.csc.itrust.exception.DBException; +import edu.ncsu.csc.itrust.exception.FormValidationException; +import edu.ncsu.csc.itrust.exception.ITrustException; +import edu.ncsu.csc.itrust.validate.PatientValidator; + + +/** + * Edits a patient Used by editPatient.jsp + * + * + */ +public class ActivateAndDeactivatePreRegi extends PatientBaseAction { + private PatientValidator validator = new PatientValidator(); + private PatientDAO patientDAO; + private PersonnelDAO personnelDAO; + private AuthDAO authDAO; + private long loggedInMID; + + + /** + * The super class validates the patient id + * + * @param factory The DAOFactory used to create the DAOs for this action. + * @param loggedInMID The MID of the user who is authorizing this action. + * @param pidString The MID of the patient being edited. + * @throws ITrustException + */ + public ActivateAndDeactivatePreRegi(DAOFactory factory, long loggedInMID, String pidString) throws ITrustException { + super(factory, pidString); + this.patientDAO = factory.getPatientDAO(); + this.personnelDAO = factory.getPersonnelDAO(); + this.authDAO = factory.getAuthDAO(); + this.loggedInMID = loggedInMID; + + } + + /** + * Takes the information out of the PatientBean param and updates the patient's information + * + * @param p + * the new patient information + * @throws ITrustException + * @throws FormValidationException + */ + public void updateInformation(PatientBean p) throws ITrustException, FormValidationException { + p.setMID(pid); // for security reasons + validator.validate(p); + patientDAO.editPatient(p, loggedInMID); + + } + + /** + * Returns a PatientBean for the patient + * + * @return the PatientBean + * @throws DBException + */ + public PatientBean getPatient() throws DBException { + return patientDAO.getPatient(this.getPid()); + } + + + + /** + * The DateOfDeactivationStr of the PatientBean when not null indicates that the user has been deactivated. + * @throws DBException + */ + public void deactivate() throws DBException{ + PatientBean p=patientDAO.getPatient(this.getPid()); + p.setMID(pid); + p.setDateOfDeactivationStr(new SimpleDateFormat("MM/dd/yyyy").format(Calendar.getInstance().getTime())); + patientDAO.editPatient(p, loggedInMID); + patientDAO.removeAllRepresented(pid); + patientDAO.removeAllRepresentee(pid); + } + + /** + * The DateOfDeactivationStr of the PatientBean is null when the patient is activated + * @throws DBException + */ + public long activate() throws DBException{ + PatientBean p=patientDAO.getPatient(this.getPid()); + p.setMID(pid); + p.setDateOfDeactivationStr(null); + //patientDAO.editPatient(p, loggedInMID); + patientDAO.ConvertPreRegisteredPatientsToPatient(this.getPid());//this.getPid());//411); //////////// this.getPid() + + return this.getPid(); + } + + + + +}