Search in sources :

Example 46 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.

the class QueryPlannerUtils method getLevelOrgUnitMap.

/**
     * Creates a mapping between level and organisation unit for the given 
     * organisation units.
     * 
     * @param orgUnits list of organisation units.
     */
public static ListMap<Integer, DimensionalItemObject> getLevelOrgUnitMap(List<DimensionalItemObject> orgUnits) {
    ListMap<Integer, DimensionalItemObject> map = new ListMap<>();
    for (DimensionalItemObject orgUnit : orgUnits) {
        OrganisationUnit ou = (OrganisationUnit) orgUnit;
        int level = ou.getLevel();
        map.putValue(level, orgUnit);
    }
    return map;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ListMap(org.hisp.dhis.common.ListMap)

Example 47 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject 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 48 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject 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 49 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject 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 50 with DimensionalItemObject

use of org.hisp.dhis.common.DimensionalItemObject in project dhis2-core by dhis2.

the class PartitionUtils method getPeriodTypePeriodMap.

/**
     * Creates a mapping between period type name and period for the given periods.
     */
public static ListMap<String, DimensionalItemObject> getPeriodTypePeriodMap(Collection<DimensionalItemObject> periods) {
    ListMap<String, DimensionalItemObject> map = new ListMap<>();
    for (DimensionalItemObject period : periods) {
        String periodTypeName = ((Period) period).getPeriodType().getName();
        map.putValue(periodTypeName, period);
    }
    return map;
}
Also used : DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) ListMap(org.hisp.dhis.common.ListMap)

Aggregations

DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)55 ArrayList (java.util.ArrayList)15 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)15 DimensionalObject (org.hisp.dhis.common.DimensionalObject)15 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)14 Test (org.junit.Test)12 Period (org.hisp.dhis.period.Period)11 ListMap (org.hisp.dhis.common.ListMap)10 DataElement (org.hisp.dhis.dataelement.DataElement)10 DhisSpringTest (org.hisp.dhis.DhisSpringTest)7 BaseDimensionalItemObject (org.hisp.dhis.common.BaseDimensionalItemObject)7 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)7 HashMap (java.util.HashMap)6 List (java.util.List)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)6 PeriodType (org.hisp.dhis.period.PeriodType)6 SqlRowSet (org.springframework.jdbc.support.rowset.SqlRowSet)5 Matcher (java.util.regex.Matcher)4 Grid (org.hisp.dhis.common.Grid)4 HashSet (java.util.HashSet)3