Search in sources :

Example 31 with TrackerImportValidationContext

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

the class PreCheckMetaValidationHook method validateEnrollment.

@Override
public void validateEnrollment(ValidationErrorReporter reporter, Enrollment enrollment) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    OrganisationUnit organisationUnit = context.getOrganisationUnit(enrollment.getOrgUnit());
    reporter.addErrorIfNull(organisationUnit, enrollment, E1070, enrollment.getOrgUnit());
    Program program = context.getProgram(enrollment.getProgram());
    reporter.addErrorIfNull(program, enrollment, E1069, enrollment.getProgram());
    reporter.addErrorIf(() -> !trackedEntityInstanceExist(context, enrollment.getTrackedEntity()), enrollment, E1068, enrollment.getTrackedEntity());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext)

Example 32 with TrackerImportValidationContext

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

the class EnrollmentAttributeValidationHook 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);
    TrackedEntityInstance tei = context.getTrackedEntityInstance(enrollment.getTrackedEntity());
    OrganisationUnit orgUnit = context.getOrganisationUnit(getOrgUnitUidFromTei(context, enrollment.getTrackedEntity()));
    Map<String, String> attributeValueMap = Maps.newHashMap();
    for (Attribute attribute : enrollment.getAttributes()) {
        validateRequiredProperties(reporter, enrollment, attribute, program);
        TrackedEntityAttribute teAttribute = context.getTrackedEntityAttribute(attribute.getAttribute());
        if (attribute.getAttribute() != null && attribute.getValue() != null && teAttribute != null) {
            attributeValueMap.put(attribute.getAttribute(), attribute.getValue());
            validateAttrValueType(reporter, enrollment, attribute, teAttribute);
            validateOptionSet(reporter, enrollment, teAttribute, attribute.getValue());
            validateAttributeUniqueness(reporter, enrollment, attribute.getValue(), teAttribute, tei, orgUnit);
        }
    }
    validateMandatoryAttributes(reporter, program, attributeValueMap, enrollment);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) Attribute(org.hisp.dhis.tracker.domain.Attribute) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 33 with TrackerImportValidationContext

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

the class EventDateValidationHook method validateExpiryDays.

private void validateExpiryDays(ValidationErrorReporter reporter, Event event, Program program) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    User actingUser = context.getBundle().getUser();
    checkNotNull(actingUser, TrackerImporterAssertErrors.USER_CANT_BE_NULL);
    checkNotNull(event, TrackerImporterAssertErrors.EVENT_CANT_BE_NULL);
    checkNotNull(program, TrackerImporterAssertErrors.PROGRAM_CANT_BE_NULL);
    if (actingUser.isAuthorized(Authorities.F_EDIT_EXPIRED.getAuthority())) {
        return;
    }
    if ((program.getCompleteEventsExpiryDays() > 0 && EventStatus.COMPLETED == event.getStatus())) {
        if (event.getCompletedAt() == null) {
            reporter.addErrorIfNull(event.getCompletedAt(), event, E1042, event);
        } else {
            if (now().isAfter(event.getCompletedAt().plus(ofDays(program.getCompleteEventsExpiryDays())))) {
                reporter.addError(event, E1043, event);
            }
        }
    }
}
Also used : User(org.hisp.dhis.user.User) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext)

Example 34 with TrackerImportValidationContext

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

the class PreCheckDataRelationsValidationHook method validateEvent.

@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    ProgramStage programStage = context.getProgramStage(event.getProgramStage());
    OrganisationUnit organisationUnit = context.getOrganisationUnit(event.getOrgUnit());
    Program program = context.getProgram(event.getProgram());
    validateProgramStageInProgram(reporter, event, programStage, program);
    validateRegistrationProgram(reporter, event, context, program);
    validateProgramHasOrgUnit(reporter, event, context, organisationUnit, program);
    validateEventCategoryOptionCombo(reporter, event, program);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 35 with TrackerImportValidationContext

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

the class PreCheckDataRelationsValidationHook method validateEnrollment.

@Override
public void validateEnrollment(ValidationErrorReporter reporter, Enrollment enrollment) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    Program program = context.getProgram(enrollment.getProgram());
    OrganisationUnit organisationUnit = context.getOrganisationUnit(enrollment.getOrgUnit());
    reporter.addErrorIf(() -> !program.isRegistration(), enrollment, E1014, program);
    if (programDoesNotHaveOrgUnit(program, organisationUnit, context.getProgramWithOrgUnitsMap())) {
        reporter.addError(enrollment, E1041, organisationUnit, program);
    }
    if (program.getTrackedEntityType() != null && !program.getTrackedEntityType().getUid().equals(getTrackedEntityTypeUidFromEnrollment(context, enrollment))) {
        reporter.addError(enrollment, E1022, enrollment.getTrackedEntity(), program);
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Program(org.hisp.dhis.program.Program) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext)

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