use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class TrackerPreheatServiceIntegration method testPreheatWithDifferentIdSchemes.
@Test
@Disabled
void testPreheatWithDifferentIdSchemes() {
TrackedEntity teA = TrackedEntity.builder().orgUnit("OUA").trackedEntityType(TET_UID).build();
Enrollment enrollmentA = Enrollment.builder().orgUnit("OUA").program("PROGRAM1").trackedEntity(TE_UID).build();
TrackerImportParams trackerPreheatParams = TrackerImportParams.builder().trackedEntities(Lists.newArrayList(teA)).enrollments(Lists.newArrayList(enrollmentA)).identifiers(TrackerIdentifierParams.builder().idScheme(TrackerIdentifier.UID).orgUnitIdScheme(TrackerIdentifier.CODE).programIdScheme(TrackerIdentifier.builder().idScheme(TrackerIdScheme.ATTRIBUTE).value(ATTRIBUTE_UID).build()).build()).build();
TrackerPreheat preheat = trackerPreheatService.preheat(trackerPreheatParams);
assertNotNull(preheat);
assertNotNull(preheat.getMap());
}
use of org.hisp.dhis.tracker.domain.Enrollment in project dhis2-core by dhis2.
the class SetMandatoryFieldValidatorTest method getEnrollmentWithMandatoryAttributeNOTSet.
private Enrollment getEnrollmentWithMandatoryAttributeNOTSet() {
Enrollment enrollment = new Enrollment();
enrollment.setEnrollment(COMPLETED_ENROLLMENT_ID);
enrollment.setTrackedEntity(TEI_ID);
enrollment.setStatus(EnrollmentStatus.COMPLETED);
return enrollment;
}
use of org.hisp.dhis.tracker.domain.Enrollment 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.domain.Enrollment 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.domain.Enrollment in project dhis2-core by dhis2.
the class StrategyPreProcessor method preProcessEnrollments.
public void preProcessEnrollments(TrackerBundle bundle) {
for (Enrollment enrollment : bundle.getEnrollments()) {
TrackerImportStrategy importStrategy = bundle.getImportStrategy();
ProgramInstance existingPI = bundle.getPreheat().getEnrollment(TrackerIdScheme.UID, enrollment.getEnrollment());
if (importStrategy.isCreateAndUpdate()) {
if (existingPI == null) {
bundle.setStrategy(enrollment, TrackerImportStrategy.CREATE);
} else {
bundle.setStrategy(enrollment, TrackerImportStrategy.UPDATE);
}
} else {
bundle.setStrategy(enrollment, importStrategy);
}
}
}
Aggregations