Search in sources :

Example 16 with DataValue

use of org.hisp.dhis.dxf2.events.event.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());
}
Also used : DataValue(org.hisp.dhis.datavalue.DataValue) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) ClassPathResource(org.springframework.core.io.ClassPathResource) ImportOptions(org.hisp.dhis.dxf2.common.ImportOptions) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 17 with DataValue

use of org.hisp.dhis.dxf2.events.event.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);
}
Also used : DataValue(org.hisp.dhis.dxf2.events.event.DataValue) ArrayList(java.util.ArrayList) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) Event(org.hisp.dhis.dxf2.events.event.Event)

Example 18 with DataValue

use of org.hisp.dhis.dxf2.events.event.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;
}
Also used : Events(org.hisp.dhis.dxf2.events.event.Events) Coordinate(org.hisp.dhis.dxf2.events.event.Coordinate) DataValue(org.hisp.dhis.dxf2.events.event.DataValue) Event(org.hisp.dhis.dxf2.events.event.Event) ObjectReader(com.fasterxml.jackson.databind.ObjectReader)

Example 19 with DataValue

use of org.hisp.dhis.dxf2.events.event.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;
}
Also used : SqlRowSet(org.springframework.jdbc.support.rowset.SqlRowSet) IdSchemes(org.hisp.dhis.common.IdSchemes) Attribute(org.hisp.dhis.dxf2.events.trackedentity.Attribute) ArrayList(java.util.ArrayList) DateUtils.getMediumDateString(org.hisp.dhis.system.util.DateUtils.getMediumDateString) ProgramType(org.hisp.dhis.program.ProgramType) EventRow(org.hisp.dhis.dxf2.events.report.EventRow) HashSet(java.util.HashSet)

Example 20 with DataValue

use of org.hisp.dhis.dxf2.events.event.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);
    }
}
Also used : DataValue(org.hisp.dhis.dxf2.events.event.DataValue) Event(org.hisp.dhis.dxf2.events.event.Event)

Aggregations

DataValue (org.hisp.dhis.datavalue.DataValue)22 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)20 DhisSpringTest (org.hisp.dhis.DhisSpringTest)17 Test (org.junit.Test)17 ClassPathResource (org.springframework.core.io.ClassPathResource)16 DataElement (org.hisp.dhis.dataelement.DataElement)8 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)7 DataValue (org.hisp.dhis.dxf2.events.event.DataValue)7 Event (org.hisp.dhis.dxf2.events.event.Event)7 Period (org.hisp.dhis.period.Period)7 ImportOptions (org.hisp.dhis.dxf2.common.ImportOptions)6 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)6 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 DataValueAudit (org.hisp.dhis.datavalue.DataValueAudit)4 IdScheme (org.hisp.dhis.common.IdScheme)3 IdSchemes (org.hisp.dhis.common.IdSchemes)3 CompleteDataSetRegistration (org.hisp.dhis.dataset.CompleteDataSetRegistration)3