Search in sources :

Example 26 with DataElementCategoryCombo

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

the class DhisConvenienceTest method createCategoryCombo.

/**
     * @param categoryComboUniqueIdentifier A unique character to identify the
     *                                      category option combo.
     * @param categories                    the categories
     *                                      category options.
     * @return DataElementCategoryOptionCombo
     */
public static DataElementCategoryCombo createCategoryCombo(char categoryComboUniqueIdentifier, DataElementCategory... categories) {
    DataElementCategoryCombo categoryCombo = new DataElementCategoryCombo("CategoryCombo" + categoryComboUniqueIdentifier, DataDimensionType.DISAGGREGATION);
    categoryCombo.setAutoFields();
    for (DataElementCategory category : categories) {
        categoryCombo.getCategories().add(category);
    }
    return categoryCombo;
}
Also used : DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory)

Example 27 with DataElementCategoryCombo

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

the class ExpressionStoreTest method setUpTest.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    DataElement dataElementA = createDataElement('A');
    DataElement dataElementB = createDataElement('B');
    DataElement dataElementC = createDataElement('C');
    DataElement dataElementD = createDataElement('D');
    dataElementIdA = dataElementService.addDataElement(dataElementA);
    dataElementIdB = dataElementService.addDataElement(dataElementB);
    dataElementIdC = dataElementService.addDataElement(dataElementC);
    dataElementIdD = dataElementService.addDataElement(dataElementD);
    DataElementCategoryCombo categoryCombo = categoryService.getDataElementCategoryComboByName(DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME);
    DataElementCategoryOptionCombo categoryOptionCombo = categoryCombo.getOptionCombos().iterator().next();
    optionCombos = new HashSet<>();
    optionCombos.add(categoryOptionCombo);
    expressionA = "[" + dataElementIdA + "] + [" + dataElementIdB + "]";
    expressionB = "[" + dataElementIdC + "] - [" + dataElementIdD + "]";
    descriptionA = "Expression A";
    descriptionB = "Expression B";
    dataElements.add(dataElementA);
    dataElements.add(dataElementB);
    dataElements.add(dataElementC);
    dataElements.add(dataElementD);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 28 with DataElementCategoryCombo

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

the class DataSetController method getCategoryCombinations.

@RequestMapping(value = "/{uid}/categoryCombos", method = RequestMethod.GET)
@ResponseBody
public RootNode getCategoryCombinations(@PathVariable("uid") String uid, HttpServletRequest request, TranslateParams translateParams, HttpServletResponse response) throws Exception {
    setUserContext(translateParams);
    DataSet dataSet = manager.get(DataSet.class, uid);
    if (dataSet == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Data set does not exist: " + uid));
    }
    List<DataElementCategoryCombo> categoryCombos = dataSet.getDataSetElements().stream().map(DataSetElement::getResolvedCategoryCombo).distinct().collect(Collectors.toList());
    Collections.sort(categoryCombos);
    List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
    RootNode rootNode = NodeUtils.createMetadata();
    rootNode.addChild(fieldFilterService.filter(DataElementCategoryCombo.class, categoryCombos, fields));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) DataSetElement(org.hisp.dhis.dataset.DataSetElement) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 29 with DataElementCategoryCombo

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

the class DataApprovalController method getApprovalByCategoryOptionCombos.

@RequestMapping(value = APPROVALS_PATH + "/categoryOptionCombos", method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON)
public void getApprovalByCategoryOptionCombos(@RequestParam Set<String> ds, @RequestParam String pe, @RequestParam(required = false) String ou, HttpServletResponse response) throws IOException, WebMessageException {
    Set<DataSet> dataSets = parseDataSetsWithWorkflow(ds);
    Period period = PeriodType.getPeriodFromIsoString(pe);
    if (period == null) {
        throw new WebMessageException(WebMessageUtils.conflict("Illegal period identifier: " + pe));
    }
    OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(ou);
    if (orgUnit != null && orgUnit.isRoot()) {
        // Look for all org units.
        orgUnit = null;
    }
    SetMap<DataApprovalWorkflow, DataElementCategoryCombo> workflowCategoryComboMap = new SetMap<>();
    for (DataSet dataSet : dataSets) {
        workflowCategoryComboMap.putValue(dataSet.getWorkflow(), dataSet.getCategoryCombo());
    }
    List<DataApprovalStatus> statusList = new ArrayList<>();
    for (DataApprovalWorkflow workflow : workflowCategoryComboMap.keySet()) {
        for (DataElementCategoryCombo attributeCombo : workflowCategoryComboMap.get(workflow)) {
            statusList.addAll(dataApprovalService.getUserDataApprovalsAndPermissions(workflow, period, orgUnit, attributeCombo));
        }
    }
    List<Map<String, Object>> list = new ArrayList<>();
    for (DataApprovalStatus status : statusList) {
        Map<String, Object> item = new HashMap<>();
        Map<String, String> approvalLevel = new HashMap<>();
        if (status.getApprovedLevel() != null) {
            approvalLevel.put("id", status.getApprovedLevel().getUid());
            approvalLevel.put("level", String.valueOf(status.getApprovedLevel().getLevel()));
        }
        item.put("id", status.getAttributeOptionComboUid());
        item.put("level", approvalLevel);
        item.put("ou", status.getOrganisationUnitUid());
        item.put("ouName", status.getOrganisationUnitName());
        item.put("accepted", status.isAccepted());
        item.put("permissions", status.getPermissions());
        list.add(item);
    }
    response.setContentType(MediaType.APPLICATION_JSON_VALUE);
    renderService.toJson(response.getOutputStream(), list);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) HashMap(java.util.HashMap) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) DataApprovalWorkflow(org.hisp.dhis.dataapproval.DataApprovalWorkflow) DataApprovalStatus(org.hisp.dhis.dataapproval.DataApprovalStatus) SetMap(org.hisp.dhis.common.SetMap) Map(java.util.Map) SetMap(org.hisp.dhis.common.SetMap) HashMap(java.util.HashMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with DataElementCategoryCombo

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

the class DefaultDataSetReportService method getDefaultDataSetReport.

@Override
public List<Grid> getDefaultDataSetReport(DataSet dataSet, Period period, OrganisationUnit unit, Set<String> dimensions, boolean selectedUnitOnly, I18nFormat format, I18n i18n) {
    ListMap<DataElementCategoryCombo, DataElement> map = new ListMap<>();
    for (DataSetElement element : dataSet.getDataSetElements()) {
        map.putValue(element.getResolvedCategoryCombo(), element.getDataElement());
    }
    DataSet tmpDataSet = new DataSet(dataSet.getName(), dataSet.getShortName(), dataSet.getPeriodType());
    tmpDataSet.setDataSetElements(dataSet.getDataSetElements());
    for (DataElementCategoryCombo categoryCombo : map.keySet()) {
        List<DataElement> dataElements = map.get(categoryCombo);
        String name = categoryCombo.isDefault() ? dataSet.getName() : categoryCombo.getName();
        Section section = new Section(name, dataSet, dataElements, null);
        tmpDataSet.getSections().add(section);
    }
    return getSectionDataSetReport(tmpDataSet, period, unit, dimensions, selectedUnitOnly, format, i18n);
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataSet(org.hisp.dhis.dataset.DataSet) DataSetElement(org.hisp.dhis.dataset.DataSetElement) Section(org.hisp.dhis.dataset.Section) ListMap(org.hisp.dhis.common.ListMap)

Aggregations

DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)32 DataElement (org.hisp.dhis.dataelement.DataElement)14 DataSet (org.hisp.dhis.dataset.DataSet)12 ArrayList (java.util.ArrayList)11 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)10 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)8 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)8 Section (org.hisp.dhis.dataset.Section)7 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)7 HashSet (java.util.HashSet)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)5 List (java.util.List)4 Map (java.util.Map)4 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)3 SectionOrderComparator (org.hisp.dhis.dataset.comparator.SectionOrderComparator)3 OptionSet (org.hisp.dhis.option.OptionSet)3 Period (org.hisp.dhis.period.Period)3 Program (org.hisp.dhis.program.Program)3