Exemplo n.º 1
0
    public void LoadFile(
        InputStream fileContent,
        DAOFactory factory,
        EventLoggingAction loggingAction,
        long loggedInMID)
        throws IOException, DBException {
      NDCodesDAO ndcodesDAO = factory.getNDCodesDAO();
      Scanner fileScanner = new Scanner(fileContent);
      while (fileScanner.hasNextLine()) {
        String ndCodeWithDash;
        MedicationBean bean = new MedicationBean();
        StringTokenizer tok = new StringTokenizer(fileScanner.nextLine(), "\t");
        ndCodeWithDash = tok.nextToken();
        String parts[] = ndCodeWithDash.split("-");

        // Skip drug type field
        tok.nextToken();

        bean.setNDCode(parts[0].concat(parts[1]));
        bean.setDescription(tok.nextToken());
        try {
          ndcodesDAO.addNDCode(bean);
          loggingAction.logEvent(
              TransactionType.DRUG_CODE_ADD,
              loggedInMID,
              0,
              "" + bean.getNDCode() + bean.getDescription());
        } catch (Exception e) {
          // We just want to skip duplicate-entries. Let it pass.
        }
      }
    }
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.
  }