Search in sources :

Example 26 with DataValue

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();
}
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 27 with DataValue

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;
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue)

Example 28 with 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;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataElementOperand(org.hisp.dhis.dataelement.DataElementOperand) DataValue(org.hisp.dhis.datavalue.DataValue) Period(org.hisp.dhis.period.Period)

Example 29 with DataValue

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);
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) Test(org.junit.Test) DhisTest(org.hisp.dhis.DhisTest)

Example 30 with DataValue

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);
}
Also used : AttributeValue(org.hisp.dhis.attribute.AttributeValue) DataValue(org.hisp.dhis.datavalue.DataValue) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService)

Aggregations

DataValue (org.hisp.dhis.datavalue.DataValue)49 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)20 Period (org.hisp.dhis.period.Period)19 Test (org.junit.Test)19 DhisSpringTest (org.hisp.dhis.DhisSpringTest)18 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)18 ClassPathResource (org.springframework.core.io.ClassPathResource)16 DataElement (org.hisp.dhis.dataelement.DataElement)15 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)11 Date (java.util.Date)7 ArrayList (java.util.ArrayList)4 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)4 DataValueAudit (org.hisp.dhis.datavalue.DataValueAudit)4 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 DataElementOperand (org.hisp.dhis.dataelement.DataElementOperand)3 DataSet (org.hisp.dhis.dataset.DataSet)3 DataExportParams (org.hisp.dhis.datavalue.DataExportParams)3 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)3 SMSCode (org.hisp.dhis.sms.command.code.SMSCode)3