Search in sources :

Example 1 with CampaignDiagramCriteria

use of de.symeda.sormas.api.campaign.diagram.CampaignDiagramCriteria in project SORMAS-Project by hzi-braunschweig.

the class CampaignDashboardDataProvider method createDiagramsData.

protected void createDiagramsData(String tabId, String subTabId) {
    getCampaignDashboardDiagrams().forEach(campaignDashboardDiagramDto -> {
        final CampaignDashboardElement campaignDashboardElement = campaignDashboardDiagramDto.getCampaignDashboardElement();
        if (campaignDashboardElement.getTabId().equals(tabId) && (subTabId == null || campaignDashboardElement.getSubTabId().equals(subTabId))) {
            List<CampaignDiagramDataDto> diagramData = FacadeProvider.getCampaignFormDataFacade().getDiagramData(campaignDashboardDiagramDto.getCampaignDiagramDefinitionDto().getCampaignDiagramSeries(), new CampaignDiagramCriteria(campaign, area, region, district, campaignJurisdictionLevelGroupBy));
            campaignFormDataMap.put(campaignDashboardDiagramDto, diagramData);
            List<CampaignDiagramSeries> campaignSeriesTotal = campaignDashboardDiagramDto.getCampaignDiagramDefinitionDto().getCampaignSeriesTotal();
            List<CampaignDiagramDataDto> percentageDiagramData = null;
            if (campaignSeriesTotal != null) {
                Optional populationGroup = campaignSeriesTotal.stream().filter(e -> Objects.nonNull(e.getPopulationGroup())).findFirst();
                Optional formIdOptional = campaignSeriesTotal.stream().filter(e -> Objects.nonNull(e.getFormId())).findFirst();
                {
                    if (populationGroup.isPresent()) {
                        percentageDiagramData = FacadeProvider.getCampaignFormDataFacade().getDiagramDataByAgeGroup((CampaignDiagramSeries) populationGroup.get(), campaignDashboardDiagramDto.getCampaignDiagramDefinitionDto().getCampaignDiagramSeries().get(0), new CampaignDiagramCriteria(campaign, area, region, district, campaignJurisdictionLevelGroupBy));
                        if (formIdOptional.isPresent()) {
                            logger.warn(String.format(I18nProperties.getString(Strings.errorFormIdPopulationAgeGroup)));
                        }
                    } else {
                        percentageDiagramData = FacadeProvider.getCampaignFormDataFacade().getDiagramData(campaignDashboardDiagramDto.getCampaignDiagramDefinitionDto().getCampaignSeriesTotal(), new CampaignDiagramCriteria(campaign, area, region, district, campaignJurisdictionLevelGroupBy));
                    }
                    Map<CampaignDashboardTotalsReference, Double> percentageMap = new HashMap<>();
                    for (CampaignDiagramDataDto data : percentageDiagramData) {
                        CampaignDashboardTotalsReference totals = new CampaignDashboardTotalsReference(data.getGroupingKey(), data.getStack());
                        Double value = percentageMap.getOrDefault(totals, 0D);
                        value += data.getValueSum().doubleValue();
                        percentageMap.put(totals, value);
                    }
                    campaignFormTotalsMap.put(campaignDashboardDiagramDto, percentageMap);
                }
            }
        }
    });
}
Also used : FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) LoggerFactory(org.slf4j.LoggerFactory) CampaignDiagramCriteria(de.symeda.sormas.api.campaign.diagram.CampaignDiagramCriteria) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CampaignDiagramDataDto(de.symeda.sormas.api.campaign.diagram.CampaignDiagramDataDto) CampaignDiagramSeries(de.symeda.sormas.api.campaign.diagram.CampaignDiagramSeries) Map(java.util.Map) CampaignDiagramDefinitionDto(de.symeda.sormas.api.campaign.diagram.CampaignDiagramDefinitionDto) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) CampaignReferenceDto(de.symeda.sormas.api.campaign.CampaignReferenceDto) CampaignJurisdictionLevel(de.symeda.sormas.api.campaign.CampaignJurisdictionLevel) Collectors(java.util.stream.Collectors) CampaignDashboardElement(de.symeda.sormas.api.campaign.diagram.CampaignDashboardElement) Objects(java.util.Objects) List(java.util.List) AreaReferenceDto(de.symeda.sormas.api.infrastructure.area.AreaReferenceDto) Optional(java.util.Optional) Comparator(java.util.Comparator) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) CampaignDashboardElement(de.symeda.sormas.api.campaign.diagram.CampaignDashboardElement) CampaignDiagramCriteria(de.symeda.sormas.api.campaign.diagram.CampaignDiagramCriteria) Optional(java.util.Optional) CampaignDiagramSeries(de.symeda.sormas.api.campaign.diagram.CampaignDiagramSeries) HashMap(java.util.HashMap) Map(java.util.Map) CampaignDiagramDataDto(de.symeda.sormas.api.campaign.diagram.CampaignDiagramDataDto)

Example 2 with CampaignDiagramCriteria

use of de.symeda.sormas.api.campaign.diagram.CampaignDiagramCriteria in project SORMAS-Project by hzi-braunschweig.

the class CampaignFormDataFacadeEjb method getDiagramDataByAgeGroup.

public List<CampaignDiagramDataDto> getDiagramDataByAgeGroup(CampaignDiagramSeries diagramSeriesTotal, CampaignDiagramSeries diagramSeries, CampaignDiagramCriteria campaignDiagramCriteria) {
    List<CampaignDiagramDataDto> resultData = new ArrayList<>();
    final AreaReferenceDto area = campaignDiagramCriteria.getArea();
    final RegionReferenceDto region = campaignDiagramCriteria.getRegion();
    final DistrictReferenceDto district = campaignDiagramCriteria.getDistrict();
    final CampaignJurisdictionLevel grouping = campaignDiagramCriteria.getCampaignJurisdictionLevelGroupBy();
    if (grouping == CampaignJurisdictionLevel.AREA) {
        List<Area> areas = areaService.getAll();
        areas.forEach(areaItem -> {
            Integer population = populationDataFacadeEjb.getAreaPopulation(areaItem.getUuid(), diagramSeriesTotal.getPopulationGroup());
            if (population == 0) {
                resultData.add(new CampaignDiagramDataDto(areaItem.getName(), 0, areaItem.getUuid(), areaItem.getName(), diagramSeries.getFieldId(), diagramSeries.getFormId(), false));
            } else {
                resultData.add(new CampaignDiagramDataDto(areaItem.getName(), population, areaItem.getUuid(), areaItem.getName(), diagramSeries.getFieldId(), diagramSeries.getFormId(), true));
            }
        });
    } else if (grouping == CampaignJurisdictionLevel.REGION) {
        List<RegionReferenceDto> regions;
        if (area != null)
            regions = regionFacadeEjb.getAllActiveByArea(area.getUuid());
        else
            regions = regionFacadeEjb.getAllActiveAsReference();
        // this should not be needed
        // if (regions.isEmpty()) {
        // resultData.add(
        // new CampaignDiagramDataDto(
        // area.getCaption(),
        // 0,
        // area.getUuid(),
        // area.getCaption(),
        // diagramSeries.getFieldId(),
        // diagramSeries.getFormId(),
        // false));
        // } else {
        regions.stream().forEach(regionReferenceDto -> {
            PopulationDataCriteria criteria = new PopulationDataCriteria();
            criteria.sexIsNull(true);
            criteria.region(regionReferenceDto);
            criteria.ageGroup(diagramSeriesTotal.getPopulationGroup());
            List<PopulationDataDto> populationDataDto = populationDataFacadeEjb.getPopulationData(criteria);
            Integer populationSum = 0;
            if (!populationDataDto.isEmpty()) {
                populationSum = populationDataDto.stream().mapToInt(e -> e.getPopulation()).sum();
                resultData.add(new CampaignDiagramDataDto(regionReferenceDto.getCaption(), populationSum, regionReferenceDto.getUuid(), regionReferenceDto.getCaption(), diagramSeries.getFieldId(), diagramSeries.getFormId(), true));
            } else {
                resultData.add(new CampaignDiagramDataDto(regionReferenceDto.getCaption(), 0, regionReferenceDto.getUuid(), regionReferenceDto.getCaption(), diagramSeries.getFieldId(), diagramSeries.getFormId(), false));
            }
        });
    // }
    } else if (grouping == CampaignJurisdictionLevel.DISTRICT || Objects.isNull(district)) {
        List<DistrictReferenceDto> districts;
        if (region != null) {
            districts = districtFacadeEjb.getAllActiveByRegion(region.getUuid());
        } else if (area != null) {
            districts = districtFacadeEjb.getAllActiveByArea(area.getUuid());
        } else {
            districts = districtFacadeEjb.getAllActiveAsReference();
        }
        // this should not be needed
        // if (districts.isEmpty()) {
        // resultData.add(
        // new CampaignDiagramDataDto(
        // region.getCaption(),
        // 0,
        // region.getUuid(),
        // region.getCaption(),
        // diagramSeries.getFieldId(),
        // diagramSeries.getFormId(),
        // false));
        // } else {
        districts.stream().forEach(districtReferenceDto -> {
            PopulationDataCriteria criteria = new PopulationDataCriteria();
            criteria.sexIsNull(true);
            criteria.district(districtReferenceDto);
            criteria.region(region);
            criteria.ageGroup(diagramSeriesTotal.getPopulationGroup());
            List<PopulationDataDto> populationDataDtoList = populationDataFacadeEjb.getPopulationData(criteria);
            Integer populationSum = 0;
            if (!populationDataDtoList.isEmpty()) {
                populationSum = populationDataDtoList.stream().mapToInt(e -> e.getPopulation()).sum();
                resultData.add(new CampaignDiagramDataDto(districtReferenceDto.getCaption(), populationSum, districtReferenceDto.getUuid(), districtReferenceDto.getCaption(), diagramSeries.getFieldId(), diagramSeries.getFormId(), true));
            } else {
                resultData.add(new CampaignDiagramDataDto(districtReferenceDto.getCaption(), populationSum, districtReferenceDto.getUuid(), districtReferenceDto.getCaption(), diagramSeries.getFieldId(), diagramSeries.getFormId(), false));
            }
        });
    // }
    } else if (district != null) {
        resultData.add(new CampaignDiagramDataDto(district.getCaption(), 0, district.getUuid(), district.getCaption(), diagramSeries.getFieldId(), diagramSeries.getFormId(), true));
    }
    return resultData;
}
Also used : PopulationDataCriteria(de.symeda.sormas.api.infrastructure.PopulationDataCriteria) DtoHelper(de.symeda.sormas.backend.util.DtoHelper) Join(javax.persistence.criteria.Join) CampaignFormDataReferenceDto(de.symeda.sormas.api.campaign.data.CampaignFormDataReferenceDto) AbstractDomainObject(de.symeda.sormas.backend.common.AbstractDomainObject) Date(java.util.Date) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) CampaignDiagramCriteria(de.symeda.sormas.api.campaign.diagram.CampaignDiagramCriteria) CampaignFormMetaFacadeEjb(de.symeda.sormas.backend.campaign.form.CampaignFormMetaFacadeEjb) CommunityFacadeEjb(de.symeda.sormas.backend.infrastructure.community.CommunityFacadeEjb) DistrictService(de.symeda.sormas.backend.infrastructure.district.DistrictService) Valid(javax.validation.Valid) CampaignService(de.symeda.sormas.backend.campaign.CampaignService) Predicate(javax.persistence.criteria.Predicate) UserFacadeEjb(de.symeda.sormas.backend.user.UserFacadeEjb) CampaignDiagramSeries(de.symeda.sormas.api.campaign.diagram.CampaignDiagramSeries) Area(de.symeda.sormas.backend.infrastructure.area.Area) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) JoinType(javax.persistence.criteria.JoinType) CampaignFormDataFacade(de.symeda.sormas.api.campaign.data.CampaignFormDataFacade) Stateless(javax.ejb.Stateless) CampaignFormElementType(de.symeda.sormas.api.campaign.form.CampaignFormElementType) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) CommunityService(de.symeda.sormas.backend.infrastructure.community.CommunityService) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) NotNull(javax.validation.constraints.NotNull) CampaignJurisdictionLevel(de.symeda.sormas.api.campaign.CampaignJurisdictionLevel) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Query(javax.persistence.Query) UserService(de.symeda.sormas.backend.user.UserService) CampaignFormDataCriteria(de.symeda.sormas.api.campaign.data.CampaignFormDataCriteria) DistrictFacadeEjb(de.symeda.sormas.backend.infrastructure.district.DistrictFacadeEjb) Campaign(de.symeda.sormas.backend.campaign.Campaign) Order(javax.persistence.criteria.Order) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) CampaignFormMeta(de.symeda.sormas.backend.campaign.form.CampaignFormMeta) Community(de.symeda.sormas.backend.infrastructure.community.Community) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) CampaignFormElement(de.symeda.sormas.api.campaign.form.CampaignFormElement) PopulationDataFacadeEjb(de.symeda.sormas.backend.infrastructure.PopulationDataFacadeEjb) ArrayList(java.util.ArrayList) CampaignFormDataDto(de.symeda.sormas.api.campaign.data.CampaignFormDataDto) CampaignDiagramDataDto(de.symeda.sormas.api.campaign.diagram.CampaignDiagramDataDto) LocalBean(javax.ejb.LocalBean) Expression(javax.persistence.criteria.Expression) CampaignFormDataEntry(de.symeda.sormas.api.campaign.data.CampaignFormDataEntry) CriteriaBuilderHelper(de.symeda.sormas.backend.common.CriteriaBuilderHelper) AreaService(de.symeda.sormas.backend.infrastructure.area.AreaService) EJB(javax.ejb.EJB) Root(javax.persistence.criteria.Root) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) CampaignFormMetaService(de.symeda.sormas.backend.campaign.form.CampaignFormMetaService) CampaignFormDataIndexDto(de.symeda.sormas.api.campaign.data.CampaignFormDataIndexDto) Validations(de.symeda.sormas.api.i18n.Validations) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) CampaignReferenceDto(de.symeda.sormas.api.campaign.CampaignReferenceDto) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) SortProperty(de.symeda.sormas.api.utils.SortProperty) RegionFacadeEjb(de.symeda.sormas.backend.infrastructure.region.RegionFacadeEjb) RegionService(de.symeda.sormas.backend.infrastructure.region.RegionService) UserRight(de.symeda.sormas.api.user.UserRight) PopulationDataDto(de.symeda.sormas.api.infrastructure.PopulationDataDto) CampaignFacadeEjb(de.symeda.sormas.backend.campaign.CampaignFacadeEjb) AreaReferenceDto(de.symeda.sormas.api.infrastructure.area.AreaReferenceDto) Collections(java.util.Collections) ArrayList(java.util.ArrayList) CampaignJurisdictionLevel(de.symeda.sormas.api.campaign.CampaignJurisdictionLevel) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) Area(de.symeda.sormas.backend.infrastructure.area.Area) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) PopulationDataCriteria(de.symeda.sormas.api.infrastructure.PopulationDataCriteria) AreaReferenceDto(de.symeda.sormas.api.infrastructure.area.AreaReferenceDto) List(java.util.List) ArrayList(java.util.ArrayList) PopulationDataDto(de.symeda.sormas.api.infrastructure.PopulationDataDto) CampaignDiagramDataDto(de.symeda.sormas.api.campaign.diagram.CampaignDiagramDataDto)

Aggregations

CampaignJurisdictionLevel (de.symeda.sormas.api.campaign.CampaignJurisdictionLevel)2 CampaignReferenceDto (de.symeda.sormas.api.campaign.CampaignReferenceDto)2 CampaignDiagramCriteria (de.symeda.sormas.api.campaign.diagram.CampaignDiagramCriteria)2 CampaignDiagramDataDto (de.symeda.sormas.api.campaign.diagram.CampaignDiagramDataDto)2 CampaignDiagramSeries (de.symeda.sormas.api.campaign.diagram.CampaignDiagramSeries)2 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)2 AreaReferenceDto (de.symeda.sormas.api.infrastructure.area.AreaReferenceDto)2 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)2 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)2 FacadeProvider (de.symeda.sormas.api.FacadeProvider)1 CampaignFormDataCriteria (de.symeda.sormas.api.campaign.data.CampaignFormDataCriteria)1 CampaignFormDataDto (de.symeda.sormas.api.campaign.data.CampaignFormDataDto)1 CampaignFormDataEntry (de.symeda.sormas.api.campaign.data.CampaignFormDataEntry)1 CampaignFormDataFacade (de.symeda.sormas.api.campaign.data.CampaignFormDataFacade)1 CampaignFormDataIndexDto (de.symeda.sormas.api.campaign.data.CampaignFormDataIndexDto)1 CampaignFormDataReferenceDto (de.symeda.sormas.api.campaign.data.CampaignFormDataReferenceDto)1 CampaignDashboardElement (de.symeda.sormas.api.campaign.diagram.CampaignDashboardElement)1 CampaignDiagramDefinitionDto (de.symeda.sormas.api.campaign.diagram.CampaignDiagramDefinitionDto)1 CampaignFormElement (de.symeda.sormas.api.campaign.form.CampaignFormElement)1 CampaignFormElementType (de.symeda.sormas.api.campaign.form.CampaignFormElementType)1