use of de.symeda.sormas.api.AgeGroup in project SORMAS-Project by hzi-braunschweig.
the class CaseStatisticsFacadeEjb method extendGroupingBuilderWithAgeInterval.
private void extendGroupingBuilderWithAgeInterval(StringBuilder groupingBuilder, StatisticsCaseAttribute grouping, String groupAlias) {
groupingBuilder.append("CASE ");
switch(grouping) {
case AGE_INTERVAL_1_YEAR:
for (int i = 0; i < 80; i++) {
groupingBuilder.append("WHEN ").append(Case.TABLE_NAME).append(".").append(Case.CASE_AGE).append(" = ").append(i < 10 ? "0" + i : i).append(" THEN ").append("'").append(i < 10 ? "0" + i : i).append("' ");
}
break;
case AGE_INTERVAL_5_YEARS:
for (AgeGroup ageGroup : AgeGroup.values()) {
addAgeGroupToStringBuilder(groupingBuilder, ageGroup);
}
break;
case AGE_INTERVAL_CHILDREN_COARSE:
addAgeIntervalToStringBuilder(groupingBuilder, 0, 14);
for (int i = 15; i < 30; i += 5) {
addAgeIntervalToStringBuilder(groupingBuilder, i, 4);
}
for (int i = 30; i < 80; i += 10) {
addAgeIntervalToStringBuilder(groupingBuilder, i, 9);
}
break;
case AGE_INTERVAL_CHILDREN_FINE:
for (int i = 0; i < 5; i++) {
groupingBuilder.append("WHEN ").append(Case.TABLE_NAME).append(".").append(Case.CASE_AGE).append(" = ").append(i).append(" THEN ").append("'").append("0" + i).append("-").append("0" + i).append("' ");
}
for (int i = 5; i < 30; i += 5) {
addAgeIntervalToStringBuilder(groupingBuilder, i, 4);
}
for (int i = 30; i < 80; i += 10) {
addAgeIntervalToStringBuilder(groupingBuilder, i, 9);
}
break;
case AGE_INTERVAL_CHILDREN_MEDIUM:
for (int i = 0; i < 30; i += 5) {
addAgeIntervalToStringBuilder(groupingBuilder, i, 4);
}
for (int i = 30; i < 80; i += 10) {
addAgeIntervalToStringBuilder(groupingBuilder, i, 9);
}
break;
case AGE_INTERVAL_BASIC:
addAgeIntervalToStringBuilder(groupingBuilder, 0, 0);
addAgeIntervalToStringBuilder(groupingBuilder, 1, 3);
addAgeIntervalToStringBuilder(groupingBuilder, 5, 9);
groupingBuilder.append("WHEN ").append(Case.TABLE_NAME).append(".").append(Case.CASE_AGE).append(" >= 15 THEN '15+' ");
break;
default:
throw new IllegalArgumentException(grouping.toString());
}
if (grouping != StatisticsCaseAttribute.AGE_INTERVAL_BASIC && grouping != StatisticsCaseAttribute.AGE_INTERVAL_5_YEARS) {
groupingBuilder.append("WHEN ").append(Case.TABLE_NAME).append(".").append(Case.CASE_AGE).append(" >= 80 THEN '80+' ");
}
groupingBuilder.append("ELSE NULL END AS " + groupAlias);
}
use of de.symeda.sormas.api.AgeGroup in project SORMAS-Project by hzi-braunschweig.
the class ImportFacadeEjb method generatePopulationDataImportTemplateFile.
@Override
public void generatePopulationDataImportTemplateFile() throws IOException {
createExportDirectoryIfNecessary();
char separator = configFacade.getCsvSeparator();
List<ImportColumn> importColumns = new ArrayList<>();
importColumns.add(ImportColumn.from(PopulationDataDto.class, PopulationDataDto.REGION, RegionReferenceDto.class, separator));
importColumns.add(ImportColumn.from(PopulationDataDto.class, PopulationDataDto.DISTRICT, DistrictReferenceDto.class, separator));
importColumns.add(ImportColumn.from(PopulationDataDto.class, PopulationDataDto.COMMUNITY, CommunityReferenceDto.class, separator));
importColumns.add(ImportColumn.from(RegionDto.class, RegionDto.GROWTH_RATE, Float.class, separator));
importColumns.add(ImportColumn.from(PopulationDataDto.class, "TOTAL", Integer.class, separator));
importColumns.add(ImportColumn.from(PopulationDataDto.class, "MALE_TOTAL", Integer.class, separator));
importColumns.add(ImportColumn.from(PopulationDataDto.class, "FEMALE_TOTAL", Integer.class, separator));
importColumns.add(ImportColumn.from(PopulationDataDto.class, "OTHER_TOTAL", Integer.class, separator));
for (AgeGroup ageGroup : AgeGroup.values()) {
importColumns.add(ImportColumn.from(PopulationDataDto.class, "TOTAL_" + ageGroup.name(), Integer.class, separator));
importColumns.add(ImportColumn.from(PopulationDataDto.class, "MALE_" + ageGroup.name(), Integer.class, separator));
importColumns.add(ImportColumn.from(PopulationDataDto.class, "FEMALE_" + ageGroup.name(), Integer.class, separator));
importColumns.add(ImportColumn.from(PopulationDataDto.class, "OTHER_" + ageGroup.name(), Integer.class, separator));
}
writeTemplate(Paths.get(getPopulationDataImportTemplateFilePath()), importColumns, false);
}
use of de.symeda.sormas.api.AgeGroup in project SORMAS-Project by hzi-braunschweig.
the class DownloadUtil method createPopulationDataExportResource.
@SuppressWarnings("serial")
public static StreamResource createPopulationDataExportResource() {
String exportFileName = createFileNameWithCurrentDate(ExportEntityName.POPULATION_DATA, ".csv");
StreamResource populationDataStreamResource = new StreamResource(new StreamSource() {
@Override
public InputStream getStream() {
try (ByteArrayOutputStream byteStream = new ByteArrayOutputStream()) {
try (CSVWriter writer = CSVUtils.createCSVWriter(new OutputStreamWriter(byteStream, StandardCharsets.UTF_8.name()), FacadeProvider.getConfigFacade().getCsvSeparator())) {
// Generate and write columns to CSV writer
List<String> columnNames = new ArrayList<>();
columnNames.add(I18nProperties.getPrefixCaption(PopulationDataDto.I18N_PREFIX, PopulationDataDto.REGION));
columnNames.add(I18nProperties.getPrefixCaption(PopulationDataDto.I18N_PREFIX, PopulationDataDto.DISTRICT));
columnNames.add(I18nProperties.getPrefixCaption(PopulationDataDto.I18N_PREFIX, PopulationDataDto.COMMUNITY));
columnNames.add(I18nProperties.getString(Strings.total));
columnNames.add(I18nProperties.getCaption(Captions.populationDataMaleTotal));
columnNames.add(I18nProperties.getCaption(Captions.populationDataFemaleTotal));
Map<AgeGroup, Integer> ageGroupPositions = new HashMap<>();
int ageGroupIndex = 6;
for (AgeGroup ageGroup : AgeGroup.values()) {
columnNames.add(DataHelper.getSexAndAgeGroupString(ageGroup, null));
columnNames.add(DataHelper.getSexAndAgeGroupString(ageGroup, Sex.MALE));
columnNames.add(DataHelper.getSexAndAgeGroupString(ageGroup, Sex.FEMALE));
columnNames.add(DataHelper.getSexAndAgeGroupString(ageGroup, Sex.OTHER));
ageGroupPositions.put(ageGroup, ageGroupIndex);
ageGroupIndex += 4;
}
writer.writeNext(columnNames.toArray(new String[columnNames.size()]));
List<Object[]> populationExportDataList = FacadeProvider.getPopulationDataFacade().getPopulationDataForExport();
String[] exportLine = new String[columnNames.size()];
String regionName = "";
String districtName = "";
String communityName = "";
for (Object[] populationExportData : populationExportDataList) {
String dataRegionName = (String) populationExportData[0];
String dataDistrictName = populationExportData[1] == null ? "" : (String) populationExportData[1];
String dataCommunityName = populationExportData[2] == null ? "" : (String) populationExportData[2];
if (exportLine[0] != null && (!dataRegionName.equals(regionName) || !dataDistrictName.equals(districtName) || !dataCommunityName.equals(communityName))) {
// New region or district reached; write line to CSV
writer.writeNext(exportLine);
exportLine = new String[columnNames.size()];
}
regionName = dataRegionName;
districtName = dataDistrictName;
communityName = dataCommunityName;
// Region
if (exportLine[0] == null) {
exportLine[0] = (String) populationExportData[0];
}
// District
if (exportLine[1] == null) {
exportLine[1] = (String) populationExportData[1];
}
// Community
if (exportLine[2] == null) {
exportLine[2] = (String) populationExportData[2];
}
if (populationExportData[3] == null) {
// Total population
String sexString = (String) populationExportData[4];
if (Sex.MALE.getName().equals(sexString)) {
exportLine[4] = String.valueOf((int) populationExportData[5]);
} else if (Sex.FEMALE.getName().equals(sexString)) {
exportLine[5] = String.valueOf((int) populationExportData[5]);
} else if (Sex.OTHER.getName().equals(sexString)) {
exportLine[6] = String.valueOf((int) populationExportData[5]);
} else {
exportLine[3] = String.valueOf((int) populationExportData[5]);
}
} else {
// Population based on age group position and sex
Integer ageGroupPosition = ageGroupPositions.get(AgeGroup.valueOf((String) populationExportData[3]));
String sexString = (String) populationExportData[4];
if (Sex.MALE.getName().equals(sexString)) {
ageGroupPosition += 1;
} else if (Sex.FEMALE.getName().equals(sexString)) {
ageGroupPosition += 2;
} else if (Sex.OTHER.getName().equals(sexString)) {
ageGroupPosition += 3;
}
exportLine[ageGroupPosition] = String.valueOf((int) populationExportData[5]);
}
}
// Write last line to CSV
writer.writeNext(exportLine);
writer.flush();
}
return new ByteArrayInputStream(byteStream.toByteArray());
} catch (IOException e) {
// TODO This currently requires the user to click the "Export" button again or reload the page as the UI
// is not automatically updated; this should be changed once Vaadin push is enabled (see #516)
new Notification(I18nProperties.getString(Strings.headingExportFailed), I18nProperties.getString(Strings.messageExportFailed), Type.ERROR_MESSAGE, false).show(Page.getCurrent());
return null;
}
}
}, exportFileName);
populationDataStreamResource.setMIMEType("text/csv");
populationDataStreamResource.setCacheTime(0);
return populationDataStreamResource;
}
use of de.symeda.sormas.api.AgeGroup in project SORMAS-Project by hzi-braunschweig.
the class StatisticsView method fillCaseCriteria.
private void fillCaseCriteria(boolean showCaseIncidence) {
caseCriteria = new StatisticsCaseCriteria();
for (StatisticsFilterComponent filterComponent : filterComponents) {
StatisticsFilterElement filterElement = filterComponent.getFilterElement();
switch(filterComponent.getSelectedAttribute()) {
case SEX:
if (filterElement.getSelectedValues() != null) {
List<Sex> sexes = new ArrayList<>();
for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
if (tokenizableValue.getValue().equals(I18nProperties.getString(Strings.notSpecified))) {
caseCriteria.sexUnknown(true);
} else {
sexes.add((Sex) tokenizableValue.getValue());
}
}
caseCriteria.sexes(sexes);
}
break;
case DISEASE:
if (filterElement.getSelectedValues() != null) {
List<Disease> diseases = new ArrayList<>();
for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
diseases.add((Disease) tokenizableValue.getValue());
}
caseCriteria.diseases(diseases);
}
break;
case CLASSIFICATION:
if (filterElement.getSelectedValues() != null) {
List<CaseClassification> classifications = new ArrayList<>();
for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
classifications.add((CaseClassification) tokenizableValue.getValue());
}
caseCriteria.classifications(classifications);
}
break;
case OUTCOME:
if (filterElement.getSelectedValues() != null) {
List<CaseOutcome> outcomes = new ArrayList<>();
for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
outcomes.add((CaseOutcome) tokenizableValue.getValue());
}
caseCriteria.outcomes(outcomes);
}
break;
case AGE_INTERVAL_1_YEAR:
case AGE_INTERVAL_5_YEARS:
case AGE_INTERVAL_CHILDREN_COARSE:
case AGE_INTERVAL_CHILDREN_FINE:
case AGE_INTERVAL_CHILDREN_MEDIUM:
case AGE_INTERVAL_BASIC:
if (filterElement.getSelectedValues() != null) {
List<IntegerRange> ageIntervals = new ArrayList<>();
for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
ageIntervals.add((IntegerRange) tokenizableValue.getValue());
}
caseCriteria.addAgeIntervals(ageIntervals);
// Fill age groups if 5 years interval has been selected and case incidence is shown
if (showCaseIncidence && filterComponent.getSelectedAttribute() == StatisticsCaseAttribute.AGE_INTERVAL_5_YEARS) {
List<AgeGroup> ageGroups = new ArrayList<>();
for (IntegerRange ageInterval : ageIntervals) {
if (ageInterval.getFrom() != null || ageInterval.getTo() != null) {
ageGroups.add(AgeGroup.getAgeGroupFromIntegerRange(ageInterval));
}
}
caseCriteria.addAgeGroups(ageGroups);
}
}
break;
case JURISDICTION:
StatisticsFilterJurisdictionElement jurisdictionElement = (StatisticsFilterJurisdictionElement) filterElement;
if (jurisdictionElement.getSelectedRegions() != null) {
List<RegionReferenceDto> regions = new ArrayList<>();
for (TokenizableValue tokenizableValue : jurisdictionElement.getSelectedRegions()) {
regions.add((RegionReferenceDto) tokenizableValue.getValue());
}
caseCriteria.regions(regions);
}
if (jurisdictionElement.getSelectedDistricts() != null) {
List<DistrictReferenceDto> districts = new ArrayList<>();
for (TokenizableValue tokenizableValue : jurisdictionElement.getSelectedDistricts()) {
districts.add((DistrictReferenceDto) tokenizableValue.getValue());
}
caseCriteria.districts(districts);
}
if (jurisdictionElement.getSelectedCommunities() != null) {
List<CommunityReferenceDto> communities = new ArrayList<>();
for (TokenizableValue tokenizableValue : jurisdictionElement.getSelectedCommunities()) {
communities.add((CommunityReferenceDto) tokenizableValue.getValue());
}
caseCriteria.communities(communities);
}
if (jurisdictionElement.getSelectedHealthFacilities() != null) {
List<FacilityReferenceDto> facilities = new ArrayList<>();
for (TokenizableValue tokenizableValue : jurisdictionElement.getSelectedHealthFacilities()) {
facilities.add((FacilityReferenceDto) tokenizableValue.getValue());
}
caseCriteria.healthFacilities(facilities);
}
break;
case PLACE_OF_RESIDENCE:
StatisticsFilterResidenceElement residenceElement = (StatisticsFilterResidenceElement) filterElement;
if (residenceElement.getSelectedRegions() != null) {
List<RegionReferenceDto> regions = new ArrayList<>();
for (TokenizableValue tokenizableValue : residenceElement.getSelectedRegions()) {
regions.add((RegionReferenceDto) tokenizableValue.getValue());
}
caseCriteria.personRegions(regions);
}
if (residenceElement.getSelectedDistricts() != null) {
List<DistrictReferenceDto> districts = new ArrayList<>();
for (TokenizableValue tokenizableValue : residenceElement.getSelectedDistricts()) {
districts.add((DistrictReferenceDto) tokenizableValue.getValue());
}
caseCriteria.personDistricts(districts);
}
if (residenceElement.getSelectedCommunities() != null) {
List<CommunityReferenceDto> communities = new ArrayList<>();
for (TokenizableValue tokenizableValue : residenceElement.getSelectedCommunities()) {
communities.add((CommunityReferenceDto) tokenizableValue.getValue());
}
caseCriteria.personCommunities(communities);
}
if (residenceElement.getCity() != null) {
caseCriteria.setPersonCity(residenceElement.getCity());
}
if (residenceElement.getPostcode() != null) {
caseCriteria.setPersonPostcode(residenceElement.getPostcode());
}
break;
case REPORTING_USER_ROLE:
if (filterElement.getSelectedValues() != null) {
List<UserRole> reportingUserRoles = new ArrayList<>();
for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
reportingUserRoles.add((UserRole) tokenizableValue.getValue());
}
caseCriteria.reportingUserRoles(reportingUserRoles);
}
break;
default:
switch(filterComponent.getSelectedSubAttribute()) {
case YEAR:
if (filterElement.getSelectedValues() != null) {
List<Year> years = new ArrayList<>();
for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
years.add((Year) tokenizableValue.getValue());
}
caseCriteria.years(years, filterComponent.getSelectedAttribute());
}
break;
case QUARTER:
if (filterElement.getSelectedValues() != null) {
List<Quarter> quarters = new ArrayList<>();
for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
quarters.add((Quarter) tokenizableValue.getValue());
}
caseCriteria.quarters(quarters, filterComponent.getSelectedAttribute());
}
break;
case MONTH:
if (filterElement.getSelectedValues() != null) {
List<Month> months = new ArrayList<>();
for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
months.add((Month) tokenizableValue.getValue());
}
caseCriteria.months(months, filterComponent.getSelectedAttribute());
}
break;
case EPI_WEEK:
if (filterElement.getSelectedValues() != null) {
List<EpiWeek> epiWeeks = new ArrayList<>();
for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
epiWeeks.add((EpiWeek) tokenizableValue.getValue());
}
caseCriteria.epiWeeks(epiWeeks, filterComponent.getSelectedAttribute());
}
break;
case QUARTER_OF_YEAR:
if (filterElement.getSelectedValues() != null) {
List<QuarterOfYear> quartersOfYear = new ArrayList<>();
for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
quartersOfYear.add((QuarterOfYear) tokenizableValue.getValue());
}
caseCriteria.quartersOfYear(quartersOfYear, filterComponent.getSelectedAttribute());
}
break;
case MONTH_OF_YEAR:
if (filterElement.getSelectedValues() != null) {
List<MonthOfYear> monthsOfYear = new ArrayList<>();
for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
monthsOfYear.add((MonthOfYear) tokenizableValue.getValue());
}
caseCriteria.monthsOfYear(monthsOfYear, filterComponent.getSelectedAttribute());
}
break;
case EPI_WEEK_OF_YEAR:
if (filterElement.getSelectedValues() != null) {
List<EpiWeek> epiWeeksOfYear = new ArrayList<>();
for (TokenizableValue tokenizableValue : filterElement.getSelectedValues()) {
epiWeeksOfYear.add((EpiWeek) tokenizableValue.getValue());
}
caseCriteria.epiWeeksOfYear(epiWeeksOfYear, filterComponent.getSelectedAttribute());
}
break;
case DATE_RANGE:
caseCriteria.dateRange((Date) filterElement.getSelectedValues().get(0).getValue(), (Date) filterElement.getSelectedValues().get(1).getValue(), filterComponent.getSelectedAttribute());
break;
default:
throw new IllegalArgumentException(filterComponent.getSelectedSubAttribute().toString());
}
}
}
}
Aggregations