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());
}
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))));
}
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());
}
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());
}
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());
}
Aggregations