Search in sources :

Example 36 with DataElementOperand

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

the class PredictionDataValueFetcher method addValueToMap.

/**
 * Adds a non-deleted value to the value map.
 * <p>
 * The two types of dimensional item object that are needed from the data
 * value table are DataElement (the sum of all category option combos for
 * that data element) and DataElementOperand (a particular combination of
 * DataElement and CategoryOptionCombo).
 */
private void addValueToMap(DataValue dv, MapMapMap<CategoryOptionCombo, Period, DimensionalItemObject, Object> map) {
    Object value = getObjectValue(dv.getValue(), dv.getDataElement().getValueType());
    if (value != null) {
        DataElementOperand dataElementOperand = new DataElementOperand(dv.getDataElement(), dv.getCategoryOptionCombo());
        addToMap(dataElementOperand, dataElementOperands, dv, value, map);
        addToMap(dv.getDataElement(), dataElements, dv, value, map);
    }
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject)

Example 37 with DataElementOperand

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

the class DataElementGroupController method getOperands.

@GetMapping("/{uid}/operands")
public String getOperands(@PathVariable("uid") String uid, @RequestParam Map<String, String> parameters, Model model, TranslateParams translateParams, 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(dataElementCategoryService.getOperands(dataElementGroups.get(0).getMembers()));
    Collections.sort(dataElementOperands);
    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)

Example 38 with DataElementOperand

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

the class DataElementOperandController method getObjectList.

@GetMapping
@SuppressWarnings("unchecked")
@ResponseBody
public RootNode getObjectList(@RequestParam Map<String, String> rpParameters, OrderParams orderParams, @CurrentUser User currentUser) throws QueryParserException {
    Schema schema = schemaService.getDynamicSchema(DataElementOperand.class);
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
    List<Order> orders = orderParams.getOrders(schema);
    if (fields.isEmpty()) {
        fields.addAll(Preset.ALL.getFields());
    }
    WebOptions options = new WebOptions(rpParameters);
    WebMetadata metadata = new WebMetadata();
    List<DataElementOperand> dataElementOperands;
    if (options.isTrue("persisted")) {
        dataElementOperands = Lists.newArrayList(manager.getAll(DataElementOperand.class));
    } else {
        boolean totals = options.isTrue("totals");
        String deg = CollectionUtils.popStartsWith(filters, "dataElement.dataElementGroups.id:eq:");
        deg = deg != null ? deg.substring("dataElement.dataElementGroups.id:eq:".length()) : null;
        String ds = options.get("dataSet");
        if (deg != null) {
            DataElementGroup dataElementGroup = manager.get(DataElementGroup.class, deg);
            dataElementOperands = dataElementCategoryService.getOperands(dataElementGroup.getMembers(), totals);
        } else if (ds != null) {
            DataSet dataSet = manager.get(DataSet.class, ds);
            dataElementOperands = dataElementCategoryService.getOperands(dataSet, totals);
        } else {
            List<DataElement> dataElements = new ArrayList<>(manager.getAllSorted(DataElement.class));
            dataElementOperands = dataElementCategoryService.getOperands(dataElements, totals);
        }
    }
    // This is needed for two reasons:
    // 1) We are doing in-memory paging;
    // 2) We have to count all items respecting the filtering and the
    // initial universe of elements. In this case, the variable
    // "dataElementOperands".
    Query queryForCount = queryService.getQueryFromUrl(DataElementOperand.class, filters, orders);
    queryForCount.setObjects(dataElementOperands);
    List<DataElementOperand> totalOfItems = (List<DataElementOperand>) queryService.query(queryForCount);
    Query query = queryService.getQueryFromUrl(DataElementOperand.class, filters, orders, PaginationUtils.getPaginationData(options), options.getRootJunction());
    query.setDefaultOrder();
    query.setObjects(dataElementOperands);
    dataElementOperands = (List<DataElementOperand>) queryService.query(query);
    Pager pager = metadata.getPager();
    if (options.hasPaging() && pager == null) {
        final long countTotal = isNotEmpty(totalOfItems) ? totalOfItems.size() : 0;
        // fetch the count for the current query from a short-lived cache
        long cachedCountTotal = paginationCountCache.computeIfAbsent(calculatePaginationCountKey(currentUser, filters, options), () -> countTotal);
        pager = new Pager(options.getPage(), cachedCountTotal, options.getPageSize());
        linkService.generatePagerLinks(pager, DataElementOperand.class);
    }
    RootNode rootNode = NodeUtils.createMetadata();
    if (pager != null) {
        rootNode.addChild(NodeUtils.createPager(pager));
    }
    rootNode.addChild(fieldFilterService.toCollectionNode(DataElementOperand.class, new FieldFilterParams(dataElementOperands, fields)));
    return rootNode;
}
Also used : Order(org.hisp.dhis.query.Order) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) RootNode(org.hisp.dhis.node.types.RootNode) Query(org.hisp.dhis.query.Query) DataSet(org.hisp.dhis.dataset.DataSet) Schema(org.hisp.dhis.schema.Schema) WebOptions(org.hisp.dhis.webapi.webdomain.WebOptions) WebMetadata(org.hisp.dhis.webapi.webdomain.WebMetadata) Pager(org.hisp.dhis.common.Pager) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) ArrayList(java.util.ArrayList) List(java.util.List) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 39 with DataElementOperand

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

the class LoadFormAction method getSectionForm.

// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
private void getSectionForm(DataSet dataSet) {
    sections = new ArrayList<>(dataSet.getSections());
    Collections.sort(sections, new SectionOrderComparator());
    for (Section section : sections) {
        if (!section.getCategoryCombos().isEmpty()) {
            if (section.isDisableDataElementAutoGroup()) {
                processSectionForUserOrdering(section);
            } else {
                processSectionForAutoOrdering(section);
            }
        }
        for (DataElementOperand operand : section.getGreyedFields()) {
            if (operand != null && operand.getDataElement() != null && operand.getCategoryOptionCombo() != null) {
                greyedFields.put(operand.getDataElement().getUid() + ":" + operand.getCategoryOptionCombo().getUid(), true);
            }
        }
    }
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) SectionOrderComparator(org.hisp.dhis.dataset.comparator.SectionOrderComparator) Section(org.hisp.dhis.dataset.Section)

Example 40 with DataElementOperand

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

the class DataElementOperandControllerTest method buildResponse.

private CollectionNode buildResponse(List<DataElementOperand> dataElementOperands) {
    CollectionNode collectionNode = new CollectionNode("dataElementOperands");
    collectionNode.setWrapping(true);
    collectionNode.setNamespace("http://dhis2.org/schema/dxf/2.0");
    for (DataElementOperand dataElementOperand : dataElementOperands) {
        ComplexNode complexNode = new ComplexNode("dataElementOperand");
        complexNode.setNamespace(collectionNode.getNamespace());
        complexNode.addChild(new SimpleNode("displayName", dataElementOperand.getDisplayName(), false));
        complexNode.addChild(new SimpleNode("id", dataElementOperand.getDimensionItem(), true));
        collectionNode.addChild(complexNode);
    }
    return collectionNode;
}
Also used : DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) ComplexNode(org.hisp.dhis.node.types.ComplexNode) CollectionNode(org.hisp.dhis.node.types.CollectionNode) SimpleNode(org.hisp.dhis.node.types.SimpleNode)

Aggregations

DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)75 DataElement (org.hisp.dhis.dataelement.DataElement)36 Test (org.junit.jupiter.api.Test)30 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)25 Period (org.hisp.dhis.period.Period)24 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)23 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)19 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)17 Matchers.emptyOrNullString (org.hamcrest.Matchers.emptyOrNullString)14 PeriodType.getPeriodFromIsoString (org.hisp.dhis.period.PeriodType.getPeriodFromIsoString)14 ProgramIndicator (org.hisp.dhis.program.ProgramIndicator)13 Indicator (org.hisp.dhis.indicator.Indicator)11 HashMap (java.util.HashMap)10 DhisSpringTest (org.hisp.dhis.DhisSpringTest)10 IndicatorType (org.hisp.dhis.indicator.IndicatorType)10 DimensionalItemId (org.hisp.dhis.common.DimensionalItemId)9 DataSet (org.hisp.dhis.dataset.DataSet)9 ArrayList (java.util.ArrayList)8 DataValue (org.hisp.dhis.datavalue.DataValue)8 List (java.util.List)7