Search in sources :

Example 66 with DataValue

use of org.hisp.dhis.dxf2.events.event.DataValue in project dhis2-core by dhis2.

the class EventDataValueRowCallbackHandler method getDataValue.

private List<DataValue> getDataValue(ResultSet rs) throws SQLException {
    // TODO not sure this is the most efficient way to handle JSONB -> java
    List<DataValue> dataValues = new ArrayList<>();
    PGobject values = (PGobject) rs.getObject("eventdatavalues");
    Map<String, ?> eventDataValuesJson = gson.fromJson(values.getValue(), Map.class);
    for (String dataElementUid : eventDataValuesJson.keySet()) {
        Map jsonValues = (Map) eventDataValuesJson.get(dataElementUid);
        DataValue value = new DataValue(dataElementUid, (String) jsonValues.get("value"));
        value.setCreated((String) jsonValues.get("created"));
        value.setLastUpdated((String) jsonValues.get("lastUpdated"));
        value.setStoredBy((String) jsonValues.get("storedBy"));
        value.setProvidedElsewhere((Boolean) jsonValues.get("providedElsewhere"));
        dataValues.add(value);
    }
    return dataValues;
}
Also used : DataValue(org.hisp.dhis.dxf2.events.event.DataValue) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) PGobject(org.postgresql.util.PGobject)

Example 67 with DataValue

use of org.hisp.dhis.dxf2.events.event.DataValue in project dhis2-core by dhis2.

the class DefaultEventStore method getDataValuesPartitioned.

private Map<String, List<DataValue>> getDataValuesPartitioned(List<Long> programStageInstanceId) {
    EventDataValueRowCallbackHandler handler = new EventDataValueRowCallbackHandler();
    jdbcTemplate.query(GET_DATAVALUES_SQL, createIdsParam(programStageInstanceId), handler);
    return handler.getItems();
}
Also used : EventDataValueRowCallbackHandler(org.hisp.dhis.dxf2.events.trackedentity.store.mapper.EventDataValueRowCallbackHandler)

Example 68 with DataValue

use of org.hisp.dhis.dxf2.events.event.DataValue in project dhis2-core by dhis2.

the class AdxDataServiceIntegrationTest method testImport.

private void testImport(String filePath, IdSchemes idSchemes) throws IOException {
    assertEquals(0, dataValueService.getAllDataValues().size());
    InputStream in = new ClassPathResource(filePath).getInputStream();
    ImportOptions importOptions = ImportOptions.getDefaultImportOptions();
    importOptions.setIdSchemes(idSchemes);
    adxDataService.saveDataValueSet(in, importOptions, null);
    List<DataValue> dataValues = dataValueService.getAllDataValues();
    assertContainsOnly(dataValues, new DataValue(deA, pe202001, ouA, cocFUnder5, cocDefault, "1"), new DataValue(deA, pe202001, ouA, cocMUnder5, cocDefault, "2"), new DataValue(deA, pe202001, ouA, cocFOver5, cocDefault, "3"), new DataValue(deA, pe202001, ouA, cocMOver5, cocDefault, "4"), new DataValue(deB, pe202001, ouA, cocDefault, cocDefault, "Text data value"), new DataValue(deA, pe202002, ouB, cocFUnder5, cocDefault, "6"), new DataValue(deA, pe2021Q1, ouB, cocFUnder5, cocPepfar, "10"), new DataValue(deA, pe2021Q1, ouB, cocFOver5, cocMcDonalds, "20"), new DataValue(deA, pe2021Q1, ouB, cocMUnder5, cocMcDonalds, "30"));
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) InputStream(java.io.InputStream) ClassPathResource(org.springframework.core.io.ClassPathResource) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions)

Example 69 with DataValue

use of org.hisp.dhis.dxf2.events.event.DataValue in project dhis2-core by dhis2.

the class PdfDataEntryFormUtil method getDataValueSet.

/**
 * Creates data value set from Input Stream (PDF) for PDF data import
 */
public static DataValueSet getDataValueSet(InputStream in) {
    PdfReader reader = null;
    DataValueSet dataValueSet = new DataValueSet();
    List<org.hisp.dhis.dxf2.datavalue.DataValue> dataValueList = new ArrayList<>();
    try {
        reader = new PdfReader(in);
        AcroFields form = reader.getAcroFields();
        if (form != null) {
            // Process OrgUnitUID and PeriodID from the PDF Form
            String orgUnitUid = form.getField(PdfDataEntryFormUtil.LABELCODE_ORGID).trim();
            String periodId = form.getField(PdfDataEntryFormUtil.LABELCODE_PERIODID).trim();
            if (periodId == null || periodId.isEmpty()) {
                throw new InvalidIdentifierReferenceException(ERROR_EMPTY_PERIOD);
            }
            if (orgUnitUid == null || orgUnitUid.isEmpty()) {
                throw new InvalidIdentifierReferenceException(ERROR_EMPTY_ORG_UNIT);
            }
            Period period = PeriodType.getPeriodFromIsoString(periodId);
            if (period == null) {
                throw new InvalidIdentifierReferenceException(ERROR_INVALID_PERIOD + periodId);
            }
            // Loop Through the Fields and get data.
            @SuppressWarnings("unchecked") Set<String> fldNames = form.getFields().keySet();
            for (String fldName : fldNames) {
                if (fldName.startsWith(PdfDataEntryFormUtil.LABELCODE_DATAENTRYTEXTFIELD)) {
                    String[] strArrFldName = fldName.split("_");
                    org.hisp.dhis.dxf2.datavalue.DataValue dataValue = new org.hisp.dhis.dxf2.datavalue.DataValue();
                    dataValue.setDataElement(strArrFldName[1]);
                    dataValue.setCategoryOptionCombo(strArrFldName[2]);
                    dataValue.setOrgUnit(orgUnitUid);
                    dataValue.setPeriod(period.getIsoDate());
                    dataValue.setValue(fieldValueFormat(strArrFldName, form.getField(fldName)));
                    dataValue.setStoredBy(DATAVALUE_IMPORT_STOREBY);
                    dataValue.setComment(DATAVALUE_IMPORT_COMMENT);
                    dataValue.setFollowup(false);
                    dataValue.setLastUpdated(DateUtils.getMediumDateString());
                    dataValueList.add(dataValue);
                }
            }
            dataValueSet.setDataValues(dataValueList);
        } else {
            throw new RuntimeException("Could not generate PDF AcroFields form from input");
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
    return dataValueSet;
}
Also used : DataValueSet(org.hisp.dhis.dxf2.datavalueset.DataValueSet) ArrayList(java.util.ArrayList) Period(org.hisp.dhis.period.Period) PdfReader(com.lowagie.text.pdf.PdfReader) InvalidIdentifierReferenceException(org.hisp.dhis.common.exception.InvalidIdentifierReferenceException) AcroFields(com.lowagie.text.pdf.AcroFields) InvalidIdentifierReferenceException(org.hisp.dhis.common.exception.InvalidIdentifierReferenceException)

Example 70 with DataValue

use of org.hisp.dhis.dxf2.events.event.DataValue in project dhis2-core by dhis2.

the class DataValueSetImportValidatorTest method testCheckDataValueCategoryOptionCombo.

/*
     * DataValue Constraints
     */
@Test
void testCheckDataValueCategoryOptionCombo() {
    DataValue dataValue = createRandomDataValue();
    dataValue.setCategoryOptionCombo(null);
    DataValueContext valueContext = createDataValueContext(dataValue).build();
    DataSetContext dataSetContext = createMinimalDataSetContext().build();
    ImportContext context = createMinimalImportContext(valueContext).requireCategoryOptionCombo(true).build();
    assertTrue(validator.skipDataValue(dataValue, context, dataSetContext, valueContext));
    assertConflict(ErrorCode.E7630, "Category option combo is required but is not specified", context);
}
Also used : DataValue(org.hisp.dhis.dxf2.datavalue.DataValue) DataSetContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext) DataValueContext(org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)58 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)33 DataValue (org.hisp.dhis.dxf2.datavalue.DataValue)32 DataValue (org.hisp.dhis.datavalue.DataValue)31 DataSetContext (org.hisp.dhis.dxf2.datavalueset.ImportContext.DataSetContext)29 DataValueContext (org.hisp.dhis.dxf2.datavalueset.ImportContext.DataValueContext)28 DataElement (org.hisp.dhis.dataelement.DataElement)26 DataValue (org.hisp.dhis.dxf2.events.event.DataValue)26 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)21 Event (org.hisp.dhis.dxf2.events.event.Event)20 ClassPathResource (org.springframework.core.io.ClassPathResource)20 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)16 Period (org.hisp.dhis.period.Period)16 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)11 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)11 ArrayList (java.util.ArrayList)10 Date (java.util.Date)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)8 User (org.hisp.dhis.user.User)8