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());
}
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());
}
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;
}
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);
}
}
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;
}
Aggregations