Search in sources :

Example 1 with MonthOfYear

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

the class StatisticsHelperTest method testBuildGroupingKey.

@Test
public void testBuildGroupingKey() {
    EpiWeek epiWeek = (EpiWeek) StatisticsHelper.buildGroupingKey(1803, StatisticsCaseAttribute.REPORT_TIME, StatisticsCaseSubAttribute.EPI_WEEK_OF_YEAR, null, null, null, null);
    assertThat(epiWeek.getYear(), equalTo(18));
    assertThat(epiWeek.getWeek(), equalTo(3));
    MonthOfYear monthOfYear = (MonthOfYear) StatisticsHelper.buildGroupingKey(1811, StatisticsCaseAttribute.REPORT_TIME, StatisticsCaseSubAttribute.MONTH_OF_YEAR, null, null, null, null);
    assertThat(monthOfYear.getYear().getValue(), equalTo(18));
    assertThat(monthOfYear.getMonth(), equalTo(Month.NOVEMBER));
    QuarterOfYear quarterOfYear = (QuarterOfYear) StatisticsHelper.buildGroupingKey(182, StatisticsCaseAttribute.REPORT_TIME, StatisticsCaseSubAttribute.QUARTER_OF_YEAR, null, null, null, null);
    assertThat(quarterOfYear.getYear().getValue(), equalTo(18));
    assertThat(quarterOfYear.getQuarter().getValue(), equalTo(2));
}
Also used : MonthOfYear(de.symeda.sormas.api.MonthOfYear) QuarterOfYear(de.symeda.sormas.api.QuarterOfYear) EpiWeek(de.symeda.sormas.api.utils.EpiWeek) Test(org.junit.Test)

Example 2 with MonthOfYear

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

the class StatisticsHelper method getTimeGroupingKeys.

/**
 * @param attribute
 * @param subAttribute
 * @param caseFacade Needed for StatisticsCaseAttribute.ONSET_TIME, REPORT_TIME, OUTCOME_TIME
 * @return
 */
public static List<StatisticsGroupingKey> getTimeGroupingKeys(StatisticsCaseAttribute attribute, StatisticsCaseSubAttribute subAttribute, CaseFacade caseFacade) {
    Date oldestCaseDate = null;
    switch(attribute) {
        case ONSET_TIME:
            oldestCaseDate = caseFacade.getOldestCaseOnsetDate();
            break;
        case REPORT_TIME:
            oldestCaseDate = caseFacade.getOldestCaseReportDate();
            break;
        case OUTCOME_TIME:
            oldestCaseDate = caseFacade.getOldestCaseOutcomeDate();
            break;
        default:
            return new ArrayList<>();
    }
    LocalDate earliest = oldestCaseDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
    LocalDate now = LocalDate.now();
    switch(subAttribute) {
        case YEAR:
            List<StatisticsGroupingKey> years = new ArrayList<>();
            for (int i = earliest.getYear(); i <= now.getYear(); i++) {
                years.add(new Year(i));
            }
            return years;
        case QUARTER:
            List<StatisticsGroupingKey> quarters = new ArrayList<>();
            for (int i = 1; i <= 4; i++) {
                quarters.add(new Quarter(i));
            }
            return quarters;
        case MONTH:
            return toGroupingKeys(Month.values());
        case EPI_WEEK:
            List<StatisticsGroupingKey> epiWeeks = new ArrayList<>();
            for (int i = 1; i <= DateHelper.getMaximumEpiWeekNumber(); i++) {
                epiWeeks.add(new EpiWeek(null, i));
            }
            return epiWeeks;
        case QUARTER_OF_YEAR:
            List<StatisticsGroupingKey> quarterOfYearList = new ArrayList<>();
            QuarterOfYear earliestQuarter = new QuarterOfYear(new Quarter(1), new Year(earliest.getYear()));
            QuarterOfYear latestQuarter = new QuarterOfYear(new Quarter(4), new Year(now.getYear()));
            while (earliestQuarter.getYear().getValue() <= latestQuarter.getYear().getValue()) {
                quarterOfYearList.add(new QuarterOfYear(earliestQuarter.getQuarter(), earliestQuarter.getYear()));
                earliestQuarter.increaseQuarter();
            }
            return quarterOfYearList;
        case MONTH_OF_YEAR:
            List<StatisticsGroupingKey> monthOfYearList = new ArrayList<>();
            for (int year = earliest.getYear(); year <= now.getYear(); year++) {
                for (Month month : Month.values()) {
                    monthOfYearList.add(new MonthOfYear(month, year));
                }
            }
            return monthOfYearList;
        case EPI_WEEK_OF_YEAR:
            List<StatisticsGroupingKey> epiWeekOfYearList = new ArrayList<>();
            for (int year = earliest.getYear(); year <= now.getYear(); year++) {
                epiWeekOfYearList.addAll(DateHelper.createEpiWeekList(year));
            }
            return epiWeekOfYearList;
        default:
            return new ArrayList<>();
    }
}
Also used : Quarter(de.symeda.sormas.api.Quarter) Month(de.symeda.sormas.api.Month) QuarterOfYear(de.symeda.sormas.api.QuarterOfYear) Year(de.symeda.sormas.api.Year) MonthOfYear(de.symeda.sormas.api.MonthOfYear) MonthOfYear(de.symeda.sormas.api.MonthOfYear) QuarterOfYear(de.symeda.sormas.api.QuarterOfYear) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) EpiWeek(de.symeda.sormas.api.utils.EpiWeek)

Example 3 with MonthOfYear

use of de.symeda.sormas.api.MonthOfYear 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

MonthOfYear (de.symeda.sormas.api.MonthOfYear)3 QuarterOfYear (de.symeda.sormas.api.QuarterOfYear)3 EpiWeek (de.symeda.sormas.api.utils.EpiWeek)3 Month (de.symeda.sormas.api.Month)2 Quarter (de.symeda.sormas.api.Quarter)2 Year (de.symeda.sormas.api.Year)2 ArrayList (java.util.ArrayList)2 AgeGroup (de.symeda.sormas.api.AgeGroup)1 Disease (de.symeda.sormas.api.Disease)1 IntegerRange (de.symeda.sormas.api.IntegerRange)1 CaseClassification (de.symeda.sormas.api.caze.CaseClassification)1 CaseOutcome (de.symeda.sormas.api.caze.CaseOutcome)1 CommunityReferenceDto (de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto)1 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)1 FacilityReferenceDto (de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto)1 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)1 Sex (de.symeda.sormas.api.person.Sex)1 StatisticsCaseCriteria (de.symeda.sormas.api.statistics.StatisticsCaseCriteria)1 UserRole (de.symeda.sormas.api.user.UserRole)1 TokenizableValue (de.symeda.sormas.ui.statistics.StatisticsFilterElement.TokenizableValue)1