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()));
}
}
}
}
}
}
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());
}
}
Aggregations