Search in sources :

Example 36 with EventQueryParams

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);
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) HashMap(java.util.HashMap) TrackedEntity(org.hisp.dhis.trackedentity.TrackedEntity) Period(org.hisp.dhis.period.Period) DataElement(org.hisp.dhis.dataelement.DataElement) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 37 with EventQueryParams

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());
}
Also used : TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) EventChart(org.hisp.dhis.eventchart.EventChart) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 38 with EventQueryParams

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());
}
Also used : TrackedEntityAttributeDimension(org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension) EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) EventChart(org.hisp.dhis.eventchart.EventChart) TrackedEntityDataElementDimension(org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 39 with EventQueryParams

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());
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) HashSet(java.util.HashSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 40 with EventQueryParams

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());
    }
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)42 Test (org.junit.Test)20 DhisSpringTest (org.hisp.dhis.DhisSpringTest)18 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 Grid (org.hisp.dhis.common.Grid)13 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 DateTime (org.joda.time.DateTime)6 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)4 Partitions (org.hisp.dhis.analytics.Partitions)4 QueryItem (org.hisp.dhis.common.QueryItem)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 EventChart (org.hisp.dhis.eventchart.EventChart)3 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)3 TrackedEntityAttributeDimension (org.hisp.dhis.trackedentity.TrackedEntityAttributeDimension)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 DataElement (org.hisp.dhis.dataelement.DataElement)2