use of de.symeda.sormas.api.infrastructure.PopulationDataCriteria 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());
}
use of de.symeda.sormas.api.infrastructure.PopulationDataCriteria in project SORMAS-Project by hzi-braunschweig.
the class PopulationDataFacadeEjb method getProjectedRegionPopulation.
@Override
public Integer getProjectedRegionPopulation(String regionUuid) {
Float growthRate = regionService.getByUuid(regionUuid).getGrowthRate();
if (growthRate == null || growthRate == 0) {
return getRegionPopulation(regionUuid);
}
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<PopulationData> cq = cb.createQuery(PopulationData.class);
Root<PopulationData> root = cq.from(PopulationData.class);
PopulationDataCriteria criteria = new PopulationDataCriteria().ageGroupIsNull(true).sexIsNull(true).districtIsNull(true).communityIsNull(true).region(new RegionReferenceDto(regionUuid, null, null));
Predicate filter = service.buildCriteriaFilter(criteria, cb, root);
cq.where(filter);
try {
PopulationData populationData = em.createQuery(cq).getSingleResult();
return InfrastructureHelper.getProjectedPopulation(populationData.getPopulation(), populationData.getCollectionDate(), growthRate);
} catch (NoResultException | NonUniqueResultException e) {
return null;
}
}
use of de.symeda.sormas.api.infrastructure.PopulationDataCriteria in project SORMAS-Project by hzi-braunschweig.
the class PopulationDataFacadeEjb method getDistrictPopulation.
@Override
public Integer getDistrictPopulation(String districtUuid) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Integer> cq = cb.createQuery(Integer.class);
Root<PopulationData> root = cq.from(PopulationData.class);
PopulationDataCriteria criteria = new PopulationDataCriteria().ageGroupIsNull(true).sexIsNull(true).communityIsNull(true).district(new DistrictReferenceDto(districtUuid, null, null));
Predicate filter = service.buildCriteriaFilter(criteria, cb, root);
cq.where(filter);
cq.select(root.get(PopulationData.POPULATION));
return QueryHelper.getSingleResult(em, cq);
}
use of de.symeda.sormas.api.infrastructure.PopulationDataCriteria 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;
}
use of de.symeda.sormas.api.infrastructure.PopulationDataCriteria in project SORMAS-Project by hzi-braunschweig.
the class PopulationDataFacadeEjb method getRegionPopulation.
@Override
public Integer getRegionPopulation(String regionUuid) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Integer> cq = cb.createQuery(Integer.class);
Root<PopulationData> root = cq.from(PopulationData.class);
PopulationDataCriteria criteria = new PopulationDataCriteria().ageGroupIsNull(true).sexIsNull(true).districtIsNull(true).communityIsNull(true).region(new RegionReferenceDto(regionUuid, null, null));
Predicate filter = service.buildCriteriaFilter(criteria, cb, root);
cq.where(filter);
cq.select(root.get(PopulationData.POPULATION));
return QueryHelper.getSingleResult(em, cq);
}
Aggregations