Search in sources :

Example 71 with DataElementCategoryOptionCombo

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

the class DefaultDataValueSetService method getCompleteDate.

private Date getCompleteDate(DataExportParams params) {
    if (params.isSingleDataValueSet()) {
        //TODO
        DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
        CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration(params.getFirstDataSet(), params.getFirstPeriod(), params.getFirstOrganisationUnit(), optionCombo);
        return registration != null ? registration.getDate() : null;
    }
    return null;
}
Also used : CompleteDataSetRegistration(org.hisp.dhis.dataset.CompleteDataSetRegistration) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 72 with DataElementCategoryOptionCombo

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

the class DefaultAdxDataService method writeDataValueSet.

@Override
public void writeDataValueSet(DataExportParams params, OutputStream out) throws AdxException {
    dataValueSetService.decideAccess(params);
    dataValueSetService.validate(params);
    XMLWriter adxWriter = XMLFactory.getXMLWriter(out);
    adxWriter.openElement(AdxDataService.ROOT);
    adxWriter.writeAttribute("xmlns", AdxDataService.NAMESPACE);
    for (DataSet dataSet : params.getDataSets()) {
        AdxDataSetMetadata metadata = new AdxDataSetMetadata(dataSet);
        DataElementCategoryCombo categoryCombo = dataSet.getCategoryCombo();
        for (DataElementCategoryOptionCombo aoc : categoryCombo.getOptionCombos()) {
            Map<String, String> attributeDimensions = metadata.getExplodedCategoryAttributes(aoc.getId());
            for (OrganisationUnit orgUnit : params.getOrganisationUnits()) {
                for (Period period : params.getPeriods()) {
                    adxWriter.openElement(AdxDataService.GROUP);
                    adxWriter.writeAttribute(AdxDataService.DATASET, dataSet.getCode());
                    adxWriter.writeAttribute(AdxDataService.PERIOD, AdxPeriod.serialize(period));
                    adxWriter.writeAttribute(AdxDataService.ORGUNIT, orgUnit.getCode());
                    for (String attribute : attributeDimensions.keySet()) {
                        adxWriter.writeAttribute(attribute, attributeDimensions.get(attribute));
                    }
                    for (DataValue dv : dataValueService.getDataValues(orgUnit, period, dataSet.getDataElements(), aoc)) {
                        adxWriter.openElement(AdxDataService.DATAVALUE);
                        adxWriter.writeAttribute(AdxDataService.DATAELEMENT, dv.getDataElement().getCode());
                        DataElementCategoryOptionCombo coc = dv.getCategoryOptionCombo();
                        Map<String, String> categoryDimensions = metadata.getExplodedCategoryAttributes(coc.getId());
                        for (String attribute : categoryDimensions.keySet()) {
                            adxWriter.writeAttribute(attribute, categoryDimensions.get(attribute));
                        }
                        if (dv.getDataElement().getValueType().isNumeric()) {
                            adxWriter.writeAttribute(AdxDataService.VALUE, dv.getValue());
                        } else {
                            adxWriter.writeAttribute(AdxDataService.VALUE, "0");
                            adxWriter.openElement(AdxDataService.ANNOTATION);
                            adxWriter.writeCharacters(dv.getValue());
                            // ANNOTATION
                            adxWriter.closeElement();
                        }
                        // DATAVALUE
                        adxWriter.closeElement();
                    }
                    // GROUP
                    adxWriter.closeElement();
                }
            }
        }
    }
    // ADX
    adxWriter.closeElement();
    adxWriter.closeWriter();
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementCategoryCombo(org.hisp.dhis.dataelement.DataElementCategoryCombo) DataSet(org.hisp.dhis.dataset.DataSet) DataValue(org.hisp.dhis.datavalue.DataValue) Period(org.hisp.dhis.period.Period) XMLWriter(org.hisp.staxwax.writer.XMLWriter) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 73 with DataElementCategoryOptionCombo

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

the class DefaultAdxDataService method getCatOptComboFromAttributes.

private DataElementCategoryOptionCombo getCatOptComboFromAttributes(Map<String, String> attributes, DataElementCategoryCombo catcombo, IdentifiableProperty scheme) throws AdxException {
    CategoryComboMap catcomboMap;
    try {
        catcomboMap = new CategoryComboMap(catcombo, scheme);
    } catch (CategoryComboMapException ex) {
        log.info("Failed to create category combo map from: " + catcombo);
        throw new AdxException(ex.getMessage());
    }
    String compositeIdentifier = StringUtils.EMPTY;
    for (DataElementCategory category : catcomboMap.getCategories()) {
        String categoryCode = category.getCode();
        if (categoryCode == null) {
            throw new AdxException("No category matching: " + categoryCode);
        }
        String catAttribute = attributes.get(categoryCode);
        if (catAttribute == null) {
            throw new AdxException("Missing required attribute from category combo: " + categoryCode);
        }
        compositeIdentifier += "\"" + catAttribute + "\"";
    }
    DataElementCategoryOptionCombo catOptionCombo = catcomboMap.getCategoryOptionCombo(compositeIdentifier);
    if (catOptionCombo == null) {
        throw new AdxException("Invalid attributes:" + attributes);
    }
    return catOptionCombo;
}
Also used : CategoryComboMap(org.hisp.dhis.dataelement.CategoryComboMap) CategoryComboMapException(org.hisp.dhis.dataelement.CategoryComboMap.CategoryComboMapException) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 74 with DataElementCategoryOptionCombo

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

the class ValidationRuleGroupStoreTest method setUpTest.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
    dataElementA = createDataElement('A');
    dataElementB = createDataElement('B');
    dataElementC = createDataElement('C');
    dataElementD = createDataElement('D');
    dataElementService.addDataElement(dataElementA);
    dataElementService.addDataElement(dataElementB);
    dataElementService.addDataElement(dataElementC);
    dataElementService.addDataElement(dataElementD);
    DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
    optionCombos = new HashSet<>();
    optionCombos.add(categoryOptionCombo);
    expressionA = new Expression("expressionA", "descriptionA");
    expressionB = new Expression("expressionB", "descriptionB");
    expressionService.addExpression(expressionB);
    expressionService.addExpression(expressionA);
    periodType = PeriodType.getAvailablePeriodTypes().iterator().next();
}
Also used : Expression(org.hisp.dhis.expression.Expression) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Example 75 with DataElementCategoryOptionCombo

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

the class DhisConvenienceTest method createCategoryOptionCombo.

/**
     * @param categoryComboUniqueIdentifier A unique character to identify the
     *                                      category option combo.
     * @param dataElementCategoryCombo      The associated category combination.
     * @param categoryOptions               the category options.
     * @return DataElementCategoryOptionCombo
     */
public static DataElementCategoryOptionCombo createCategoryOptionCombo(char categoryComboUniqueIdentifier, DataElementCategoryCombo dataElementCategoryCombo, DataElementCategoryOption... categoryOptions) {
    DataElementCategoryOptionCombo categoryOptionCombo = new DataElementCategoryOptionCombo();
    categoryOptionCombo.setAutoFields();
    categoryOptionCombo.setCategoryCombo(dataElementCategoryCombo);
    for (DataElementCategoryOption categoryOption : categoryOptions) {
        categoryOptionCombo.getCategoryOptions().add(categoryOption);
        categoryOption.getCategoryOptionCombos().add(categoryOptionCombo);
    }
    return categoryOptionCombo;
}
Also used : DataElementCategoryOption(org.hisp.dhis.dataelement.DataElementCategoryOption) DataElementCategoryOptionCombo(org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)

Aggregations

DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)97 DataElement (org.hisp.dhis.dataelement.DataElement)43 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)36 Period (org.hisp.dhis.period.Period)31 DataValue (org.hisp.dhis.datavalue.DataValue)19 ArrayList (java.util.ArrayList)18 Date (java.util.Date)18 DataSet (org.hisp.dhis.dataset.DataSet)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)13 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)12 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)12 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)10 DataElementCategoryCombo (org.hisp.dhis.dataelement.DataElementCategoryCombo)9 HashSet (java.util.HashSet)8 Test (org.junit.Test)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 Matcher (java.util.regex.Matcher)5 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)5 HashMap (java.util.HashMap)4