Search in sources :

Example 1 with INDICATOR_EXPRESSION

use of org.hisp.dhis.expression.ParseType.INDICATOR_EXPRESSION in project dhis2-core by dhis2.

the class CategoryOptionResolver method resolve.

@Override
public String resolve(String expression) {
    Set<DimensionalItemId> dimItemIds = expressionService.getExpressionDimensionalItemIds(expression, INDICATOR_EXPRESSION);
    for (DimensionalItemId id : dimItemIds) {
        if (id.getItem() != null && id.getId1() != null && id.getId1().startsWith(CATEGORY_OPTION_PREFIX)) {
            CategoryOption co = categoryOptionStore.getByUid(id.getId1().replace(CATEGORY_OPTION_PREFIX, EMPTY_STRING));
            if (co != null) {
                List<String> resolved = co.getCategoryOptionCombos().stream().map(coc -> id.getItem().replace(id.getId1(), coc.getUid())).collect(Collectors.toList());
                expression = expression.replace(id.getItem(), LEFT_BRACKET + Joiner.on("+").join(resolved) + RIGHT_BRACKET);
            }
        }
    }
    return expression;
}
Also used : List(java.util.List) ExpressionService(org.hisp.dhis.expression.ExpressionService) CategoryOption(org.hisp.dhis.category.CategoryOption) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) Service(org.springframework.stereotype.Service) Set(java.util.Set) INDICATOR_EXPRESSION(org.hisp.dhis.expression.ParseType.INDICATOR_EXPRESSION) AllArgsConstructor(lombok.AllArgsConstructor) Collectors(java.util.stream.Collectors) CategoryOptionStore(org.hisp.dhis.category.CategoryOptionStore) Joiner(com.google.common.base.Joiner) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) CategoryOption(org.hisp.dhis.category.CategoryOption)

Example 2 with INDICATOR_EXPRESSION

use of org.hisp.dhis.expression.ParseType.INDICATOR_EXPRESSION in project dhis2-core by dhis2.

the class DataElementGroupResolver method resolve.

@Override
public String resolve(String expression) {
    Set<DimensionalItemId> dimItemIds = expressionService.getExpressionDimensionalItemIds(expression, INDICATOR_EXPRESSION);
    for (DimensionalItemId id : dimItemIds) {
        if (id.getItem() != null && id.getId0() != null && id.getId0().startsWith(DATA_ELEMENT_GROUP_PREFIX)) {
            DataElementGroup deGroup = dataElementGroupStore.getByUid(id.getId0().replace(DATA_ELEMENT_GROUP_PREFIX, EMPTY_STRING));
            if (deGroup != null) {
                List<String> resolved = deGroup.getMembers().stream().map(de -> id.getItem().replace(id.getId0(), de.getUid())).collect(Collectors.toList());
                expression = expression.replace(id.getItem(), LEFT_BRACKET + Joiner.on("+").join(resolved) + RIGHT_BRACKET);
            }
        }
    }
    return expression;
}
Also used : List(java.util.List) ExpressionService(org.hisp.dhis.expression.ExpressionService) DataElementGroupStore(org.hisp.dhis.dataelement.DataElementGroupStore) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) Service(org.springframework.stereotype.Service) Set(java.util.Set) INDICATOR_EXPRESSION(org.hisp.dhis.expression.ParseType.INDICATOR_EXPRESSION) AllArgsConstructor(lombok.AllArgsConstructor) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) Collectors(java.util.stream.Collectors) Joiner(com.google.common.base.Joiner) DimensionalItemId(org.hisp.dhis.common.DimensionalItemId) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup)

Aggregations

Joiner (com.google.common.base.Joiner)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 AllArgsConstructor (lombok.AllArgsConstructor)2 DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)2 ExpressionService (org.hisp.dhis.expression.ExpressionService)2 INDICATOR_EXPRESSION (org.hisp.dhis.expression.ParseType.INDICATOR_EXPRESSION)2 Service (org.springframework.stereotype.Service)2 CategoryOption (org.hisp.dhis.category.CategoryOption)1 CategoryOptionStore (org.hisp.dhis.category.CategoryOptionStore)1 DataElementGroup (org.hisp.dhis.dataelement.DataElementGroup)1 DataElementGroupStore (org.hisp.dhis.dataelement.DataElementGroupStore)1