Search in sources :

Example 6 with IntegerRange

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

Aggregations

IntegerRange (de.symeda.sormas.api.IntegerRange)6 Year (de.symeda.sormas.api.Year)3 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)3 StatisticsCaseCriteria (de.symeda.sormas.api.statistics.StatisticsCaseCriteria)3 ArrayList (java.util.ArrayList)3 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)2 PersonDto (de.symeda.sormas.api.person.PersonDto)2 StatisticsCaseCountDto (de.symeda.sormas.api.statistics.StatisticsCaseCountDto)2 UserDto (de.symeda.sormas.api.user.UserDto)2 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)2 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)2 LocalDate (java.time.LocalDate)2 Date (java.util.Date)2 Test (org.junit.Test)2 AgeGroup (de.symeda.sormas.api.AgeGroup)1 Disease (de.symeda.sormas.api.Disease)1 Month (de.symeda.sormas.api.Month)1 MonthOfYear (de.symeda.sormas.api.MonthOfYear)1 Quarter (de.symeda.sormas.api.Quarter)1 QuarterOfYear (de.symeda.sormas.api.QuarterOfYear)1