Search in sources :

Example 91 with ProgramStage

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());
    }
}
Also used : ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 92 with ProgramStage

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));
}
Also used : Event(org.hisp.dhis.tracker.domain.Event) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Collectors(java.util.stream.Collectors) ProgramStage(org.hisp.dhis.program.ProgramStage) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) List(java.util.List) Component(org.springframework.stereotype.Component) Pair(org.apache.commons.lang3.tuple.Pair) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Map(java.util.Map) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) ProgramInstance(org.hisp.dhis.program.ProgramInstance) TrackerBundle(org.hisp.dhis.tracker.bundle.TrackerBundle) Event(org.hisp.dhis.tracker.domain.Event) List(java.util.List) ProgramStage(org.hisp.dhis.program.ProgramStage) Map(java.util.Map) Pair(org.apache.commons.lang3.tuple.Pair)

Example 93 with ProgramStage

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");
}
Also used : TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 94 with ProgramStage

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));
    }
}
Also used : ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataValue(org.hisp.dhis.tracker.domain.DataValue) Event(org.hisp.dhis.tracker.domain.Event) FileResource(org.hisp.dhis.fileresource.FileResource) ValidationUtils(org.hisp.dhis.system.util.ValidationUtils) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) E1076(org.hisp.dhis.tracker.report.TrackerErrorCode.E1076) Set(java.util.Set) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) E1084(org.hisp.dhis.tracker.report.TrackerErrorCode.E1084) ValidationUtils.needsToValidateDataValues(org.hisp.dhis.tracker.validation.hooks.ValidationUtils.needsToValidateDataValues) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) ProgramStage(org.hisp.dhis.program.ProgramStage) TrackerErrorCode(org.hisp.dhis.tracker.report.TrackerErrorCode) DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) Component(org.springframework.stereotype.Component) E1009(org.hisp.dhis.tracker.report.TrackerErrorCode.E1009) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) E1303(org.hisp.dhis.tracker.report.TrackerErrorCode.E1303) Optional(java.util.Optional) ValidationUtils.validateMandatoryDataValue(org.hisp.dhis.tracker.validation.hooks.ValidationUtils.validateMandatoryDataValue) ProgramStage(org.hisp.dhis.program.ProgramStage)

Example 95 with ProgramStage

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());
    }
}
Also used : TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) ProgramStage(org.hisp.dhis.program.ProgramStage)

Aggregations

ProgramStage (org.hisp.dhis.program.ProgramStage)209 Test (org.junit.jupiter.api.Test)86 Program (org.hisp.dhis.program.Program)82 DataElement (org.hisp.dhis.dataelement.DataElement)67 Event (org.hisp.dhis.tracker.domain.Event)47 ValidationErrorReporter (org.hisp.dhis.tracker.report.ValidationErrorReporter)40 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)39 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)39 ProgramInstance (org.hisp.dhis.program.ProgramInstance)38 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)26 DhisConvenienceTest.createProgramStage (org.hisp.dhis.DhisConvenienceTest.createProgramStage)22 DataValue (org.hisp.dhis.tracker.domain.DataValue)22 TrackedEntityInstance (org.hisp.dhis.trackedentity.TrackedEntityInstance)21 User (org.hisp.dhis.user.User)20 TrackerBundle (org.hisp.dhis.tracker.bundle.TrackerBundle)17 ArrayList (java.util.ArrayList)16 Date (java.util.Date)16 List (java.util.List)16 DhisConvenienceTest.createDataElement (org.hisp.dhis.DhisConvenienceTest.createDataElement)16 TrackerImportValidationContext (org.hisp.dhis.tracker.validation.TrackerImportValidationContext)16