Search in sources :

Example 11 with Enrollment

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());
}
Also used : TrackerImportParams(org.hisp.dhis.tracker.TrackerImportParams) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 12 with Enrollment

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;
}
Also used : Enrollment(org.hisp.dhis.tracker.domain.Enrollment)

Example 13 with 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;
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) EnrollmentTrackerConverterService(org.hisp.dhis.tracker.converter.EnrollmentTrackerConverterService) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Set(java.util.Set) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) TrackerType(org.hisp.dhis.tracker.TrackerType) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Relationship(org.hisp.dhis.tracker.domain.Relationship) TrackerObjectReport(org.hisp.dhis.tracker.report.TrackerObjectReport) Collectors(java.util.stream.Collectors) TrackedEntityInstanceService(org.hisp.dhis.trackedentity.TrackedEntityInstanceService) ProgramStageInstanceService(org.hisp.dhis.program.ProgramStageInstanceService) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) List(java.util.List) Lists(com.google.common.collect.Lists) RelationshipService(org.hisp.dhis.relationship.RelationshipService) Service(org.springframework.stereotype.Service) EventTrackerConverterService(org.hisp.dhis.tracker.converter.EventTrackerConverterService) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ProgramInstanceService(org.hisp.dhis.program.ProgramInstanceService) AllArgsConstructor(lombok.AllArgsConstructor) TrackerTypeReport(org.hisp.dhis.tracker.report.TrackerTypeReport) TrackerTypeReport(org.hisp.dhis.tracker.report.TrackerTypeReport) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) TrackerObjectReport(org.hisp.dhis.tracker.report.TrackerObjectReport) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle)

Example 14 with Enrollment

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;
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) EnrollmentTrackerConverterService(org.hisp.dhis.tracker.converter.EnrollmentTrackerConverterService) TrackedEntity(org.hisp.dhis.tracker.domain.TrackedEntity) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Set(java.util.Set) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) TrackerType(org.hisp.dhis.tracker.TrackerType) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Relationship(org.hisp.dhis.tracker.domain.Relationship) TrackerObjectReport(org.hisp.dhis.tracker.report.TrackerObjectReport) Collectors(java.util.stream.Collectors) TrackedEntityInstanceService(org.hisp.dhis.trackedentity.TrackedEntityInstanceService) ProgramStageInstanceService(org.hisp.dhis.program.ProgramStageInstanceService) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) List(java.util.List) Lists(com.google.common.collect.Lists) RelationshipService(org.hisp.dhis.relationship.RelationshipService) Service(org.springframework.stereotype.Service) EventTrackerConverterService(org.hisp.dhis.tracker.converter.EventTrackerConverterService) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ProgramInstanceService(org.hisp.dhis.program.ProgramInstanceService) AllArgsConstructor(lombok.AllArgsConstructor) TrackerTypeReport(org.hisp.dhis.tracker.report.TrackerTypeReport) TrackerTypeReport(org.hisp.dhis.tracker.report.TrackerTypeReport) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackerObjectReport(org.hisp.dhis.tracker.report.TrackerObjectReport) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) Event(org.hisp.dhis.tracker.domain.Event) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 15 with Enrollment

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);
        }
    }
}
Also used : TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Enrollment(org.hisp.dhis.tracker.domain.Enrollment)

Aggregations

Enrollment (org.hisp.dhis.tracker.domain.Enrollment)88 Test (org.junit.jupiter.api.Test)67 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)53 Event (org.hisp.dhis.tracker.domain.Event)25 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)25 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)24 Program (org.hisp.dhis.program.Program)21 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)19 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)17 List (java.util.List)16 Optional (java.util.Optional)15 ProgramInstance (org.hisp.dhis.program.ProgramInstance)15 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)15 Sets (com.google.common.collect.Sets)14 Collectors (java.util.stream.Collectors)14 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)14 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)14 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)14 BeforeEach (org.junit.jupiter.api.BeforeEach)14 Mockito.when (org.mockito.Mockito.when)14