Example #1
0
 public EditReferralsAction(DAOFactory factory, long hcpid, String pidString)
     throws iTrustException {
   super(factory, hcpid, pidString);
   referralDAO = factory.getReferralDAO();
   patientDAO = factory.getPatientDAO();
   personnelDAO = factory.getPersonnelDAO();
 }
 /**
  * Setup
  *
  * @param factory The DAOFactory used to create the DAOs used in this action.
  * @param loggedInMID UAP who is logged in
  */
 public LabProcUAPAction(DAOFactory factory, long loggedInMID) {
   transDAO = factory.getTransactionDAO();
   lpDAO = factory.getLabProcedureDAO();
   this.loggedInMID = loggedInMID;
   validator = new LabProcedureValidator();
   this.factory = factory;
 }
Example #3
0
 /**
  * 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 EditPatientAction(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;
   emailutil = new EmailUtil(factory);
 }
 public void testInvalidData()
     throws CSVFormatException, AddPatientFileException, FileNotFoundException {
   DAOFactory prodDAO = DAOFactory.getProductionInstance();
   AuthDAO authDAO = prodDAO.getAuthDAO();
   InputStream testFile = new FileInputStream(fileDirectory + "HCPPatientUploadInvalidData.csv");
   AddPatientFileAction apfa = new AddPatientFileAction(testFile, null, 0);
   assertEquals(1, apfa.getPatients().size());
   assertTrue(apfa.getErrors().hasErrors());
 }
 public void testInvalidHeader()
     throws CSVFormatException, AddPatientFileException, FileNotFoundException {
   DAOFactory prodDAO = DAOFactory.getProductionInstance();
   AuthDAO authDAO = prodDAO.getAuthDAO();
   InputStream testFile = new FileInputStream(fileDirectory + "HCPPatientUploadInvalidField.csv");
   try {
     new AddPatientFileAction(testFile, null, 0);
   } catch (AddPatientFileException e) {
     return;
   }
   assertTrue(false);
 }
 /**
  * Inserts a lab procedure into the database.
  *
  * @param b The LabProcedureBean to be inserted.
  * @return A long containing the ID of the newly inserted lab procedure bean.
  * @throws DBException
  */
 public long addLabProcedure(LabProcedureBean b) throws DBException {
   Connection conn = null;
   PreparedStatement ps = null;
   try {
     if (b.getPid() == 0L) throw new SQLException("PatientMID cannot be null");
     conn = factory.getConnection();
     ps =
         conn.prepareStatement(
             "INSERT INTO LabProcedure (PatientMID, LaboratoryProcedureCode, Status, Commentary, Results, OfficeVisitID, Rights) VALUES (?,?,?,?,?,?,?)");
     ps.setLong(1, b.getPid());
     ps.setString(2, b.getLoinc());
     ps.setString(3, b.getStatus());
     ps.setString(4, b.getCommentary());
     ps.setString(5, b.getResults());
     ps.setLong(6, b.getOvID());
     ps.setString(7, b.getRights());
     ps.executeUpdate();
     return DBUtil.getLastInsert(conn);
   } catch (SQLException e) {
     e.printStackTrace();
     throw new DBException(e);
   } finally {
     DBUtil.closeConnection(conn, ps);
   }
 }
  /**
   * Returns a list of information related to prescription reports given all of the office visits
   * and the patient ID. The patient ID is necessary in case the office visit IDs are for different
   * patients (the disambiguation is for security reasons).
   *
   * @param ovIDs A java.util.List of Longs for the office visits.
   * @param patientID A long representing the MID of the patient in question.
   * @return A java.util.List of prescription reports.
   * @throws DBException
   */
  public List<PrescriptionReportBean> byOfficeVisitAndPatient(List<Long> ovIDs, long patientID)
      throws DBException {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
      conn = factory.getConnection();
      String preps = buildPreps(ovIDs.size());
      ps =
          conn.prepareStatement(
              "SELECT * FROM ndcodes, ovmedication, officevisits "
                  + "WHERE ndcodes.Code=ovmedication.NDCode AND ovmedication.VisitID=officevisits.ID "
                  + "AND PatientID=? AND VisitID IN("
                  + preps
                  + ") ORDER BY VisitDate DESC");
      ps.setLong(1, patientID);
      prepareOVIDs(ps, ovIDs);
      ResultSet rs = ps.executeQuery();
      List<PrescriptionReportBean> loadlist = loader.loadList(rs);
      rs.close();
      return loadlist;
    } catch (SQLException e) {

      throw new DBException(e);
    } finally {
      DBUtil.closeConnection(conn, ps);
    }
  }
  /**
   * Returns a list of information related to prescription reports given all of the office visits
   * and the patient ID. The patient ID is necessary in case the office visit IDs are for different
   * patients (the disambiguation is for security reasons).
   *
   * @param ovIDs A java.util.List of Longs for the office visits.
   * @param patientID A long representing the MID of the patient in question.
   * @return A java.util.List of prescription reports.
   * @throws DBException
   */
  public List<PrescriptionReportBean> byDate(long patientID, String startDate, String endDate)
      throws DBException {
    Connection conn = null;
    PreparedStatement ps = null;
    try {
      conn = factory.getConnection();
      ps =
          conn.prepareStatement(
              "SELECT * FROM ndcodes, ovmedication, officevisits "
                  + "WHERE ndcodes.Code=ovmedication.NDCode AND ovmedication.VisitID=officevisits.ID "
                  + "AND PatientID=? AND ((DATE(?) < ovmedication.EndDate AND DATE(?) > ovmedication.StartDate)"
                  + "OR (DATE(?) > ovmedication.StartDate  AND DATE(?) < ovmedication.EndDate ) OR "
                  + "(DATE(?) <= ovmedication.StartDate AND DATE(?) >= ovmedication.StartDate)) "
                  + "ORDER BY VisitDate DESC");
      ps.setLong(1, patientID);
      ps.setString(2, startDate);
      ps.setString(3, startDate);
      ps.setString(4, endDate);
      ps.setString(5, endDate);
      ps.setString(6, startDate);
      ps.setString(7, endDate);
      ResultSet rs = ps.executeQuery();
      List<PrescriptionReportBean> loadlist = loader.loadList(rs);
      rs.close();
      return loadlist;
    } catch (SQLException e) {

      throw new DBException(e);
    } finally {
      DBUtil.closeConnection(conn, ps);
    }
  }
  /**
   * Tries to add a condition to the table of existing conditions
   *
   * @param mid The patient ID to add the condition for
   * @param condition The string of the condition to add
   * @return A message of whether it was successfully added or not
   */
  public String putConditionByMID(long mid, String condition) {
    if (condition == null || condition.length() < 1)
      return "Cannot add empty string as a pre-existing condition";
    if (condition.length() > CONDITION_MAX_STR_LEN)
      return "Maximum length of " + CONDITION_MAX_STR_LEN + " exceeded";
    if (!validateStr(condition))
      return "Illegal condition. Only alphanumerics - , and _ are allowed.";
    try {
      Connection conn = factory.getConnection();
      Statement stmt = conn.createStatement();
      String request =
          "INSERT INTO `obstetricsconditions` (`mid`, `condition`) VALUES ('"
              + mid
              + "', '"
              + condition
              + "');";

      stmt.execute(request);
      conn.close();
      stmt.close();
      return "Pre-existing condition added OK";
    } catch (SQLException e) {
      return "Database error while inserting";
    }
  }
Example #10
0
 /**
  * Adds a LOINCCode to an office visit.
  *
  * @param LOINCCode A string of the code being added.
  * @param visitID The ID of the office visit the code is being added to.
  * @param pid The patient's MID associated with this transaction.
  * @return The unique ID of the code that was added.
  * @throws DBException
  */
 public long addLabProcedureToOfficeVisit(String LOINCCode, long visitID, long pid)
     throws DBException {
   Connection conn = null;
   PreparedStatement ps = null;
   try {
     conn = factory.getConnection();
     ps =
         conn.prepareStatement(
             "INSERT INTO LabProcedure (LaboratoryProcedureCode,OfficeVisitID,"
                 + "Commentary, Results, PatientMID, Status, Rights) VALUES (?,?,?,?,?,?,?)");
     ps.setString(1, LOINCCode);
     ps.setLong(2, visitID);
     ps.setString(3, "");
     ps.setString(4, "");
     ps.setLong(5, pid);
     ps.setString(6, LabProcedureBean.Not_Received);
     ps.setString(7, "ALLOWED");
     ps.executeUpdate();
     return DBUtil.getLastInsert(conn);
   } catch (SQLException e) {
     e.printStackTrace();
     throw new DBException(e);
   } finally {
     DBUtil.closeConnection(conn, ps);
   }
 }
Example #11
0
 /**
  * Returns a list of information related to prescription reports given all of the office visits
  * and the patient ID. The patient ID is necessary in case the office visit IDs are for different
  * patients (the disambiguation is for security reasons).
  *
  * @param ovIDs A java.util.List of Longs for the office visits.
  * @param patientID A long representing the MID of the patient in question.
  * @return A java.util.List of prescription reports.
  * @throws DBException
  */
 public List<PrescriptionReportBean> getPrescriptionReportsByDate(
     long patientID, String startDate, String endDate) throws DBException {
   Connection conn = null;
   PreparedStatement ps = null;
   try {
     conn = factory.getConnection();
     ps =
         conn.prepareStatement(
             "SELECT * FROM NDCodes, OVMedication, OfficeVisits "
                 + "WHERE NDCodes.Code=OVMedication.NDCode AND OVMedication.VisitID=OfficeVisits.ID "
                 + "AND PatientID=? AND ((DATE(?) < OVMedication.EndDate AND DATE(?) > OVMedication.StartDate)"
                 + "OR (DATE(?) > OVMedication.StartDate  AND DATE(?) < OVMedication.EndDate ) OR "
                 + "(DATE(?) <= OVMedication.StartDate AND DATE(?) >= OVMedication.StartDate)) "
                 + "ORDER BY VisitDate DESC");
     ps.setLong(1, patientID);
     ps.setString(2, startDate);
     ps.setString(3, startDate);
     ps.setString(4, endDate);
     ps.setString(5, endDate);
     ps.setString(6, startDate);
     ps.setString(7, endDate);
     ResultSet rs = ps.executeQuery();
     return prescriptionReportBeanLoader.loadList(rs);
   } catch (SQLException e) {
     e.printStackTrace();
     throw new DBException(e);
   } finally {
     DBUtil.closeConnection(conn, ps);
   }
 }
Example #12
0
 /**
  * Returns a list of information related to prescription reports given all of the office visits
  * and the patient ID. The patient ID is necessary in case the office visit IDs are for different
  * patients (the disambiguation is for security reasons).
  *
  * @param ovIDs A java.util.List of Longs for the office visits.
  * @param patientID A long representing the MID of the patient in question.
  * @return A java.util.List of prescription reports.
  * @throws DBException
  */
 public List<PrescriptionReportBean> getPrescriptionReports(List<Long> ovIDs, long patientID)
     throws DBException {
   Connection conn = null;
   PreparedStatement ps = null;
   try {
     conn = factory.getConnection();
     String preps = buildPreps(ovIDs.size());
     ps =
         conn.prepareStatement(
             "SELECT * FROM NDCodes, OVMedication, OfficeVisits "
                 + "WHERE NDCodes.Code=OVMedication.NDCode AND OVMedication.VisitID=OfficeVisits.ID "
                 + "AND PatientID=? AND VisitID IN("
                 + preps
                 + ") ORDER BY VisitDate DESC");
     ps.setLong(1, patientID);
     prepareOVIDs(ps, ovIDs);
     ResultSet rs = ps.executeQuery();
     return prescriptionReportBeanLoader.loadList(rs);
   } catch (SQLException e) {
     e.printStackTrace();
     throw new DBException(e);
   } finally {
     DBUtil.closeConnection(conn, ps);
   }
 }
Example #13
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.
        }
      }
    }
 /**
  * @author Yuang Returns the person's most recent weight that matches the inputMID param
  * @param inputMID The MID to look up.
  * @return the person's name
  * @throws DBException
  * @throws ITrustException
  */
 public double getPatientWeight(long inputMID) throws ITrustException {
   try {
     long mid = Long.valueOf(inputMID);
     return factory.getHealthRecordsDAO().getPatientsLatestWeight(mid);
   } catch (NumberFormatException e) {
     throw new ITrustException("MID not in correct form");
   }
 }
 /**
  * Accepts the DAO factory and the CSV stream from the view and parses it.
  *
  * @param factory The DAO factory
  * @param loggedInMID The MID of the HCP
  * @param CSVStream The CSV stream uploaded by the user
  * @throws CSVFormatException
  * @throws AddPatientFileExceptionTest
  */
 public AddPatientFileAction(InputStream CSVStream, DAOFactory factory, long loggedInMID)
     throws CSVFormatException, AddPatientFileException {
   if (factory != null) {
     this.patientDAO = factory.getPatientDAO();
     this.loggedInMID = loggedInMID;
     this.authDAO = factory.getAuthDAO();
   }
   CSVParser parser = new CSVParser(CSVStream);
   CSVHeader = parser.getHeader();
   CSVData = parser.getData();
   errors = parser.getErrors();
   buildMappings(CSVHeader);
   try {
     createPatients();
   } catch (DBException e) {
     throw new AddPatientFileException("Database error while adding new patients!");
   }
 }
 @Override
 protected void setUp() throws Exception {
   factor = new ChildhoodInfectionFactor(factory, 2L, 250.3, 487);
   gen = new TestDataGenerator();
   gen.clearAllTables();
   gen.hospitals();
   gen.hcp0();
   gen.patient2();
   p = factory.getPatientDAO().getPatient(2L);
 }
public class PersonnelReportFilterTest extends TestCase {

  private DAOFactory factory = TestDAOFactory.getTestInstance();
  private PatientDAO pDAO = factory.getPatientDAO();
  private List<PatientBean> allPatients;
  private PersonnelReportFilter filter;
  private TestDataGenerator gen = new TestDataGenerator();

  protected void setUp() throws Exception {
    gen.clearAllTables();
    gen.standardData();
    allPatients = pDAO.getAllPatients();
  }

  public void testFilterByProcedure() throws Exception {
    filter = new PersonnelReportFilter(PersonnelReportFilterType.DLHCP, "Beaker Beaker", factory);
    List<PatientBean> res = filter.filter(allPatients);
    assertEquals(2, res.size());
    assertTrue(res.get(0).getMID() == 22L);
    assertTrue(res.get(1).getMID() == 23L);
  }

  public void testFilterByProcedureNoResult() {
    filter = new PersonnelReportFilter(PersonnelReportFilterType.DLHCP, "Dalpe", factory);
    List<PatientBean> res = filter.filter(allPatients);
    assertTrue(res.isEmpty());
  }

  public void testToString() {
    String expected = "";
    filter = new PersonnelReportFilter(PersonnelReportFilterType.DLHCP, "val", factory);
    expected = "Filter by DECLARED HCP with value val";
    assertEquals(expected, filter.toString());
  }

  public void testFilterTypeFromString() {
    PersonnelReportFilterType expected = PersonnelReportFilterType.DLHCP;
    PersonnelReportFilterType actual = PersonnelReportFilter.filterTypeFromString("dLhCP");
    assertEquals(expected, actual);
  }

  public void testGetFilterType() {
    filter = new PersonnelReportFilter(PersonnelReportFilterType.DLHCP, "city!", factory);
    PersonnelReportFilterType expected = PersonnelReportFilterType.DLHCP;
    assertEquals(expected, filter.getFilterType());
  }

  public void testGetFilterValue() {
    filter = new PersonnelReportFilter(PersonnelReportFilterType.DLHCP, "city!", factory);
    String expected = "city!";
    assertEquals(expected, filter.getFilterValue());
  }
}
Example #18
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;
 }
Example #19
0
  /**
   * Insert survey data into database.
   *
   * @param surveyBean The Bean representing the user's responses which will be inserted.
   * @param date The date the survey was completed.
   */
  public void addCompletedSurvey(SurveyBean surveyBean, Date date) throws DBException {
    Connection conn = null;
    PreparedStatement ps = null;

    try {
      if (surveyBean == null) throw new SQLException("Null survey exception.");
      conn = factory.getConnection();
      ps = conn.prepareStatement("INSERT INTO ovsurvey (VisitID, SurveyDate) VALUES (?,?)");
      ps.setLong(1, surveyBean.getVisitID());
      ps.setTimestamp(2, new java.sql.Timestamp(date.getTime()));
      ps.executeUpdate();
      ps.close();
      if (surveyBean.getWaitingRoomMinutes() > 0) {
        ps = conn.prepareStatement("update ovsurvey set WaitingRoomMinutes = ? where VisitID = ?");
        ps.setFloat(1, surveyBean.getWaitingRoomMinutes());
        ps.setLong(2, surveyBean.getVisitID());
        ps.executeUpdate();
        ps.close();
      }
      if (surveyBean.getExamRoomMinutes() > 0) {
        ps = conn.prepareStatement("update ovsurvey set ExamRoomMinutes = ? where VisitID = ?");
        ps.setFloat(1, surveyBean.getExamRoomMinutes());
        ps.setLong(2, surveyBean.getVisitID());
        ps.executeUpdate();
        ps.close();
      }
      if (surveyBean.getVisitSatisfaction() > 0) {
        ps = conn.prepareStatement("update ovsurvey set VisitSatisfaction = ? where VisitID = ?");
        ps.setFloat(1, surveyBean.getVisitSatisfaction());
        ps.setLong(2, surveyBean.getVisitID());
        ps.executeUpdate();
        ps.close();
      }
      if (surveyBean.getTreatmentSatisfaction() > 0) {
        ps =
            conn.prepareStatement(
                "update ovsurvey set TreatmentSatisfaction = ? where VisitID = ?");
        ps.setFloat(1, surveyBean.getTreatmentSatisfaction());
        ps.setLong(2, surveyBean.getVisitID());
        ps.executeUpdate();
        ps.close();
      }
    } catch (SQLException e) {

      throw new DBException(e);
    } finally {
      DBUtil.closeConnection(conn, ps);
    }
  }
Example #20
0
 /**
  * Removes a given lab procedure.
  *
  * @param labProcedureID The unique ID of the lab procedure.
  * @throws DBException
  */
 public void removeLabProcedureFromOfficeVisit(long labProcedureID) throws DBException {
   Connection conn = null;
   PreparedStatement ps = null;
   try {
     conn = factory.getConnection();
     ps = conn.prepareStatement("DELETE FROM LabProcedure WHERE LaboratoryProcedureID=?");
     ps.setLong(1, labProcedureID);
     ps.executeUpdate();
   } catch (SQLException e) {
     e.printStackTrace();
     throw new DBException(e);
   } finally {
     DBUtil.closeConnection(conn, ps);
   }
 }
Example #21
0
 /**
  * Removes a particular diagnosis from its office visit
  *
  * @param ovDiagnosisID The ID for the office visit diagnosis to be removed.
  * @throws DBException
  */
 public void removeDiagnosisFromOfficeVisit(long ovDiagnosisID) throws DBException {
   Connection conn = null;
   PreparedStatement ps = null;
   try {
     conn = factory.getConnection();
     ps = conn.prepareStatement("DELETE FROM OVDiagnosis WHERE ID=? ");
     ps.setLong(1, ovDiagnosisID);
     ps.executeUpdate();
   } catch (SQLException e) {
     e.printStackTrace();
     throw new DBException(e);
   } finally {
     DBUtil.closeConnection(conn, ps);
   }
 }
Example #22
0
  /**
   * Gets all lab procedures, period.
   *
   * @return A java.util.List of LabProcedureBeans.
   * @throws DBException
   */
  public List<LabProcedureBean> getAllLabProcedures() throws DBException {
    Connection conn = null;
    PreparedStatement ps = null;

    try {
      conn = factory.getConnection();
      ps = conn.prepareStatement("SELECT * FROM LabProcedure ORDER BY UpdatedDate ASC");
      ResultSet rs = ps.executeQuery();
      return labProcedureLoader.loadList(rs);
    } catch (SQLException e) {
      e.printStackTrace();
      throw new DBException(e);
    } finally {
      DBUtil.closeConnection(conn, ps);
    }
  }
  public void testGetFluShotDelinquentsEmptyList() throws Exception {
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    gen.patient1();
    gen.patient2();
    gen.patient3();
    boolean thisYear = DateUtil.currentlyInMonthRange(9, 12);

    java.sql.Date september = new java.sql.Date(0l), december = new java.sql.Date(0l);
    DateUtil.setSQLMonthRange(september, 8, thisYear ? 0 : 1, december, 11, thisYear ? 0 : 1);
    try {
      conn = factory.getConnection();
      ps =
          conn.prepareStatement(
              "SELECT DISTINCT "
                  + "? as hid, ov.patientid, p.lastname, p.firstname, "
                  + "p.phone "
                  + "FROM officevisits ov, patients p "
                  + "WHERE ov.patientid=p.mid "
                  + "AND p.dateofdeath IS NULL "
                  + "AND p.dateofbirth < DATE_SUB(CURDATE(), INTERVAL 50 YEAR) "
                  + "AND patientid NOT IN "
                  + "(SELECT patientid FROM officevisits ov, ovmedication om "
                  + "WHERE ov.id=om.visitid "
                  + "AND NDCode IN (90656, 90658, 90660) "
                  + "AND ((StartDate BETWEEN ? AND ?) "
                  + "OR (EndDate BETWEEN ? AND ?))) "
                  + "ORDER BY lastname, firstname, ov.patientid");
      ps.setLong(1, this.LHCP);
      ps.setDate(2, september);
      ps.setDate(3, december);
      ps.setDate(4, september);
      ps.setDate(5, december);
      rs = ps.executeQuery();
      VisitReminderReturnFormLoader loader = new VisitReminderReturnFormLoader();
      List<VisitReminderReturnForm> patients = loader.loadList(rs);
      assertEquals(2, patients.size());
      VisitReminderReturnForm patient1 = patients.get(0);
      assertEquals(9000000003l, patient1.getHcpID());
      assertEquals(3l, patient1.getPatientID());
      assertEquals("Care", patient1.getFirstName());
      assertEquals("919-971-0000", patient1.getPhoneNumber());
    } finally {
      DBUtil.closeConnection(conn, ps);
    }
  }
Example #24
0
  /**
   * Gets all office visits corresponding to a particular ICD diagnosis.
   *
   * @param icdcode A string represnting the ICD diagnosis to look up.
   * @return A java.util.List of Office visits.
   * @throws DBException
   */
  public List<OfficeVisitBean> getAllOfficeVisitsForDiagnosis(String icdcode) throws DBException {

    List<DiagnosisBean> diags = null;
    List<OfficeVisitBean> ovs = new ArrayList<OfficeVisitBean>();
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      if (icdcode == null) throw new SQLException("icdcode cannot be null");

      conn = factory.getConnection();

      ps =
          conn.prepareStatement(
              "SELECT * FROM ovdiagnosis ovd, icdcodes icd WHERE ovd.ICDCode=? and icd.Code=?");
      ps.setString(1, icdcode);
      ps.setString(2, icdcode);
      rs = ps.executeQuery();
      diags = diagnosisLoader.loadList(rs);
      rs.close();
      ps.close();
      ps = null;
      rs = null;

      for (DiagnosisBean bean : diags) {
        ps = conn.prepareStatement("SELECT * FROM officevisits ov WHERE ov.ID=?");
        ps.setInt(1, (int) bean.getVisitID());
        rs = ps.executeQuery();

        if (rs.next()) {
          ovs.add(loadFullOfficeVist(rs, bean.getVisitID()));
        }
        rs.close();
        ps.close();
      }

      return ovs;

    } catch (SQLException e) {
      e.printStackTrace();
      throw new DBException(e);
    } finally {
      DBUtil.closeConnection(conn, ps);
    }
  }
Example #25
0
 /**
  * Returns a list of all office visits at a given hospital
  *
  * @param hospitalID the id of the hospital
  * @return a list of the OfficeVisitBeans that hold the office visits
  * @throws DBException in the event of a database error
  */
 public List<OfficeVisitBean> getOfficeVisitsFromHospital(String hospitalID) throws DBException {
   Connection conn = null;
   PreparedStatement ps = null;
   try {
     conn = factory.getConnection();
     ps =
         conn.prepareStatement("SELECT * FROM officevisits WHERE hospitalID = ? ORDER BY ID DESC");
     ps.setString(1, hospitalID);
     ResultSet rs = ps.executeQuery();
     return officeVisitLoader.loadList(rs);
   } catch (SQLException e) {
     e.printStackTrace();
     throw new DBException(e);
   } finally {
     DBUtil.closeConnection(conn, ps);
   }
 }
Example #26
0
 /**
  * Gets an individual lab procedure.
  *
  * @param id The ID of the lab procedure.
  * @return A LabProcedureBean representing the procedure.
  * @throws DBException
  */
 public LabProcedureBean getLabProcedure(long id) throws DBException {
   Connection conn = null;
   PreparedStatement ps = null;
   try {
     conn = factory.getConnection();
     ps = conn.prepareStatement("SELECT * FROM LabProcedure WHERE LaboratoryProcedureID = ?");
     ps.setLong(1, id);
     ResultSet rs = ps.executeQuery();
     rs.next();
     return labProcedureLoader.loadSingle(rs);
   } catch (SQLException e) {
     e.printStackTrace();
     throw new DBException(e);
   } finally {
     DBUtil.closeConnection(conn, ps);
   }
 }
Example #27
0
  /**
   * This gets all the procedures for a particular patient on a particular office visit
   *
   * @param mid The MID of the patient.
   * @param ovid The Office Visit ID.
   * @return A java.util.List of LabProcedureBeans
   * @throws DBException
   */
  public List<LabProcedureBean> getAllLabProceduresForDocOV(long ovid) throws DBException {
    Connection conn = null;
    PreparedStatement ps = null;

    try {
      conn = factory.getConnection();
      ps = conn.prepareStatement("SELECT * FROM LabProcedure WHERE OfficeVisitID = ? ");
      ps.setLong(1, ovid);
      ResultSet rs = ps.executeQuery();
      return labProcedureLoader.loadList(rs);
    } catch (SQLException e) {
      e.printStackTrace();
      throw new DBException(e);
    } finally {
      DBUtil.closeConnection(conn, ps);
    }
  }
Example #28
0
 /**
  * Returns whether or not an office visit actually exists
  *
  * @param ovID The ID of the office visit to be checked.
  * @param pid The MID of the patient associated with this transaction.
  * @return A boolean indicating its existence.
  * @throws DBException
  */
 public boolean checkOfficeVisitExists(long ovID, long pid) throws DBException {
   Connection conn = null;
   PreparedStatement ps = null;
   try {
     conn = factory.getConnection();
     ps = conn.prepareStatement("SELECT * FROM OfficeVisits WHERE ID=? AND PatientID=?");
     ps.setLong(1, ovID);
     ps.setLong(2, pid);
     ResultSet rs = ps.executeQuery();
     return rs.next();
   } catch (SQLException e) {
     e.printStackTrace();
     throw new DBException(e);
   } finally {
     DBUtil.closeConnection(conn, ps);
   }
 }
Example #29
0
 /**
  * Adds the given CPT codes to the given office visit
  *
  * @param icd A double representing the ICD code to be added.
  * @param visitID The ID of the office visit we are adding the code to.
  * @return A long for the new ICD code's ID.
  * @throws DBException
  */
 public long addDiagnosisToOfficeVisit(double icd, long visitID) throws DBException {
   Connection conn = null;
   PreparedStatement ps = null;
   try {
     conn = factory.getConnection();
     ps = conn.prepareStatement("INSERT INTO OVDiagnosis (ICDCode,VisitID) VALUES (?,?)");
     ps.setDouble(1, icd);
     ps.setLong(2, visitID);
     ps.executeUpdate();
     return DBUtil.getLastInsert(conn);
   } catch (SQLException e) {
     e.printStackTrace();
     throw new DBException(e);
   } finally {
     DBUtil.closeConnection(conn, ps);
   }
 }
Example #30
0
 /**
  * Returns a particular office visit given an ID
  *
  * @param visitID The unique ID of the office visit.
  * @return An OfficeVisitBean with the specifics for that office visit.
  * @throws DBException
  */
 public OfficeVisitBean getOfficeVisit(long visitID) throws DBException {
   Connection conn = null;
   PreparedStatement ps = null;
   try {
     conn = factory.getConnection();
     ps = conn.prepareStatement("Select * From OfficeVisits Where ID = ?");
     ps.setLong(1, visitID);
     ResultSet rs = ps.executeQuery();
     if (rs.next()) return loadFullOfficeVist(rs, visitID);
     else return null;
   } catch (SQLException e) {
     e.printStackTrace();
     throw new DBException(e);
   } finally {
     DBUtil.closeConnection(conn, ps);
   }
 }