Search in sources :

Example 26 with TrackerImportValidationContext

use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.

the class EventNoteValidationHookTest method testNoteWithExistingUidAndNoTextIsIgnored.

@Test
void testNoteWithExistingUidAndNoTextIsIgnored() {
    // Given
    final Note note = rnd.nextObject(Note.class);
    note.setValue(null);
    TrackerBundle trackerBundle = mock(TrackerBundle.class);
    TrackerImportValidationContext ctx = mock(TrackerImportValidationContext.class);
    when(ctx.getBundle()).thenReturn(trackerBundle);
    when(trackerBundle.getValidationMode()).thenReturn(ValidationMode.FULL);
    when(ctx.getNote(note.getNote())).thenReturn(Optional.of(new TrackedEntityComment()));
    ValidationErrorReporter reporter = new ValidationErrorReporter(ctx);
    event.setNotes(Collections.singletonList(note));
    // When
    this.hook.validateEvent(reporter, event);
    // Then
    assertFalse(reporter.hasErrors());
    assertThat(event.getNotes(), hasSize(0));
}
Also used : TrackedEntityComment(org.hisp.dhis.trackedentitycomment.TrackedEntityComment) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Note(org.hisp.dhis.tracker.domain.Note) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test)

Example 27 with TrackerImportValidationContext

use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.

the class EnrollmentRuleValidationHook method validateEnrollment.

@Override
public void validateEnrollment(ValidationErrorReporter reporter, Enrollment enrollment) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    List<ProgramRuleIssue> programRuleIssues = validators.stream().flatMap(v -> v.validateEnrollments(context.getBundle()).getOrDefault(enrollment.getEnrollment(), Lists.newArrayList()).stream()).collect(Collectors.toList());
    addIssuesToReporter(reporter, enrollment, programRuleIssues);
}
Also used : ValidationUtils.addIssuesToReporter(org.hisp.dhis.tracker.validation.hooks.ValidationUtils.addIssuesToReporter) Enrollment(org.hisp.dhis.tracker.domain.Enrollment) List(java.util.List) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Autowired(org.springframework.beans.factory.annotation.Autowired) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Collectors(java.util.stream.Collectors) RuleActionImplementer(org.hisp.dhis.tracker.programrule.RuleActionImplementer) ProgramRuleIssue(org.hisp.dhis.tracker.programrule.ProgramRuleIssue) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) ProgramRuleIssue(org.hisp.dhis.tracker.programrule.ProgramRuleIssue)

Example 28 with TrackerImportValidationContext

use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.

the class EventDataValuesValidationHook method validateEvent.

@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    ProgramStage programStage = context.getProgramStage(event.getProgramStage());
    checkNotNull(programStage, TrackerImporterAssertErrors.PROGRAM_STAGE_CANT_BE_NULL);
    for (DataValue dataValue : event.getDataValues()) {
        // event dates (createdAt, updatedAt) are ignored and set by the
        // system
        DataElement dataElement = context.getDataElement(dataValue.getDataElement());
        if (dataElement == null) {
            reporter.addError(event, TrackerErrorCode.E1304, dataValue.getDataElement());
            continue;
        }
        validateDataElement(reporter, dataElement, dataValue, programStage, event);
        if (dataValue.getValue() != null) {
            validateOptionSet(reporter, event, dataElement, dataValue.getValue());
        }
    }
    validateMandatoryDataValues(event, context, reporter);
    validateDataValueDataElementIsConnectedToProgramStage(reporter, event, programStage);
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue) ValidationUtils.validateMandatoryDataValue(org.hisp.dhis.tracker.validation.hooks.ValidationUtils.validateMandatoryDataValue) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 29 with TrackerImportValidationContext

use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.

the class PreCheckExistenceValidationHook method validateEnrollment.

@Override
public void validateEnrollment(ValidationErrorReporter reporter, Enrollment enrollment) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    TrackerImportStrategy importStrategy = context.getStrategy(enrollment);
    ProgramInstance existingPi = context.getProgramInstance(enrollment.getEnrollment());
    // If the tracked entity is soft-deleted no operation is allowed
    if (existingPi != null && existingPi.isDeleted()) {
        reporter.addError(enrollment, E1113, enrollment.getEnrollment());
        return;
    }
    if (existingPi != null && importStrategy.isCreate()) {
        reporter.addError(enrollment, E1080, enrollment.getEnrollment());
    } else if (existingPi == null && importStrategy.isUpdateOrDelete()) {
        reporter.addError(enrollment, E1081, enrollment.getEnrollment());
    }
}
Also used : TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) ProgramInstance(org.hisp.dhis.program.ProgramInstance)

Example 30 with TrackerImportValidationContext

use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext in project dhis2-core by dhis2.

the class PreCheckExistenceValidationHook method validateEvent.

@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    TrackerImportStrategy importStrategy = context.getStrategy(event);
    ProgramStageInstance existingPsi = context.getProgramStageInstance(event.getEvent());
    // If the event is soft-deleted no operation is allowed
    if (existingPsi != null && existingPsi.isDeleted()) {
        reporter.addError(event, E1082, event.getEvent());
        return;
    }
    if (existingPsi != null && importStrategy.isCreate()) {
        reporter.addError(event, E1030, event.getEvent());
    } else if (existingPsi == null && importStrategy.isUpdateOrDelete()) {
        reporter.addError(event, E1032, event.getEvent());
    }
}
Also used : TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Aggregations

TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)46 Program (org.hisp.dhis.program.Program)14 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)14 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)13 ProgramStage (org.hisp.dhis.program.ProgramStage)11 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)10 TrackerImportStrategy (org.hisp.dhis.tracker.TrackerImportStrategy)8 Test (org.junit.jupiter.api.Test)8 List (java.util.List)7 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)7 Event (org.hisp.dhis.tracker.domain.Event)7 Note (org.hisp.dhis.tracker.domain.Note)7 Collectors (java.util.stream.Collectors)6 ProgramInstance (org.hisp.dhis.program.ProgramInstance)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 TrackerErrorCode (org.hisp.dhis.tracker.report.TrackerErrorCode)5 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)4 TrackedEntityComment (org.hisp.dhis.trackedentitycomment.TrackedEntityComment)4 TrackerType (org.hisp.dhis.tracker.TrackerType)4 User (org.hisp.dhis.user.User)4