use of org.hisp.dhis.dxf2.datavalue.DataValue in project dhis2-core by dhis2.
the class DataValueSetServiceTest method testImportDataValuesXmlDryRun.
@Test
public void testImportDataValuesXmlDryRun() throws Exception {
in = new ClassPathResource("datavalueset/dataValueSetB.xml").getInputStream();
ImportOptions importOptions = new ImportOptions().setDryRun(true).setIdScheme("UID").setDataElementIdScheme("UID").setOrgUnitIdScheme("UID");
ImportSummary summary = dataValueSetService.saveDataValueSet(in, importOptions);
assertEquals(ImportStatus.SUCCESS, summary.getStatus());
assertEquals(summary.getConflicts().toString(), 0, summary.getConflicts().size());
Collection<DataValue> dataValues = mockDataValueBatchHandler.getInserts();
assertNotNull(dataValues);
assertEquals(0, dataValues.size());
}
use of org.hisp.dhis.dxf2.datavalue.DataValue in project dhis2-core by dhis2.
the class DefaultCsvEventService method writeEvents.
@Override
public void writeEvents(OutputStream outputStream, Events events, boolean withHeader) throws IOException {
ObjectWriter writer = CSV_MAPPER.writer(CSV_SCHEMA.withUseHeader(withHeader));
List<CsvEventDataValue> dataValues = new ArrayList<>();
for (Event event : events.getEvents()) {
CsvEventDataValue templateDataValue = new CsvEventDataValue();
templateDataValue.setEvent(event.getEvent());
templateDataValue.setStatus(event.getStatus() != null ? event.getStatus().name() : null);
templateDataValue.setProgram(event.getProgram());
templateDataValue.setProgramStage(event.getProgramStage());
templateDataValue.setEnrollment(event.getEnrollment());
templateDataValue.setOrgUnit(event.getOrgUnit());
templateDataValue.setEventDate(event.getEventDate());
templateDataValue.setDueDate(event.getDueDate());
templateDataValue.setStoredBy(event.getStoredBy());
if (event.getCoordinate() != null) {
templateDataValue.setLatitude(event.getCoordinate().getLatitude());
templateDataValue.setLongitude(event.getCoordinate().getLongitude());
}
for (DataValue value : event.getDataValues()) {
CsvEventDataValue dataValue = new CsvEventDataValue(templateDataValue);
dataValue.setDataElement(value.getDataElement());
dataValue.setValue(value.getValue());
dataValue.setProvidedElsewhere(value.getProvidedElsewhere());
if (value.getStoredBy() != null) {
dataValue.setStoredBy(value.getStoredBy());
}
dataValues.add(dataValue);
}
}
writer.writeValue(outputStream, dataValues);
}
use of org.hisp.dhis.dxf2.datavalue.DataValue in project dhis2-core by dhis2.
the class DefaultCsvEventService method readEvents.
@Override
public Events readEvents(InputStream inputStream, boolean skipFirst) throws IOException {
Events events = new Events();
ObjectReader reader = CSV_MAPPER.readerFor(CsvEventDataValue.class).with(CSV_SCHEMA.withSkipFirstDataRow(skipFirst));
MappingIterator<CsvEventDataValue> iterator = reader.readValues(inputStream);
Event event = new Event();
event.setEvent("not_valid");
while (iterator.hasNext()) {
CsvEventDataValue dataValue = iterator.next();
if (!event.getEvent().equals(dataValue.getEvent())) {
event = new Event();
event.setEvent(dataValue.getEvent());
event.setStatus(StringUtils.isEmpty(dataValue.getStatus()) ? EventStatus.ACTIVE : Enum.valueOf(EventStatus.class, dataValue.getStatus()));
event.setProgram(dataValue.getProgram());
event.setProgramStage(dataValue.getProgramStage());
event.setEnrollment(dataValue.getEnrollment());
event.setOrgUnit(dataValue.getOrgUnit());
event.setEventDate(dataValue.getEventDate());
event.setDueDate(dataValue.getDueDate());
if (dataValue.getLongitude() != null && dataValue.getLatitude() != null) {
event.setCoordinate(new Coordinate(dataValue.getLongitude(), dataValue.getLatitude()));
}
events.getEvents().add(event);
}
DataValue value = new DataValue(dataValue.getDataElement(), dataValue.getValue());
value.setStoredBy(dataValue.getStoredBy());
value.setProvidedElsewhere(dataValue.getProvidedElsewhere());
event.getDataValues().add(value);
}
return events;
}
use of org.hisp.dhis.dxf2.datavalue.DataValue in project dhis2-core by dhis2.
the class JdbcEventStore method getEventRows.
@Override
public List<EventRow> getEventRows(EventSearchParams params, List<OrganisationUnit> organisationUnits) {
List<EventRow> eventRows = new ArrayList<>();
String sql = buildSql(params, organisationUnits);
SqlRowSet rowSet = jdbcTemplate.queryForRowSet(sql);
log.debug("Event query SQL: " + sql);
EventRow eventRow = new EventRow();
eventRow.setEvent("not_valid");
Set<String> notes = new HashSet<>();
IdSchemes idSchemes = ObjectUtils.firstNonNull(params.getIdSchemes(), new IdSchemes());
while (rowSet.next()) {
if (rowSet.getString("psi_uid") == null) {
continue;
}
if (eventRow.getUid() == null || !eventRow.getUid().equals(rowSet.getString("psi_uid"))) {
eventRow = new EventRow();
eventRow.setUid(rowSet.getString("psi_uid"));
eventRow.setEvent(IdSchemes.getValue(rowSet.getString("psi_uid"), rowSet.getString("psi_code"), idSchemes.getProgramStageInstanceIdScheme()));
eventRow.setTrackedEntityInstance(rowSet.getString("tei_uid"));
eventRow.setTrackedEntityInstanceOrgUnit(rowSet.getString("tei_ou"));
eventRow.setTrackedEntityInstanceOrgUnitName(rowSet.getString("tei_ou_name"));
eventRow.setTrackedEntityInstanceCreated(rowSet.getString("tei_created"));
eventRow.setTrackedEntityInstanceInactive(rowSet.getBoolean("tei_inactive"));
eventRow.setDeleted(rowSet.getBoolean("psi_deleted"));
eventRow.setProgram(IdSchemes.getValue(rowSet.getString("p_uid"), rowSet.getString("p_code"), idSchemes.getProgramIdScheme()));
eventRow.setProgramStage(IdSchemes.getValue(rowSet.getString("ps_uid"), rowSet.getString("ps_code"), idSchemes.getProgramStageIdScheme()));
eventRow.setOrgUnit(IdSchemes.getValue(rowSet.getString("ou_uid"), rowSet.getString("ou_code"), idSchemes.getOrgUnitIdScheme()));
ProgramType programType = ProgramType.fromValue(rowSet.getString("p_type"));
if (programType == ProgramType.WITHOUT_REGISTRATION) {
eventRow.setEnrollment(rowSet.getString("pi_uid"));
eventRow.setFollowup(rowSet.getBoolean("pi_followup"));
}
eventRow.setTrackedEntityInstance(rowSet.getString("tei_uid"));
eventRow.setOrgUnitName(rowSet.getString("ou_name"));
eventRow.setDueDate(DateUtils.getIso8601NoTz(rowSet.getDate("psi_duedate")));
eventRow.setEventDate(DateUtils.getIso8601NoTz(rowSet.getDate("psi_executiondate")));
eventRows.add(eventRow);
}
if (rowSet.getString("pav_value") != null && rowSet.getString("ta_uid") != null) {
String valueType = rowSet.getString("ta_valuetype");
Attribute attribute = new Attribute();
attribute.setCreated(DateUtils.getIso8601NoTz(rowSet.getDate("pav_created")));
attribute.setLastUpdated(DateUtils.getIso8601NoTz(rowSet.getDate("pav_lastupdated")));
attribute.setValue(rowSet.getString("pav_value"));
attribute.setDisplayName(rowSet.getString("ta_name"));
attribute.setValueType(valueType != null ? ValueType.valueOf(valueType.toUpperCase()) : null);
attribute.setAttribute(rowSet.getString("ta_uid"));
eventRow.getAttributes().add(attribute);
}
if (rowSet.getString("pdv_value") != null && rowSet.getString("de_uid") != null) {
DataValue dataValue = new DataValue();
dataValue.setCreated(DateUtils.getIso8601NoTz(rowSet.getDate("pdv_created")));
dataValue.setLastUpdated(DateUtils.getIso8601NoTz(rowSet.getDate("pdv_lastupdated")));
dataValue.setValue(rowSet.getString("pdv_value"));
dataValue.setProvidedElsewhere(rowSet.getBoolean("pdv_providedelsewhere"));
dataValue.setDataElement(IdSchemes.getValue(rowSet.getString("de_uid"), rowSet.getString("de_code"), idSchemes.getDataElementIdScheme()));
dataValue.setStoredBy(rowSet.getString("pdv_storedby"));
eventRow.getDataValues().add(dataValue);
}
if (rowSet.getString("psinote_value") != null && !notes.contains(rowSet.getString("psinote_id"))) {
Note note = new Note();
note.setValue(rowSet.getString("psinote_value"));
note.setStoredDate(rowSet.getString("psinote_storeddate"));
note.setStoredBy(rowSet.getString("psinote_storedby"));
eventRow.getNotes().add(note);
notes.add(rowSet.getString("psinote_id"));
}
}
return eventRows;
}
use of org.hisp.dhis.dxf2.datavalue.DataValue in project dhis2-core by dhis2.
the class EventAnalyticsServiceTest method parseEventData.
// -------------------------------------------------------------------------
// Internal Logic
// -------------------------------------------------------------------------
private void parseEventData(ArrayList<String[]> lines) {
String storedBy = "johndoe";
for (String[] line : lines) {
Event event = new Event();
event.setProgram(line[0]);
event.setProgramStage(line[1]);
DataValue dataValue = new DataValue();
dataValue.setDataElement(line[2]);
dataValue.setValue(line[6]);
dataValue.setStoredBy(storedBy);
event.setEventDate(line[3]);
event.setOrgUnit(line[4]);
event.setDataValues(Lists.newArrayList(dataValue));
event.setCompletedDate(line[3]);
event.setTrackedEntityInstance(line[5]);
event.setStatus(EventStatus.COMPLETED);
}
}
Aggregations