Search in sources :

Example 21 with Event

use of org.hisp.dhis.tracker.domain.Event 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 22 with Event

use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.

the class StrategyPreProcessor method preProcessEvents.

public void preProcessEvents(TrackerBundle bundle) {
    for (Event event : bundle.getEvents()) {
        TrackerImportStrategy importStrategy = bundle.getImportStrategy();
        ProgramStageInstance existingPsi = bundle.getPreheat().getEvent(TrackerIdScheme.UID, event.getEvent());
        if (importStrategy.isCreateAndUpdate()) {
            if (existingPsi == null) {
                bundle.setStrategy(event, TrackerImportStrategy.CREATE);
            } else {
                bundle.setStrategy(event, TrackerImportStrategy.UPDATE);
            }
        } else {
            bundle.setStrategy(event, importStrategy);
        }
    }
}
Also used : TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) Event(org.hisp.dhis.tracker.domain.Event) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 23 with Event

use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.

the class EventDataValuesValidationHookTest method failsOnActiveEventWithDataElementValueNullAndValidationStrategyOnUpdate.

@Test
void failsOnActiveEventWithDataElementValueNullAndValidationStrategyOnUpdate() {
    setUpIdentifiers();
    DataElement validDataElement = dataElement();
    when(context.getDataElement(dataElementUid)).thenReturn(validDataElement);
    ProgramStage programStage = programStage(validDataElement, true);
    programStage.setValidationStrategy(ValidationStrategy.ON_UPDATE_AND_INSERT);
    when(context.getProgramStage(programStageUid)).thenReturn(programStage);
    ValidationErrorReporter reporter = new ValidationErrorReporter(context);
    DataValue validDataValue = dataValue();
    validDataValue.setValue(null);
    Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.ACTIVE).dataValues(Set.of(validDataValue)).build();
    hook.validateEvent(reporter, event);
    assertThat(reporter.getReportList(), hasSize(1));
    assertEquals(TrackerErrorCode.E1076, reporter.getReportList().get(0).getErrorCode());
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 24 with Event

use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.

the class EventDataValuesValidationHookTest method failsOnCompletedEventWithDataElementValueIsNullAndValidationStrategyOnComplete.

@Test
void failsOnCompletedEventWithDataElementValueIsNullAndValidationStrategyOnComplete() {
    setUpIdentifiers();
    DataElement validDataElement = dataElement();
    when(context.getDataElement(dataElementUid)).thenReturn(validDataElement);
    ProgramStage programStage = programStage(validDataElement, true);
    programStage.setValidationStrategy(ValidationStrategy.ON_COMPLETE);
    when(context.getProgramStage(programStageUid)).thenReturn(programStage);
    ValidationErrorReporter reporter = new ValidationErrorReporter(context);
    DataValue validDataValue = dataValue();
    validDataValue.setValue(null);
    Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.COMPLETED).dataValues(Set.of(validDataValue)).build();
    hook.validateEvent(reporter, event);
    assertThat(reporter.getReportList(), hasSize(1));
    assertEquals(TrackerErrorCode.E1076, reporter.getReportList().get(0).getErrorCode());
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Example 25 with Event

use of org.hisp.dhis.tracker.domain.Event in project dhis2-core by dhis2.

the class EventDataValuesValidationHookTest method failValidationWhenUpdatedAtIsNull.

@Test
void failValidationWhenUpdatedAtIsNull() {
    setUpIdentifiers();
    DataElement dataElement = dataElement();
    when(context.getDataElement(dataElementUid)).thenReturn(dataElement);
    ProgramStage programStage = programStage(dataElement);
    when(context.getProgramStage(programStageUid)).thenReturn(programStage);
    ValidationErrorReporter reporter = new ValidationErrorReporter(context);
    DataValue validDataValue = dataValue();
    validDataValue.setUpdatedAt(null);
    Event event = Event.builder().programStage(programStage.getUid()).status(EventStatus.SKIPPED).dataValues(Set.of(validDataValue)).build();
    hook.validateEvent(reporter, event);
    assertFalse(reporter.hasErrors());
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) ProgramStage(org.hisp.dhis.program.ProgramStage) Test(org.junit.jupiter.api.Test)

Aggregations

Event (org.hisp.dhis.tracker.domain.Event)192 Test (org.junit.jupiter.api.Test)153 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)114 ProgramStage (org.hisp.dhis.program.ProgramStage)68 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)64 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)53 Enrollment (org.hisp.dhis.tracker.domain.Enrollment)43 TrackedEntity (org.hisp.dhis.tracker.domain.TrackedEntity)41 Mockito.when (org.mockito.Mockito.when)38 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)37 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)36 DataElement (org.hisp.dhis.dataelement.DataElement)35 Program (org.hisp.dhis.program.Program)35 ProgramInstance (org.hisp.dhis.program.ProgramInstance)35 DataValue (org.hisp.dhis.tracker.domain.DataValue)35 TrackerPreheat (org.hisp.dhis.tracker.preheat.TrackerPreheat)35 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)34 TrackerErrorCode (org.hisp.dhis.tracker.report.TrackerErrorCode)33 CodeGenerator (org.hisp.dhis.common.CodeGenerator)32 BeforeEach (org.junit.jupiter.api.BeforeEach)32