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