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