use of de.symeda.sormas.api.report.AggregatedCaseCountDto in project SORMAS-Project by hzi-braunschweig.
the class AggregateReportFacadeEjb method getIndexList.
@Override
public List<AggregatedCaseCountDto> getIndexList(AggregateReportCriteria criteria) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
Root<AggregateReport> root = cq.from(AggregateReport.class);
Predicate filter = service.createUserFilter(cb, cq, root);
if (criteria != null) {
Predicate criteriaFilter = service.createCriteriaFilter(criteria, cb, cq, root);
filter = CriteriaBuilderHelper.and(cb, filter, criteriaFilter);
}
if (filter != null) {
cq.where(filter);
}
cq.multiselect(root.get(AggregateReport.DISEASE), cb.sum(root.get(AggregateReport.NEW_CASES)), cb.sum(root.get(AggregateReport.LAB_CONFIRMATIONS)), cb.sum(root.get(AggregateReport.DEATHS)));
cq.groupBy(root.get(AggregateReport.DISEASE));
List<Object[]> resultList = em.createQuery(cq).getResultList();
Map<Disease, AggregatedCaseCountDto> reportSet = new HashMap<>();
for (Object[] result : resultList) {
reportSet.put((Disease) result[0], new AggregatedCaseCountDto((Disease) result[0], ((Long) result[1]).intValue(), ((Long) result[2]).intValue(), ((Long) result[3]).intValue()));
}
for (Disease disease : diseaseConfigurationFacade.getAllDiseases(true, false, false)) {
if (!reportSet.containsKey(disease)) {
reportSet.put(disease, new AggregatedCaseCountDto(disease, 0, 0, 0));
}
}
List<AggregatedCaseCountDto> reportList = new ArrayList<>(reportSet.values());
reportList.sort(Comparator.comparing(r -> r.getDisease().toString()));
return reportList;
}
Aggregations