@Override
  public float getAvgNumOfAssessmentPerClinicianClinicFor593(
      String fromDate, String toDate, List<Integer> clinicIds) {

    Query q =
        entityManager.createNativeQuery(
            "SELECT "
                + "count(*) "
                + "FROM "
                + "veteran_assessment va, clinic c, user u "
                + "WHERE va.assessment_status_id <> 7 AND "
                + "va.clinic_id = c.clinic_id AND "
                + "va.clinician_id = u.user_id AND "
                + "va.date_completed BETWEEN :fromDate AND :toDate AND "
                + "va.clinic_id IN (:clinicIds) "
                + "GROUP BY c.clinic_id , u.user_id");
    setParametersFor593(q, fromDate, toDate, clinicIds);
    final List<BigInteger> resultList = q.getResultList();

    float sum = 0;
    for (BigInteger assessmentCnt : resultList) {
      sum += Float.parseFloat(assessmentCnt.toString());
    }
    float avgNumOfAssessmentPerClinicianClinicFor593 =
        resultList.isEmpty() ? 0.0f : sum / Float.valueOf(resultList.size());
    return avgNumOfAssessmentPerClinicianClinicFor593;
  }
  public static Predicate[] deviceListPredicates(
      CriteriaBuilder cb,
      Root<Device> from,
      List<String> guids,
      Optional<HivePrincipal> principal) {
    final List<Predicate> predicates = deviceSpecificPrincipalPredicates(cb, from, principal);
    if (guids != null && !guids.isEmpty()) {
      predicates.add(from.get(GUID).in(guids));
    }

    return predicates.toArray(new Predicate[predicates.size()]);
  }
  @Override
  public Date getDateModified(int veteranAssessmentId) {
    String sql =
        "SELECT UNIX_TIMESTAMP(max(date_created)), UNIX_TIMESTAMP(max(date_modified)) FROM survey_measure_response WHERE veteran_assessment_id = :veteranAssessmentId";

    @SuppressWarnings("unchecked")
    List<Object[]> rows =
        entityManager
            .createNativeQuery(sql)
            .setParameter("veteranAssessmentId", veteranAssessmentId)
            .getResultList();

    if (rows.isEmpty()) {
      // no results saved for this assessment
      return new Date(0);
    }

    Object[] row = rows.get(0);

    Long created = null;
    try {
      created = Long.valueOf(row[0].toString());
    } catch (Exception e) {
    }

    Long modified = null;
    try {
      modified = Long.valueOf(row[1].toString());
    } catch (Exception e) {
    }

    if (created == null) {
      if (modified == null) {
        // no results saved for this assessment
        return new Date(0);
      }
      // this should never happen but we know what happens when we say that :)
      return new Date(modified);
    } else if (modified == null) {
      return new Date(created);
    }

    // found both
    return new Date(Math.max(created, modified));
  }