Search in sources :

Example 1 with PopulationDataDto

use of de.symeda.sormas.api.infrastructure.PopulationDataDto in project SORMAS-Project by hzi-braunschweig.

the class CaseStatisticsFacadeEjbTest method testQueryCaseCountPopulation.

@Test
public void testQueryCaseCountPopulation() {
    RDCF rdcf = creator.createRDCF("Region", "District", "Community", "Facility");
    UserDto user = creator.createUser(rdcf.region.getUuid(), rdcf.district.getUuid(), rdcf.facility.getUuid(), "Surv", "Sup", UserRole.SURVEILLANCE_SUPERVISOR);
    PersonDto cazePerson = creator.createPerson("Case", "Person");
    cazePerson.setApproximateAge(30);
    cazePerson.setApproximateAgeReferenceDate(new Date());
    cazePerson.setApproximateAgeType(ApproximateAgeType.YEARS);
    cazePerson = getPersonFacade().savePerson(cazePerson);
    CaseDataDto caze = creator.createCase(user.toReference(), cazePerson.toReference(), Disease.EVD, CaseClassification.PROBABLE, InvestigationStatus.PENDING, new Date(), rdcf);
    caze = getCaseFacade().getCaseDataByUuid(caze.getUuid());
    StatisticsCaseCriteria criteria = new StatisticsCaseCriteria();
    criteria.regions(Arrays.asList(rdcf.region));
    List<StatisticsCaseCountDto> results = getCaseStatisticsFacade().queryCaseCount(criteria, StatisticsCaseAttribute.JURISDICTION, StatisticsCaseSubAttribute.REGION, null, null, true, false, null);
    assertNull(results.get(0).getPopulation());
    PopulationDataDto populationData = PopulationDataDto.build(new Date());
    RegionDto region = getRegionFacade().getByUuid(rdcf.region.getUuid());
    region.setGrowthRate(10f);
    getRegionFacade().save(region);
    populationData.setRegion(rdcf.region);
    populationData.setPopulation(new Integer(10000));
    getPopulationDataFacade().savePopulationData(Arrays.asList(populationData));
    results = getCaseStatisticsFacade().queryCaseCount(criteria, StatisticsCaseAttribute.JURISDICTION, StatisticsCaseSubAttribute.REGION, null, null, true, false, LocalDate.now().getYear() + 2);
    // List should have one entry
    assertEquals(Integer.valueOf(12214), results.get(0).getPopulation());
}
Also used : RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) StatisticsCaseCriteria(de.symeda.sormas.api.statistics.StatisticsCaseCriteria) PopulationDataDto(de.symeda.sormas.api.infrastructure.PopulationDataDto) RegionDto(de.symeda.sormas.api.infrastructure.region.RegionDto) StatisticsCaseCountDto(de.symeda.sormas.api.statistics.StatisticsCaseCountDto) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 2 with PopulationDataDto

use of de.symeda.sormas.api.infrastructure.PopulationDataDto in project SORMAS-Project by hzi-braunschweig.

the class PopulationDataFacadeEjb method getPopulationData.

@Override
public List<PopulationDataDto> getPopulationData(PopulationDataCriteria criteria) {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<PopulationData> cq = cb.createQuery(PopulationData.class);
    Root<PopulationData> root = cq.from(PopulationData.class);
    Predicate filter = service.buildCriteriaFilter(criteria, cb, root);
    cq.where(filter);
    return em.createQuery(cq).getResultStream().map(populationData -> toDto(populationData)).collect(Collectors.toList());
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) PopulationDataCriteria(de.symeda.sormas.api.infrastructure.PopulationDataCriteria) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) DtoHelper(de.symeda.sormas.backend.util.DtoHelper) Join(javax.persistence.criteria.Join) Community(de.symeda.sormas.backend.infrastructure.community.Community) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) NoResultException(javax.persistence.NoResultException) CommunityFacadeEjb(de.symeda.sormas.backend.infrastructure.community.CommunityFacadeEjb) DistrictService(de.symeda.sormas.backend.infrastructure.district.DistrictService) TypedQuery(javax.persistence.TypedQuery) AgeGroup(de.symeda.sormas.api.AgeGroup) ArrayList(java.util.ArrayList) Valid(javax.validation.Valid) NonUniqueResultException(javax.persistence.NonUniqueResultException) Predicate(javax.persistence.criteria.Predicate) PopulationDataFacade(de.symeda.sormas.api.infrastructure.PopulationDataFacade) CollectionUtils(org.apache.commons.collections.CollectionUtils) Area(de.symeda.sormas.backend.infrastructure.area.Area) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) LocalBean(javax.ejb.LocalBean) StatisticsCaseCriteria(de.symeda.sormas.api.statistics.StatisticsCaseCriteria) 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) InfrastructureHelper(de.symeda.sormas.api.infrastructure.InfrastructureHelper) Validations(de.symeda.sormas.api.i18n.Validations) CommunityService(de.symeda.sormas.backend.infrastructure.community.CommunityService) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) 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) Objects(java.util.Objects) List(java.util.List) Query(javax.persistence.Query) PopulationDataDto(de.symeda.sormas.api.infrastructure.PopulationDataDto) DistrictFacadeEjb(de.symeda.sormas.backend.infrastructure.district.DistrictFacadeEjb) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) Predicate(javax.persistence.criteria.Predicate)

Example 3 with PopulationDataDto

use of de.symeda.sormas.api.infrastructure.PopulationDataDto in project SORMAS-Project by hzi-braunschweig.

the class PopulationDataFacadeEjb method toDto.

public static PopulationDataDto toDto(PopulationData source) {
    if (source == null) {
        return null;
    }
    PopulationDataDto target = new PopulationDataDto();
    DtoHelper.fillDto(target, source);
    target.setRegion(RegionFacadeEjb.toReferenceDto(source.getRegion()));
    target.setDistrict(DistrictFacadeEjb.toReferenceDto(source.getDistrict()));
    target.setCommunity(CommunityFacadeEjb.toReferenceDto(source.getCommunity()));
    target.setAgeGroup(source.getAgeGroup());
    target.setSex(source.getSex());
    target.setPopulation(source.getPopulation());
    target.setCollectionDate(source.getCollectionDate());
    return target;
}
Also used : PopulationDataDto(de.symeda.sormas.api.infrastructure.PopulationDataDto)

Example 4 with PopulationDataDto

use of de.symeda.sormas.api.infrastructure.PopulationDataDto in project SORMAS-Project by hzi-braunschweig.

the class PopulationDataFacadeEjb method savePopulationData.

@Override
public void savePopulationData(@Valid List<PopulationDataDto> populationDataList) throws ValidationRuntimeException {
    for (PopulationDataDto populationData : populationDataList) {
        validate(populationData);
        PopulationData entity = fromDto(populationData, true);
        service.ensurePersisted(entity);
    }
}
Also used : PopulationDataDto(de.symeda.sormas.api.infrastructure.PopulationDataDto)

Example 5 with PopulationDataDto

use of de.symeda.sormas.api.infrastructure.PopulationDataDto 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

PopulationDataDto (de.symeda.sormas.api.infrastructure.PopulationDataDto)7 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)3 Validations (de.symeda.sormas.api.i18n.Validations)3 PopulationDataCriteria (de.symeda.sormas.api.infrastructure.PopulationDataCriteria)3 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)3 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)3 ValidationRuntimeException (de.symeda.sormas.api.utils.ValidationRuntimeException)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 List (java.util.List)3 AgeGroup (de.symeda.sormas.api.AgeGroup)2 RegionDto (de.symeda.sormas.api.infrastructure.region.RegionDto)2 StatisticsCaseCriteria (de.symeda.sormas.api.statistics.StatisticsCaseCriteria)2 UserDto (de.symeda.sormas.api.user.UserDto)2 FacadeProvider (de.symeda.sormas.api.FacadeProvider)1 CampaignJurisdictionLevel (de.symeda.sormas.api.campaign.CampaignJurisdictionLevel)1 CampaignReferenceDto (de.symeda.sormas.api.campaign.CampaignReferenceDto)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