use of de.symeda.sormas.api.campaign.CampaignJurisdictionLevel in project SORMAS-Project by hzi-braunschweig.
the class CampaignStatisticsService method getCampaignStatistics.
public List<CampaignStatisticsDto> getCampaignStatistics(CampaignStatisticsCriteria criteria) {
Query campaignsStatisticsQuery = em.createNativeQuery(buildStatisticsQuery(criteria));
final CampaignJurisdictionLevel groupingLevel = criteria.getGroupingLevel();
Map<CampaignStatisticsGroupingDto, CampaignStatisticsDto> results = new LinkedHashMap<>();
((Stream<Object[]>) campaignsStatisticsQuery.getResultStream()).forEach(result -> {
CampaignStatisticsGroupingDto campaignStatisticsGroupingDto = new CampaignStatisticsGroupingDto((String) result[1], (String) result[2], (String) result[3], shouldIncludeRegion(groupingLevel) ? (String) result[4] : "", shouldIncludeDistrict(groupingLevel) ? (String) result[5] : "", shouldIncludeCommunity(groupingLevel) ? (String) result[6] : "");
if (!results.containsKey(campaignStatisticsGroupingDto)) {
CampaignStatisticsDto campaignStatisticsDto = new CampaignStatisticsDto(campaignStatisticsGroupingDto, result[0] != null ? ((Number) result[0]).intValue() : null);
results.put(campaignStatisticsGroupingDto, campaignStatisticsDto);
}
int length = result.length;
CampaignFormDataEntry campaignFormDataEntry = new CampaignFormDataEntry((String) result[length - 2], result[length - 1]);
results.get(campaignStatisticsGroupingDto).addStatisticsData(campaignFormDataEntry);
});
return results.values().stream().collect(Collectors.toList());
}
use of de.symeda.sormas.api.campaign.CampaignJurisdictionLevel 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.campaign.CampaignJurisdictionLevel in project SORMAS-Project by hzi-braunschweig.
the class CampaignStatisticsService method buildGroupByExpression.
private String buildGroupByExpression(CampaignStatisticsCriteria criteria) {
CampaignJurisdictionLevel groupingLevel = criteria.getGroupingLevel();
StringBuilder groupByFilter = new StringBuilder(" GROUP BY ");
groupByFilter.append(Campaign.TABLE_NAME).append(".").append(Campaign.NAME).append(", ").append(CampaignFormMeta.TABLE_NAME).append(".").append(CampaignFormMeta.FORM_NAME).append(", ").append(Area.TABLE_NAME).append(".").append(Area.NAME);
if (shouldIncludeRegion(groupingLevel)) {
groupByFilter.append(", ").append(Region.TABLE_NAME).append(".").append(Region.NAME);
}
if (shouldIncludeDistrict(groupingLevel)) {
groupByFilter.append(", ").append(District.TABLE_NAME).append(".").append(District.NAME);
}
if (shouldIncludeCommunity(groupingLevel)) {
groupByFilter.append(", ").append(Community.TABLE_NAME).append(".").append(Community.NAME);
}
return groupByFilter.toString();
}
use of de.symeda.sormas.api.campaign.CampaignJurisdictionLevel in project SORMAS-Project by hzi-braunschweig.
the class CampaignStatisticsService method buildOrderByExpression.
private String buildOrderByExpression(CampaignStatisticsCriteria criteria) {
CampaignJurisdictionLevel groupingLevel = criteria.getGroupingLevel();
StringBuilder orderByFilter = new StringBuilder(" ORDER BY ");
orderByFilter.append(Campaign.TABLE_NAME).append(".").append(Campaign.NAME).append(", ").append(CampaignFormMeta.TABLE_NAME).append(".").append(CampaignFormMeta.FORM_NAME).append(", ").append(Area.TABLE_NAME).append(".").append(Area.NAME);
if (shouldIncludeRegion(groupingLevel)) {
orderByFilter.append(", ").append(Region.TABLE_NAME).append(".").append(Region.NAME);
}
if (shouldIncludeDistrict(groupingLevel)) {
orderByFilter.append(", ").append(District.TABLE_NAME).append(".").append(District.NAME);
}
if (shouldIncludeCommunity(groupingLevel)) {
orderByFilter.append(", ").append(Community.TABLE_NAME).append(".").append(Community.NAME);
}
return orderByFilter.toString();
}
use of de.symeda.sormas.api.campaign.CampaignJurisdictionLevel in project SORMAS-Project by hzi-braunschweig.
the class CampaignStatisticsService method buildSelectExpression.
private String buildSelectExpression(CampaignStatisticsCriteria criteria) {
StringBuilder selectBuilder = new StringBuilder().append(buildSelectField(Campaign.TABLE_NAME, Campaign.NAME)).append(", ").append(buildSelectField(CampaignFormMeta.TABLE_NAME, CampaignFormMeta.FORM_NAME)).append(", ").append(buildSelectField(Area.TABLE_NAME, Area.NAME));
CampaignJurisdictionLevel groupingLevel = criteria.getGroupingLevel();
if (shouldIncludeRegion(groupingLevel)) {
selectBuilder.append(", ").append(buildSelectField(Region.TABLE_NAME, Region.NAME));
}
if (shouldIncludeDistrict(groupingLevel)) {
selectBuilder.append(", ").append(buildSelectField(District.TABLE_NAME, District.NAME));
}
if (shouldIncludeCommunity(groupingLevel)) {
selectBuilder.append(", ").append(buildSelectField(Community.TABLE_NAME, Community.NAME));
}
return selectBuilder.toString();
}
Aggregations