Search in sources :

Example 1 with AggregateReportCriteria

use of de.symeda.sormas.api.report.AggregateReportCriteria 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)

Example 2 with AggregateReportCriteria

use of de.symeda.sormas.api.report.AggregateReportCriteria in project SORMAS-Project by hzi-braunschweig.

the class AggregateReportsEditLayout method checkForExistingData.

private void checkForExistingData() {
    if (comboBoxEpiweek.getValue() != null && (comboBoxFacility.getValue() != null || comboBoxPoe.getValue() != null) && !popUpIsShown) {
        AggregateReportCriteria criteria = new AggregateReportCriteria();
        criteria.setDistrict(comboBoxDistrict.getValue());
        criteria.setEpiWeekFrom(comboBoxEpiweek.getValue());
        criteria.setEpiWeekTo(comboBoxEpiweek.getValue());
        criteria.setHealthFacility(comboBoxFacility.getValue());
        criteria.setPointOfEntry(comboBoxPoe.getValue());
        criteria.setRegion(comboBoxRegion.getValue());
        reports = FacadeProvider.getAggregateReportFacade().getList(criteria).stream().collect(Collectors.toMap(AggregateReportDto::getDisease, dto -> dto));
        if (!reports.isEmpty()) {
            popUpIsShown = true;
            Consumer<Boolean> resultConsumer = new Consumer<Boolean>() {

                @Override
                public void accept(Boolean edit) {
                    if (edit) {
                        switchToEditMode();
                    } else {
                        comboBoxFacility.clear();
                        comboBoxPoe.clear();
                    }
                    popUpIsShown = false;
                }
            };
            VaadinUiUtil.showChooseOptionPopup(I18nProperties.getCaption(Captions.aggregateReportReportFound), new Label(I18nProperties.getString(Strings.messageAggregateReportFound)), I18nProperties.getCaption(Captions.aggregateReportEditReport), I18nProperties.getCaption(Captions.aggregateReportDiscardSelection), new Integer(480), resultConsumer);
        }
    }
}
Also used : AggregateReportDto(de.symeda.sormas.api.report.AggregateReportDto) Consumer(java.util.function.Consumer) Label(com.vaadin.ui.Label) AggregateReportCriteria(de.symeda.sormas.api.report.AggregateReportCriteria)

Aggregations

AggregateReportCriteria (de.symeda.sormas.api.report.AggregateReportCriteria)2 AggregateReportDto (de.symeda.sormas.api.report.AggregateReportDto)2 Label (com.vaadin.ui.Label)1 Disease (de.symeda.sormas.api.Disease)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