Search in sources :

Example 1 with ValidationPolicy

use of org.hl7.fhir.r5.elementmodel.ParserBase.ValidationPolicy in project org.hl7.fhir.core by hapifhir.

the class InstanceValidator method checkPrimitiveBinding.

private void checkPrimitiveBinding(ValidatorHostContext hostContext, List<ValidationMessage> errors, String path, String type, ElementDefinition elementContext, Element element, StructureDefinition profile, NodeStack stack) {
    // We ignore bindings that aren't on string, uri or code
    if (!element.hasPrimitiveValue() || !("code".equals(type) || "string".equals(type) || "uri".equals(type) || "url".equals(type) || "canonical".equals(type))) {
        return;
    }
    if (noTerminologyChecks)
        return;
    String value = element.primitiveValue();
    // System.out.println("check "+value+" in "+path);
    // firstly, resolve the value set
    ElementDefinitionBindingComponent binding = elementContext.getBinding();
    if (binding.hasValueSet()) {
        ValueSet vs = resolveBindingReference(profile, binding.getValueSet(), profile.getUrl());
        if (vs == null) {
            CodeSystem cs = context.fetchCodeSystem(binding.getValueSet());
            if (rule(errors, IssueType.CODEINVALID, element.line(), element.col(), path, cs == null, I18nConstants.TERMINOLOGY_TX_VALUESET_NOTFOUND_CS, describeReference(binding.getValueSet()))) {
                warning(errors, IssueType.CODEINVALID, element.line(), element.col(), path, vs != null, I18nConstants.TERMINOLOGY_TX_VALUESET_NOTFOUND, describeReference(binding.getValueSet()));
            }
        } else {
            CodedContentValidationPolicy validationPolicy = getPolicyAdvisor() == null ? CodedContentValidationPolicy.VALUESET : getPolicyAdvisor().policyForCodedContent(this, hostContext, stack.getLiteralPath(), elementContext, profile, BindingKind.PRIMARY, vs, new ArrayList<>());
            if (validationPolicy != CodedContentValidationPolicy.IGNORE) {
                long t = System.nanoTime();
                ValidationResult vr = null;
                if (binding.getStrength() != BindingStrength.EXAMPLE) {
                    ValidationOptions options = baseOptions.setLanguage(stack.getWorkingLang()).guessSystem();
                    if (validationPolicy == CodedContentValidationPolicy.CODE) {
                        options = options.noCheckValueSetMembership();
                    }
                    vr = checkCodeOnServer(stack, vs, value, options);
                }
                timeTracker.tx(t, "vc " + value + "");
                if (binding.getStrength() == BindingStrength.REQUIRED) {
                    removeTrackedMessagesForLocation(errors, element, path);
                }
                if (vr != null && !vr.isOk()) {
                    if (vr.IsNoService())
                        txHint(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_NOVALID_15, value);
                    else if (binding.getStrength() == BindingStrength.REQUIRED)
                        txRule(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_NOVALID_16, value, describeValueSet(binding.getValueSet()), getErrorMessage(vr.getMessage()));
                    else if (binding.getStrength() == BindingStrength.EXTENSIBLE) {
                        if (binding.hasExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"))
                            checkMaxValueSet(errors, path, element, profile, ToolingExtensions.readStringExtension(binding, "http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet"), value, stack);
                        else if (!noExtensibleWarnings && !isOkExtension(value, vs))
                            txWarningForLaterRemoval(element, errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_NOVALID_17, value, describeValueSet(binding.getValueSet()), getErrorMessage(vr.getMessage()));
                    } else if (binding.getStrength() == BindingStrength.PREFERRED) {
                        if (baseOnly) {
                            txHint(errors, vr.getTxLink(), IssueType.CODEINVALID, element.line(), element.col(), path, false, I18nConstants.TERMINOLOGY_TX_NOVALID_18, value, describeValueSet(binding.getValueSet()), getErrorMessage(vr.getMessage()));
                        }
                    }
                }
            }
        }
    } else if (!noBindingMsgSuppressed)
        hint(errors, IssueType.CODEINVALID, element.line(), element.col(), path, !type.equals("code"), I18nConstants.TERMINOLOGY_TX_BINDING_NOSOURCE2);
}
Also used : ArrayList(java.util.ArrayList) ValidationResult(org.hl7.fhir.r5.context.IWorkerContext.ValidationResult) ValidationOptions(org.hl7.fhir.utilities.validation.ValidationOptions) ElementDefinitionBindingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent) ValueSet(org.hl7.fhir.r5.model.ValueSet) CodeSystem(org.hl7.fhir.r5.model.CodeSystem)

Aggregations

ArrayList (java.util.ArrayList)1 ValidationResult (org.hl7.fhir.r5.context.IWorkerContext.ValidationResult)1 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)1 ElementDefinitionBindingComponent (org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent)1 ValueSet (org.hl7.fhir.r5.model.ValueSet)1 ValidationOptions (org.hl7.fhir.utilities.validation.ValidationOptions)1