use of org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams in project dhis2-core by dhis2.
the class AbstractEnrollmentService method getEnrollment.
@Override
public Enrollment getEnrollment(ProgramInstance programInstance, TrackedEntityInstanceParams params) {
Enrollment enrollment = new Enrollment();
enrollment.setEnrollment(programInstance.getUid());
if (programInstance.getEntityInstance() != null) {
enrollment.setTrackedEntity(programInstance.getEntityInstance().getTrackedEntity().getUid());
enrollment.setTrackedEntityInstance(programInstance.getEntityInstance().getUid());
}
if (programInstance.getOrganisationUnit() != null) {
enrollment.setOrgUnit(programInstance.getOrganisationUnit().getUid());
enrollment.setOrgUnitName(programInstance.getOrganisationUnit().getName());
}
if (programInstance.getProgram().getCaptureCoordinates()) {
Coordinate coordinate = null;
if (programInstance.getLongitude() != null && programInstance.getLatitude() != null) {
coordinate = new Coordinate(programInstance.getLongitude(), programInstance.getLatitude());
try {
List<Double> list = OBJECT_MAPPER.readValue(coordinate.getCoordinateString(), new TypeReference<List<Double>>() {
});
coordinate.setLongitude(list.get(0));
coordinate.setLatitude(list.get(1));
} catch (IOException ignored) {
}
}
if (coordinate != null && coordinate.isValid()) {
enrollment.setCoordinate(coordinate);
}
}
enrollment.setCreated(DateUtils.getIso8601NoTz(programInstance.getCreated()));
enrollment.setCreatedAtClient(DateUtils.getIso8601NoTz(programInstance.getCreatedAtClient()));
enrollment.setLastUpdated(DateUtils.getIso8601NoTz(programInstance.getLastUpdated()));
enrollment.setLastUpdatedAtClient(DateUtils.getIso8601NoTz(programInstance.getLastUpdatedAtClient()));
enrollment.setProgram(programInstance.getProgram().getUid());
enrollment.setStatus(EnrollmentStatus.fromProgramStatus(programInstance.getStatus()));
enrollment.setEnrollmentDate(programInstance.getEnrollmentDate());
enrollment.setIncidentDate(programInstance.getIncidentDate());
enrollment.setFollowup(programInstance.getFollowup());
enrollment.setCompletedDate(programInstance.getEndDate());
enrollment.setCompletedBy(programInstance.getCompletedBy());
List<TrackedEntityComment> comments = programInstance.getComments();
for (TrackedEntityComment comment : comments) {
Note note = new Note();
note.setValue(comment.getCommentText());
note.setStoredBy(comment.getCreator());
if (comment.getCreatedDate() != null) {
note.setStoredDate(comment.getCreatedDate().toString());
}
enrollment.getNotes().add(note);
}
if (params.isIncludeEvents()) {
for (ProgramStageInstance programStageInstance : programInstance.getProgramStageInstances()) {
enrollment.getEvents().add(eventService.getEvent(programStageInstance));
}
}
return enrollment;
}
use of org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams in project dhis2-core by dhis2.
the class AbstractRelationshipService method includeRelationshipItem.
private org.hisp.dhis.dxf2.events.trackedentity.RelationshipItem includeRelationshipItem(RelationshipItem dao, boolean uidOnly) {
TrackedEntityInstanceParams teiParams = TrackedEntityInstanceParams.FALSE;
org.hisp.dhis.dxf2.events.trackedentity.RelationshipItem relationshipItem = new org.hisp.dhis.dxf2.events.trackedentity.RelationshipItem();
if (dao.getTrackedEntityInstance() != null) {
org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance tei = new org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance();
String uid = dao.getTrackedEntityInstance().getUid();
if (uidOnly) {
tei.clear();
tei.setTrackedEntityInstance(uid);
} else {
tei = trackedEntityInstanceService.getTrackedEntityInstance(dao.getTrackedEntityInstance(), teiParams);
}
relationshipItem.setTrackedEntityInstance(tei);
} else if (dao.getProgramInstance() != null) {
Enrollment enrollment = new Enrollment();
String uid = dao.getProgramInstance().getUid();
if (uidOnly) {
enrollment.clear();
enrollment.setEnrollment(uid);
} else {
enrollment = enrollmentService.getEnrollment(dao.getProgramInstance(), teiParams);
}
relationshipItem.setEnrollment(enrollment);
} else if (dao.getProgramStageInstance() != null) {
Event event = new Event();
String uid = dao.getProgramStageInstance().getUid();
if (uidOnly) {
event.clear();
event.setEvent(uid);
} else {
event = eventService.getEvent(dao.getProgramStageInstance());
event.setRelationships(null);
}
relationshipItem.setEvent(event);
}
return relationshipItem;
}
use of org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams in project dhis2-core by dhis2.
the class TrackedEntityInstanceAggregateTest method testFetchTrackedEntityInstancesWithEvents.
@Test
void testFetchTrackedEntityInstancesWithEvents() {
doInTransaction(() -> {
this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
});
TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
queryParams.setTrackedEntityType(trackedEntityTypeA);
queryParams.setIncludeAllAttributes(true);
TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
params.setIncludeEnrollments(true);
params.setIncludeEvents(true);
final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(trackedEntityInstances, hasSize(4));
assertThat(trackedEntityInstances.get(0).getEnrollments(), hasSize(1));
assertThat(trackedEntityInstances.get(1).getEnrollments(), hasSize(1));
assertThat(trackedEntityInstances.get(2).getEnrollments(), hasSize(1));
assertThat(trackedEntityInstances.get(3).getEnrollments(), hasSize(1));
assertThat(trackedEntityInstances.get(0).getEnrollments().get(0).getEvents(), hasSize(5));
assertThat(trackedEntityInstances.get(1).getEnrollments().get(0).getEvents(), hasSize(5));
assertThat(trackedEntityInstances.get(2).getEnrollments().get(0).getEvents(), hasSize(5));
assertThat(trackedEntityInstances.get(3).getEnrollments().get(0).getEvents(), hasSize(5));
}
use of org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams in project dhis2-core by dhis2.
the class TrackedEntityInstanceAggregateTest method testFetchTrackedEntityInstancesWithoutEvents.
@Test
void testFetchTrackedEntityInstancesWithoutEvents() {
doInTransaction(() -> {
this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
});
TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
queryParams.setTrackedEntityType(trackedEntityTypeA);
queryParams.setIncludeAllAttributes(true);
TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
params.setIncludeEnrollments(true);
params.setIncludeEvents(false);
final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(trackedEntityInstances, hasSize(4));
assertThat(trackedEntityInstances.get(0).getEnrollments(), hasSize(1));
assertThat(trackedEntityInstances.get(1).getEnrollments(), hasSize(1));
assertThat(trackedEntityInstances.get(2).getEnrollments(), hasSize(1));
assertThat(trackedEntityInstances.get(3).getEnrollments(), hasSize(1));
assertThat(trackedEntityInstances.get(0).getEnrollments().get(0).getEvents(), hasSize(0));
assertThat(trackedEntityInstances.get(1).getEnrollments().get(0).getEvents(), hasSize(0));
assertThat(trackedEntityInstances.get(2).getEnrollments().get(0).getEvents(), hasSize(0));
assertThat(trackedEntityInstances.get(3).getEnrollments().get(0).getEvents(), hasSize(0));
}
use of org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams in project dhis2-core by dhis2.
the class TrackedEntityInstanceAggregateTest method testFetchTrackedEntityInstancesWithoutEnrollments.
@Test
void testFetchTrackedEntityInstancesWithoutEnrollments() {
doInTransaction(() -> {
this.persistTrackedEntityInstanceWithEnrollment();
this.persistTrackedEntityInstanceWithEnrollment();
this.persistTrackedEntityInstanceWithEnrollment();
this.persistTrackedEntityInstanceWithEnrollment();
});
TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
queryParams.setTrackedEntityType(trackedEntityTypeA);
queryParams.setIncludeAllAttributes(true);
TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
params.setIncludeEnrollments(false);
final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(trackedEntityInstances, hasSize(4));
assertThat(trackedEntityInstances.get(0).getEnrollments(), hasSize(0));
assertThat(trackedEntityInstances.get(1).getEnrollments(), hasSize(0));
assertThat(trackedEntityInstances.get(2).getEnrollments(), hasSize(0));
assertThat(trackedEntityInstances.get(3).getEnrollments(), hasSize(0));
}
Aggregations