Search in sources :

Example 6 with GEOMETRY

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.GEOMETRY in project dhis2-core by dhis2.

the class EventGeometryCheck method check.

@Override
public ImportSummary check(ImmutableEvent event, WorkContext ctx) {
    IdScheme scheme = ctx.getImportOptions().getIdSchemes().getProgramStageIdScheme();
    ProgramStage programStage = ctx.getProgramStage(scheme, event.getProgramStage());
    if (Objects.nonNull(event.getGeometry()) && programStageFeatureCompatibleWithEventGeometry(event, programStage)) {
        return new ImportSummary(ImportStatus.ERROR, "Geometry (" + event.getGeometry().getGeometryType() + ") does not conform to the feature type (" + programStage.getFeatureType().value() + ") specified for the program stage: " + programStage.getUid()).setReference(event.getEvent()).incrementIgnored();
    }
    return success();
}
Also used : ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) IdScheme(org.hisp.dhis.common.IdScheme) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 7 with GEOMETRY

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.GEOMETRY in project dhis2-core by dhis2.

the class EnrollmentRowCallbackHandler method getEnrollment.

private Enrollment getEnrollment(ResultSet rs) throws SQLException {
    Enrollment enrollment = new Enrollment();
    enrollment.setEnrollment(rs.getString(getColumnName(UID)));
    MapperGeoUtils.resolveGeometry(rs.getBytes(getColumnName(GEOMETRY))).ifPresent(enrollment::setGeometry);
    enrollment.setTrackedEntityType(rs.getString(getColumnName(TEI_TYPE_UID)));
    enrollment.setTrackedEntityInstance(rs.getString(getColumnName(TEI_UID)));
    enrollment.setOrgUnit(rs.getString(getColumnName(ORGUNIT_UID)));
    enrollment.setOrgUnitName(rs.getString(getColumnName(ORGUNIT_NAME)));
    enrollment.setCreated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATED))));
    enrollment.setCreatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATEDCLIENT))));
    setUserInfoSnapshot(rs, getColumnName(CREATED_BY), enrollment::setCreatedByUserInfo);
    enrollment.setLastUpdated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATED))));
    enrollment.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATEDCLIENT))));
    setUserInfoSnapshot(rs, getColumnName(LAST_UPDATED_BY), enrollment::setLastUpdatedByUserInfo);
    enrollment.setProgram(rs.getString(getColumnName(PROGRAM_UID)));
    enrollment.setStatus(EnrollmentStatus.fromStatusString(rs.getString(getColumnName(STATUS))));
    enrollment.setEnrollmentDate(rs.getTimestamp(getColumnName(ENROLLMENTDATE)));
    enrollment.setIncidentDate(rs.getTimestamp(getColumnName(INCIDENTDATE)));
    final boolean followup = rs.getBoolean(getColumnName(FOLLOWUP));
    enrollment.setFollowup(rs.wasNull() ? null : followup);
    enrollment.setCompletedDate(rs.getTimestamp(getColumnName(COMPLETED)));
    enrollment.setCompletedBy(rs.getString(getColumnName(COMPLETEDBY)));
    enrollment.setStoredBy(rs.getString(getColumnName(STOREDBY)));
    enrollment.setDeleted(rs.getBoolean(getColumnName(DELETED)));
    enrollment.setId(rs.getLong(getColumnName(ID)));
    return enrollment;
}
Also used : Enrollment(org.hisp.dhis.dxf2.events.enrollment.Enrollment)

Example 8 with GEOMETRY

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.GEOMETRY in project dhis2-core by dhis2.

the class TrackedEntityInstanceRowCallbackHandler method getTei.

private TrackedEntityInstance getTei(ResultSet rs) throws SQLException {
    TrackedEntityInstance tei = new TrackedEntityInstance();
    tei.setTrackedEntityInstance(rs.getString(getColumnName(UID)));
    tei.setOrgUnit(rs.getString(getColumnName(ORGUNIT_UID)));
    tei.setTrackedEntityType(rs.getString(getColumnName(TYPE_UID)));
    tei.setCreated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATED))));
    tei.setCreatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(CREATEDCLIENT))));
    setUserInfoSnapshot(rs, getColumnName(CREATED_BY), tei::setCreatedByUserInfo);
    tei.setLastUpdated(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATED))));
    tei.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(rs.getTimestamp(getColumnName(UPDATEDCLIENT))));
    setUserInfoSnapshot(rs, getColumnName(LAST_UPDATED_BY), tei::setLastUpdatedByUserInfo);
    tei.setInactive(rs.getBoolean(getColumnName(INACTIVE)));
    tei.setDeleted(rs.getBoolean(getColumnName(DELETED)));
    Optional<Geometry> geo = MapperGeoUtils.resolveGeometry(rs.getBytes(getColumnName(GEOMETRY)));
    if (geo.isPresent()) {
        tei.setGeometry(geo.get());
        tei.setFeatureType(FeatureType.getTypeFromName(geo.get().getGeometryType()));
        tei.setCoordinates(GeoUtils.getCoordinatesFromGeometry(geo.get()));
    }
    return tei;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) TrackedEntityInstance(org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance)

Aggregations

ProgramStage (org.hisp.dhis.program.ProgramStage)3 IOException (java.io.IOException)2 Date (java.util.Date)2 IdScheme (org.hisp.dhis.common.IdScheme)2 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)2 Geometry (org.locationtech.jts.geom.Geometry)2 CsvReader (com.csvreader.CsvReader)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 Joiner (com.google.common.base.Joiner)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Lists (com.google.common.collect.Lists)1 Multimap (com.google.common.collect.Multimap)1 Gson (com.google.gson.Gson)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Timestamp (java.sql.Timestamp)1