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());
}
}
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());
}
}
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);
}
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");
}
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);
}
Aggregations