use of org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams in project dhis2-core by dhis2.
the class TrackedEntityInstanceAggregateTest method testTrackedEntityInstanceMapping.
@Test
void testTrackedEntityInstanceMapping() {
final Date currentTime = new Date();
doInTransaction(this::persistTrackedEntityInstanceWithEnrollmentAndEvents);
TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
queryParams.setTrackedEntityType(trackedEntityTypeA);
queryParams.setIncludeAllAttributes(true);
TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
params.setIncludeEnrollments(false);
params.setIncludeEvents(false);
final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
TrackedEntityInstance trackedEntityInstance = trackedEntityInstances.get(0);
assertThat(trackedEntityInstance.getTrackedEntityType(), is(trackedEntityTypeA.getUid()));
assertTrue(CodeGenerator.isValidUid(trackedEntityInstance.getTrackedEntityInstance()));
assertThat(trackedEntityInstance.getOrgUnit(), is(organisationUnitA.getUid()));
assertThat(trackedEntityInstance.isInactive(), is(false));
assertThat(trackedEntityInstance.isDeleted(), is(false));
assertThat(trackedEntityInstance.getFeatureType(), is(FeatureType.NONE));
// Dates
checkDate(currentTime, trackedEntityInstance.getCreated(), 50L);
checkDate(currentTime, trackedEntityInstance.getCreatedAtClient(), 50L);
checkDate(currentTime, trackedEntityInstance.getLastUpdatedAtClient(), 50L);
checkDate(currentTime, trackedEntityInstance.getLastUpdated(), 300L);
// get stored by is always null
assertThat(trackedEntityInstance.getStoredBy(), is(nullValue()));
}
use of org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams in project dhis2-core by dhis2.
the class TrackedEntityInstanceAggregateTest method testIncludeDeletedIsPropagetedFromTeiToEnrollmentsAndEvents.
@Test
void testIncludeDeletedIsPropagetedFromTeiToEnrollmentsAndEvents() {
TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
queryParams.setTrackedEntityType(trackedEntityTypeA);
queryParams.setIncludeDeleted(true);
TrackedEntityInstanceParams params = TrackedEntityInstanceParams.TRUE;
doInTransaction(() -> {
this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
});
List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(trackedEntityInstances, hasSize(4));
assertThat(trackedEntityInstances.get(0).getEnrollments(), hasSize(1));
assertFalse(trackedEntityInstances.get(0).getEnrollments().get(0).isDeleted());
assertThat(trackedEntityInstances.get(1).getEnrollments().get(0).getEvents(), hasSize(5));
assertFalse(trackedEntityInstances.get(1).getEnrollments().get(0).getEvents().stream().anyMatch(Event::isDeleted));
this.deleteOneEnrollment(trackedEntityInstances.get(0));
this.deleteOneEvent(trackedEntityInstances.get(1).getEnrollments().get(0));
trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(trackedEntityInstances, hasSize(4));
assertThat(trackedEntityInstances.get(0).getEnrollments(), hasSize(1));
assertTrue(trackedEntityInstances.get(0).getEnrollments().get(0).isDeleted());
assertThat(trackedEntityInstances.get(1).getEnrollments().get(0).getEvents(), hasSize(5));
assertTrue(trackedEntityInstances.get(1).getEnrollments().get(0).getEvents().stream().anyMatch(Event::isDeleted));
queryParams.setIncludeDeleted(false);
trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(trackedEntityInstances, hasSize(4));
assertThat(trackedEntityInstances.get(0).getEnrollments(), hasSize(0));
assertThat(trackedEntityInstances.get(1).getEnrollments().get(0).getEvents(), hasSize(4));
assertFalse(trackedEntityInstances.get(1).getEnrollments().get(0).getEvents().stream().anyMatch(Event::isDeleted));
}
use of org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams in project dhis2-core by dhis2.
the class TrackedEntityInstanceAggregateTest method testEnrollmentMapping.
@Test
void testEnrollmentMapping() {
final Date currentTime = new Date();
doInTransaction(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);
Enrollment enrollment = trackedEntityInstances.get(0).getEnrollments().get(0);
assertThat("Tracked Entity Type does not match", enrollment.getTrackedEntityType(), is(trackedEntityTypeA.getUid()));
assertThat("Tracked Entity Instance UID does not match", enrollment.getTrackedEntityInstance(), is(trackedEntityInstances.get(0).getTrackedEntityInstance()));
assertThat("Org Unit UID does not match", enrollment.getOrgUnit(), is(organisationUnitA.getUid()));
assertThat("Org Unit Name does not match", enrollment.getOrgUnitName(), is(organisationUnitA.getName()));
assertTrue(CodeGenerator.isValidUid(enrollment.getEnrollment()));
assertThat(enrollment.getProgram(), is(programA.getUid()));
assertThat(enrollment.getStatus(), is(EnrollmentStatus.COMPLETED));
assertThat(enrollment.isDeleted(), is(false));
assertThat(enrollment.getStoredBy(), is("system-process"));
assertThat(enrollment.getFollowup(), is(nullValue()));
// Dates
checkDate(currentTime, enrollment.getCreated(), 200L);
checkDate(currentTime, enrollment.getCreatedAtClient(), 200L);
checkDate(currentTime, enrollment.getLastUpdatedAtClient(), 200L);
checkDate(currentTime, enrollment.getLastUpdated(), 300L);
checkDate(currentTime, enrollment.getEnrollmentDate(), 300L);
checkDate(currentTime, enrollment.getIncidentDate(), 300L);
checkDate(currentTime, enrollment.getCompletedDate(), 200L);
assertThat(enrollment.getCompletedBy(), is("hello-world"));
// The Enrollment ID is not serialized to JSON
assertThat(enrollment.getId(), is(notNullValue()));
}
use of org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams in project dhis2-core by dhis2.
the class TrackedEntityInstanceAggregateTest method testTrackedEntityInstanceRelationshipsTei2Enrollment.
@Test
void testTrackedEntityInstanceRelationshipsTei2Enrollment() {
final String[] relationshipItemsUid = new String[2];
doInTransaction(() -> {
org.hisp.dhis.trackedentity.TrackedEntityInstance t1 = this.persistTrackedEntityInstance();
org.hisp.dhis.trackedentity.TrackedEntityInstance t2 = this.persistTrackedEntityInstanceWithEnrollment();
ProgramInstance pi = t2.getProgramInstances().iterator().next();
this.persistRelationship(t1, pi);
relationshipItemsUid[0] = t1.getUid();
relationshipItemsUid[1] = pi.getUid();
});
TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
queryParams.setTrackedEntityType(trackedEntityTypeA);
queryParams.setIncludeAllAttributes(true);
TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
params.setIncludeRelationships(true);
final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
// Fetch the TEI which is the vertex of the relationship TEI <-->
// ENROLLMENT
Optional<TrackedEntityInstance> trackedEntityInstance = trackedEntityInstances.stream().filter(t -> t.getTrackedEntityInstance().equals(relationshipItemsUid[0])).findFirst();
if (trackedEntityInstance.isPresent()) {
assertThat(trackedEntityInstance.get().getRelationships(), hasSize(1));
final Relationship relationship = trackedEntityInstance.get().getRelationships().get(0);
assertThat(relationship.getFrom().getTrackedEntityInstance().getTrackedEntityInstance(), is(relationshipItemsUid[0]));
assertThat(relationship.getTo().getEnrollment().getEnrollment(), is(relationshipItemsUid[1]));
} else {
fail();
}
}
use of org.hisp.dhis.dxf2.events.TrackedEntityInstanceParams in project dhis2-core by dhis2.
the class TrackedEntityInstanceAggregateTest method testEventMapping.
@Test
void testEventMapping() {
final Date currentTime = new Date();
doInTransaction(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);
TrackedEntityInstance tei = trackedEntityInstances.get(0);
Enrollment enrollment = tei.getEnrollments().get(0);
Event event = enrollment.getEvents().get(0);
assertNotNull(event);
// The id is not serialized to JSON
assertThat(event.getId(), is(notNullValue()));
assertThat(event.getUid(), is(nullValue()));
assertTrue(CodeGenerator.isValidUid(event.getEvent()));
assertThat(event.getStatus(), is(EventStatus.COMPLETED));
assertThat(event.getProgram(), is(programA.getUid()));
assertThat(event.getProgramStage(), is(programStageA1.getUid()));
assertThat(event.getEnrollment(), is(enrollment.getEnrollment()));
assertThat(event.getEnrollmentStatus(), is(enrollment.getStatus()));
assertThat(event.getOrgUnit(), is(organisationUnitA.getUid()));
assertThat(event.getOrgUnitName(), is(organisationUnitA.getName()));
assertThat(event.getTrackedEntityInstance(), is(tei.getTrackedEntityInstance()));
assertThat(event.getAttributeOptionCombo(), is(DEF_COC_UID));
assertThat(event.isDeleted(), is(false));
assertThat(event.getStoredBy(), is("[Unknown]"));
assertThat(event.getFollowup(), is(nullValue()));
// Dates
checkDate(currentTime, event.getCreated(), 500L);
checkDate(currentTime, event.getLastUpdated(), 500L);
assertThat(event.getEventDate(), is(notNullValue()));
checkDate(currentTime, event.getDueDate(), 500L);
checkDate(currentTime, event.getCreatedAtClient(), 500L);
checkDate(currentTime, event.getLastUpdatedAtClient(), 500L);
checkDate(currentTime, event.getCompletedDate(), 500L);
assertThat(event.getCompletedBy(), is("[Unknown]"));
}
Aggregations