Exemplo n.º 1
0
  @Test
  public void testGetPatient() {
    PatientBean bean1 = null;
    try {
      bean1 = action.getPatient("2");
    } catch (ITrustException e) {
      fail();
    }
    if (bean1 == null) fail();
    assertEquals(bean1.getMID(), 2L); // and just test that the right record came back

    PatientBean bean2 = null;
    try {
      bean2 = action.getPatient("1");
    } catch (ITrustException e) {
      assertNull(bean2);
    }

    PatientBean bean3 = null;
    try {
      bean3 = action.getPatient("a");
    } catch (ITrustException e) {
      assertNull(bean3);
    }
  }
Exemplo n.º 2
0
 /**
  * Checks to see if the family member is dead and returns their cause of death if so
  *
  * @param member the family member to check
  * @return the cause of death if there is one; otherwise null
  * @throws ITrustException
  */
 public String getFamilyMemberCOD(FamilyMemberBean member) throws ITrustException {
   PatientBean patient = patientDAO.getPatient(member.getMid());
   if (patient.getCauseOfDeath() == null) return "";
   DiagnosisBean diag = icdDAO.getICDCode(patient.getCauseOfDeath());
   if (diag == null) return "";
   return diag.getDescription();
 }
  public void testGetPatient() throws iTrustException {
    PatientBean pBean = action.getPatient();
    assertEquals(2L, pBean.getMID());

    pBean = action.getPatient(2L);
    assertEquals(2L, pBean.getMID());
  }
Exemplo n.º 4
0
 /**
  * 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);
 }
Exemplo n.º 5
0
  /**
   * Sends an e-mail informing the patient that their procedure has been updated
   *
   * @param b the procedure that was updated
   * @return an e-mail to the patient with the notice
   * @throws DBException
   */
  private Email makeEmail(LabProcedureBean b) throws DBException {

    PatientBean p = new PatientDAO(factory).getPatient(b.getPid());

    Email email = new Email();
    email.setFrom("*****@*****.**");
    email.setToList(Arrays.asList(p.getEmail()));
    email.setSubject("A Lab Procedure Was Updated");
    email.setBody(
        String.format(
            "Dear %s, \n Your Lab Procedure (%s) has a new updated status of %s. Log on to iTrust to view.",
            p.getFullName(), b.getLoinc(), b.getStatus()));
    return email;
  }
  /**
   * Returns a list of TransactionBeans between the two dates passed as params
   *
   * @param lowerDate the first date
   * @param upperDate the second date
   * @return list of TransactionBeans
   * @throws DBException
   * @throws FormValidationException
   */
  public List<TransactionBean> getAccesses(
      String lowerDate, String upperDate, String logMID, boolean getByRole)
      throws ITrustException, DBException, FormValidationException {
    List<TransactionBean> accesses; // stores the log entries
    List<PersonnelBean> dlhcps;

    // get the medical dependents for a signed in user. If the selected user is not the
    // signed in user or one of the dependents, then the user doesn't have access to the log
    List<PatientBean> patientRelatives = getRepresented(loggedInMID);

    long mid = loggedInMID;
    try {
      mid = Long.parseLong(logMID);
    } catch (Exception e) {
      // TODO
    }

    dlhcps = patientDAO.getDeclaredHCPs(mid);

    boolean midInScope = false;
    for (PatientBean pb : patientRelatives) {
      if (pb.getMID() == mid) midInScope = true;
    }
    if (mid != loggedInMID
        && !midInScope) { // the selected user in the form is out of scope and can't be shown to the
                          // user
      throw new FormValidationException("Log to View.");
    }

    // user has either 0 or 1 DLHCP's. Get one if exists so it can be filtered from results
    long dlhcpID = -1;
    if (!dlhcps.isEmpty()) dlhcpID = dlhcps.get(0).getMID();

    if (lowerDate == null || upperDate == null)
      return transDAO.getAllRecordAccesses(mid, dlhcpID, getByRole);

    try {
      Date lower = new SimpleDateFormat("MM/dd/yyyy").parse(lowerDate);
      Date upper = new SimpleDateFormat("MM/dd/yyyy").parse(upperDate);

      if (lower.after(upper))
        throw new FormValidationException("Start date must be before end date!");
      accesses = transDAO.getRecordAccesses(mid, dlhcpID, lower, upper, getByRole);
    } catch (ParseException e) {
      throw new FormValidationException("Enter dates in MM/dd/yyyy");
    }
    return accesses;
  }
Exemplo n.º 7
0
  /**
   * Adds an allergy to the patient's records
   *
   * @param pid pid
   * @param ndcode ndcode
   * @return "Allergy Added", exception message, a list of invalid fields, or "" (only if
   *     description is null)
   * @throws FormValidationException
   * @throws ITrustException
   */
  public String updateAllergies(long pid, String description)
      throws FormValidationException, ITrustException {
    AllergyBean bean = new AllergyBean();
    bean.setPatientID(pid);
    bean.setDescription(description);
    AllergyBeanValidator abv = new AllergyBeanValidator();
    abv.validate(bean);

    // now, set the ndcode if it happens to exist for the description
    for (MedicationBean med : ndcodesDAO.getAllNDCodes()) {
      if (med.getDescription().equalsIgnoreCase(bean.getDescription())) {
        bean.setNDCode(med.getNDCode());
        break;
      }
    }

    String patientName = patientDAO.getName(pid);
    List<AllergyBean> allergies = allergyDAO.getAllergies(pid);
    for (AllergyBean current : allergies) {
      if (current.getDescription().equalsIgnoreCase(bean.getDescription())) {
        return "Allergy "
            + bean.getNDCode()
            + " - "
            + bean.getDescription()
            + " has already been added for "
            + patientName
            + ".";
      }
    }

    allergyDAO.addAllergy(bean);
    emailutil.sendEmail(makeEmail());
    /*
     * adding loop that checks for allergy conflicts. The loop runs through every prescription bean
     * and checks for conflict.
     */
    List<PrescriptionBean> beansRx = patientDAO.getCurrentPrescriptions(pid);
    for (int i = 0; i < beansRx.size(); i++) {
      if (beansRx.get(i).getMedication().getNDCode().equals(bean.getNDCode())) {
        return "Medication "
            + beansRx.get(i).getMedication().getNDCode()
            + " - "
            + beansRx.get(i).getMedication().getDescription()
            + " is currently prescribed to "
            + patientName
            + ".";
      }
    }

    // log that this was added
    loggingAction.logEvent(
        TransactionType.parse(6700),
        HCPUAP.getMID(),
        patient.getMID(),
        "An allergy record has been added: " + bean.getId());

    return "Allergy Added"; // If loop is successful, it will never reach here.
  }
Exemplo n.º 8
0
  /**
   * Creates a fake e-mail to notify the user that their records have been altered.
   *
   * @return the e-mail to be sent
   * @throws DBException
   */
  private Email makeEmail() throws DBException {

    Email email = new Email();
    List<PatientBean> reps = patientDAO.getRepresenting(patient.getMID());

    List<String> toAddrs = new ArrayList<String>();
    toAddrs.add(patient.getEmail());
    for (PatientBean r : reps) {
      toAddrs.add(r.getEmail());
    }

    email.setFrom("*****@*****.**");
    email.setToList(toAddrs); // patient and personal representative
    email.setSubject(String.format("Your medical records have been altered"));
    email.setBody(
        "Health care professional "
            + HCPUAP.getFullName()
            + " has altered your medical records. "
            + "She is not on your list of designated health care professionals.");
    return email;
  }
  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()));
  }
Exemplo n.º 10
0
  /**
   * Creates and e-mail to inform the patient that their information has been updated.
   *
   * @return the email with the notice
   * @throws DBException
   */
  private Email makeEmail() throws DBException {

    Email email = new Email();
    List<PatientBean> reps = patientDAO.getRepresenting(pid);
    PatientBean pb = patientDAO.getPatient(pid);

    List<String> toAddrs = new ArrayList<String>();
    toAddrs.add(pb.getEmail());
    for (PatientBean r : reps) {
      toAddrs.add(r.getEmail());
    }

    email.setFrom("*****@*****.**");
    email.setToList(toAddrs); // patient and personal representative
    email.setSubject(String.format("Patient Information Updated"));
    email.setBody(
        "Dear "
            + pb.getFullName()
            + ",\n\tYour patient record information has been updated. "
            + "Please login to iTrust to see who has viewed your records.");
    return email;
  }
  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());
  }
Exemplo n.º 12
0
 /**
  * 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());
 }
Exemplo n.º 13
0
 /**
  * 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);
 }
Exemplo n.º 14
0
  /**
   * 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()
                + "\"!");
      }
    }
  }
  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());
  }
 private void assertIsPatient2(PatientBean p) {
   assertEquals(2L, p.getMID());
   assertEquals("Andy", p.getFirstName());
   assertEquals("Programmer", p.getLastName());
   assertEquals("05/19/1984", p.getDateOfBirthStr());
   assertEquals("250.10", p.getCauseOfDeath());
   assertEquals("*****@*****.**", p.getEmail());
   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("Mr Emergency", p.getEmergencyName());
   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());
   assertEquals("This person is absolutely crazy. Do not touch them.", p.getTopicalNotes());
 }
 public void testManyInfectionsDuringChildhood() throws Exception {
   addInfection(new SimpleDateFormat("MM/dd/yyyy").parse(p.getDateOfBirthStr()), 250.3);
   addInfection(new SimpleDateFormat("MM/dd/yyyy").parse(p.getDateOfBirthStr()), 487);
   assertTrue(factor.hasRiskFactor());
 }