Search in sources :

Example 21 with TrackerImportValidationContext

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

the class PreCheckMetaValidationHook method validateRelationship.

@Override
public void validateRelationship(ValidationErrorReporter reporter, Relationship relationship) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    RelationshipType relationshipType = context.getRelationShipType(relationship.getRelationshipType());
    reporter.addErrorIfNull(relationshipType, relationship, E4006, relationship.getRelationshipType());
}
Also used : TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) RelationshipType(org.hisp.dhis.relationship.RelationshipType)

Example 22 with TrackerImportValidationContext

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

the class EnrollmentGeoValidationHook method validateEnrollment.

@Override
public void validateEnrollment(ValidationErrorReporter reporter, Enrollment enrollment) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    Program program = context.getProgram(enrollment.getProgram());
    checkNotNull(program, TrackerImporterAssertErrors.PROGRAM_CANT_BE_NULL);
    if (enrollment.getGeometry() != null) {
        ValidationUtils.validateGeometry(reporter, enrollment, enrollment.getGeometry(), program.getFeatureType());
    }
}
Also used : Program(org.hisp.dhis.program.Program) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext)

Example 23 with TrackerImportValidationContext

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

the class EventCategoryOptValidationHook method validateEvent.

@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    Program program = context.getProgram(event.getProgram());
    checkNotNull(program, TrackerImporterAssertErrors.PROGRAM_CANT_BE_NULL);
    checkNotNull(context.getBundle().getUser(), TrackerImporterAssertErrors.USER_CANT_BE_NULL);
    checkNotNull(program, TrackerImporterAssertErrors.PROGRAM_CANT_BE_NULL);
    checkNotNull(event, TrackerImporterAssertErrors.EVENT_CANT_BE_NULL);
    CategoryOptionCombo categoryOptionCombo = reporter.getValidationContext().getCachedEventCategoryOptionCombo(event.getUid());
    checkNotNull(categoryOptionCombo, TrackerImporterAssertErrors.CATEGORY_OPTION_COMBO_CANT_BE_NULL);
    Date eventDate;
    try {
        eventDate = DateUtils.fromInstant(ObjectUtils.firstNonNull(event.getOccurredAt(), event.getScheduledAt(), Instant.now()));
    } catch (IllegalArgumentException e) {
        log.debug("Failed to parse dates, an error should already be reported.");
        return;
    }
    I18nFormat i18nFormat = i18nManager.getI18nFormat();
    for (CategoryOption option : categoryOptionCombo.getCategoryOptions()) {
        if (option.getStartDate() != null && eventDate.compareTo(option.getStartDate()) < 0) {
            reporter.addError(event, E1056, i18nFormat.formatDate(eventDate), i18nFormat.formatDate(option.getStartDate()), option.getName());
        }
        if (option.getEndDate() != null && eventDate.compareTo(option.getAdjustedEndDate(program)) > 0) {
            reporter.addError(event, E1057, i18nFormat.formatDate(eventDate), i18nFormat.formatDate(option.getAdjustedEndDate(program)), option.getName(), program.getName());
        }
    }
}
Also used : Program(org.hisp.dhis.program.Program) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) CategoryOption(org.hisp.dhis.category.CategoryOption) I18nFormat(org.hisp.dhis.i18n.I18nFormat) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) Date(java.util.Date)

Example 24 with TrackerImportValidationContext

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

the class EventDateValidationHook method validateEvent.

@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    Program program = context.getProgram(event.getProgram());
    if (event.getOccurredAt() == null && occuredAtDateIsMandatory(event, program)) {
        reporter.addError(event, E1031, event);
        return;
    }
    if (event.getScheduledAt() == null && EventStatus.SCHEDULE == event.getStatus()) {
        reporter.addError(event, E1050, event);
        return;
    }
    validateExpiryDays(reporter, event, program);
    validatePeriodType(reporter, event, program);
}
Also used : Program(org.hisp.dhis.program.Program) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext)

Example 25 with TrackerImportValidationContext

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

the class RepeatedEventsValidationHookTest method testTwoEventInNotRepeatableProgramStageAreNotPassingValidation.

@Test
void testTwoEventInNotRepeatableProgramStageAreNotPassingValidation() {
    List<Event> events = Lists.newArrayList(notRepeatableEvent("A"), notRepeatableEvent("B"));
    bundle.setEvents(events);
    events.forEach(e -> bundle.setStrategy(e, TrackerImportStrategy.CREATE_AND_UPDATE));
    ValidationErrorReporter errorReporter = new ValidationErrorReporter(new TrackerImportValidationContext(bundle));
    validatorToTest.validate(errorReporter, ctx);
    assertEquals(2, errorReporter.getReportList().size());
    assertThat(errorReporter.getReportList().get(0).getErrorCode(), is(TrackerErrorCode.E1039));
    assertThat(errorReporter.getReportList().get(0).getTrackerType(), is(EVENT));
    assertThat(errorReporter.getReportList().get(0).getUid(), is(events.get(0).getUid()));
    assertThat(errorReporter.getReportList().get(0).getErrorMessage(), is("ProgramStage: `" + NOT_REPEATABLE_PROGRAM_STAGE_WITH_REGISTRATION + "`, is not repeatable and an event already exists."));
    assertThat(errorReporter.getReportList().get(1).getErrorCode(), is(TrackerErrorCode.E1039));
    assertThat(errorReporter.getReportList().get(1).getTrackerType(), is(EVENT));
    assertThat(errorReporter.getReportList().get(1).getUid(), is(events.get(1).getUid()));
    assertThat(errorReporter.getReportList().get(1).getErrorMessage(), is("ProgramStage: `" + NOT_REPEATABLE_PROGRAM_STAGE_WITH_REGISTRATION + "`, is not repeatable and an event already exists."));
}
Also used : TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Event(org.hisp.dhis.tracker.domain.Event) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Test(org.junit.jupiter.api.Test) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

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