use of de.symeda.sormas.backend.infrastructure.area.Area in project SORMAS-Project by hzi-braunschweig.
the class RegionFacadeEjb method getIndexList.
@Override
public List<RegionIndexDto> getIndexList(RegionCriteria criteria, Integer first, Integer max, List<SortProperty> sortProperties) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Region> cq = cb.createQuery(Region.class);
Root<Region> region = cq.from(Region.class);
Join<Region, Area> area = region.join(Region.AREA, JoinType.LEFT);
Join<Region, Country> country = region.join(Region.COUNTRY, JoinType.LEFT);
Predicate filter = null;
if (criteria != null) {
filter = service.buildCriteriaFilter(criteria, cb, region);
}
if (filter != null) {
cq.where(filter);
}
if (CollectionUtils.isNotEmpty(sortProperties)) {
List<Order> order = new ArrayList<>(sortProperties.size());
for (SortProperty sortProperty : sortProperties) {
Expression<?> expression;
switch(sortProperty.propertyName) {
case Region.NAME:
case Region.EPID_CODE:
case Region.GROWTH_RATE:
case Region.EXTERNAL_ID:
expression = region.get(sortProperty.propertyName);
break;
case Region.AREA:
expression = area.get(Area.NAME);
break;
case RegionIndexDto.COUNTRY:
expression = country.get(Country.DEFAULT_NAME);
break;
default:
throw new IllegalArgumentException(sortProperty.propertyName);
}
order.add(sortProperty.ascending ? cb.asc(expression) : cb.desc(expression));
}
cq.orderBy(order);
} else {
cq.orderBy(cb.asc(region.get(Region.NAME)));
}
cq.select(region);
return QueryHelper.getResultList(em, cq, first, max, this::toIndexDto);
}
use of de.symeda.sormas.backend.infrastructure.area.Area in project SORMAS-Project by hzi-braunschweig.
the class PopulationDataFacadeEjb method getAreaPopulation.
public Integer getAreaPopulation(String areaUuid, AgeGroup ageGroup) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Integer> cq = cb.createQuery(Integer.class);
Root<PopulationData> root = cq.from(PopulationData.class);
Join<PopulationData, Region> regionJoin = root.join(PopulationData.REGION);
Join<Region, Area> areaJoin = regionJoin.join(Region.AREA);
Predicate areaFilter = cb.equal(areaJoin.get(Area.UUID), areaUuid);
Predicate ageFilter = cb.and(cb.equal(root.get(PopulationData.AGE_GROUP), ageGroup));
cq.where(areaFilter, ageFilter);
cq.select(root.get(PopulationData.POPULATION));
TypedQuery query = em.createQuery(cq);
try {
Integer totalPopulation = 0;
for (Object i : query.getResultList()) {
if (Objects.nonNull(i)) {
totalPopulation = totalPopulation + (Integer) i;
}
}
return totalPopulation;
} catch (NoResultException e) {
return null;
}
}
use of de.symeda.sormas.backend.infrastructure.area.Area 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.backend.infrastructure.area.Area in project SORMAS-Project by hzi-braunschweig.
the class DistrictService method getAllActiveByArea.
public List<District> getAllActiveByArea(Area area) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<District> cq = cb.createQuery(getElementClass());
Root<District> from = cq.from(getElementClass());
Path<Area> regionJoin = from.join(District.REGION, JoinType.LEFT);
cq.where(cb.and(createBasicFilter(cb, from), cb.equal(regionJoin.get(Region.AREA), area)));
cq.orderBy(cb.asc(from.get(District.NAME)));
return em.createQuery(cq).getResultList();
}
Aggregations