Search in sources :

Example 6 with DataSetElement

use of org.hisp.dhis.dataset.DataSetElement in project dhis2-core by dhis2.

the class ObjectBundleServiceTest method testCreateDataSetNoDSEDefaults.

@Test
@Disabled
void testCreateDataSetNoDSEDefaults() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/dataset_with_compulsory.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertFalse(validate.hasErrorReports());
    objectBundleService.commit(bundle);
    List<DataSet> dataSets = manager.getAll(DataSet.class);
    assertEquals(1, dataSets.size());
    DataSet dataSet = dataSets.get(0);
    assertEquals(dataSet.getDataSetElements().size(), 1);
    DataSetElement dataSetElement = dataSet.getDataSetElements().iterator().next();
    assertNull(dataSetElement.getCategoryCombo());
}
Also used : ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) DataSet(org.hisp.dhis.dataset.DataSet) List(java.util.List) DataSetElement(org.hisp.dhis.dataset.DataSetElement) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 7 with DataSetElement

use of org.hisp.dhis.dataset.DataSetElement 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)

Example 8 with DataSetElement

use of org.hisp.dhis.dataset.DataSetElement in project dhis2-core by dhis2.

the class DefaultValidationRuleService method getValidationRulesForDataSet.

@Transactional(readOnly = true)
@Override
public Collection<ValidationRule> getValidationRulesForDataSet(DataSet dataSet) {
    Set<String> elementsAndOptionCombos = new HashSet<>();
    for (DataSetElement dataSetElement : dataSet.getDataSetElements()) {
        DataElement dataElement = dataSetElement.getDataElement();
        elementsAndOptionCombos.add(dataElement.getUid());
        CategoryCombo catCombo = dataSetElement.hasCategoryCombo() ? dataSetElement.getCategoryCombo() : dataElement.getCategoryCombo();
        for (CategoryOptionCombo optionCombo : catCombo.getOptionCombos()) {
            elementsAndOptionCombos.add(dataElement.getUid() + Expression.SEPARATOR + optionCombo.getUid());
        }
    }
    Set<ValidationRule> rulesForDataSet = new HashSet<>();
    for (ValidationRule rule : getAllFormValidationRules()) {
        Set<String> leftSideElementsAndCombos = expressionService.getExpressionElementAndOptionComboIds(rule.getLeftSide().getExpression(), VALIDATION_RULE_EXPRESSION);
        Set<String> rightSideElementsAndCombos = expressionService.getExpressionElementAndOptionComboIds(rule.getRightSide().getExpression(), VALIDATION_RULE_EXPRESSION);
        if (!Sets.intersection(leftSideElementsAndCombos, elementsAndOptionCombos).isEmpty() || !Sets.intersection(rightSideElementsAndCombos, elementsAndOptionCombos).isEmpty()) {
            rulesForDataSet.add(rule);
        }
    }
    return rulesForDataSet;
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) CategoryCombo(org.hisp.dhis.category.CategoryCombo) DataSetElement(org.hisp.dhis.dataset.DataSetElement) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with DataSetElement

use of org.hisp.dhis.dataset.DataSetElement in project dhis2-core by dhis2.

the class DataSetController method getCategoryCombinations.

@GetMapping("/{uid}/categoryCombos")
@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(conflict("Data set does not exist: " + uid));
    }
    List<CategoryCombo> 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.toCollectionNode(CategoryCombo.class, new FieldFilterParams(categoryCombos, fields)));
    return rootNode;
}
Also used : RootNode(org.hisp.dhis.node.types.RootNode) DataSet(org.hisp.dhis.dataset.DataSet) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) CategoryCombo(org.hisp.dhis.category.CategoryCombo) FieldFilterParams(org.hisp.dhis.fieldfilter.FieldFilterParams) DataSetElement(org.hisp.dhis.dataset.DataSetElement) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

DataSetElement (org.hisp.dhis.dataset.DataSetElement)9 DataSet (org.hisp.dhis.dataset.DataSet)5 CategoryCombo (org.hisp.dhis.category.CategoryCombo)4 DataElement (org.hisp.dhis.dataelement.DataElement)4 List (java.util.List)2 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)2 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)2 ListMap (org.hisp.dhis.common.ListMap)2 Section (org.hisp.dhis.dataset.Section)2 Test (org.junit.jupiter.api.Test)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)1 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)1 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)1 FieldFilterParams (org.hisp.dhis.fieldfilter.FieldFilterParams)1 RootNode (org.hisp.dhis.node.types.RootNode)1