/** the measure is updated if it's already registered. */ @Override public Measure addMeasure(Resource resource, Measure measure) { Bucket bucket = checkIndexed(resource); if (bucket != null && !bucket.isExcluded()) { Metric metric = metricFinder.findByKey(measure.getMetricKey()); if (metric == null) { throw new SonarException("Unknown metric: " + measure.getMetricKey()); } measure.setMetric(metric); bucket.addMeasure(measure); if (measure.getPersistenceMode().useDatabase()) { persistence.saveMeasure(resource, measure); } } return measure; }
@Override public List<Report595DTO> getTopSkippedQuestions( List<Integer> clinicIds, String fromDate, String toDate) { List<Report595DTO> resultList = new ArrayList<>(); Query q = entityManager.createNativeQuery( "SELECT count(*), measure_id FROM veteran_assessment_question_presence vsaq " + "INNER JOIN veteran_assessment va ON vsaq.veteran_assessment_id = va.veteran_assessment_id " + " WHERE skipped = -1 AND date_completed >= :fromDate AND date_completed <= :toDate " + "AND clinic_id IN (:clinicIds) AND date_completed IS NOT NULL " + " GROUP BY measure_id " + " ORDER BY count(*) DESC "); setParametersFor593(q, fromDate, toDate, clinicIds); List r = q.getResultList(); if (r != null && r.size() > 0) { for (Object aRow : q.getResultList()) { Object[] data = (Object[]) aRow; int count = ((Number) data[0]).intValue(); if (count == 0) break; int measureId = ((Number) data[1]).intValue(); Measure m = measureRepository.findOne(measureId); // only allow singleSelect or multiSelect int measureType = m.getMeasureType().getMeasureTypeId(); if (measureType != 1 && measureType != 2 && measureType != 3) { continue; } Report595DTO dto = new Report595DTO(); Query q1 = entityManager.createNativeQuery( "select count(*) from veteran_assessment_question_presence vsaq " + "inner join veteran_assessment va on vsaq.veteran_assessment_id = va.veteran_assessment_id " + " where date_completed >= :fromDate and date_completed <= :toDate " + "and clinic_id in (:clinicIds) and date_completed is not null " + " and measure_id =" + measureId); setParametersFor593(q1, fromDate, toDate, clinicIds); int total = ((Number) q1.getSingleResult()).intValue(); DecimalFormat formatter = new DecimalFormat("###.##"); String percent = formatter.format(count * 100d / total); dto.setPercentage(percent + "% (" + count + "/" + total + ")"); dto.setQuestions(((Number) data[1]).intValue() + ""); dto.setQuestions(m.getMeasureText()); dto.setVariableName(m.getVariableName()); resultList.add(dto); } } Collections.sort( resultList, new Comparator<Report595DTO>() { @Override public int compare(Report595DTO o1, Report595DTO o2) { String[] a1 = o1.getPercentage().split("%"); String[] a2 = o2.getPercentage().split("%"); float one = Float.parseFloat(a1[0]); float two = Float.parseFloat(a2[0]); if (one > two) return 1; else if (one < two) return -1; return 0; } }); int index = 1; List<Report595DTO> results = new ArrayList<>(20); for (Report595DTO dto : resultList) { dto.setOrder(Integer.toString(index++)); results.add(dto); if (index > 20) break; } return results; }