Skip to content
Snippets Groups Projects
Commit 038e14cc authored by xuechen5's avatar xuechen5
Browse files

Backend: Activate and Deactivate a Pre-Registered Patient

parent ba8159b3
No related branches found
No related tags found
2 merge requests!22Merge UC92 into Master,!15Merge 5-uc-92-activate-pre-registered-patient-2 into UC92v2
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();
}
}
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