Search in sources :

Example 1 with EventDataQueryRequest

use of org.hisp.dhis.common.EventDataQueryRequest in project dhis2-core by dhis2.

the class EventDataQueryServiceTest method testGetFromUrlWithProgramAttributeSorting.

@Test
void testGetFromUrlWithProgramAttributeSorting() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("ou:" + ouA.getUid() + ";" + ouB.getId());
    dimensionParams.add(atA.getUid() + ":LE:5");
    Set<String> filterParams = new HashSet<>();
    filterParams.add("pe:201401");
    Set<String> desc = new HashSet<>();
    desc.add(atA.getUid());
    EventDataQueryRequest request = EventDataQueryRequest.builder().program(prA.getUid()).dimension(dimensionParams).filter(filterParams).value(deA.getUid()).aggregationType(AggregationType.AVERAGE).desc(desc).build();
    EventQueryParams params = dataQueryService.getFromRequest(request);
    assertEquals(prA, params.getProgram());
    assertEquals(1, params.getOrganisationUnits().size());
    assertEquals(1, params.getItems().size());
    assertEquals(1, params.getFilterPeriods().size());
    assertEquals(deA, params.getValue());
    assertEquals(1, params.getDesc().size());
    assertEquals(atA.getUid(), params.getDesc().get(0).getItem().getUid());
    assertEquals(AnalyticsAggregationType.AVERAGE, params.getAggregationType());
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) EventDataQueryRequest(org.hisp.dhis.common.EventDataQueryRequest) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 2 with EventDataQueryRequest

use of org.hisp.dhis.common.EventDataQueryRequest in project dhis2-core by dhis2.

the class EventDataQueryServiceTest method testGetPeriods.

@Test
void testGetPeriods() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("ou:" + ouA.getUid() + ";");
    dimensionParams.add("pe:LAST_WEEK;TODAY:LAST_UPDATED;20220101_20220201:INCIDENT_DATE");
    EventDataQueryRequest request = EventDataQueryRequest.builder().program(prA.getUid()).dimension(dimensionParams).build();
    EventQueryParams params = dataQueryService.getFromRequest(request);
    DimensionalObject pe = params.getDimension("pe");
    assertEquals(3, pe.getItems().size());
    assertTrue(streamOfPeriods(pe).anyMatch(Period::isDefault));
    assertTrue(streamOfPeriods(pe).map(Period::getDateField).anyMatch(s -> s.equals("LAST_UPDATED")));
    assertTrue(streamOfPeriods(pe).map(Period::getDateField).anyMatch(s -> s.equals("INCIDENT_DATE")));
    assertTrue(streamOfPeriods(pe).filter(period -> "INCIDENT_DATE".equals(period.getDateField())).anyMatch(period -> period.getStartDate().equals(of(2022, 1, 1)) && period.getEndDate().equals(of(2022, 2, 1))));
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) ListGrid(org.hisp.dhis.system.grid.ListGrid) Date(java.util.Date) ValueType(org.hisp.dhis.common.ValueType) Autowired(org.springframework.beans.factory.annotation.Autowired) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) TrackedEntityAttributeService(org.hisp.dhis.trackedentity.TrackedEntityAttributeService) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) EventChart(org.hisp.dhis.eventchart.EventChart) EventDataQueryService(org.hisp.dhis.analytics.event.EventDataQueryService) Period(org.hisp.dhis.period.Period) EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) AnalyticsType(org.hisp.dhis.common.AnalyticsType) Set(java.util.Set) DimensionType(org.hisp.dhis.common.DimensionType) ZoneId(java.time.ZoneId) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) LocalDate(java.time.LocalDate) Legend(org.hisp.dhis.legend.Legend) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) LegendSetService(org.hisp.dhis.legend.LegendSetService) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DataElementService(org.hisp.dhis.dataelement.DataElementService) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException) Program(org.hisp.dhis.program.Program) HashSet(java.util.HashSet) DataElement(org.hisp.dhis.dataelement.DataElement) GridHeader(org.hisp.dhis.common.GridHeader) AnalyticsAggregationType(org.hisp.dhis.analytics.AnalyticsAggregationType) LegendSet(org.hisp.dhis.legend.LegendSet) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DimensionalObjectUtils(org.hisp.dhis.common.DimensionalObjectUtils) AggregationType(org.hisp.dhis.analytics.AggregationType) ProgramStageService(org.hisp.dhis.program.ProgramStageService) Grid(org.hisp.dhis.common.Grid) ProgramStage(org.hisp.dhis.program.ProgramStage) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DhisSpringTest(org.hisp.dhis.DhisSpringTest) TrackedEntityDataElementDimension(org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension) PeriodType(org.hisp.dhis.period.PeriodType) ProgramService(org.hisp.dhis.program.ProgramService) EventDataQueryRequest(org.hisp.dhis.common.EventDataQueryRequest) EventDataQueryRequest(org.hisp.dhis.common.EventDataQueryRequest) Period(org.hisp.dhis.period.Period) HashSet(java.util.HashSet) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 3 with EventDataQueryRequest

use of org.hisp.dhis.common.EventDataQueryRequest in project dhis2-core by dhis2.

the class EventDataQueryServiceTest method testGetFromUrlWithDataElementSorting.

@Test
void testGetFromUrlWithDataElementSorting() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("ou:" + ouA.getUid() + ";" + ouB.getId());
    dimensionParams.add(atA.getUid() + ":LE:5");
    Set<String> filterParams = new HashSet<>();
    filterParams.add("pe:201401");
    Set<String> desc = new HashSet<>();
    desc.add(deA.getUid());
    EventDataQueryRequest request = EventDataQueryRequest.builder().program(prA.getUid()).dimension(dimensionParams).filter(filterParams).value(deA.getUid()).aggregationType(AggregationType.AVERAGE).desc(desc).build();
    EventQueryParams params = dataQueryService.getFromRequest(request);
    assertEquals(prA, params.getProgram());
    assertEquals(1, params.getOrganisationUnits().size());
    assertEquals(1, params.getItems().size());
    assertEquals(1, params.getFilterPeriods().size());
    assertEquals(deA, params.getValue());
    assertEquals(1, params.getDesc().size());
    assertEquals(deA.getUid(), params.getDesc().get(0).getItem().getUid());
    assertEquals(AnalyticsAggregationType.AVERAGE, params.getAggregationType());
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) EventDataQueryRequest(org.hisp.dhis.common.EventDataQueryRequest) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 4 with EventDataQueryRequest

use of org.hisp.dhis.common.EventDataQueryRequest in project dhis2-core by dhis2.

the class EventDataQueryServiceTest method testGetFromUrlLegendSet.

@Test
void testGetFromUrlLegendSet() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add(deA.getUid() + "-" + legendSetA.getUid() + ":IN:" + legendA.getUid() + ";" + legendB.getUid());
    Set<String> filterParams = new HashSet<>();
    filterParams.add("pe:201401;201402");
    filterParams.add(atA.getUid() + ":LE:5");
    EventDataQueryRequest request = EventDataQueryRequest.builder().program(prA.getUid()).dimension(dimensionParams).filter(filterParams).build();
    EventQueryParams params = dataQueryService.getFromRequest(request);
    assertEquals(prA, params.getProgram());
    assertEquals(1, params.getItems().size());
    assertEquals(legendSetA, params.getItems().get(0).getLegendSet());
    assertEquals(1, params.getItemFilters().size());
    assertEquals(2, params.getFilterPeriods().size());
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) EventDataQueryRequest(org.hisp.dhis.common.EventDataQueryRequest) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 5 with EventDataQueryRequest

use of org.hisp.dhis.common.EventDataQueryRequest in project dhis2-core by dhis2.

the class EventDataQueryServiceTest method testGetFromUrlWithEventDateSorting.

@Test
void testGetFromUrlWithEventDateSorting() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("ou:" + ouA.getUid() + ";" + ouB.getId());
    dimensionParams.add(atA.getUid() + ":LE:5");
    Set<String> filterParams = new HashSet<>();
    filterParams.add("pe:201401");
    Set<String> desc = new HashSet<>();
    desc.add("eventdate");
    EventDataQueryRequest request = EventDataQueryRequest.builder().program(prA.getUid()).dimension(dimensionParams).filter(filterParams).value(deA.getUid()).aggregationType(AggregationType.AVERAGE).desc(desc).build();
    EventQueryParams params = dataQueryService.getFromRequest(request);
    assertEquals(prA, params.getProgram());
    assertEquals(1, params.getOrganisationUnits().size());
    assertEquals(1, params.getItems().size());
    assertEquals(1, params.getFilterPeriods().size());
    assertEquals(deA, params.getValue());
    assertEquals(1, params.getDesc().size());
    assertEquals("executiondate", params.getDesc().get(0).getItem().getName());
    assertEquals(AnalyticsAggregationType.AVERAGE, params.getAggregationType());
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) EventDataQueryRequest(org.hisp.dhis.common.EventDataQueryRequest) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

HashSet (java.util.HashSet)8 DhisSpringTest (org.hisp.dhis.DhisSpringTest)8 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)8 EventDataQueryRequest (org.hisp.dhis.common.EventDataQueryRequest)8 Test (org.junit.jupiter.api.Test)8 Sets (com.google.common.collect.Sets)1 LocalDate (java.time.LocalDate)1 ZoneId (java.time.ZoneId)1 Date (java.util.Date)1 List (java.util.List)1 Set (java.util.Set)1 Stream (java.util.stream.Stream)1 AggregationType (org.hisp.dhis.analytics.AggregationType)1 AnalyticsAggregationType (org.hisp.dhis.analytics.AnalyticsAggregationType)1 EventDataQueryService (org.hisp.dhis.analytics.event.EventDataQueryService)1 AnalyticsType (org.hisp.dhis.common.AnalyticsType)1 DimensionType (org.hisp.dhis.common.DimensionType)1 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)1 DimensionalObject (org.hisp.dhis.common.DimensionalObject)1 DimensionalObjectUtils (org.hisp.dhis.common.DimensionalObjectUtils)1