/**
   * 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;
  }