use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.
the class EventAnalyticsServiceTest method setUpTest.
@Override
public void setUpTest() throws IOException {
Period peJan = createPeriod("2017-01");
Period peFeb = createPeriod("2017-02");
Period peMar = createPeriod("2017-03");
Period peApril = createPeriod("2017-04");
idObjectManager.save(peJan);
idObjectManager.save(peFeb);
idObjectManager.save(peMar);
idObjectManager.save(peApril);
DataElement deA = createDataElement('A');
DataElement deB = createDataElement('B');
DataElement deC = createDataElement('C');
DataElement deD = createDataElement('D');
idObjectManager.save(deA);
idObjectManager.save(deB);
idObjectManager.save(deC);
idObjectManager.save(deD);
OrganisationUnit ouA = createOrganisationUnit('A');
OrganisationUnit ouB = createOrganisationUnit('B');
OrganisationUnit ouC = createOrganisationUnit('C');
ouC.setOpeningDate(getDate(2016, 4, 10));
ouC.setClosedDate(null);
OrganisationUnit ouD = createOrganisationUnit('D');
ouD.setOpeningDate(getDate(2016, 12, 10));
ouD.setClosedDate(null);
OrganisationUnit ouE = createOrganisationUnit('E');
AnalyticsTestUtils.configureHierarchy(ouA, ouB, ouC, ouD, ouE);
idObjectManager.save(ouA);
idObjectManager.save(ouB);
idObjectManager.save(ouC);
idObjectManager.save(ouD);
idObjectManager.save(ouE);
Program programA = createProgram('A', null, null, Sets.newHashSet(ouA, ouB), null);
programA.setUid("programA123");
idObjectManager.save(programA);
ProgramStage psA = createProgramStage('A', 0);
psA.setUid("programStgA");
psA.addDataElement(deA, 0);
psA.addDataElement(deB, 1);
idObjectManager.save(psA);
ProgramStage psB = createProgramStage('B', 0);
psB.setUid("programStgB");
psB.addDataElement(deA, 0);
psB.addDataElement(deB, 1);
idObjectManager.save(psB);
ProgramStage psC = createProgramStage('C', 0);
psC.setUid("programStgC");
psC.addDataElement(deA, 0);
psC.addDataElement(deB, 1);
idObjectManager.save(psC);
programA.getProgramStages().add(psA);
TrackedEntity trackedEntity = createTrackedEntity('A');
idObjectManager.save(trackedEntity);
org.hisp.dhis.trackedentity.TrackedEntityInstance maleA = createTrackedEntityInstance('A', ouA);
maleA.setUid("person1234A");
org.hisp.dhis.trackedentity.TrackedEntityInstance femaleB = createTrackedEntityInstance('B', ouB);
femaleB.setUid("person1234B");
maleA.setTrackedEntity(trackedEntity);
femaleB.setTrackedEntity(trackedEntity);
idObjectManager.save(maleA);
idObjectManager.save(femaleB);
programInstanceService.enrollTrackedEntityInstance(maleA, programA, null, null, ouA);
programInstanceService.enrollTrackedEntityInstance(femaleB, programA, null, null, ouA);
// Read event data from CSV file
// --------------------------------------------------------------------
ArrayList<String[]> eventDataLines = AnalyticsTestUtils.readInputFile("csv/eventData.csv");
parseEventData(eventDataLines);
// Generate analytics tables
// --------------------------------------------------------------------
analyticsTableGenerator.generateTables(null, null, null, false);
// Set parameters
// --------------------------------------------------------------------
// all events in program A - 2017
EventQueryParams events_2017_params = new EventQueryParams.Builder().withOrganisationUnits(Lists.newArrayList(ouA)).withStartDate(getDate(2017, 1, 1)).withEndDate(getDate(2017, 12, 31)).withProgram(programA).build();
eventQueryParams.put("events_2017", events_2017_params);
// Set results
// --------------------------------------------------------------------
Map<String, Double> events_2017_keyValue = new HashMap<>();
events_2017_keyValue.put("ouabcdefghA", 6.0);
results.put("events_2017", events_2017_keyValue);
}
use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.
the class EventDataQueryServiceTest method testGetFromAnalyticalObjectA.
@Test
public void testGetFromAnalyticalObjectA() {
EventChart eventChart = new EventChart();
eventChart.setAutoFields();
eventChart.setProgram(prA);
eventChart.getColumnDimensions().add(atA.getUid());
eventChart.getRowDimensions().add(DimensionalObject.ORGUNIT_DIM_ID);
eventChart.getFilterDimensions().add(DimensionalObject.PERIOD_DIM_ID);
eventChart.getAttributeDimensions().add(new TrackedEntityAttributeDimension(atA, null, "LE:5"));
eventChart.getPeriods().add(peA);
eventChart.getPeriods().add(peB);
eventChart.getOrganisationUnits().add(ouA);
eventChart.getOrganisationUnits().add(ouB);
EventQueryParams params = dataQueryService.getFromAnalyticalObject(eventChart);
assertNotNull(params);
assertEquals(1, params.getItems().size());
assertEquals(2, params.getOrganisationUnits().size());
assertEquals(2, params.getFilterPeriods().size());
}
use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.
the class EventDataQueryServiceTest method testGetFromAnalyticalObjectC.
@Test
public void testGetFromAnalyticalObjectC() {
EventChart eventChart = new EventChart();
eventChart.setAutoFields();
eventChart.setProgram(prA);
eventChart.getColumnDimensions().add(deA.getUid());
eventChart.getColumnDimensions().add(atA.getUid());
eventChart.getRowDimensions().add(DimensionalObject.ORGUNIT_DIM_ID);
eventChart.getFilterDimensions().add(DimensionalObject.PERIOD_DIM_ID);
eventChart.getDataElementDimensions().add(new TrackedEntityDataElementDimension(deA, null, "GT:2000"));
eventChart.getAttributeDimensions().add(new TrackedEntityAttributeDimension(atA, null, "LE:5"));
eventChart.getPeriods().add(peA);
eventChart.getPeriods().add(peB);
eventChart.getOrganisationUnits().add(ouA);
EventQueryParams params = dataQueryService.getFromAnalyticalObject(eventChart);
assertNotNull(params);
assertEquals(2, params.getItems().size());
assertEquals(1, params.getOrganisationUnits().size());
assertEquals(2, params.getFilterPeriods().size());
}
use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.
the class EventDataQueryServiceTest method testGetFromUrlB.
@Test
public void testGetFromUrlB() {
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");
EventQueryParams params = dataQueryService.getFromUrl(prA.getUid(), null, null, null, dimensionParams, filterParams, deA.getUid(), AggregationType.AVERAGE, false, false, false, false, false, false, null, null, null, null, null, false, false, null, null, null, null);
assertEquals(prA, params.getProgram());
assertEquals(1, params.getOrganisationUnits().size());
assertEquals(1, params.getItems().size());
assertEquals(1, params.getFilterPeriods().size());
assertEquals(deA, params.getValue());
assertEquals(AggregationType.AVERAGE, params.getAggregationType());
}
use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.
the class EventQueryPlannerTest method testPlanAggregateDataQueryA.
@Test
public void testPlanAggregateDataQueryA() {
DataQueryParams dataQueryParams = DataQueryParams.newBuilder().withProgramDataElements(getList(pdeA, pdeB, pdeC, pdeD)).withProgramAttributes(getList(patA, patB)).withOrganisationUnits(getList(ouA, ouB, ouC)).withPeriods(getList(createPeriod("200101"), createPeriod("200103"), createPeriod("200105"), createPeriod("200107"))).build();
EventQueryParams params = EventQueryParams.fromDataQueryParams(dataQueryParams);
List<EventQueryParams> queries = queryPlanner.planAggregateQuery(params);
assertEquals(12, queries.size());
for (EventQueryParams query : queries) {
assertTrue(query.hasValueDimension());
}
}
Aggregations