Search in sources :

Example 16 with TrackerImportValidationContext

use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext 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 17 with TrackerImportValidationContext

use of org.hisp.dhis.tracker.validation.TrackerImportValidationContext 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)

Example 18 with TrackerImportValidationContext

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

the class EventRuleValidationHook method validateEvent.

@Override
public void validateEvent(ValidationErrorReporter reporter, Event event) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    List<ProgramRuleIssue> programRuleIssues = validators.stream().flatMap(v -> v.validateEvents(context.getBundle()).getOrDefault(event.getEvent(), Lists.newArrayList()).stream()).collect(Collectors.toList());
    addIssuesToReporter(reporter, event, programRuleIssues);
}
Also used : ValidationUtils.addIssuesToReporter(org.hisp.dhis.tracker.validation.hooks.ValidationUtils.addIssuesToReporter) Event(org.hisp.dhis.tracker.domain.Event) List(java.util.List) Component(org.springframework.stereotype.Component) Lists(com.google.common.collect.Lists) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) Autowired(org.springframework.beans.factory.annotation.Autowired) ValidationErrorReporter(org.hisp.dhis.tracker.report.ValidationErrorReporter) Collectors(java.util.stream.Collectors) RuleActionImplementer(org.hisp.dhis.tracker.programrule.RuleActionImplementer) ProgramRuleIssue(org.hisp.dhis.tracker.programrule.ProgramRuleIssue) TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) ProgramRuleIssue(org.hisp.dhis.tracker.programrule.ProgramRuleIssue)

Example 19 with TrackerImportValidationContext

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

the class PreCheckExistenceValidationHook method validateTrackedEntity.

@Override
public void validateTrackedEntity(ValidationErrorReporter reporter, TrackedEntity trackedEntity) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    TrackerImportStrategy importStrategy = context.getStrategy(trackedEntity);
    TrackedEntityInstance existingTe = context.getTrackedEntityInstance(trackedEntity.getTrackedEntity());
    // If the tracked entity is soft-deleted no operation is allowed
    if (existingTe != null && existingTe.isDeleted()) {
        reporter.addError(trackedEntity, E1114, trackedEntity.getTrackedEntity());
        return;
    }
    if (existingTe != null && importStrategy.isCreate()) {
        reporter.addError(trackedEntity, E1002, trackedEntity.getTrackedEntity());
    } else if (existingTe == null && importStrategy.isUpdateOrDelete()) {
        reporter.addError(trackedEntity, E1063, trackedEntity.getTrackedEntity());
    }
}
Also used : TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext) TrackerImportStrategy(org.hisp.dhis.tracker.TrackerImportStrategy) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance)

Example 20 with TrackerImportValidationContext

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

the class PreCheckExistenceValidationHook method validateRelationship.

@Override
public void validateRelationship(ValidationErrorReporter reporter, Relationship relationship) {
    TrackerImportValidationContext context = reporter.getValidationContext();
    org.hisp.dhis.relationship.Relationship existingRelationship = context.getRelationship(relationship);
    if (existingRelationship != null) {
        reporter.addWarning(relationship, E4015, relationship.getRelationship());
    }
}
Also used : TrackerImportValidationContext(org.hisp.dhis.tracker.validation.TrackerImportValidationContext)

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