public void testRemoveAllRepresented() throws Exception {
    // 2 represents 1, but not 4
    gen.patient1();
    gen.patient4();

    // Add patient 4 to be represented by patient 2
    patientDAO.addRepresentative(2L, 4L);

    // Ensure the representatives were added correctly
    assertEquals(2, patientDAO.getRepresented(2L).size());

    // Remove all patient's from being represented by patient 2
    patientDAO.removeAllRepresented(2L);
    // Assert that no more patients are represented by patient 2
    assertTrue(patientDAO.getRepresented(2L).isEmpty());

    // Test with an evil factory
    patientDAO = new PatientDAO(EvilDAOFactory.getEvilInstance());

    try {
      patientDAO.removeAllRepresented(2L);
      fail("Exception should be caught");
    } catch (DBException e) {
      // Successful test
    }
  }
Exemplo n.º 2
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.º 3
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.º 4
0
 public void testAddExistingRepresentative() throws Exception {
   patientDAO.addRepresentative(1L, 2L);
   try {
     patientDAO.addRepresentative(1L, 2L);
     fail("exception should have been thrown");
   } catch (iTrustException e) {
     assertEquals("Patient 1 already represents patient 2", e.getMessage());
   }
 }
  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()));
  }
Exemplo n.º 7
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();
 }
Exemplo n.º 8
0
 /**
  * Checks to see if a particular family member has heart disease
  *
  * @param member the family member to check
  * @return true if the family member has heart disease. False if there are no records or the
  *     family member does not
  * @throws ITrustException
  */
 public boolean doesFamilyMemberHaveHeartDisease(FamilyMemberBean member) throws ITrustException {
   List<DiagnosisBean> diagnoses = patientDAO.getDiagnoses(member.getMid());
   if (diagnoses.size() == 0) return false;
   for (DiagnosisBean diag : diagnoses) {
     if (diag.getICDCode().startsWith("402")) return true;
   }
   return false;
 }
Exemplo n.º 9
0
  public boolean setDependent(boolean dependency) {
    try {
      authDAO.setDependent(pid, dependency);
      if (dependency) patientDAO.removeAllRepresented(pid);
    } catch (DBException e) {
      // If a DBException occurs print a stack trace and return false
      e.printStackTrace();
      return false;
    }

    return true;
  }
  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());
  }
Exemplo n.º 11
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;
  }
  /**
   * 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.º 13
0
 /**
  * Super class validates the patient id
  *
  * @param factory The DAOFactory to be used in creating DAOs for this action.
  * @param loggedInMID The MID of the currently logged in user who is authorizing this action.
  * @param pidString The MID of the patient whose personal health records are being added.
  * @throws ITrustException
  * @throws NoHealthRecordsException
  */
 public EditPHRAction(DAOFactory factory, long loggedInMID, String pidString)
     throws ITrustException {
   super(factory, pidString);
   this.patientDAO = factory.getPatientDAO();
   this.allergyDAO = factory.getAllergyDAO();
   this.familyDAO = factory.getFamilyDAO();
   this.hrDAO = factory.getHealthRecordsDAO();
   this.ovDAO = factory.getOfficeVisitDAO();
   this.icdDAO = factory.getICDCodesDAO();
   this.personnelDAO = factory.getPersonnelDAO();
   this.HCPUAP = personnelDAO.getPersonnel(loggedInMID);
   this.patient = patientDAO.getPatient(pid);
   this.procDAO = factory.getProceduresDAO();
   this.ndcodesDAO = factory.getNDCodesDAO(); // NEW
   this.loggingAction = new EventLoggingAction(factory);
   emailutil = new EmailUtil(factory);
   this.factory = factory;
 }
Exemplo n.º 14
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;
  }
Exemplo n.º 15
0
 public void testRepresentsFalse() throws Exception {
   assertFalse(patientDAO.represents(1L, 2L));
 }
Exemplo n.º 16
0
 public void testRepresentsTrue() throws Exception {
   assertTrue(patientDAO.represents(2L, 1L));
 }
Exemplo n.º 17
0
 public void testGetNonExistentRepresented() throws Exception {
   assertEquals(0, patientDAO.getRepresented(500L).size());
 }
Exemplo n.º 18
0
 public void testGetRepresented() throws Exception {
   List<PatientBean> rep = patientDAO.getRepresented(2L);
   assertEquals(1, rep.size());
   assertEquals(1L, rep.get(0).getMID());
 }
Exemplo n.º 19
0
 /**
  * Get the patient name associated with the given referral.
  *
  * @param bean
  * @return The patient's name as a String.
  * @throws iTrustException
  */
 public String getPatientName(ReferralBean bean) throws iTrustException {
   return patientDAO.getName(bean.getPatientID());
 }
Exemplo n.º 20
0
 /**
  * Returns a PatientBean for the patient
  *
  * @return the PatientBean
  * @throws DBException
  */
 public PatientBean getPatient() throws DBException {
   return patientDAO.getPatient(this.getPid());
 }
Exemplo n.º 21
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()
                + "\"!");
      }
    }
  }
Exemplo n.º 22
0
 public void testAddRepresentative() throws Exception {
   assertEquals(0, patientDAO.getRepresented(1L).size());
   patientDAO.addRepresentative(1L, 2L);
   assertEquals(1, patientDAO.getRepresented(1L).size());
 }
Exemplo n.º 23
0
 public List<PatientHistoryBean> getHistory() throws DBException {
   return patientDAO.getPatientHistory(this.getPid());
 }
Exemplo n.º 24
0
 public void testRemoveRepresentative() throws Exception {
   assertEquals(1, patientDAO.getRepresented(2L).size());
   boolean confirm = patientDAO.removeRepresentative(2L, 1L);
   assertEquals(0, patientDAO.getRepresented(2L).size());
   assertTrue(confirm);
 }
 protected void setUp() throws Exception {
   gen.clearAllTables();
   gen.standardData();
   allPatients = pDAO.getAllPatients();
 }
 /**
  * Return a list of patients that pid represents
  *
  * @param pid The id of the personnel we are looking up representees for.
  * @return a list of PatientBeans
  * @throws ITrustException
  */
 public List<PatientBean> getRepresented(long pid) throws ITrustException {
   return patientDAO.getRepresented(pid);
 }
Exemplo n.º 27
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.º 28
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.º 29
0
 public void testRemoveNonExistingRepresentative() throws Exception {
   assertEquals(1, patientDAO.getRepresented(2L).size());
   boolean confirm = patientDAO.removeRepresentative(2L, 3L);
   assertEquals(1, patientDAO.getRepresented(2L).size());
   assertFalse(confirm);
 }
Exemplo n.º 30
0
 public boolean hasHistory() throws DBException {
   return patientDAO.hasHistory(this.getPid());
 }