Search in sources :

Example 1 with AggregatedCaseCountDto

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;
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) PointOfEntryFacadeEjb(de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntryFacadeEjb) DtoHelper(de.symeda.sormas.backend.util.DtoHelper) Date(java.util.Date) FacilityFacadeEjb(de.symeda.sormas.backend.infrastructure.facility.FacilityFacadeEjb) HashMap(java.util.HashMap) DistrictService(de.symeda.sormas.backend.infrastructure.district.DistrictService) ArrayList(java.util.ArrayList) Valid(javax.validation.Valid) Predicate(javax.persistence.criteria.Predicate) UserFacadeEjb(de.symeda.sormas.backend.user.UserFacadeEjb) Map(java.util.Map) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) LocalBean(javax.ejb.LocalBean) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) Stateless(javax.ejb.Stateless) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) FacilityService(de.symeda.sormas.backend.infrastructure.facility.FacilityService) DiseaseConfigurationFacadeEjbLocal(de.symeda.sormas.backend.disease.DiseaseConfigurationFacadeEjb.DiseaseConfigurationFacadeEjbLocal) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) NotNull(javax.validation.constraints.NotNull) RegionFacadeEjb(de.symeda.sormas.backend.infrastructure.region.RegionFacadeEjb) RegionService(de.symeda.sormas.backend.infrastructure.region.RegionService) Collectors(java.util.stream.Collectors) PointOfEntryService(de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntryService) AggregateReportDto(de.symeda.sormas.api.report.AggregateReportDto) UserRight(de.symeda.sormas.api.user.UserRight) List(java.util.List) UserService(de.symeda.sormas.backend.user.UserService) Disease(de.symeda.sormas.api.Disease) DistrictFacadeEjb(de.symeda.sormas.backend.infrastructure.district.DistrictFacadeEjb) User(de.symeda.sormas.backend.user.User) AggregateReportFacade(de.symeda.sormas.api.report.AggregateReportFacade) AggregateReportCriteria(de.symeda.sormas.api.report.AggregateReportCriteria) Comparator(java.util.Comparator) Collections(java.util.Collections) UserRoleConfigFacadeEjbLocal(de.symeda.sormas.backend.user.UserRoleConfigFacadeEjb.UserRoleConfigFacadeEjbLocal) AggregatedCaseCountDto(de.symeda.sormas.api.report.AggregatedCaseCountDto) Disease(de.symeda.sormas.api.Disease) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Predicate(javax.persistence.criteria.Predicate) AggregatedCaseCountDto(de.symeda.sormas.api.report.AggregatedCaseCountDto)

Aggregations

Disease (de.symeda.sormas.api.Disease)1 AggregateReportCriteria (de.symeda.sormas.api.report.AggregateReportCriteria)1 AggregateReportDto (de.symeda.sormas.api.report.AggregateReportDto)1 AggregateReportFacade (de.symeda.sormas.api.report.AggregateReportFacade)1 AggregatedCaseCountDto (de.symeda.sormas.api.report.AggregatedCaseCountDto)1 UserRight (de.symeda.sormas.api.user.UserRight)1 CriteriaBuilderHelper (de.symeda.sormas.backend.common.CriteriaBuilderHelper)1 DiseaseConfigurationFacadeEjbLocal (de.symeda.sormas.backend.disease.DiseaseConfigurationFacadeEjb.DiseaseConfigurationFacadeEjbLocal)1 DistrictFacadeEjb (de.symeda.sormas.backend.infrastructure.district.DistrictFacadeEjb)1 DistrictService (de.symeda.sormas.backend.infrastructure.district.DistrictService)1 FacilityFacadeEjb (de.symeda.sormas.backend.infrastructure.facility.FacilityFacadeEjb)1 FacilityService (de.symeda.sormas.backend.infrastructure.facility.FacilityService)1 PointOfEntryFacadeEjb (de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntryFacadeEjb)1 PointOfEntryService (de.symeda.sormas.backend.infrastructure.pointofentry.PointOfEntryService)1 RegionFacadeEjb (de.symeda.sormas.backend.infrastructure.region.RegionFacadeEjb)1 RegionService (de.symeda.sormas.backend.infrastructure.region.RegionService)1 User (de.symeda.sormas.backend.user.User)1 UserFacadeEjb (de.symeda.sormas.backend.user.UserFacadeEjb)1 UserRoleConfigFacadeEjbLocal (de.symeda.sormas.backend.user.UserRoleConfigFacadeEjb.UserRoleConfigFacadeEjbLocal)1 UserService (de.symeda.sormas.backend.user.UserService)1