use of org.hisp.dhis.dxf2.events.enrollment.Enrollment 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.enrollment.Enrollment 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.enrollment.Enrollment 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]"));
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class TrackerRelationshipCriteriaTest method getIdentifierNameThrowsIfAllParamsAreSet.
@Test
void getIdentifierNameThrowsIfAllParamsAreSet() {
TrackerRelationshipCriteria criteria = new TrackerRelationshipCriteria();
criteria.setTrackedEntity("Hq3Kc6HK4OZ");
criteria.setTei("Hq3Kc6HK4OZ");
criteria.setEnrollment("Hq3Kc6HK4OZ");
criteria.setEvent("Hq3Kc6HK4OZ");
WebMessageException exception = assertThrows(WebMessageException.class, criteria::getIdentifierName);
assertEquals(BAD_REQUEST.value(), exception.getWebMessage().getHttpStatusCode());
assertEquals("Only one of parameters 'trackedEntity', 'enrollment' or 'event' is allowed.", exception.getWebMessage().getMessage());
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class TrackerRelationshipCriteriaTest method getIdentifierParamThrowsIfTeiAndEnrollmentAreSet.
@Test
void getIdentifierParamThrowsIfTeiAndEnrollmentAreSet() {
TrackerRelationshipCriteria criteria = new TrackerRelationshipCriteria();
criteria.setTei("Hq3Kc6HK4OZ");
criteria.setEnrollment("Hq3Kc6HK4OZ");
WebMessageException exception = assertThrows(WebMessageException.class, criteria::getIdentifierParam);
assertEquals(BAD_REQUEST.value(), exception.getWebMessage().getHttpStatusCode());
assertEquals("Only one of parameters 'trackedEntity', 'enrollment' or 'event' is allowed.", exception.getWebMessage().getMessage());
}
Aggregations