Search in sources :

Example 16 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class DefaultAdxDataService method parseAdxDataValueToDxf.

private void parseAdxDataValueToDxf(XMLReader adxReader, XMLStreamWriter dxfWriter, Map<String, String> groupAttributes, ImportOptions importOptions, CachingMap<String, DataElement> dataElementMap, IdentifiableObjectCallable<DataElement> dataElementCallable) throws XMLStreamException, AdxException {
    Map<String, String> dvAttributes = adxReader.readAttributes();
    log.debug("Processing data value: " + dvAttributes);
    if (!dvAttributes.containsKey(AdxDataService.DATAELEMENT)) {
        throw new AdxException(AdxDataService.DATAELEMENT + " attribute is required on 'dataValue'");
    }
    if (!dvAttributes.containsKey(AdxDataService.VALUE)) {
        throw new AdxException(AdxDataService.VALUE + " attribute is required on 'dataValue'");
    }
    String dataElementStr = trimToNull(dvAttributes.get(AdxDataService.DATAELEMENT));
    final DataElement dataElement = dataElementMap.get(dataElementStr, dataElementCallable.setId(dataElementStr));
    if (dataElement == null) {
        throw new AdxException("No data element matching " + dataElementCallable.getIdScheme().name().toLowerCase() + " '" + dataElementStr + "'");
    }
    // process ADX data value attributes
    if (!dvAttributes.containsKey(AdxDataService.CATOPTCOMBO)) {
        log.debug("No category option combo present");
        // TODO expand to allow for category combos part of DataSetElements.
        CategoryCombo categoryCombo = dataElement.getCategoryCombo();
        convertAttributesToDxf(dvAttributes, AdxDataService.CATOPTCOMBO, categoryCombo, importOptions.getIdSchemes());
    }
    // 'annotation' element
    if (!dataElement.getValueType().isNumeric()) {
        adxReader.moveToStartElement(AdxDataService.ANNOTATION, AdxDataService.DATAVALUE);
        if (adxReader.isStartElement(AdxDataService.ANNOTATION)) {
            String textValue = adxReader.getElementValue();
            dvAttributes.put(AdxDataService.VALUE, textValue);
        } else {
            throw new AdxException(dvAttributes.get(AdxDataService.DATAELEMENT), "DataElement expects text annotation");
        }
    }
    log.debug("Processing data value as DXF: " + dvAttributes);
    dxfWriter.writeStartElement("dataValue");
    // write the group attributes through to DXF stream
    for (String attribute : groupAttributes.keySet()) {
        writeAttribute(dxfWriter, attribute, groupAttributes.get(attribute));
    }
    // pass through the remaining attributes to DXF
    for (String attribute : dvAttributes.keySet()) {
        writeAttribute(dxfWriter, attribute, dvAttributes.get(attribute));
    }
    // dataValue
    dxfWriter.writeEndElement();
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) CategoryCombo(org.hisp.dhis.category.CategoryCombo)

Example 17 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class CategoryComboTest method before.

// -------------------------------------------------------------------------
// Fixture
// -------------------------------------------------------------------------
@BeforeEach
void before() {
    categoryOptionA = new CategoryOption("OptionA");
    categoryOptionB = new CategoryOption("OptionB");
    categoryOptionC = new CategoryOption("OptionC");
    categoryOptionD = new CategoryOption("OptionD");
    categoryOptionE = new CategoryOption("OptionE");
    categoryOptionF = new CategoryOption("OptionF");
    categoryA = new Category("CategoryA", DataDimensionType.DISAGGREGATION);
    categoryB = new Category("CategoryB", DataDimensionType.DISAGGREGATION);
    categoryC = new Category("CategoryC", DataDimensionType.DISAGGREGATION);
    categoryA.getCategoryOptions().add(categoryOptionA);
    categoryA.getCategoryOptions().add(categoryOptionB);
    categoryB.getCategoryOptions().add(categoryOptionC);
    categoryB.getCategoryOptions().add(categoryOptionD);
    categoryC.getCategoryOptions().add(categoryOptionE);
    categoryC.getCategoryOptions().add(categoryOptionF);
    categoryOptionA.getCategories().add(categoryA);
    categoryOptionB.getCategories().add(categoryA);
    categoryOptionC.getCategories().add(categoryB);
    categoryOptionD.getCategories().add(categoryB);
    categoryOptionE.getCategories().add(categoryC);
    categoryOptionF.getCategories().add(categoryC);
    categoryCombo = new CategoryCombo("CategoryCombo", DataDimensionType.DISAGGREGATION);
    categoryCombo.getCategories().add(categoryA);
    categoryCombo.getCategories().add(categoryB);
    categoryCombo.getCategories().add(categoryC);
}
Also used : Category(org.hisp.dhis.category.Category) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOption(org.hisp.dhis.category.CategoryOption) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 18 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class EventQueryParamsTest method testIsOrgUnitFieldValidWithMultipleProgramIndicator2.

@Test
void testIsOrgUnitFieldValidWithMultipleProgramIndicator2() {
    QueryItem iA = new QueryItem(createDataElement('A', new CategoryCombo()));
    // This PI has a Program that has a Tracked Entity Attribute of type Org
    // Unit
    ProgramIndicator programIndicatorA = createProgramIndicator('A', prC, "", "");
    EventQueryParams params = new EventQueryParams.Builder().withProgram(null).withOrgUnitField(deD.getUid()).addItem(iA).addItemProgramIndicator(programIndicatorA).build();
    assertTrue(params.orgUnitFieldIsValid());
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) CategoryCombo(org.hisp.dhis.category.CategoryCombo) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 19 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class EventQueryParamsTest method testIsOrgUnitFieldValidWithMultipleProgramIndicator.

@Test
void testIsOrgUnitFieldValidWithMultipleProgramIndicator() {
    QueryItem iA = new QueryItem(createDataElement('A', new CategoryCombo()));
    ProgramIndicator programIndicatorA = createProgramIndicator('A', prA, "", "");
    // this PI has 0 Data Element of type OrgUnit -> test should fail
    ProgramIndicator programIndicatorB = createProgramIndicator('B', prB, "", "");
    EventQueryParams params = new EventQueryParams.Builder().withProgram(null).withOrgUnitField(deD.getUid()).addItem(iA).addItemProgramIndicator(programIndicatorA).addItemProgramIndicator(programIndicatorB).build();
    assertFalse(params.orgUnitFieldIsValid());
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) CategoryCombo(org.hisp.dhis.category.CategoryCombo) ProgramIndicator(org.hisp.dhis.program.ProgramIndicator) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Example 20 with CategoryCombo

use of org.hisp.dhis.category.CategoryCombo in project dhis2-core by dhis2.

the class EventQueryParamsTest method testIsOrgUnitFieldValid.

@Test
void testIsOrgUnitFieldValid() {
    QueryItem iA = new QueryItem(createDataElement('A', new CategoryCombo()));
    EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).withOrgUnitField(deD.getUid()).addItem(iA).build();
    assertTrue(params.orgUnitFieldIsValid());
    params = new EventQueryParams.Builder().withProgram(prA).withOrgUnitField("someInvalidOrgUnitField").addItem(iA).build();
    assertFalse(params.orgUnitFieldIsValid());
}
Also used : QueryItem(org.hisp.dhis.common.QueryItem) CategoryCombo(org.hisp.dhis.category.CategoryCombo) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Aggregations

CategoryCombo (org.hisp.dhis.category.CategoryCombo)114 Test (org.junit.jupiter.api.Test)66 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)53 CategoryOption (org.hisp.dhis.category.CategoryOption)47 Category (org.hisp.dhis.category.Category)41 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)39 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)36 Program (org.hisp.dhis.program.Program)31 Event (org.hisp.dhis.tracker.domain.Event)27 TrackedEntityType (org.hisp.dhis.trackedentity.TrackedEntityType)23 BeforeEach (org.junit.jupiter.api.BeforeEach)23 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)22 Collectors (java.util.stream.Collectors)21 ProgramInstance (org.hisp.dhis.program.ProgramInstance)21 Collections (java.util.Collections)20 CategoryService (org.hisp.dhis.category.CategoryService)20 CodeGenerator (org.hisp.dhis.common.CodeGenerator)20 ProgramStage (org.hisp.dhis.program.ProgramStage)20 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)20 Sets (com.google.common.collect.Sets)19