use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class AbstractTrackedEntityInstanceService method updateTrackedEntityInstances.
// -------------------------------------------------------------------------
// UPDATE
// -------------------------------------------------------------------------
private ImportSummaries updateTrackedEntityInstances(List<TrackedEntityInstance> trackedEntityInstances, ImportOptions importOptions) {
List<List<TrackedEntityInstance>> partitions = Lists.partition(trackedEntityInstances, FLUSH_FREQUENCY);
importOptions = updateImportOptions(importOptions);
ImportSummaries importSummaries = new ImportSummaries();
List<Enrollment> enrollments = new ArrayList<>();
for (List<TrackedEntityInstance> _trackedEntityInstances : partitions) {
reloadUser(importOptions);
prepareCaches(_trackedEntityInstances, importOptions.getUser());
for (TrackedEntityInstance trackedEntityInstance : _trackedEntityInstances) {
ImportSummary importSummary = updateTrackedEntityInstance(trackedEntityInstance, null, importOptions, false, false);
importSummaries.addImportSummary(importSummary);
if (importSummary.isStatus(ImportStatus.SUCCESS)) {
enrollments.addAll(trackedEntityInstance.getEnrollments());
}
}
clearSession();
}
ImportSummaries enrollmentImportSummaries = enrollmentService.addEnrollmentList(enrollments, importOptions);
linkEnrollmentSummaries(importSummaries, enrollmentImportSummaries, enrollments);
return importSummaries;
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class AbstractTrackedEntityInstanceService method addTrackedEntityInstance.
private ImportSummary addTrackedEntityInstance(TrackedEntityInstance dtoEntityInstance, ImportOptions importOptions, boolean handleEnrollments, boolean bulkImport) {
if (!bulkImport && teiService.trackedEntityInstanceExistsIncludingDeleted(dtoEntityInstance.getTrackedEntityInstance())) {
return new ImportSummary(ImportStatus.ERROR, "Tracked entity instance " + dtoEntityInstance.getTrackedEntityInstance() + " already exists or was deleted earlier").setReference(dtoEntityInstance.getTrackedEntityInstance()).incrementIgnored();
}
importOptions = updateImportOptions(importOptions);
dtoEntityInstance.trimValuesToNull();
ImportSummary importSummary = new ImportSummary(dtoEntityInstance.getTrackedEntityInstance());
checkTrackedEntityType(dtoEntityInstance, importOptions, importSummary);
checkAttributes(dtoEntityInstance, importOptions, importSummary, false);
if (importSummary.hasConflicts()) {
importSummary.setStatus(ImportStatus.ERROR);
importSummary.getImportCount().incrementIgnored();
return importSummary;
}
org.hisp.dhis.trackedentity.TrackedEntityInstance daoEntityInstance = createDAOTrackedEntityInstance(dtoEntityInstance, importOptions, importSummary);
if (importSummary.hasConflicts()) {
importSummary.setStatus(ImportStatus.ERROR);
importSummary.getImportCount().incrementIgnored();
return importSummary;
}
if (daoEntityInstance == null) {
return importSummary;
}
List<String> errors = trackerAccessManager.canWrite(importOptions.getUser(), daoEntityInstance);
if (!errors.isEmpty()) {
return new ImportSummary(ImportStatus.ERROR, errors.toString()).incrementIgnored();
}
teiService.addTrackedEntityInstance(daoEntityInstance);
addAttributeValues(dtoEntityInstance, daoEntityInstance, importOptions.getUser());
importSummary.setReference(daoEntityInstance.getUid());
importSummary.getImportCount().incrementImported();
if (handleEnrollments) {
importSummary.setEnrollments(handleEnrollments(dtoEntityInstance, daoEntityInstance, importOptions));
} else {
for (Enrollment enrollment : dtoEntityInstance.getEnrollments()) {
enrollment.setTrackedEntityType(dtoEntityInstance.getTrackedEntityType());
enrollment.setTrackedEntityInstance(daoEntityInstance.getUid());
}
}
return importSummary;
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment 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;
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class RelationshipRowCallbackHandler method createItem.
/**
* The SQL query that generates the ResultSet used by this
* {@see RowCallbackHandler} fetches both sides of a relationship: since
* each side can be a Tracked Entity Instance, a Program Instance or a
* Program Stage Instance, the query adds an "hint" to the final result to
* help this Handler to correctly associate the type to the left or right
* side of the relationship. The "typeWithUid" variable contains the UID of
* the object and a string representing the type. E.g.
*
* tei|dj3382832 psi|332983893
*
* This function parses the string and extract the type and the uid, in
* order to instantiate the appropriate object and assign it to the
* {@see RelationshipItem}
*
* @param typeWithUid a String containing the object type and the UID of the
* object, separated by | (pipe)
* @return a {@see RelationshipItem}
*/
private RelationshipItem createItem(String typeWithUid) {
if (StringUtils.isEmpty(typeWithUid)) {
return new RelationshipItem();
}
RelationshipItem ri = new RelationshipItem();
final String type = typeWithUid.split("\\|")[0];
final String uid = typeWithUid.split("\\|")[1];
switch(type) {
case "tei":
TrackedEntityInstance tei = new TrackedEntityInstance();
tei.clear();
tei.setTrackedEntityInstance(uid);
ri.setTrackedEntityInstance(tei);
break;
case "pi":
Enrollment pi = new Enrollment();
pi.setEnrollment(uid);
ri.setEnrollment(pi);
break;
case "psi":
Event psi = new Event();
psi.setEvent(uid);
ri.setEvent(psi);
break;
default:
log.warn("Expecting tei|psi|pi as type when fetching a relationship, got: " + type);
}
return ri;
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class DefaultEnrollmentStore method getEnrollmentsByTrackedEntityInstanceIdsPartitioned.
private Multimap<String, Enrollment> getEnrollmentsByTrackedEntityInstanceIdsPartitioned(List<Long> ids, AggregateContext ctx) {
EnrollmentRowCallbackHandler handler = new EnrollmentRowCallbackHandler();
jdbcTemplate.query(getQuery(GET_ENROLLMENT_SQL_BY_TEI, ctx, " pi.programid IN (:programIds)", FILTER_OUT_DELETED_ENROLLMENTS), createIdsParam(ids).addValue("programIds", ctx.getPrograms()), handler);
return handler.getItems();
}
Aggregations