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