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();
}
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);
}
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());
}
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());
}
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());
}
Aggregations