use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class RepeatedEventsValidationHook method validateNotMultipleEvents.
private void validateNotMultipleEvents(ValidationErrorReporter reporter, TrackerImportValidationContext context, Event event) {
ProgramInstance programInstance = context.getProgramInstance(event.getEnrollment());
ProgramStage programStage = context.getProgramStage(event.getProgramStage());
TrackerImportStrategy strategy = context.getStrategy(event);
if (strategy == TrackerImportStrategy.CREATE && programStage != null && programInstance != null && !programStage.getRepeatable() && context.programStageHasEvents(programStage.getUid(), programInstance.getUid())) {
reporter.addError(event, TrackerErrorCode.E1039, event.getProgramStage());
}
}
use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class RepeatedEventsValidationHook method validate.
@Override
public void validate(ValidationErrorReporter reporter, TrackerImportValidationContext context) {
TrackerBundle bundle = context.getBundle();
Map<Pair<String, String>, List<Event>> eventsByEnrollmentAndNotRepeatableProgramStage = bundle.getEvents().stream().filter(e -> !reporter.isInvalid(e)).filter(e -> !context.getStrategy(e).isDelete()).filter(e -> {
ProgramStage programStage = context.getProgramStage(e.getProgramStage());
return programStage.getProgram().isRegistration() && !programStage.getRepeatable();
}).collect(Collectors.groupingBy(e -> Pair.of(e.getProgramStage(), e.getEnrollment())));
for (Map.Entry<Pair<String, String>, List<Event>> mapEntry : eventsByEnrollmentAndNotRepeatableProgramStage.entrySet()) {
if (mapEntry.getValue().size() > 1) {
for (Event event : mapEntry.getValue()) {
reporter.addError(event, TrackerErrorCode.E1039, mapEntry.getKey().getLeft());
}
}
}
bundle.getEvents().forEach(e -> validateNotMultipleEvents(reporter, context, e));
}
use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class PreCheckMandatoryFieldsValidationHook method validateEvent.
@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
reporter.addErrorIf(() -> StringUtils.isEmpty(event.getOrgUnit()), event, E1123, ORG_UNIT);
reporter.addErrorIf(() -> StringUtils.isEmpty(event.getProgramStage()), event, E1123, "programStage");
// TODO remove if once metadata import is fixed
TrackerImportValidationContext context = reporter.getValidationContext();
ProgramStage programStage = context.getProgramStage(event.getProgramStage());
if (programStage != null) {
// Program stages should always have a program! Due to how metadata
// import is currently implemented
// it's possible that users run into the edge case that a program
// stage does not have an associated
// program. Tell the user it's an issue with the metadata and not
// the event itself. This should be
// fixed in the metadata import. For more see
// https://jira.dhis2.org/browse/DHIS2-12123
reporter.addErrorIfNull(programStage.getProgram(), event, E1008, event.getProgramStage());
// the DB entry of the program stage and not the payload itself
return;
}
reporter.addErrorIf(() -> StringUtils.isEmpty(event.getProgram()), event, E1123, "program");
}
use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class EventDataValuesValidationHook method validateMandatoryDataValues.
private void validateMandatoryDataValues(Event event, TrackerImportValidationContext context, ValidationErrorReporter reporter) {
if (StringUtils.isNotEmpty(event.getProgramStage())) {
ProgramStage programStage = context.getProgramStage(event.getProgramStage());
final List<String> mandatoryDataElements = programStage.getProgramStageDataElements().stream().filter(ProgramStageDataElement::isCompulsory).map(de -> context.getIdentifiers().getDataElementIdScheme().getIdentifier(de.getDataElement())).collect(Collectors.toList());
List<String> missingDataValue = validateMandatoryDataValue(programStage, event, mandatoryDataElements);
missingDataValue.forEach(de -> reporter.addError(event, E1303, de));
}
}
use of org.hisp.dhis.program.ProgramStage in project dhis2-core by dhis2.
the class EventGeoValidationHook method validateEvent.
@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
TrackerImportValidationContext context = reporter.getValidationContext();
ProgramStage programStage = context.getProgramStage(event.getProgramStage());
checkNotNull(programStage, TrackerImporterAssertErrors.PROGRAM_STAGE_CANT_BE_NULL);
if (event.getGeometry() != null) {
ValidationUtils.validateGeometry(reporter, event, event.getGeometry(), programStage.getFeatureType());
}
}
Aggregations