Search in sources :

Example 1 with DataElementCategoryCombo

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

the class InputUtils method getAttributeOptionCombo.

/**
     * Validates and retrieves the attribute option combo. 409 conflict as
     * status code along with a textual message will be set on the response in
     * case of invalid input.
     *
     * @param cc the category combo identifier.
     * @param cp the category and option query string.
     * @param skipFallback whether to skip fallback to default option combo if
     *        attribute option combo is not found.
     * @return the attribute option combo identified from the given input, or
     *         null. if the input was invalid.
     */
public DataElementCategoryOptionCombo getAttributeOptionCombo(String cc, String cp, boolean skipFallback) {
    Set<String> opts = TextUtils.splitToArray(cp, TextUtils.SEMICOLON);
    if ((cc == null && opts != null || (cc != null && opts == null))) {
        throw new IllegalQueryException("Both or none of category combination and category options must be present");
    }
    DataElementCategoryCombo categoryCombo = null;
    if (cc != null && (categoryCombo = idObjectManager.get(DataElementCategoryCombo.class, cc)) == null) {
        throw new IllegalQueryException("Illegal category combo identifier: " + cc);
    }
    if (categoryCombo == null && opts == null) {
        if (skipFallback) {
            return null;
        }
        categoryCombo = categoryService.getDefaultDataElementCategoryCombo();
    }
    return getAttributeOptionCombo(categoryCombo, cp, null, IdScheme.UID);
}
Also used : DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException)

Example 2 with DataElementCategoryCombo

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

the class GetMetaDataAction method execute.

// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
    User user = currentUserService.getCurrentUser();
    Date lastUpdated = DateUtils.max(Sets.newHashSet(identifiableObjectManager.getLastUpdated(DataElement.class), identifiableObjectManager.getLastUpdated(OptionSet.class), identifiableObjectManager.getLastUpdated(Indicator.class), identifiableObjectManager.getLastUpdated(DataSet.class), identifiableObjectManager.getLastUpdated(DataElementCategoryCombo.class), identifiableObjectManager.getLastUpdated(DataElementCategory.class), identifiableObjectManager.getLastUpdated(DataElementCategoryOption.class)));
    String tag = lastUpdated != null && user != null ? (DateUtils.getLongDateString(lastUpdated) + SEP + user.getUid()) : null;
    if (ContextUtils.isNotModified(ServletActionContext.getRequest(), ServletActionContext.getResponse(), tag)) {
        return SUCCESS;
    }
    if (user != null && user.getOrganisationUnits().isEmpty()) {
        emptyOrganisationUnits = true;
        return SUCCESS;
    }
    significantZeros = dataElementService.getDataElementsByZeroIsSignificant(true);
    dataElements = dataElementService.getDataElementsWithDataSets();
    for (DataElement dataElement : dataElements) {
        if (dataElement != null && dataElement.getOptionSet() != null) {
            dataElementsWithOptionSet.add(dataElement);
        }
    }
    indicators = indicatorService.getIndicatorsWithDataSets();
    expressionService.substituteExpressions(indicators, null);
    dataSets = dataSetService.getCurrentUserDataSets();
    Set<DataElementCategoryCombo> categoryComboSet = new HashSet<>();
    Set<DataElementCategory> categorySet = new HashSet<>();
    for (DataSet dataSet : dataSets) {
        if (dataSet.getCategoryCombo() != null) {
            categoryComboSet.add(dataSet.getCategoryCombo());
        }
    }
    for (DataElementCategoryCombo categoryCombo : categoryComboSet) {
        if (categoryCombo.getCategories() != null) {
            categorySet.addAll(categoryCombo.getCategories());
        }
    }
    categoryCombos = new ArrayList<>(categoryComboSet);
    categories = new ArrayList<>(categorySet);
    for (DataElementCategory category : categories) {
        List<DataElementCategoryOption> categoryOptions = new ArrayList<>(categoryService.getDataElementCategoryOptions(category));
        Collections.sort(categoryOptions);
        categoryOptionMap.put(category.getUid(), categoryOptions);
    }
    Collections.sort(dataSets);
    Collections.sort(categoryCombos);
    Collections.sort(categories);
    defaultCategoryCombo = categoryService.getDefaultDataElementCategoryCombo();
    return SUCCESS;
}
Also used : User(org.hisp.dhis.user.User) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataSet(org.hisp.dhis.dataset.DataSet) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) ArrayList(java.util.ArrayList) Date(java.util.Date) DataElement(org.hisp.dhis.dataelement.DataElement) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) HashSet(java.util.HashSet)

Example 3 with DataElementCategoryCombo

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

the class DataSetOrganisationUnitCategoryResourceTable method getPopulateTempTableContent.

/**
     * Iterate over data sets and associated organisation units. If data set
     * has a category combination and the organisation unit has category options, 
     * find the intersection of the category option combinations linked to the 
     * organisation unit through its category options, and the category option 
     * combinations linked to the data set through its category combination. If
     * not, use the default category option combo.
     */
@Override
public Optional<List<Object[]>> getPopulateTempTableContent() {
    List<Object[]> batchArgs = new ArrayList<>();
    for (DataSet dataSet : objects) {
        DataElementCategoryCombo categoryCombo = dataSet.getCategoryCombo();
        for (OrganisationUnit orgUnit : dataSet.getSources()) {
            if (!categoryCombo.isDefault()) {
                if (orgUnit.hasCategoryOptions()) {
                    Set<DataElementCategoryOption> orgUnitOptions = orgUnit.getCategoryOptions();
                    for (DataElementCategoryOptionCombo optionCombo : categoryCombo.getOptionCombos()) {
                        Set<DataElementCategoryOption> optionComboOptions = optionCombo.getCategoryOptions();
                        if (orgUnitOptions.containsAll(optionComboOptions)) {
                            Date startDate = DateUtils.min(optionComboOptions.stream().map(co -> co.getStartDate()).collect(Collectors.toSet()));
                            Date endDate = DateUtils.max(optionComboOptions.stream().map(co -> co.getEndDate()).collect(Collectors.toSet()));
                            List<Object> values = Lists.newArrayList(dataSet.getId(), orgUnit.getId(), optionCombo.getId(), startDate, endDate);
                            batchArgs.add(values.toArray());
                        }
                    }
                }
            } else {
                List<Object> values = Lists.newArrayList(dataSet.getId(), orgUnit.getId(), defaultOptionCombo.getId(), null, null);
                batchArgs.add(values.toArray());
            }
        }
    }
    return Optional.of(batchArgs);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataSet(org.hisp.dhis.dataset.DataSet) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) ArrayList(java.util.ArrayList) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo) Date(java.util.Date)

Example 4 with DataElementCategoryCombo

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

the class ObjectBundleServiceTest method testPreheatValidationsWithCatCombo.

@Test
public void testPreheatValidationsWithCatCombo() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_validate1.json").getInputStream(), RenderFormat.JSON);
    DataElementCategoryCombo categoryCombo = manager.getByName(DataElementCategoryCombo.class, "default");
    categoryCombo.setUid("p0KPaWEg3cf");
    manager.update(categoryCombo);
    OptionSet optionSet = new OptionSet("OptionSet: pQYCiuosBnZ", ValueType.TEXT);
    optionSet.setAutoFields();
    optionSet.setUid("pQYCiuosBnZ");
    manager.save(optionSet);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.VALIDATE);
    params.setImportStrategy(ImportStrategy.CREATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertFalse(validate.getTypeReportMap().isEmpty());
    List<ObjectReport> objectReports = validate.getObjectReports(DataElement.class);
    assertFalse(objectReports.isEmpty());
    for (ObjectReport objectReport : objectReports) {
        for (ErrorCode errorCode : objectReport.getErrorCodes()) {
            List<ErrorReport> errorReports = objectReport.getErrorReportsByCode().get(errorCode);
            assertFalse(errorReports.isEmpty());
            for (ErrorReport errorReport : errorReports) {
                assertTrue(PreheatErrorReport.class.isInstance(errorReport));
                PreheatErrorReport preheatErrorReport = (PreheatErrorReport) errorReport;
                assertEquals(PreheatIdentifier.UID, preheatErrorReport.getPreheatIdentifier());
                if (DataElementCategoryCombo.class.isInstance(preheatErrorReport.getValue())) {
                    assertFalse(true);
                } else if (User.class.isInstance(preheatErrorReport.getValue())) {
                    assertEquals("GOLswS44mh8", preheatErrorReport.getObjectReference().getUid());
                } else if (OptionSet.class.isInstance(preheatErrorReport.getValue())) {
                    assertFalse(true);
                }
            }
        }
    }
}
Also used : DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) User(org.hisp.dhis.user.User) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) ObjectReport(org.hisp.dhis.feedback.ObjectReport) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) ErrorReport(org.hisp.dhis.feedback.ErrorReport) PreheatErrorReport(org.hisp.dhis.preheat.PreheatErrorReport) PreheatErrorReport(org.hisp.dhis.preheat.PreheatErrorReport) List(java.util.List) ErrorCode(org.hisp.dhis.feedback.ErrorCode) OptionSet(org.hisp.dhis.option.OptionSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 5 with DataElementCategoryCombo

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

the class DataValueDimensionTest method setUpTest.

@Override
public void setUpTest() {
    male = new DataElementCategoryOption("Male");
    female = new DataElementCategoryOption("Female");
    under15 = new DataElementCategoryOption("<15");
    over15 = new DataElementCategoryOption(">15");
    categoryService.addDataElementCategoryOption(male);
    categoryService.addDataElementCategoryOption(female);
    categoryService.addDataElementCategoryOption(under15);
    categoryService.addDataElementCategoryOption(over15);
    gender = new DataElementCategory("Gender", DataDimensionType.DISAGGREGATION);
    gender.getCategoryOptions().add(male);
    gender.getCategoryOptions().add(female);
    ageGroup = new DataElementCategory("Agegroup", DataDimensionType.DISAGGREGATION);
    ageGroup.getCategoryOptions().add(under15);
    ageGroup.getCategoryOptions().add(over15);
    categoryService.addDataElementCategory(gender);
    categoryService.addDataElementCategory(ageGroup);
    genderAndAgeGroup = new DataElementCategoryCombo("Gender and Agegroup", DataDimensionType.DISAGGREGATION);
    genderAndAgeGroup.getCategories().add(gender);
    genderAndAgeGroup.getCategories().add(ageGroup);
    categoryService.addDataElementCategoryCombo(genderAndAgeGroup);
    categoryService.generateOptionCombos(genderAndAgeGroup);
    dataElementA = createDataElement('A', genderAndAgeGroup);
    dataElementService.addDataElement(dataElementA);
    periodA = createPeriod(getDate(2000, 1, 1), getDate(2000, 2, 1));
    periodService.addPeriod(periodA);
    sourceA = createOrganisationUnit('A');
    organisationUnitService.addOrganisationUnit(sourceA);
    defaultOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    for (DataElementCategoryOptionCombo categoryOptionCombo : genderAndAgeGroup.getOptionCombos()) {
        dataValueService.addDataValue(createDataValue(dataElementA, periodA, sourceA, "10", categoryOptionCombo, defaultOptionCombo));
    }
}
Also used : DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

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