Search in sources :

Example 36 with TrackerImportValidationContext

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

the class EnrollmentDateValidationHook method validateEnrollment.

@Override
public void validateEnrollment(ValidationErrorReporter reporter, Enrollment enrollment) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    validateMandatoryDates(reporter, enrollment);
    Program program = context.getProgram(enrollment.getProgram());
    validateEnrollmentDatesNotInFuture(reporter, program, enrollment);
    if (Boolean.TRUE.equals(program.getDisplayIncidentDate()) && Objects.isNull(enrollment.getOccurredAt())) {
        reporter.addError(enrollment, E1023, enrollment.getOccurredAt());
    }
}
Also used : Program(org.hisp.dhis.program.Program) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext)

Example 37 with TrackerImportValidationContext

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

the class PreCheckMetaValidationHook method validateTrackedEntity.

@Override
public void validateTrackedEntity(ValidationErrorReporter reporter, TrackedEntity tei) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    OrganisationUnit organisationUnit = context.getOrganisationUnit(tei.getOrgUnit());
    if (organisationUnit == null) {
        reporter.addError(tei, TrackerErrorCode.E1049, tei.getOrgUnit());
    }
    TrackedEntityType entityType = context.getTrackedEntityType(tei.getTrackedEntityType());
    if (entityType == null) {
        reporter.addError(tei, E1005, tei.getTrackedEntityType());
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext)

Example 38 with TrackerImportValidationContext

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

the class PreCheckSecurityOwnershipValidationHook method validateEnrollment.

@Override
public void validateEnrollment(ValidationErrorReporter reporter, Enrollment enrollment) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    TrackerImportStrategy strategy = context.getStrategy(enrollment);
    TrackerBundle bundle = context.getBundle();
    User user = bundle.getUser();
    Program program = strategy.isUpdateOrDelete() ? context.getProgramInstance(enrollment.getEnrollment()).getProgram() : context.getProgram(enrollment.getProgram());
    OrganisationUnit ownerOrgUnit = context.getOwnerOrganisationUnit(enrollment.getTrackedEntity(), enrollment.getProgram());
    checkNotNull(user, USER_CANT_BE_NULL);
    checkNotNull(enrollment, ENROLLMENT_CANT_BE_NULL);
    checkNotNull(program, PROGRAM_CANT_BE_NULL);
    checkEnrollmentOrgUnit(reporter, context, strategy, enrollment, program);
    if (strategy.isDelete()) {
        boolean hasNonDeletedEvents = context.programInstanceHasEvents(enrollment.getEnrollment());
        boolean hasNotCascadeDeleteAuthority = !user.isAuthorized(Authorities.F_ENROLLMENT_CASCADE_DELETE.getAuthority());
        if (hasNonDeletedEvents && hasNotCascadeDeleteAuthority) {
            TrackerErrorReport error = TrackerErrorReport.builder().uid(enrollment.getUid()).trackerType(TrackerType.ENROLLMENT).errorCode(E1103).addArg(user).addArg(enrollment.getEnrollment()).build(bundle);
            reporter.addError(error);
        }
    }
    checkWriteEnrollmentAccess(reporter, enrollment, program, context, ownerOrgUnit);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) Program(org.hisp.dhis.program.Program) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) TrackerErrorReport(org.hisp.dhis.tracker.report.TrackerErrorReport)

Example 39 with TrackerImportValidationContext

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

the class PreCheckUpdatableFieldsValidationHook method validateEvent.

@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    ProgramStageInstance programStageInstance = context.getProgramStageInstance(event.getEvent());
    ProgramStage programStage = programStageInstance.getProgramStage();
    ProgramInstance programInstance = programStageInstance.getProgramInstance();
    reporter.addErrorIf(() -> !event.getProgramStage().equals(programStage.getUid()), event, E1128, "programStage");
    reporter.addErrorIf(() -> event.getEnrollment() != null && !event.getEnrollment().equals(programInstance.getUid()), event, E1128, "enrollment");
}
Also used : TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) ProgramInstance(org.hisp.dhis.program.ProgramInstance) ProgramStage(org.hisp.dhis.program.ProgramStage) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance)

Example 40 with TrackerImportValidationContext

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

the class TrackedEntityAttributeValidationHook method validateTrackedEntity.

@Override
public void validateTrackedEntity(ValidationErrorReporter reporter, TrackedEntity trackedEntity) {
    TrackedEntityType trackedEntityType = reporter.getValidationContext().getTrackedEntityType(trackedEntity.getTrackedEntityType());
    TrackerImportValidationContext context = reporter.getValidationContext();
    TrackedEntityInstance tei = context.getTrackedEntityInstance(trackedEntity.getTrackedEntity());
    OrganisationUnit organisationUnit = context.getOrganisationUnit(trackedEntity.getOrgUnit());
    validateMandatoryAttributes(reporter, trackedEntity, trackedEntityType);
    validateAttributes(reporter, trackedEntity, tei, organisationUnit, trackedEntityType);
}
Also used : TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

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