Search in sources :

Example 1 with DimensionItem

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

the class DefaultAnalyticsService method addIndicatorValues.

/**
     * Adds indicator values to the given grid based on the given data query
     * parameters.
     *
     * @param params the {@link DataQueryParams}.
     * @param grid the grid.
     */
private void addIndicatorValues(DataQueryParams params, Grid grid) {
    if (!params.getIndicators().isEmpty() && !params.isSkipData()) {
        DataQueryParams dataSourceParams = DataQueryParams.newBuilder(params).retainDataDimension(DataDimensionItemType.INDICATOR).withIncludeNumDen(false).build();
        List<Indicator> indicators = asTypedList(dataSourceParams.getIndicators());
        Period filterPeriod = dataSourceParams.getFilterPeriod();
        Map<String, Double> constantMap = constantService.getConstantMap();
        // -----------------------------------------------------------------
        // Get indicator values
        // -----------------------------------------------------------------
        Map<String, Map<String, Integer>> permutationOrgUnitTargetMap = getOrgUnitTargetMap(dataSourceParams, indicators);
        List<List<DimensionItem>> dimensionItemPermutations = dataSourceParams.getDimensionItemPermutations();
        Map<String, Map<DimensionalItemObject, Double>> permutationDimensionItemValueMap = getPermutationDimensionItemValueMap(dataSourceParams);
        for (Indicator indicator : indicators) {
            for (List<DimensionItem> dimensionItems : dimensionItemPermutations) {
                String permKey = DimensionItem.asItemKey(dimensionItems);
                Map<DimensionalItemObject, Double> valueMap = permutationDimensionItemValueMap.get(permKey);
                if (valueMap == null) {
                    continue;
                }
                Period period = filterPeriod != null ? filterPeriod : (Period) DimensionItem.getPeriodItem(dimensionItems);
                OrganisationUnit unit = (OrganisationUnit) DimensionItem.getOrganisationUnitItem(dimensionItems);
                String ou = unit != null ? unit.getUid() : null;
                Map<String, Integer> orgUnitCountMap = permutationOrgUnitTargetMap != null ? permutationOrgUnitTargetMap.get(ou) : null;
                IndicatorValue value = expressionService.getIndicatorValueObject(indicator, period, valueMap, constantMap, orgUnitCountMap);
                if (value != null) {
                    List<DimensionItem> row = new ArrayList<>(dimensionItems);
                    row.add(DX_INDEX, new DimensionItem(DATA_X_DIM_ID, indicator));
                    grid.addRow().addValues(DimensionItem.getItemIdentifiers(row)).addValue(AnalyticsUtils.getRoundedValue(dataSourceParams, indicator.getDecimals(), value.getValue()));
                    if (params.isIncludeNumDen()) {
                        grid.addValue(AnalyticsUtils.getRoundedValue(dataSourceParams, indicator.getDecimals(), value.getNumeratorValue())).addValue(AnalyticsUtils.getRoundedValue(dataSourceParams, indicator.getDecimals(), value.getDenominatorValue())).addValue(AnalyticsUtils.getRoundedValue(dataSourceParams, indicator.getDecimals(), value.getFactorAnnualizedValue()));
                    }
                }
            }
        }
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) IndicatorValue(org.hisp.dhis.indicator.IndicatorValue) DimensionItem(org.hisp.dhis.analytics.DimensionItem) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) PeriodType.getPeriodTypeFromIsoString(org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString) Indicator(org.hisp.dhis.indicator.Indicator) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) List(java.util.List) DimensionalObjectUtils.asTypedList(org.hisp.dhis.common.DimensionalObjectUtils.asTypedList) ArrayList(java.util.ArrayList) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) OrganisationUnit.getParentGraphMap(org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap) HashMap(java.util.HashMap) OrganisationUnit.getParentNameGraphMap(org.hisp.dhis.organisationunit.OrganisationUnit.getParentNameGraphMap)

Example 2 with DimensionItem

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

the class QueryPlannerTest method testGetDimensionOptionPermutations.

/**
     * Ignores data element dimension and generates 2 x 3 = 6 combinations based
     * on organisation unit and period dimensions.
     */
@Test
public void testGetDimensionOptionPermutations() {
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(deA, deB)).withOrganisationUnits(getList(ouA, ouB, ouC)).withPeriods(getList(createPeriod("2000Q1"), createPeriod("2000Q2"))).build();
    List<List<DimensionItem>> permutations = params.getDimensionItemPermutations();
    assertNotNull(permutations);
    assertEquals(6, permutations.size());
    for (List<DimensionItem> permutation : permutations) {
        assertNotNull(permutation);
        assertEquals(2, permutation.size());
        assertEquals(ORGUNIT_DIM_ID, permutation.get(0).getDimension());
        assertEquals(PERIOD_DIM_ID, permutation.get(1).getDimension());
    }
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionItem(org.hisp.dhis.analytics.DimensionItem) ProgramDataElementDimensionItem(org.hisp.dhis.program.ProgramDataElementDimensionItem) List(java.util.List) ArrayList(java.util.ArrayList) DimensionalObjectUtils.getList(org.hisp.dhis.common.DimensionalObjectUtils.getList) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

ArrayList (java.util.ArrayList)2 List (java.util.List)2 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)2 DimensionItem (org.hisp.dhis.analytics.DimensionItem)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DhisSpringTest (org.hisp.dhis.DhisSpringTest)1 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)1 DimensionalObjectUtils.asTypedList (org.hisp.dhis.common.DimensionalObjectUtils.asTypedList)1 DimensionalObjectUtils.getList (org.hisp.dhis.common.DimensionalObjectUtils.getList)1 Indicator (org.hisp.dhis.indicator.Indicator)1 IndicatorValue (org.hisp.dhis.indicator.IndicatorValue)1 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)1 OrganisationUnit.getParentGraphMap (org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap)1 OrganisationUnit.getParentNameGraphMap (org.hisp.dhis.organisationunit.OrganisationUnit.getParentNameGraphMap)1 Period (org.hisp.dhis.period.Period)1 PeriodType.getPeriodTypeFromIsoString (org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString)1 ProgramDataElementDimensionItem (org.hisp.dhis.program.ProgramDataElementDimensionItem)1 Test (org.junit.Test)1