Search in sources :

Example 1 with StatisticsCaseCriteria

use of de.symeda.sormas.api.statistics.StatisticsCaseCriteria 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());
}
Also used : RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) StatisticsCaseCriteria(de.symeda.sormas.api.statistics.StatisticsCaseCriteria) PopulationDataDto(de.symeda.sormas.api.infrastructure.PopulationDataDto) RegionDto(de.symeda.sormas.api.infrastructure.region.RegionDto) StatisticsCaseCountDto(de.symeda.sormas.api.statistics.StatisticsCaseCountDto) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 2 with StatisticsCaseCriteria

use of de.symeda.sormas.api.statistics.StatisticsCaseCriteria in project SORMAS-Project by hzi-braunschweig.

the class CaseStatisticsFacadeEjb method queryCaseCount.

@SuppressWarnings("unchecked")
@Override
public List<StatisticsCaseCountDto> queryCaseCount(StatisticsCaseCriteria caseCriteria, StatisticsCaseAttribute rowGrouping, StatisticsCaseSubAttribute rowSubGrouping, StatisticsCaseAttribute columnGrouping, StatisticsCaseSubAttribute columnSubGrouping, boolean includePopulation, boolean includeZeroValues, Integer populationReferenceYear) {
    // case counts
    Pair<String, List<Object>> caseCountQueryAndParams = buildCaseCountQuery(caseCriteria, rowGrouping, rowSubGrouping, columnGrouping, columnSubGrouping);
    Query caseCountQuery = em.createNativeQuery(caseCountQueryAndParams.getKey().toString());
    for (int i = 0; i < caseCountQueryAndParams.getValue().size(); i++) {
        caseCountQuery.setParameter(i + 1, caseCountQueryAndParams.getValue().get(i));
    }
    Function<Integer, RegionReferenceDto> regionProvider = id -> regionFacade.getRegionReferenceById(id);
    Function<Integer, DistrictReferenceDto> districtProvider = id -> districtFacade.getDistrictReferenceById(id);
    Function<Integer, CommunityReferenceDto> communityProvider = id -> communityFacade.getCommunityReferenceById(id);
    Function<Integer, FacilityReferenceDto> healthFacilityProvider = id -> facilityFacade.getFacilityReferenceById(id);
    List<StatisticsCaseCountDto> caseCountResults = ((Stream<Object[]>) caseCountQuery.getResultStream()).map(result -> {
        Object rowKey = "".equals(result[1]) ? null : result[1];
        Object columnKey = "".equals(result[2]) ? null : result[2];
        return new StatisticsCaseCountDto(result[0] != null ? ((Number) result[0]).intValue() : null, null, StatisticsHelper.buildGroupingKey(rowKey, rowGrouping, rowSubGrouping, regionProvider, districtProvider, communityProvider, healthFacilityProvider), StatisticsHelper.buildGroupingKey(columnKey, columnGrouping, columnSubGrouping, regionProvider, districtProvider, communityProvider, healthFacilityProvider));
    }).collect(Collectors.toList());
    if (includeZeroValues) {
        List<StatisticsGroupingKey> allRowKeys;
        if (rowGrouping != null) {
            allRowKeys = (List<StatisticsGroupingKey>) caseCriteria.getFilterValuesForGrouping(rowGrouping, rowSubGrouping);
            if (allRowKeys == null) {
                allRowKeys = StatisticsHelper.getAttributeGroupingKeys(rowGrouping, rowSubGrouping, diseaseConfigurationFacade, caseFacade, regionFacade, districtFacade);
            }
        } else {
            allRowKeys = Arrays.asList((StatisticsGroupingKey) null);
        }
        List<StatisticsGroupingKey> allColumnKeys;
        if (columnGrouping != null) {
            allColumnKeys = (List<StatisticsGroupingKey>) caseCriteria.getFilterValuesForGrouping(columnGrouping, columnSubGrouping);
            if (allColumnKeys == null) {
                allColumnKeys = StatisticsHelper.getAttributeGroupingKeys(columnGrouping, columnSubGrouping, diseaseConfigurationFacade, caseFacade, regionFacade, districtFacade);
            }
        } else {
            allColumnKeys = Arrays.asList((StatisticsGroupingKey) null);
        }
        for (StatisticsGroupingKey rowKey : allRowKeys) {
            for (StatisticsGroupingKey columnKey : allColumnKeys) {
                StatisticsCaseCountDto zeroDto = new StatisticsCaseCountDto(0, null, rowKey, columnKey);
                if (!caseCountResults.contains(zeroDto)) {
                    caseCountResults.add(zeroDto);
                }
            }
        }
    }
    // population
    if (includePopulation) {
        Pair<String, List<Object>> populationQueryAndParams = buildPopulationQuery(caseCriteria, rowGrouping, rowSubGrouping, columnGrouping, columnSubGrouping, populationReferenceYear);
        Query populationQuery = em.createNativeQuery(populationQueryAndParams.getKey().toString());
        for (int i = 0; i < populationQueryAndParams.getValue().size(); i++) {
            populationQuery.setParameter(i + 1, populationQueryAndParams.getValue().get(i));
        }
        List<StatisticsCaseCountDto> populationResults = ((Stream<Object[]>) populationQuery.getResultStream()).map(result -> {
            Object rowKey = "".equals(result[1]) ? null : result[1];
            Object columnKey = "".equals(result[2]) ? null : result[2];
            return new StatisticsCaseCountDto(null, result[0] != null ? ((Number) result[0]).intValue() : null, StatisticsHelper.buildGroupingKey(rowKey, rowGrouping, rowSubGrouping, regionProvider, districtProvider, communityProvider, healthFacilityProvider), StatisticsHelper.buildGroupingKey(columnKey, columnGrouping, columnSubGrouping, regionProvider, districtProvider, communityProvider, healthFacilityProvider));
        }).collect(Collectors.toList());
        boolean rowIsPopulation = rowGrouping != null && rowGrouping.isPopulationData();
        boolean columnIsPopulation = columnGrouping != null && columnGrouping.isPopulationData();
        if (!populationResults.isEmpty()) {
            assert ((populationResults.get(0).getRowKey() != null) == rowIsPopulation);
            assert ((populationResults.get(0).getColumnKey() != null) == columnIsPopulation);
        }
        // add the population data to the case counts
        // when a key is not a population data key, we use null instead
        StatisticsCaseCountDto searchDto = new StatisticsCaseCountDto(null, null, null, null);
        for (StatisticsCaseCountDto caseCountResult : caseCountResults) {
            if (rowIsPopulation) {
                searchDto.setRowKey(caseCountResult.getRowKey());
            }
            if (columnIsPopulation) {
                searchDto.setColumnKey(caseCountResult.getColumnKey());
            }
            int index = populationResults.indexOf(searchDto);
            if (index >= 0) {
                caseCountResult.setPopulation(populationResults.get(index).getPopulation());
            }
        }
    }
    return caseCountResults;
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) IntegerRange(de.symeda.sormas.api.IntegerRange) PopulationData(de.symeda.sormas.backend.infrastructure.PopulationData) DistrictService(de.symeda.sormas.backend.infrastructure.district.DistrictService) StringUtils(org.apache.commons.lang3.StringUtils) AgeGroup(de.symeda.sormas.api.AgeGroup) CommunityFacadeEjbLocal(de.symeda.sormas.backend.infrastructure.community.CommunityFacadeEjb.CommunityFacadeEjbLocal) StatisticsCaseAttribute(de.symeda.sormas.api.statistics.StatisticsCaseAttribute) Facility(de.symeda.sormas.backend.infrastructure.facility.Facility) Pair(org.apache.commons.lang3.tuple.Pair) Stateless(javax.ejb.Stateless) StatisticsGroupingKey(de.symeda.sormas.api.statistics.StatisticsGroupingKey) FacilityService(de.symeda.sormas.backend.infrastructure.facility.FacilityService) Person(de.symeda.sormas.backend.person.Person) CommunityService(de.symeda.sormas.backend.infrastructure.community.CommunityService) Region(de.symeda.sormas.backend.infrastructure.region.Region) District(de.symeda.sormas.backend.infrastructure.district.District) DistrictFacadeEjbLocal(de.symeda.sormas.backend.infrastructure.district.DistrictFacadeEjb.DistrictFacadeEjbLocal) Collectors(java.util.stream.Collectors) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) List(java.util.List) Query(javax.persistence.Query) Stream(java.util.stream.Stream) User(de.symeda.sormas.backend.user.User) LocalDate(java.time.LocalDate) Location(de.symeda.sormas.backend.location.Location) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) IntStream(java.util.stream.IntStream) Community(de.symeda.sormas.backend.infrastructure.community.Community) QueryHelper(de.symeda.sormas.backend.util.QueryHelper) Function(java.util.function.Function) ArrayList(java.util.ArrayList) CollectionUtils(org.apache.commons.collections.CollectionUtils) FacilityFacadeEjbLocal(de.symeda.sormas.backend.infrastructure.facility.FacilityFacadeEjb.FacilityFacadeEjbLocal) LocalBean(javax.ejb.LocalBean) Symptoms(de.symeda.sormas.backend.symptoms.Symptoms) DiseaseConfigurationFacadeEjb(de.symeda.sormas.backend.disease.DiseaseConfigurationFacadeEjb) StatisticsCaseCriteria(de.symeda.sormas.api.statistics.StatisticsCaseCriteria) EJB(javax.ejb.EJB) ModelConstants(de.symeda.sormas.backend.util.ModelConstants) CaseStatisticsFacade(de.symeda.sormas.api.caze.CaseStatisticsFacade) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) UserDto(de.symeda.sormas.api.user.UserDto) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) DiseaseConfigurationFacade(de.symeda.sormas.api.disease.DiseaseConfigurationFacade) RegionService(de.symeda.sormas.backend.infrastructure.region.RegionService) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) StatisticsCaseCountDto(de.symeda.sormas.api.statistics.StatisticsCaseCountDto) StatisticsCaseSubAttribute(de.symeda.sormas.api.statistics.StatisticsCaseSubAttribute) RegionFacadeEjbLocal(de.symeda.sormas.backend.infrastructure.region.RegionFacadeEjb.RegionFacadeEjbLocal) StatisticsHelper(de.symeda.sormas.api.statistics.StatisticsHelper) Query(javax.persistence.Query) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) List(java.util.List) ArrayList(java.util.ArrayList) StatisticsGroupingKey(de.symeda.sormas.api.statistics.StatisticsGroupingKey) StatisticsCaseCountDto(de.symeda.sormas.api.statistics.StatisticsCaseCountDto)

Example 3 with StatisticsCaseCriteria

use of de.symeda.sormas.api.statistics.StatisticsCaseCriteria in project SORMAS-Project by hzi-braunschweig.

the class CaseStatisticsFacadeEjbTest method testQueryCaseCount.

@Test
public void testQueryCaseCount() {
    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.setOutcomeDate(DateHelper.addWeeks(caze.getReportDate(), 2));
    caze = getCaseFacade().save(caze);
    StatisticsCaseCriteria criteria = new StatisticsCaseCriteria();
    int year = DateHelper8.toLocalDate(caze.getSymptoms().getOnsetDate()).getYear();
    criteria.years(Arrays.asList(new Year(year), new Year(year + 1)), StatisticsCaseAttribute.ONSET_TIME);
    criteria.regions(Arrays.asList(new RegionReferenceDto(rdcf.region.getUuid(), null, null)));
    criteria.addAgeIntervals(Arrays.asList(new IntegerRange(10, 40)));
    List<StatisticsCaseCountDto> results = getCaseStatisticsFacade().queryCaseCount(criteria, null, null, null, null, false, false, null);
    // List should have one entry
    assertEquals(1, results.size());
    // try all groupings
    for (StatisticsCaseAttribute groupingAttribute : StatisticsCaseAttribute.values()) {
        StatisticsCaseSubAttribute[] subAttributes = groupingAttribute.getSubAttributes();
        if (subAttributes.length == 0) {
            getCaseStatisticsFacade().queryCaseCount(criteria, groupingAttribute, null, null, null, false, false, null);
        } else {
            for (StatisticsCaseSubAttribute subGroupingAttribute : groupingAttribute.getSubAttributes()) {
                if (subGroupingAttribute.isUsedForGrouping()) {
                    getCaseStatisticsFacade().queryCaseCount(criteria, groupingAttribute, subGroupingAttribute, null, null, false, false, null);
                }
            }
        }
    }
}
Also used : IntegerRange(de.symeda.sormas.api.IntegerRange) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) StatisticsCaseSubAttribute(de.symeda.sormas.api.statistics.StatisticsCaseSubAttribute) Date(java.util.Date) LocalDate(java.time.LocalDate) RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) Year(de.symeda.sormas.api.Year) StatisticsCaseCriteria(de.symeda.sormas.api.statistics.StatisticsCaseCriteria) StatisticsCaseCountDto(de.symeda.sormas.api.statistics.StatisticsCaseCountDto) StatisticsCaseAttribute(de.symeda.sormas.api.statistics.StatisticsCaseAttribute) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 4 with StatisticsCaseCriteria

use of de.symeda.sormas.api.statistics.StatisticsCaseCriteria in project SORMAS-Project by hzi-braunschweig.

the class CaseStatisticsFacadeEjbTest method testQueryCaseCountZeroValues.

@Test
public void testQueryCaseCountZeroValues() {
    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();
    int year = DateHelper8.toLocalDate(caze.getSymptoms().getOnsetDate()).getYear();
    criteria.years(Arrays.asList(new Year(year), new Year(year + 1)), StatisticsCaseAttribute.ONSET_TIME);
    criteria.regions(Arrays.asList(new RegionReferenceDto(rdcf.region.getUuid(), null, null)));
    criteria.addAgeIntervals(Arrays.asList(new IntegerRange(10, 40)));
    List<StatisticsCaseCountDto> results = getCaseStatisticsFacade().queryCaseCount(criteria, StatisticsCaseAttribute.SEX, null, null, null, false, true, null);
    // List should have one entry per sex
    assertEquals(Sex.values().length, results.size());
}
Also used : RDCF(de.symeda.sormas.backend.TestDataCreator.RDCF) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) IntegerRange(de.symeda.sormas.api.IntegerRange) Year(de.symeda.sormas.api.Year) CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) PersonDto(de.symeda.sormas.api.person.PersonDto) UserDto(de.symeda.sormas.api.user.UserDto) StatisticsCaseCriteria(de.symeda.sormas.api.statistics.StatisticsCaseCriteria) StatisticsCaseCountDto(de.symeda.sormas.api.statistics.StatisticsCaseCountDto) Date(java.util.Date) LocalDate(java.time.LocalDate) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest) Test(org.junit.Test)

Example 5 with StatisticsCaseCriteria

use of de.symeda.sormas.api.statistics.StatisticsCaseCriteria 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());
                }
        }
    }
}
Also used : Quarter(de.symeda.sormas.api.Quarter) Disease(de.symeda.sormas.api.Disease) MonthOfYear(de.symeda.sormas.api.MonthOfYear) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) Sex(de.symeda.sormas.api.person.Sex) ArrayList(java.util.ArrayList) EpiWeek(de.symeda.sormas.api.utils.EpiWeek) Month(de.symeda.sormas.api.Month) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) QuarterOfYear(de.symeda.sormas.api.QuarterOfYear) TokenizableValue(de.symeda.sormas.ui.statistics.StatisticsFilterElement.TokenizableValue) IntegerRange(de.symeda.sormas.api.IntegerRange) CaseClassification(de.symeda.sormas.api.caze.CaseClassification) CaseOutcome(de.symeda.sormas.api.caze.CaseOutcome) AgeGroup(de.symeda.sormas.api.AgeGroup) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) QuarterOfYear(de.symeda.sormas.api.QuarterOfYear) Year(de.symeda.sormas.api.Year) MonthOfYear(de.symeda.sormas.api.MonthOfYear) UserRole(de.symeda.sormas.api.user.UserRole) StatisticsCaseCriteria(de.symeda.sormas.api.statistics.StatisticsCaseCriteria)

Aggregations

StatisticsCaseCriteria (de.symeda.sormas.api.statistics.StatisticsCaseCriteria)5 IntegerRange (de.symeda.sormas.api.IntegerRange)4 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)4 StatisticsCaseCountDto (de.symeda.sormas.api.statistics.StatisticsCaseCountDto)4 UserDto (de.symeda.sormas.api.user.UserDto)4 LocalDate (java.time.LocalDate)4 Date (java.util.Date)4 Year (de.symeda.sormas.api.Year)3 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)3 PersonDto (de.symeda.sormas.api.person.PersonDto)3 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)3 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)3 Test (org.junit.Test)3 AgeGroup (de.symeda.sormas.api.AgeGroup)2 CommunityReferenceDto (de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto)2 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)2 FacilityReferenceDto (de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto)2 StatisticsCaseAttribute (de.symeda.sormas.api.statistics.StatisticsCaseAttribute)2 StatisticsCaseSubAttribute (de.symeda.sormas.api.statistics.StatisticsCaseSubAttribute)2 ArrayList (java.util.ArrayList)2