use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class EventWithoutRegistrationPreProcessorTest method testEnrollmentIsAddedIntoEventWhenItBelongsToProgramWithoutRegistration.
@Test
void testEnrollmentIsAddedIntoEventWhenItBelongsToProgramWithoutRegistration() {
// Given
Event event = new Event();
event.setProgramStage("programStageUid");
TrackerBundle bundle = TrackerBundle.builder().events(Collections.singletonList(event)).build();
ProgramInstance programInstance = new ProgramInstance();
programInstance.setUid("programInstanceUid");
Program program = new Program();
program.setUid("programUid");
ProgramStage programStage = new ProgramStage();
programStage.setUid("programStageUid");
programStage.setProgram(program);
TrackerPreheat preheat = new TrackerPreheat();
preheat.putProgramInstancesWithoutRegistration("programUid", programInstance);
preheat.put(TrackerIdentifier.UID, programStage);
bundle.setPreheat(preheat);
// When
preProcessorToTest.process(bundle);
// Then
assertEquals("programInstanceUid", bundle.getEvents().get(0).getEnrollment());
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class EventWithoutRegistrationPreProcessorTest method testEnrollmentIsNotAddedIntoEventWhenItProgramStageHasNoReferenceToProgram.
@Test
void testEnrollmentIsNotAddedIntoEventWhenItProgramStageHasNoReferenceToProgram() {
// Given
Event event = new Event();
event.setProgramStage("programStageUid");
TrackerBundle bundle = TrackerBundle.builder().events(Collections.singletonList(event)).build();
ProgramInstance programInstance = new ProgramInstance();
programInstance.setUid("programInstanceUid");
Program program = new Program();
program.setUid("programUid");
ProgramStage programStage = new ProgramStage();
programStage.setUid("programStageUid");
TrackerPreheat preheat = new TrackerPreheat();
preheat.putProgramInstancesWithoutRegistration("programUid", programInstance);
preheat.put(TrackerIdentifier.UID, programStage);
bundle.setPreheat(preheat);
// When
preProcessorToTest.process(bundle);
// Then
assertNull(bundle.getEvents().get(0).getEnrollment(), "programInstanceUid");
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class DefaultTrackerObjectsDeletionService method deleteTrackedEntityInstances.
@Override
public TrackerTypeReport deleteTrackedEntityInstances(TrackerBundle bundle) {
TrackerTypeReport typeReport = new TrackerTypeReport(TrackerType.TRACKED_ENTITY);
List<TrackedEntity> trackedEntities = bundle.getTrackedEntities();
for (int idx = 0; idx < trackedEntities.size(); idx++) {
String uid = trackedEntities.get(idx).getTrackedEntity();
TrackerObjectReport objectReport = new TrackerObjectReport(TrackerType.TRACKED_ENTITY, uid, idx);
org.hisp.dhis.trackedentity.TrackedEntityInstance daoEntityInstance = teiService.getTrackedEntityInstance(uid);
Set<ProgramInstance> programInstances = daoEntityInstance.getProgramInstances();
List<Enrollment> enrollments = enrollmentTrackerConverterService.to(Lists.newArrayList(programInstances.stream().filter(pi -> !pi.isDeleted()).collect(Collectors.toList())));
TrackerBundle trackerBundle = TrackerBundle.builder().enrollments(enrollments).user(bundle.getUser()).build();
deleteEnrollments(trackerBundle);
teiService.deleteTrackedEntityInstance(daoEntityInstance);
typeReport.getStats().incDeleted();
typeReport.addObjectReport(objectReport);
}
return typeReport;
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class DefaultTrackerObjectsDeletionService method deleteEnrollments.
@Override
public TrackerTypeReport deleteEnrollments(TrackerBundle bundle) {
TrackerTypeReport typeReport = new TrackerTypeReport(TrackerType.ENROLLMENT);
List<Enrollment> enrollments = bundle.getEnrollments();
for (int idx = 0; idx < enrollments.size(); idx++) {
String uid = enrollments.get(idx).getEnrollment();
TrackerObjectReport objectReport = new TrackerObjectReport(TrackerType.ENROLLMENT, uid, idx);
ProgramInstance programInstance = programInstanceService.getProgramInstance(uid);
List<Event> events = eventTrackerConverterService.to(Lists.newArrayList(programInstance.getProgramStageInstances().stream().filter(psi -> !psi.isDeleted()).collect(Collectors.toList())));
TrackerBundle trackerBundle = TrackerBundle.builder().events(events).user(bundle.getUser()).build();
deleteEvents(trackerBundle);
TrackedEntityInstance tei = programInstance.getEntityInstance();
tei.getProgramInstances().remove(programInstance);
programInstanceService.deleteProgramInstance(programInstance);
teiService.updateTrackedEntityInstance(tei);
typeReport.getStats().incDeleted();
typeReport.addObjectReport(objectReport);
}
return typeReport;
}
use of org.hisp.dhis.tracker.bundle.TrackerBundle in project dhis2-core by dhis2.
the class EventGeoValidationHookTest method setUp.
@BeforeEach
public void setUp() {
hookToTest = new EventGeoValidationHook();
TrackerBundle bundle = TrackerBundle.builder().build();
when(validationContext.getBundle()).thenReturn(bundle);
ProgramStage programStage = new ProgramStage();
programStage.setFeatureType(FeatureType.POINT);
when(validationContext.getProgramStage(PROGRAM_STAGE)).thenReturn(programStage);
}
Aggregations