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