use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackedEntityInstanceAggregateTest method testTrackedEntityInstanceRelationshipsTei2Event.
@Test
void testTrackedEntityInstanceRelationshipsTei2Event() {
final String[] relationshipItemsUid = new String[2];
doInTransaction(() -> {
org.hisp.dhis.trackedentity.TrackedEntityInstance t1 = this.persistTrackedEntityInstance();
org.hisp.dhis.trackedentity.TrackedEntityInstance t2 = this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
sessionFactory.getCurrentSession().flush();
sessionFactory.getCurrentSession().clear();
t2 = manager.getByUid(org.hisp.dhis.trackedentity.TrackedEntityInstance.class, Collections.singletonList(t2.getUid())).get(0);
ProgramInstance pi = t2.getProgramInstances().iterator().next();
final ProgramStageInstance psi = pi.getProgramStageInstances().iterator().next();
this.persistRelationship(t1, psi);
relationshipItemsUid[0] = t1.getUid();
relationshipItemsUid[1] = psi.getUid();
});
TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
queryParams.setTrackedEntityType(trackedEntityTypeA);
queryParams.setIncludeAllAttributes(true);
TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
params.setIncludeRelationships(true);
params.setIncludeEnrollments(true);
params.setIncludeEvents(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().getEvent().getEvent(), is(relationshipItemsUid[1]));
} else {
fail();
}
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackedEntityInstanceAggregateTest method testFetchTrackedEntityInstancesWithExplicitUid.
@Test
void testFetchTrackedEntityInstancesWithExplicitUid() {
final String[] teiUid = new String[2];
doInTransaction(() -> {
org.hisp.dhis.trackedentity.TrackedEntityInstance t1 = this.persistTrackedEntityInstance();
org.hisp.dhis.trackedentity.TrackedEntityInstance t2 = this.persistTrackedEntityInstance();
teiUid[0] = t1.getUid();
teiUid[1] = t2.getUid();
});
TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
queryParams.getTrackedEntityInstanceUids().add(teiUid[0]);
TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(trackedEntityInstances, hasSize(1));
assertThat(trackedEntityInstances.get(0).getTrackedEntityInstance(), is(teiUid[0]));
// Query 2 tei uid explicitly
queryParams.getTrackedEntityInstanceUids().add(teiUid[1]);
final List<TrackedEntityInstance> multiTrackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(multiTrackedEntityInstances, hasSize(2));
Set<String> teis = multiTrackedEntityInstances.stream().map(t -> t.getTrackedEntityInstance()).collect(Collectors.toSet());
assertTrue(teis.contains(teiUid[0]));
assertTrue(teis.contains(teiUid[1]));
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackedEntityInstanceAggregateTest method testFetchTrackedEntityInstancesWithLastUpdatedParameter.
@Test
void testFetchTrackedEntityInstancesWithLastUpdatedParameter() {
doInTransaction(() -> {
this.persistTrackedEntityInstance();
this.persistTrackedEntityInstance();
this.persistTrackedEntityInstance();
this.persistTrackedEntityInstance();
});
TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
queryParams.setTrackedEntityType(trackedEntityTypeA);
queryParams.setLastUpdatedStartDate(Date.from(Instant.now().minus(1, ChronoUnit.DAYS)));
queryParams.setLastUpdatedEndDate(new Date());
TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(trackedEntityInstances, hasSize(4));
assertThat(trackedEntityInstances.get(0).getEnrollments(), hasSize(0));
// Update last updated start date to today
queryParams.setLastUpdatedStartDate(Date.from(Instant.now().plus(1, ChronoUnit.DAYS)));
final List<TrackedEntityInstance> limitedTTrackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(limitedTTrackedEntityInstances, hasSize(0));
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackedEntityInstanceAggregateTest method testEnrollmentFollowup.
@Test
void testEnrollmentFollowup() {
Map<String, Object> enrollmentValues = new HashMap<>();
enrollmentValues.put("followup", Boolean.TRUE);
doInTransaction(() -> this.persistTrackedEntityInstanceWithEnrollmentAndEvents(enrollmentValues));
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);
assertThat(enrollment.getFollowup(), is(true));
assertThat(event.getFollowup(), is(true));
}
use of org.hisp.dhis.dxf2.events.trackedentity.TrackedEntityInstance in project dhis2-core by dhis2.
the class TrackedEntityInstanceAggregateTest method testFetchTrackedEntityInstancesWithEventFilters.
@Test
void testFetchTrackedEntityInstancesWithEventFilters() {
doInTransaction(() -> {
this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
this.persistTrackedEntityInstanceWithEnrollmentAndEvents();
});
TrackedEntityInstanceQueryParams queryParams = new TrackedEntityInstanceQueryParams();
queryParams.setOrganisationUnits(Sets.newHashSet(organisationUnitA));
queryParams.setProgram(programA);
queryParams.setEventStatus(EventStatus.COMPLETED);
queryParams.setEventStartDate(Date.from(Instant.now().minus(10, ChronoUnit.DAYS)));
queryParams.setEventEndDate(Date.from(Instant.now().plus(10, ChronoUnit.DAYS)));
TrackedEntityInstanceParams params = new TrackedEntityInstanceParams();
final List<TrackedEntityInstance> trackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(trackedEntityInstances, hasSize(4));
// Update status to active
queryParams.setEventStatus(EventStatus.ACTIVE);
final List<TrackedEntityInstance> limitedTrackedEntityInstances = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(limitedTrackedEntityInstances, hasSize(0));
// Update status to overdue
queryParams.setEventStatus(EventStatus.OVERDUE);
final List<TrackedEntityInstance> limitedTrackedEntityInstances2 = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(limitedTrackedEntityInstances2, hasSize(0));
// Update status to schedule
queryParams.setEventStatus(EventStatus.SCHEDULE);
final List<TrackedEntityInstance> limitedTrackedEntityInstances3 = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(limitedTrackedEntityInstances3, hasSize(0));
// Update status to schedule
queryParams.setEventStatus(EventStatus.SKIPPED);
final List<TrackedEntityInstance> limitedTrackedEntityInstances4 = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(limitedTrackedEntityInstances4, hasSize(0));
// Update status to visited
queryParams.setEventStatus(EventStatus.VISITED);
final List<TrackedEntityInstance> limitedTrackedEntityInstances5 = trackedEntityInstanceService.getTrackedEntityInstances(queryParams, params, false, true);
assertThat(limitedTrackedEntityInstances5, hasSize(0));
}
Aggregations