Search in sources :

Example 16 with EventQueryParams

use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.

the class EventQueryPlannerTest method testPlanAggregateQueryC.

@Test
public void testPlanAggregateQueryC() {
    EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).withStartDate(new DateTime(2010, 6, 1, 0, 0).toDate()).withEndDate(new DateTime(2012, 3, 20, 0, 0).toDate()).withOrganisationUnits(Lists.newArrayList(ouA, ouB)).build();
    List<EventQueryParams> queries = queryPlanner.planAggregateQuery(params);
    assertEquals(2, queries.size());
    assertEquals(ouA, queries.get(0).getOrganisationUnits().get(0));
    assertEquals(ouB, queries.get(1).getOrganisationUnits().get(0));
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) DateTime(org.joda.time.DateTime) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 17 with EventQueryParams

use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.

the class EventQueryPlannerTest method testPlanAggregateQueryA.

@Test
public void testPlanAggregateQueryA() {
    EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).withStartDate(new DateTime(2010, 6, 1, 0, 0).toDate()).withEndDate(new DateTime(2012, 3, 20, 0, 0).toDate()).withOrganisationUnits(Lists.newArrayList(ouA)).build();
    List<EventQueryParams> queries = queryPlanner.planAggregateQuery(params);
    assertEquals(1, queries.size());
    EventQueryParams query = queries.get(0);
    assertEquals(new DateTime(2010, 6, 1, 0, 0).toDate(), query.getStartDate());
    assertEquals(new DateTime(2012, 3, 20, 0, 0).toDate(), query.getEndDate());
    Partitions partitions = query.getPartitions();
    assertEquals(3, partitions.getPartitions().size());
    assertEquals("analytics_event_2010_programuida", partitions.getPartitions().get(0));
    assertEquals("analytics_event_2011_programuida", partitions.getPartitions().get(1));
    assertEquals("analytics_event_2012_programuida", partitions.getPartitions().get(2));
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) Partitions(org.hisp.dhis.analytics.Partitions) DateTime(org.joda.time.DateTime) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 18 with EventQueryParams

use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.

the class DefaultAnalyticsService method addProgramDataElementAttributeIndicatorValues.

/**
     * Adds program data element values to the given grid based on the given data
     * query parameters.
     *
     * @param params the {@link DataQueryParams}.
     * @param grid the grid.
     */
private void addProgramDataElementAttributeIndicatorValues(DataQueryParams params, Grid grid) {
    if ((!params.getAllProgramDataElementsAndAttributes().isEmpty() || !params.getProgramIndicators().isEmpty()) && !params.isSkipData()) {
        DataQueryParams dataSourceParams = DataQueryParams.newBuilder(params).retainDataDimensions(PROGRAM_DATA_ELEMENT, PROGRAM_ATTRIBUTE, PROGRAM_INDICATOR).build();
        EventQueryParams eventQueryParams = new EventQueryParams.Builder(EventQueryParams.fromDataQueryParams(dataSourceParams)).withSkipMeta(true).build();
        Grid eventGrid = eventAnalyticsService.getAggregatedEventData(eventQueryParams);
        grid.addRows(eventGrid);
    }
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) ListGrid(org.hisp.dhis.system.grid.ListGrid) Grid(org.hisp.dhis.common.Grid)

Example 19 with EventQueryParams

use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.

the class DefaultEventDataQueryService method getFromUrl.

@Override
public EventQueryParams getFromUrl(String program, String stage, Date startDate, Date endDate, Set<String> dimension, Set<String> filter, OrganisationUnitSelectionMode ouMode, Set<String> asc, Set<String> desc, boolean skipMeta, boolean skipData, boolean completedOnly, boolean hierarchyMeta, boolean coordinatesOnly, EventStatus eventStatus, ProgramStatus programStatus, DisplayProperty displayProperty, Date relativePeriodDate, String userOrgUnit, String coordinateField, Integer page, Integer pageSize, DhisApiVersion apiVersion) {
    I18nFormat format = i18nManager.getI18nFormat();
    EventQueryParams.Builder params = new EventQueryParams.Builder();
    IdScheme idScheme = IdScheme.UID;
    List<OrganisationUnit> userOrgUnits = dataQueryService.getUserOrgUnits(null, userOrgUnit);
    Program pr = programService.getProgram(program);
    if (pr == null) {
        throw new IllegalQueryException("Program does not exist: " + program);
    }
    ProgramStage ps = programStageService.getProgramStage(stage);
    if (StringUtils.isNotEmpty(stage) && ps == null) {
        throw new IllegalQueryException("Program stage is specified but does not exist: " + stage);
    }
    if (dimension != null) {
        for (String dim : dimension) {
            String dimensionId = getDimensionFromParam(dim);
            List<String> items = getDimensionItemsFromParam(dim);
            DimensionalObject dimObj = dataQueryService.getDimension(dimensionId, items, relativePeriodDate, userOrgUnits, format, true, false, idScheme);
            if (dimObj != null) {
                params.addDimension(dimObj);
            } else {
                params.addItem(getQueryItem(dim, pr));
            }
        }
    }
    if (filter != null) {
        for (String dim : filter) {
            String dimensionId = getDimensionFromParam(dim);
            List<String> items = getDimensionItemsFromParam(dim);
            DimensionalObject dimObj = dataQueryService.getDimension(dimensionId, items, relativePeriodDate, userOrgUnits, format, true, false, idScheme);
            if (dimObj != null) {
                params.addFilter(dimObj);
            } else {
                params.addItemFilter(getQueryItem(dim, pr));
            }
        }
    }
    if (asc != null) {
        for (String sort : asc) {
            params.addAscSortItem(getSortItem(sort, pr));
        }
    }
    if (desc != null) {
        for (String sort : desc) {
            params.addDescSortItem(getSortItem(sort, pr));
        }
    }
    return params.withProgram(pr).withProgramStage(ps).withStartDate(startDate).withEndDate(endDate).withOrganisationUnitMode(ouMode).withSkipMeta(skipMeta).withSkipData(skipData).withCompletedOnly(completedOnly).withHierarchyMeta(hierarchyMeta).withCoordinatesOnly(coordinatesOnly).withEventStatus(eventStatus).withDisplayProperty(displayProperty).withCoordinateField(getCoordinateField(coordinateField)).withPage(page).withPageSize(pageSize).withProgramStatus(programStatus).withApiVersion(apiVersion).build();
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) I18nFormat(org.hisp.dhis.i18n.I18nFormat)

Example 20 with EventQueryParams

use of org.hisp.dhis.analytics.event.EventQueryParams in project dhis2-core by dhis2.

the class DefaultEventQueryPlanner method planAggregateQuery.

// TODO use list of functional groupers and single loop
@Override
public List<EventQueryParams> planAggregateQuery(EventQueryParams params) {
    Set<String> validPartitions = partitionManager.getEventAnalyticsPartitions();
    List<EventQueryParams> queries = new ArrayList<>();
    List<EventQueryParams> groupedByQueryItems = groupByQueryItems(params);
    for (EventQueryParams byQueryItem : groupedByQueryItems) {
        List<EventQueryParams> groupedByPartition = groupByPartition(byQueryItem, validPartitions);
        for (EventQueryParams byPartition : groupedByPartition) {
            List<EventQueryParams> groupedByOrgUnitLevel = QueryPlannerUtils.convert(queryPlanner.groupByOrgUnitLevel(byPartition));
            for (EventQueryParams byOrgUnitLevel : groupedByOrgUnitLevel) {
                queries.addAll(QueryPlannerUtils.convert(queryPlanner.groupByPeriodType(byOrgUnitLevel)));
            }
        }
    }
    return queries;
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) ArrayList(java.util.ArrayList)

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