Search in sources :

Example 11 with TrackerBundle

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());
}
Also used : Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Event(org.hisp.dhis.tracker.domain.Event) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 12 with TrackerBundle

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");
}
Also used : Program(org.hisp.dhis.program.Program) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Event(org.hisp.dhis.tracker.domain.Event) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerPreheat(org.hisp.dhis.tracker.preheat.TrackerPreheat) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 13 with TrackerBundle

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;
}
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 TrackerBundle

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;
}
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 TrackerBundle

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);
}
Also used : TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ProgramStage(org.hisp.dhis.program.ProgramStage) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)74 Test (org.junit.jupiter.api.Test)43 Event (org.hisp.dhis.tracker.domain.Event)29 User (org.hisp.dhis.user.User)21 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)19 List (java.util.List)17 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)15 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)14 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)14 Mockito.mock (org.mockito.Mockito.mock)14 TrackerErrorCode (org.hisp.dhis.tracker.report.TrackerErrorCode)13 TrackerImportStrategy (org.hisp.dhis.tracker.TrackerImportStrategy)12 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)12 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)12 Collections (java.util.Collections)11 ProgramStage (org.hisp.dhis.program.ProgramStage)11 Objects (java.util.Objects)10 Program (org.hisp.dhis.program.Program)10 ValidationMode (org.hisp.dhis.tracker.ValidationMode)10 Relationship (org.hisp.dhis.tracker.domain.Relationship)10