Search in sources :

Example 51 with DataElementGroup

use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.

the class DataQueryParams method getFirstDataElementGroup.

/**
 * Returns the first data element group in this query, meaning the first
 * group item within the first data element group set dimension, if any.
 * Returns null if no dimension or item exists.
 */
public DataElementGroup getFirstDataElementGroup() {
    if (!getDataElementGroupSets().isEmpty()) {
        DimensionalObject degs = getDataElementGroupSets().get(0);
        DimensionalItemObject deg = degs.hasItems() ? degs.getItems().get(0) : null;
        return (DataElementGroup) deg;
    }
    return null;
}
Also used : DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) DimensionalObject(org.hisp.dhis.common.DimensionalObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject)

Example 52 with DataElementGroup

use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.

the class DataElementGroupResolverTest method setUp.

@BeforeEach
public void setUp() {
    uid1 = CodeGenerator.generateUid();
    uid2 = CodeGenerator.generateUid();
    uid3 = CodeGenerator.generateUid();
    de1 = createDataElement('X');
    de2 = createDataElement('Y');
    de3 = createDataElement('Z');
    DataElementGroup dataElementGroup = createDataElementGroup('A');
    dataElementGroup.addDataElement(de1);
    dataElementGroup.addDataElement(de2);
    dataElementGroup.addDataElement(de3);
    resolver = new DataElementGroupResolver(expressionService, dataElementGroupStore);
    when(dataElementGroupStore.getByUid(anyString())).thenReturn(dataElementGroup);
}
Also used : DhisConvenienceTest.createDataElementGroup(org.hisp.dhis.DhisConvenienceTest.createDataElementGroup) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 53 with DataElementGroup

use of org.hisp.dhis.dataelement.DataElementGroup 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)

Example 54 with DataElementGroup

use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.

the class DhisConvenienceTest method createDataElementGroup.

/**
 * @param uniqueCharacter A unique character to identify the object.
 */
public static DataElementGroup createDataElementGroup(char uniqueCharacter) {
    DataElementGroup group = new DataElementGroup();
    group.setAutoFields();
    group.setUid(BASE_UID + uniqueCharacter);
    group.setName("DataElementGroup" + uniqueCharacter);
    group.setShortName("DataElementGroup" + uniqueCharacter);
    group.setCode("DataElementCode" + uniqueCharacter);
    return group;
}
Also used : DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup)

Example 55 with DataElementGroup

use of org.hisp.dhis.dataelement.DataElementGroup in project dhis2-core by dhis2.

the class DataElementGroupController method getOperandsByQuery.

@GetMapping("/{uid}/operands/query/{q}")
public String getOperandsByQuery(@PathVariable("uid") String uid, @PathVariable("q") String q, @RequestParam Map<String, String> parameters, TranslateParams translateParams, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    WebOptions options = new WebOptions(parameters);
    setUserContext(translateParams);
    List<DataElementGroup> dataElementGroups = getEntity(uid, NO_WEB_OPTIONS);
    if (dataElementGroups.isEmpty()) {
        throw new WebMessageException(notFound("DataElementGroup not found for uid: " + uid));
    }
    WebMetadata metadata = new WebMetadata();
    List<DataElementOperand> dataElementOperands = Lists.newArrayList();
    for (DataElementOperand dataElementOperand : dataElementCategoryService.getOperands(dataElementGroups.get(0).getMembers())) {
        if (dataElementOperand.getDisplayName().toLowerCase().contains(q.toLowerCase())) {
            dataElementOperands.add(dataElementOperand);
        }
    }
    metadata.setDataElementOperands(dataElementOperands);
    if (options.hasPaging()) {
        Pager pager = new Pager(options.getPage(), dataElementOperands.size(), options.getPageSize());
        metadata.setPager(pager);
        dataElementOperands = PagerUtils.pageCollection(dataElementOperands, pager);
    }
    metadata.setDataElementOperands(dataElementOperands);
    linkService.generateLinks(metadata, false);
    model.addAttribute("model", metadata);
    model.addAttribute("viewClass", options.getViewClass("basic"));
    return StringUtils.uncapitalize(getEntitySimpleName());
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) Pager(org.hisp.dhis.common.Pager) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

DataElementGroup (org.hisp.dhis.dataelement.DataElementGroup)55 DataElement (org.hisp.dhis.dataelement.DataElement)31 Test (org.junit.jupiter.api.Test)29 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)17 ArrayList (java.util.ArrayList)15 User (org.hisp.dhis.user.User)15 DataSet (org.hisp.dhis.dataset.DataSet)9 List (java.util.List)8 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)8 Set (java.util.Set)7 DhisSpringTest (org.hisp.dhis.DhisSpringTest)7 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)6 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)6 DataElementGroupSet (org.hisp.dhis.dataelement.DataElementGroupSet)6 DimensionalObject (org.hisp.dhis.common.DimensionalObject)5 LegendSet (org.hisp.dhis.legend.LegendSet)5 OptionSet (org.hisp.dhis.option.OptionSet)5 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)5 PeriodType (org.hisp.dhis.period.PeriodType)5 DimensionItemKeywords (org.hisp.dhis.common.DimensionItemKeywords)4