Search in sources :

Example 66 with DataQueryParams

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

the class DefaultAnalyticsService method addReportingRates.

/**
     * Adds reporting rates to the given grid based on the given data query
     * parameters.
     *
     * @param params the {@link DataQueryParams}.
     * @param grid the grid.
     */
private void addReportingRates(DataQueryParams params, Grid grid) {
    if (!params.getReportingRates().isEmpty() && !params.isSkipData()) {
        for (ReportingRateMetric metric : ReportingRateMetric.values()) {
            DataQueryParams dataSourceParams = DataQueryParams.newBuilder(params).retainDataDimensionReportingRates(metric).ignoreDataApproval().withAggregationType(AggregationType.COUNT).withTimely((REPORTING_RATE_ON_TIME == metric || ACTUAL_REPORTS_ON_TIME == metric)).build();
            addReportingRates(dataSourceParams, grid, metric);
        }
    }
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) ReportingRateMetric(org.hisp.dhis.common.ReportingRateMetric)

Example 67 with DataQueryParams

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

the class DefaultQueryPlanner method groupByOrgUnitLevel.

@Override
public List<DataQueryParams> groupByOrgUnitLevel(DataQueryParams params) {
    List<DataQueryParams> queries = new ArrayList<>();
    if (!params.getOrganisationUnits().isEmpty()) {
        ListMap<Integer, DimensionalItemObject> levelOrgUnitMap = QueryPlannerUtils.getLevelOrgUnitMap(params.getOrganisationUnits());
        for (Integer level : levelOrgUnitMap.keySet()) {
            DataQueryParams query = DataQueryParams.newBuilder(params).addOrSetDimensionOptions(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, LEVEL_PREFIX + level, levelOrgUnitMap.get(level)).build();
            queries.add(query);
        }
    } else if (!params.getFilterOrganisationUnits().isEmpty()) {
        ListMap<Integer, DimensionalItemObject> levelOrgUnitMap = QueryPlannerUtils.getLevelOrgUnitMap(params.getFilterOrganisationUnits());
        DimensionalObject filter = params.getFilter(ORGUNIT_DIM_ID);
        DataQueryParams.Builder query = DataQueryParams.newBuilder(params).removeFilter(ORGUNIT_DIM_ID);
        for (Integer level : levelOrgUnitMap.keySet()) {
            query.addFilter(new BaseDimensionalObject(filter.getDimension(), filter.getDimensionType(), LEVEL_PREFIX + level, filter.getDisplayName(), levelOrgUnitMap.get(level)));
        }
        queries.add(query.build());
    } else {
        queries.add(DataQueryParams.newBuilder(params).build());
        return queries;
    }
    if (queries.size() > 1) {
        log.debug(String.format("Split on org unit level: %d", queries.size()));
    }
    return queries;
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ArrayList(java.util.ArrayList) ListMap(org.hisp.dhis.common.ListMap) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Example 68 with DataQueryParams

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

the class DefaultQueryPlanner method groupByDataType.

/**
     * Groups queries by their data type.
     * 
     * @param params the data query parameters.
     * @return a list of {@link DataQueryParams}.
     */
private List<DataQueryParams> groupByDataType(DataQueryParams params) {
    List<DataQueryParams> queries = new ArrayList<>();
    if (!params.getDataElements().isEmpty()) {
        ListMap<DataType, DimensionalItemObject> dataTypeDataElementMap = QueryPlannerUtils.getDataTypeDataElementMap(params.getDataElements());
        for (DataType dataType : dataTypeDataElementMap.keySet()) {
            DataQueryParams query = DataQueryParams.newBuilder(params).withDataElements(dataTypeDataElementMap.get(dataType)).withDataType(dataType).build();
            queries.add(query);
        }
    } else {
        DataQueryParams query = DataQueryParams.newBuilder(params).withDataType(DataType.NUMERIC).build();
        queries.add(query);
    }
    if (queries.size() > 1) {
        log.debug(String.format("Split on data type: %d", queries.size()));
    }
    return queries;
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ArrayList(java.util.ArrayList) DataType(org.hisp.dhis.analytics.DataType)

Example 69 with DataQueryParams

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

the class AnalyticsManagerTest method testReplaceDataPeriodsWithAggregationPeriods.

@Test
public void testReplaceDataPeriodsWithAggregationPeriods() {
    Period y2012 = createPeriod("2012");
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(createDataElement('A'), createDataElement('B'))).withPeriods(getList(y2012)).withOrganisationUnits(getList(createOrganisationUnit('A'))).withDataPeriodType(new YearlyPeriodType()).withAggregationType(AggregationType.AVERAGE_SUM_INT_DISAGGREGATION).build();
    Map<String, Object> dataValueMap = new HashMap<>();
    dataValueMap.put(BASE_UID + "A-2012-" + BASE_UID + "A", 1d);
    dataValueMap.put(BASE_UID + "B-2012-" + BASE_UID + "A", 1d);
    ListMap<DimensionalItemObject, DimensionalItemObject> dataPeriodAggregationPeriodMap = new ListMap<>();
    dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q1"));
    dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q2"));
    dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q3"));
    dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q4"));
    analyticsManager.replaceDataPeriodsWithAggregationPeriods(dataValueMap, params, dataPeriodAggregationPeriodMap);
    assertEquals(8, dataValueMap.size());
    assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q1-" + BASE_UID + "A"));
    assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q2-" + BASE_UID + "A"));
    assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q3-" + BASE_UID + "A"));
    assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q4-" + BASE_UID + "A"));
    assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q1-" + BASE_UID + "A"));
    assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q2-" + BASE_UID + "A"));
    assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q3-" + BASE_UID + "A"));
    assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q4-" + BASE_UID + "A"));
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) HashMap(java.util.HashMap) Period(org.hisp.dhis.period.Period) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) ListMap(org.hisp.dhis.common.ListMap) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 70 with DataQueryParams

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

the class DataQueryServiceTest method testGetFromUrlUserOrgUnit.

@Test
public void testGetFromUrlUserOrgUnit() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("ou:" + OrganisationUnit.KEY_USER_ORGUNIT);
    dimensionParams.add("dx:" + deA.getDimensionItem() + ";" + deB.getDimensionItem());
    dimensionParams.add("pe:2011;2012");
    DataQueryParams params = dataQueryService.getFromUrl(dimensionParams, null, null, null, null, null, null, false, false, false, false, false, false, false, false, false, false, null, null, null, false, null, null, null, false, null);
    assertEquals(1, params.getOrganisationUnits().size());
    assertEquals(2, params.getDataElements().size());
    assertEquals(2, params.getPeriods().size());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)81 Test (org.junit.Test)52 DhisSpringTest (org.hisp.dhis.DhisSpringTest)51 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)24 QueryPlannerParams (org.hisp.dhis.analytics.QueryPlannerParams)22 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)19 DataQueryGroups (org.hisp.dhis.analytics.DataQueryGroups)17 ArrayList (java.util.ArrayList)16 DimensionalObject (org.hisp.dhis.common.DimensionalObject)15 HashSet (java.util.HashSet)14 LinkedHashSet (java.util.LinkedHashSet)13 HashMap (java.util.HashMap)7 PeriodType.getPeriodTypeFromIsoString (org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString)7 ImmutableMap (com.google.common.collect.ImmutableMap)6 List (java.util.List)6 Map (java.util.Map)6 OrganisationUnit.getParentGraphMap (org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap)6 OrganisationUnit.getParentNameGraphMap (org.hisp.dhis.organisationunit.OrganisationUnit.getParentNameGraphMap)6 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)5 Grid (org.hisp.dhis.common.Grid)5