/**
  * 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);
 }
  public void testGetPatientHistory() throws Exception {
    PatientBean p = patientDAO.getPatient(2);
    p.setFirstName("Person1");
    p.setEmail("another email");
    p.setEmergencyName("another emergency person");
    p.setTopicalNotes("some topical notes");
    p.setDateOfBirthStr("05/20/1984");
    patientDAO.editPatient(p, 9000000003L);

    List<PatientHistoryBean> pList = patientDAO.getPatientHistory(p.getMID());
    assertEquals(pList.size(), 1);
    assertEquals("Person1", pList.get(0).getFirstName());
    assertEquals(9000000003L, pList.get(0).getChangeMID());
  }
  public void testHasHistory() throws Exception {
    PatientBean p = patientDAO.getPatient(2);

    assertFalse(patientDAO.hasHistory(p.getMID()));

    p.setFirstName("Person1");
    p.setEmail("another email");
    p.setEmergencyName("another emergency person");
    p.setTopicalNotes("some topical notes");
    p.setDateOfBirthStr("05/20/1984");
    patientDAO.editPatient(p, 9000000003L);

    assertTrue(patientDAO.hasHistory(p.getMID()));
  }
  public void testEditPatient2() throws Exception {
    PatientBean p = patientDAO.getPatient(2);
    p.setFirstName("Person1");
    p.setEmail("another email");
    p.setEmergencyName("another emergency person");
    p.setTopicalNotes("some topical notes");
    p.setDateOfBirthStr("05/20/1984");
    p.setDateOfDeactivationStr("05/21/1984");
    patientDAO.editPatient(p, 9000000003L);

    p = patientDAO.getPatient(2);
    assertEquals("Person1", p.getFirstName());
    assertEquals("Programmer", p.getLastName());
    assertEquals("another email", p.getEmail());
    assertEquals("another emergency person", p.getEmergencyName());
    assertEquals("some topical notes", p.getTopicalNotes());
    assertEquals("05/20/1984", p.getDateOfBirthStr());
    assertEquals("05/21/1984", p.getDateOfDeactivationStr());
    assertEquals("250.10", p.getCauseOfDeath());
    assertEquals("344 Bob Street", p.getStreetAddress1());
    assertEquals("", p.getStreetAddress2());
    assertEquals("Raleigh", p.getCity());
    assertEquals("NC", p.getState());
    assertEquals("27607", p.getZip());
    assertEquals("555-555-5555", p.getPhone());
    assertEquals("555-555-5551", p.getEmergencyPhone());
    assertEquals("IC", p.getIcName());
    assertEquals("Street1", p.getIcAddress1());
    assertEquals("Street2", p.getIcAddress2());
    assertEquals("City", p.getIcCity());
    assertEquals("PA", p.getIcState());
    assertEquals("19003-2715", p.getIcZip());
    assertEquals("555-555-5555", p.getIcPhone());
    assertEquals("1", p.getIcID());
    assertEquals("1", p.getMotherMID());
    assertEquals("0", p.getFatherMID());
    assertEquals("O-", p.getBloodType().getName());
    assertEquals(Ethnicity.Caucasian, p.getEthnicity());
    assertEquals(Gender.Male, p.getGender());
  }
 /**
  * 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);
   emailutil.sendEmail(makeEmail());
 }
 /**
  * The DateOfDeactivationStr of the PatientBean is null when the patient is activated
  *
  * @throws DBException
  */
 public void activate() throws DBException {
   PatientBean p = patientDAO.getPatient(this.getPid());
   p.setMID(pid);
   p.setDateOfDeactivationStr(null);
   patientDAO.editPatient(p, loggedInMID);
 }
  /**
   * Creates the patients and adds them to the DB
   *
   * @throws DBException
   * @throws AddPatientFileExceptionTest
   */
  private void createPatients() throws DBException, AddPatientFileException {
    for (int i = 0; i < CSVData.size(); i++) {
      PatientBean temp = new PatientBean();

      temp.setFirstName(
          CSVData.get(i)
              .get(requiredFieldsMapping[Arrays.asList(requiredFields).indexOf("firstName")]));
      temp.setLastName(
          CSVData.get(i)
              .get(requiredFieldsMapping[Arrays.asList(requiredFields).indexOf("lastName")]));
      temp.setEmail(
          CSVData.get(i)
              .get(requiredFieldsMapping[Arrays.asList(requiredFields).indexOf("email")]));

      try {
        temp.setStreetAddress1(
            CSVData.get(i)
                .get(validFieldsMapping[Arrays.asList(validFields).indexOf("streetAddress1")]));
      } catch (NullPointerException e) {
      }
      try {
        temp.setStreetAddress2(
            CSVData.get(i)
                .get(validFieldsMapping[Arrays.asList(validFields).indexOf("streetAddress2")]));
      } catch (NullPointerException e) {
      }
      try {
        temp.setCity(
            CSVData.get(i).get(validFieldsMapping[Arrays.asList(validFields).indexOf("city")]));
      } catch (NullPointerException e) {
      }
      try {
        temp.setState(
            CSVData.get(i).get(validFieldsMapping[Arrays.asList(validFields).indexOf("state")]));
      } catch (NullPointerException e) {
      }
      try {
        temp.setZip(
            CSVData.get(i).get(validFieldsMapping[Arrays.asList(validFields).indexOf("zip")]));
      } catch (NullPointerException e) {
      }
      try {
        temp.setPhone(
            CSVData.get(i).get(validFieldsMapping[Arrays.asList(validFields).indexOf("phone")]));
      } catch (NullPointerException e) {
      }
      try {
        temp.setMotherMID(
            CSVData.get(i)
                .get(validFieldsMapping[Arrays.asList(validFields).indexOf("motherMID")]));
      } catch (NullPointerException e) {
      }
      try {
        temp.setFatherMID(
            CSVData.get(i)
                .get(validFieldsMapping[Arrays.asList(validFields).indexOf("fatherMID")]));
      } catch (NullPointerException e) {
      }
      try {
        temp.setCreditCardType(
            CSVData.get(i)
                .get(validFieldsMapping[Arrays.asList(validFields).indexOf("creditCardType")]));
      } catch (NullPointerException e) {
      }
      try {
        temp.setCreditCardNumber(
            CSVData.get(i)
                .get(validFieldsMapping[Arrays.asList(validFields).indexOf("creditCardNumber")]));
      } catch (NullPointerException e) {
      }

      try {
        new AddPatientValidator().validate(temp);
        new PatientValidator().validate(temp);
        if (patientDAO != null) {
          long newMID = patientDAO.addEmptyPatient();
          temp.setMID(newMID);
          String pwd = authDAO.addUser(newMID, Role.PATIENT, RandomPassword.getRandomPassword());
          temp.setPassword(pwd);
          patientDAO.editPatient(temp, loggedInMID);
        }
        patients.add(temp);
      } catch (FormValidationException e) {
        for (int j = 0; j < e.getErrorList().size(); j++) {
          System.out.println(e.getErrorList().get(j));
        }
        errors.addIfNotNull(
            "Input validation failed for patient \""
                + temp.getFirstName()
                + " "
                + temp.getLastName()
                + "\"!");
      }
    }
  }