use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class EventImportTest method testAddEventOnProgramWithRegistration.
@Test
void testAddEventOnProgramWithRegistration() throws IOException, ParseException {
String lastupdateDateBefore = trackedEntityInstanceService.getTrackedEntityInstance(trackedEntityInstanceMaleA.getTrackedEntityInstance()).getLastUpdated();
Enrollment enrollment = createEnrollment(programA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
ImportSummary importSummary = enrollmentService.addEnrollment(enrollment, null, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
InputStream is = createEventJsonInputStream(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance(), dataElementA, "10");
ImportSummaries importSummaries = eventService.addEventsJson(is, null);
assertEquals(ImportStatus.SUCCESS, importSummaries.getStatus());
cleanSession();
assertTrue(simpleDateFormat.parse(trackedEntityInstanceService.getTrackedEntityInstance(trackedEntityInstanceMaleA.getTrackedEntityInstance()).getLastUpdated()).getTime() > simpleDateFormat.parse(lastupdateDateBefore).getTime());
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class EventImportTest method createEnrollment.
private Enrollment createEnrollment(String program, String person) {
Enrollment enrollment = new Enrollment();
enrollment.setOrgUnit(organisationUnitA.getUid());
enrollment.setProgram(program);
enrollment.setTrackedEntityInstance(person);
enrollment.setEnrollmentDate(new Date());
enrollment.setIncidentDate(new Date());
return enrollment;
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment in project dhis2-core by dhis2.
the class RegistrationSingleEventServiceTest method testDeleteEventShouldReturnReference.
@Test
@Disabled("luciano -> re-enable after delete has been implemented")
void testDeleteEventShouldReturnReference() {
Enrollment enrollment = createEnrollment(programA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
ImportSummary importSummary = enrollmentService.addEnrollment(enrollment, null, null);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid(), trackedEntityInstanceMaleA.getTrackedEntityInstance());
importSummary = eventService.addEvent(event, null, false);
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
TrackedEntityInstance tei = trackedEntityInstanceService.getTrackedEntityInstance(maleA.getUid());
importSummary = eventService.deleteEvent(tei.getEnrollments().get(0).getEvents().get(0).getEvent());
assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
assertNotNull(importSummary.getReference());
assertEquals(tei.getEnrollments().get(0).getEvents().get(0).getEvent(), importSummary.getReference());
}
use of org.hisp.dhis.dxf2.events.enrollment.Enrollment 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.enrollment.Enrollment 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));
}
Aggregations