Search in sources :

Example 11 with Indicator

use of org.hisp.dhis.indicator.Indicator in project dhis2-core by dhis2.

the class DefaultDataIntegrityService method getIndicatorsViolatingExclusiveGroupSets.

@Override
public SortedMap<Indicator, Collection<IndicatorGroup>> getIndicatorsViolatingExclusiveGroupSets() {
    Collection<IndicatorGroupSet> groupSets = indicatorService.getAllIndicatorGroupSets();
    SortedMap<Indicator, Collection<IndicatorGroup>> targets = new TreeMap<>();
    for (IndicatorGroupSet groupSet : groupSets) {
        Collection<Indicator> duplicates = getDuplicates(new ArrayList<>(groupSet.getIndicators()));
        for (Indicator duplicate : duplicates) {
            targets.put(duplicate, duplicate.getGroups());
        }
    }
    return targets;
}
Also used : IndicatorGroupSet(org.hisp.dhis.indicator.IndicatorGroupSet) Collection(java.util.Collection) TreeMap(java.util.TreeMap) Indicator(org.hisp.dhis.indicator.Indicator)

Example 12 with Indicator

use of org.hisp.dhis.indicator.Indicator 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 13 with Indicator

use of org.hisp.dhis.indicator.Indicator in project dhis2-core by dhis2.

the class AnalyticsUtilsTest method testHandleGridForDataValueSet.

@Test
public void testHandleGridForDataValueSet() {
    IndicatorType itA = new IndicatorType();
    DataElementCategoryOptionCombo ocA = createCategoryOptionCombo('A');
    ocA.setUid("ceabcdefghA");
    DataElement dxA = createDataElement('A');
    dxA.setUid("deabcdefghA");
    dxA.setValueType(ValueType.INTEGER);
    DataElement dxB = createDataElement('B');
    dxB.setUid("deabcdefghB");
    dxB.setValueType(ValueType.NUMBER);
    Indicator dxC = createIndicator('C', itA);
    dxC.setUid("deabcdefghC");
    dxC.setDecimals(0);
    dxC.setAggregateExportAttributeOptionCombo("ceabcdefghA");
    Indicator dxD = createIndicator('D', itA);
    dxD.setUid("deabcdefghD");
    dxD.setDecimals(2);
    dxD.setAggregateExportCategoryOptionCombo("ceabcdefghB");
    DataElementOperand dxE = new DataElementOperand(dxA, ocA);
    DataElementOperand dxF = new DataElementOperand(dxB, ocA);
    DataQueryParams params = DataQueryParams.newBuilder().addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(dxA, dxB, dxC, dxD, dxE, dxF))).build();
    Grid grid = new ListGrid();
    grid.addHeader(new GridHeader(DimensionalObject.DATA_X_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.ORGUNIT_DIM_ID));
    grid.addHeader(new GridHeader(DimensionalObject.PERIOD_DIM_ID));
    grid.addHeader(new GridHeader(VALUE_ID, VALUE_HEADER_NAME, ValueType.NUMBER, Double.class.getName(), false, false));
    grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghA", "ouA", "peA", 1d));
    grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghB", "ouA", "peA", 2d));
    grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghC", "ouA", "peA", 3d));
    grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghD", "ouA", "peA", 4d));
    grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghA.ceabcdefghA", "ouA", "peA", 5d));
    grid.addRow().addValuesAsList(Lists.newArrayList("deabcdefghB.ceabcdefghA", "ouA", "peA", 6d));
    assertEquals(4, grid.getWidth());
    assertEquals(6, grid.getHeight());
    AnalyticsUtils.handleGridForDataValueSet(params, grid);
    assertEquals(6, grid.getWidth());
    assertEquals(6, grid.getHeight());
    assertEquals("deabcdefghA", grid.getRow(0).get(0));
    assertNull(grid.getRow(0).get(3));
    assertNull(grid.getRow(0).get(4));
    assertEquals(1, grid.getRow(0).get(5));
    assertEquals("deabcdefghB", grid.getRow(1).get(0));
    assertNull(grid.getRow(1).get(3));
    assertNull(grid.getRow(1).get(4));
    assertEquals(2d, (Double) grid.getRow(1).get(5), 0.01);
    assertEquals("deabcdefghC", grid.getRow(2).get(0));
    assertNull(grid.getRow(2).get(3));
    assertEquals("ceabcdefghA", grid.getRow(2).get(4));
    assertEquals(3, grid.getRow(2).get(5));
    assertEquals("deabcdefghD", grid.getRow(3).get(0));
    assertEquals("ceabcdefghB", grid.getRow(3).get(3));
    assertNull(grid.getRow(3).get(4));
    assertEquals(4d, (Double) grid.getRow(3).get(5), 0.01);
    assertEquals("deabcdefghA", grid.getRow(4).get(0));
    assertEquals("ceabcdefghA", grid.getRow(4).get(3));
    assertNull(grid.getRow(4).get(4));
    assertEquals(5, grid.getRow(4).get(5));
    assertEquals("deabcdefghB", grid.getRow(5).get(0));
    assertEquals("ceabcdefghA", grid.getRow(5).get(3));
    assertNull(grid.getRow(5).get(4));
    assertEquals(6d, (Double) grid.getRow(5).get(5), 0.01);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) IndicatorType(org.hisp.dhis.indicator.IndicatorType) ListGrid(org.hisp.dhis.system.grid.ListGrid) ListGrid(org.hisp.dhis.system.grid.ListGrid) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Indicator(org.hisp.dhis.indicator.Indicator) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Test(org.junit.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 14 with Indicator

use of org.hisp.dhis.indicator.Indicator in project dhis2-core by dhis2.

the class DefaultDataEntryFormService method prepareDataEntryFormForEdit.

@Override
public String prepareDataEntryFormForEdit(DataEntryForm dataEntryForm, DataSet dataSet, I18n i18n) {
    if (dataEntryForm == null || !dataEntryForm.hasForm() || dataSet == null) {
        return null;
    }
    CachingMap<String, DataElementCategoryOptionCombo> optionComboMap = new CachingMap<>();
    optionComboMap.putAll(IdentifiableObjectUtils.getUidObjectMap(dataSet.getDataElementOptionCombos()));
    StringBuffer sb = new StringBuffer();
    Matcher inputMatcher = INPUT_PATTERN.matcher(dataEntryForm.getHtmlCode());
    while (inputMatcher.find()) {
        String inputHtml = inputMatcher.group();
        Matcher identifierMatcher = IDENTIFIER_PATTERN.matcher(inputHtml);
        Matcher dataElementTotalMatcher = DATAELEMENT_TOTAL_PATTERN.matcher(inputHtml);
        Matcher indicatorMatcher = INDICATOR_PATTERN.matcher(inputHtml);
        String displayValue = null;
        String displayTitle = null;
        if (identifierMatcher.find() && identifierMatcher.groupCount() > 0) {
            String dataElementId = identifierMatcher.group(1);
            DataElement dataElement = dataElementService.getDataElement(dataElementId);
            String optionComboId = identifierMatcher.group(2);
            DataElementCategoryOptionCombo categoryOptionCombo = optionComboMap.get(optionComboId, () -> idObjectManager.getObject(DataElementCategoryOptionCombo.class, IdScheme.UID, optionComboId));
            String optionComboName = categoryOptionCombo != null ? escapeHtml3(categoryOptionCombo.getName()) : "[ " + i18n.getString("cat_option_combo_not_exist") + " ]";
            StringBuilder title = dataElement != null ? new StringBuilder("title=\"").append(dataElementId).append(" - ").append(escapeHtml3(dataElement.getDisplayName())).append(" - ").append(optionComboId).append(" - ").append(optionComboName).append(" - ").append(dataElement.getValueType()).append("\"") : new StringBuilder();
            displayValue = dataElement != null ? "value=\"[ " + escapeHtml3(dataElement.getDisplayName()) + " " + optionComboName + " ]\"" : "[ " + i18n.getString("data_element_not_exist") + " ]";
            displayTitle = dataElement != null ? title.toString() : "[ " + i18n.getString("dataelement_not_exist") + " ]";
        } else if (dataElementTotalMatcher.find() && dataElementTotalMatcher.groupCount() > 0) {
            String dataElementId = dataElementTotalMatcher.group(1);
            DataElement dataElement = dataElementService.getDataElement(dataElementId);
            displayValue = dataElement != null ? "value=\"[ " + escapeHtml3(dataElement.getDisplayName()) + " ]\"" : "[ " + i18n.getString("data_element_not_exist") + " ]";
            displayTitle = dataElement != null ? "title=\"" + escapeHtml3(dataElement.getDisplayName()) + "\"" : "[ " + i18n.getString("data_element_not_exist") + " ]";
        } else if (indicatorMatcher.find() && indicatorMatcher.groupCount() > 0) {
            String indicatorId = indicatorMatcher.group(1);
            Indicator indicator = indicatorService.getIndicator(indicatorId);
            displayValue = indicator != null ? "value=\"[ " + escapeHtml3(indicator.getDisplayName()) + " ]\"" : "[ " + i18n.getString("indicator_not_exist") + " ]";
            displayTitle = indicator != null ? "title=\"" + escapeHtml3(indicator.getDisplayName()) + "\"" : "[ " + i18n.getString("indicator_not_exist") + " ]";
        }
        if (displayValue == null || displayTitle == null) {
            log.warn("Ignoring invalid form markup: '" + inputHtml + "'");
            continue;
        }
        inputHtml = inputHtml.contains(EMPTY_VALUE_TAG) ? inputHtml.replace(EMPTY_VALUE_TAG, displayValue) : inputHtml.replace(TAG_CLOSE, (displayValue + TAG_CLOSE));
        inputHtml = inputHtml.contains(EMPTY_TITLE_TAG) ? inputHtml.replace(EMPTY_TITLE_TAG, displayTitle) : inputHtml.replace(TAG_CLOSE, (displayTitle + TAG_CLOSE));
        inputMatcher.appendReplacement(sb, inputHtml);
    }
    inputMatcher.appendTail(sb);
    return sb.toString();
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) CachingMap(org.hisp.dhis.commons.collection.CachingMap) Matcher(java.util.regex.Matcher) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Indicator(org.hisp.dhis.indicator.Indicator)

Example 15 with Indicator

use of org.hisp.dhis.indicator.Indicator in project dhis2-core by dhis2.

the class DefaultExpressionService method substituteExpressions.

@Override
@Transactional
public void substituteExpressions(Collection<Indicator> indicators, Integer days) {
    if (indicators != null && !indicators.isEmpty()) {
        Map<String, Constant> constants = new CachingMap<String, Constant>().load(idObjectManager.getAllNoAcl(Constant.class), c -> c.getUid());
        Map<String, OrganisationUnitGroup> orgUnitGroups = new CachingMap<String, OrganisationUnitGroup>().load(idObjectManager.getAllNoAcl(OrganisationUnitGroup.class), g -> g.getUid());
        for (Indicator indicator : indicators) {
            indicator.setExplodedNumerator(substituteExpression(indicator.getNumerator(), constants, orgUnitGroups, days));
            indicator.setExplodedDenominator(substituteExpression(indicator.getDenominator(), constants, orgUnitGroups, days));
        }
    }
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) Constant(org.hisp.dhis.constant.Constant) Indicator(org.hisp.dhis.indicator.Indicator) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Indicator (org.hisp.dhis.indicator.Indicator)23 Test (org.junit.Test)8 DataElement (org.hisp.dhis.dataelement.DataElement)7 IndicatorType (org.hisp.dhis.indicator.IndicatorType)7 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)7 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)7 DhisSpringTest (org.hisp.dhis.DhisSpringTest)5 Period (org.hisp.dhis.period.Period)5 DataSet (org.hisp.dhis.dataset.DataSet)4 ArrayList (java.util.ArrayList)3 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)3 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Matcher (java.util.regex.Matcher)2 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)2 DimensionalObject (org.hisp.dhis.common.DimensionalObject)2 IndicatorGroupSet (org.hisp.dhis.indicator.IndicatorGroupSet)2 IndicatorValue (org.hisp.dhis.indicator.IndicatorValue)2