use of org.hisp.dhis.datavalue.DataValue 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.datavalue.DataValue in project dhis2-core by dhis2.
the class DhisConvenienceTest method createDataValue.
/**
* @param dataElement The data element.
* @param period The period.
* @param source The source.
* @param categoryOptionCombo The category option combo.
* @param attributeOptionCombo The attribute option combo.
* @param value The value.
* @param comment The comment.
* @param storedBy The stored by.
* @param created The created date.
* @param lastupdated The last updated date.
*/
public static DataValue createDataValue(DataElement dataElement, Period period, OrganisationUnit source, DataElementCategoryOptionCombo categoryOptionCombo, DataElementCategoryOptionCombo attributeOptionCombo, String value, String comment, String storedBy, Date created, Date lastupdated) {
DataValue dataValue = new DataValue();
dataValue.setDataElement(dataElement);
dataValue.setPeriod(period);
dataValue.setSource(source);
dataValue.setCategoryOptionCombo(categoryOptionCombo);
dataValue.setAttributeOptionCombo(attributeOptionCombo);
dataValue.setValue(value);
dataValue.setComment("Comment");
dataValue.setStoredBy("StoredBy");
return dataValue;
}
use of org.hisp.dhis.datavalue.DataValue in project dhis2-core by dhis2.
the class GetValidationResultDetailsAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
validationRule = validationRuleService.getValidationRule(validationRuleId);
Period period = periodService.getPeriod(periodId);
OrganisationUnit source = organisationUnitService.getOrganisationUnit(sourceId);
for (DataElementOperand operand : expressionService.getOperandsInExpression(validationRule.getLeftSide().getExpression())) {
DataValue dataValue = dataValueService.getDataValue(operand.getDataElement(), period, source, operand.getCategoryOptionCombo());
String value = dataValue != null ? dataValue.getValue() : NULL_REPLACEMENT;
leftSideMap.put(operand.getName(), value);
}
for (DataElementOperand operand : expressionService.getOperandsInExpression(validationRule.getRightSide().getExpression())) {
DataValue dataValue = dataValueService.getDataValue(operand.getDataElement(), period, source, operand.getCategoryOptionCombo());
String value = dataValue != null ? dataValue.getValue() : NULL_REPLACEMENT;
rightSideMap.put(operand.getName(), value);
}
return SUCCESS;
}
use of org.hisp.dhis.datavalue.DataValue in project dhis2-core by dhis2.
the class DataValueBatchHandlerTest method testFindObject.
@Test
public void testFindObject() {
dataValueService.addDataValue(dataValueA);
dataValueService.addDataValue(dataValueC);
DataValue retrievedDataValueA = batchHandler.findObject(dataValueA);
DataValue retrievedDataValueB = batchHandler.findObject(dataValueB);
assertNotNull(dataValueA.getValue());
assertNotNull(dataValueA.getComment());
assertNotNull(dataValueA.getStoredBy());
assertEquals(dataValueA.getValue(), retrievedDataValueA.getValue());
assertEquals(dataValueA.getComment(), retrievedDataValueA.getComment());
assertEquals(dataValueA.getStoredBy(), retrievedDataValueA.getStoredBy());
assertEquals(dataValueA.isFollowup(), retrievedDataValueA.isFollowup());
assertNull(retrievedDataValueB);
}
use of org.hisp.dhis.datavalue.DataValue in project dhis2-core by dhis2.
the class DataValueSetServiceExportTest method setUpTest.
@Override
public void setUpTest() {
deA = createDataElement('A');
deB = createDataElement('B');
deC = createDataElement('C');
idObjectManager.save(deA);
idObjectManager.save(deB);
idObjectManager.save(deC);
ccA = createCategoryCombo('A');
categoryService.addDataElementCategoryCombo(ccA);
cocA = createCategoryOptionCombo('A');
cocB = createCategoryOptionCombo('B');
cocA.setCategoryCombo(ccA);
cocB.setCategoryCombo(ccA);
categoryService.addDataElementCategoryOptionCombo(cocA);
categoryService.addDataElementCategoryOptionCombo(cocB);
atA = createAttribute('A');
atA.setDataElementAttribute(true);
atA.setOrganisationUnitAttribute(true);
atA.setCategoryOptionComboAttribute(true);
idObjectManager.save(atA);
dsA = createDataSet('A');
dsA.addDataSetElement(deA);
dsA.addDataSetElement(deB);
dsB = createDataSet('B');
dsB.addDataSetElement(deA);
dataSetService.addDataSet(dsA);
dataSetService.addDataSet(dsB);
peA = createPeriod(PeriodType.getByNameIgnoreCase(MonthlyPeriodType.NAME), getDate(2016, 3, 1), getDate(2016, 3, 31));
peB = createPeriod(PeriodType.getByNameIgnoreCase(MonthlyPeriodType.NAME), getDate(2016, 4, 1), getDate(2016, 4, 30));
ouA = createOrganisationUnit('A');
ouB = createOrganisationUnit('B', ouA);
organisationUnitService.addOrganisationUnit(ouA);
organisationUnitService.addOrganisationUnit(ouB);
avA = new AttributeValue("AttributeValueA", atA);
avB = new AttributeValue("AttributeValueB", atA);
avC = new AttributeValue("AttributeValueC", atA);
avD = new AttributeValue("AttributeValueD", atA);
attributeService.addAttributeValue(deA, avA);
attributeService.addAttributeValue(ouA, avB);
attributeService.addAttributeValue(cocA, avC);
attributeService.addAttributeValue(cocB, avD);
// Data values
dataValueService.addDataValue(new DataValue(deA, peA, ouA, cocA, cocA, "1"));
dataValueService.addDataValue(new DataValue(deA, peA, ouA, cocB, cocB, "1"));
dataValueService.addDataValue(new DataValue(deA, peA, ouB, cocA, cocA, "1"));
dataValueService.addDataValue(new DataValue(deA, peA, ouB, cocB, cocB, "1"));
dataValueService.addDataValue(new DataValue(deA, peB, ouA, cocA, cocA, "1"));
dataValueService.addDataValue(new DataValue(deA, peB, ouA, cocB, cocB, "1"));
dataValueService.addDataValue(new DataValue(deA, peB, ouB, cocA, cocA, "1"));
dataValueService.addDataValue(new DataValue(deA, peB, ouB, cocB, cocB, "1"));
dataValueService.addDataValue(new DataValue(deB, peA, ouA, cocA, cocA, "1"));
dataValueService.addDataValue(new DataValue(deB, peA, ouA, cocB, cocB, "1"));
dataValueService.addDataValue(new DataValue(deB, peA, ouB, cocA, cocA, "1"));
dataValueService.addDataValue(new DataValue(deB, peA, ouB, cocB, cocB, "1"));
// Flush session to make data values visible to JDBC query
dbmsManager.flushSession();
// Service mocks
user = createUser('A');
user.setOrganisationUnits(Sets.newHashSet(ouA, ouB));
CurrentUserService currentUserService = new MockCurrentUserService(user);
setDependency(dataValueSetService, "currentUserService", currentUserService);
setDependency(organisationUnitService, "currentUserService", currentUserService);
}
Aggregations