Search in sources :

Example 1 with ImplementationGuideGlobalComponent

use of org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideGlobalComponent in project org.hl7.fhir.core by hapifhir.

the class InstanceValidator method start.

// checkSpecials = we're only going to run these tests if we are actually validating this content (as opposed to we looked it up)
private void start(ValidatorHostContext hostContext, List<ValidationMessage> errors, Element resource, Element element, StructureDefinition defn, NodeStack stack) throws FHIRException {
    checkLang(resource, stack);
    if (crumbTrails) {
        element.addMessage(signpost(errors, IssueType.INFORMATIONAL, element.line(), element.col(), stack.getLiteralPath(), I18nConstants.VALIDATION_VAL_PROFILE_SIGNPOST, defn.getUrl()));
    }
    if (BUNDLE.equals(element.fhirType())) {
        resolveBundleReferences(element, new ArrayList<Element>());
    }
    startInner(hostContext, errors, resource, element, defn, stack, hostContext.isCheckSpecials());
    Element meta = element.getNamedChild(META);
    if (meta != null) {
        List<Element> profiles = new ArrayList<Element>();
        meta.getNamedChildren("profile", profiles);
        int i = 0;
        for (Element profile : profiles) {
            StructureDefinition sd = context.fetchResource(StructureDefinition.class, profile.primitiveValue());
            if (!defn.getUrl().equals(profile.primitiveValue())) {
                // is this a version specific reference?
                VersionURLInfo vu = VersionUtilities.parseVersionUrl(profile.primitiveValue());
                if (vu != null) {
                    if (!VersionUtilities.versionsCompatible(vu.getVersion(), context.getVersion())) {
                        hint(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath() + ".meta.profile[" + i + "]", false, I18nConstants.VALIDATION_VAL_PROFILE_OTHER_VERSION, vu.getVersion());
                    } else if (vu.getUrl().equals(defn.getUrl())) {
                        hint(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath() + ".meta.profile[" + i + "]", false, I18nConstants.VALIDATION_VAL_PROFILE_THIS_VERSION_OK);
                    } else {
                        StructureDefinition sdt = context.fetchResource(StructureDefinition.class, vu.getUrl());
                        rule(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath() + ".meta.profile[" + i + "]", false, I18nConstants.VALIDATION_VAL_PROFILE_THIS_VERSION_OTHER, sdt == null ? "null" : sdt.getType());
                    }
                } else {
                    if (sd == null) {
                        // we'll try fetching it directly from it's source, but this is likely to fail later even if the resolution succeeds
                        if (fetcher == null) {
                            warning(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath() + ".meta.profile[" + i + "]", false, I18nConstants.VALIDATION_VAL_PROFILE_UNKNOWN, profile.primitiveValue());
                        } else if (!fetcher.fetchesCanonicalResource(this, profile.primitiveValue())) {
                            warning(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath() + ".meta.profile[" + i + "]", false, I18nConstants.VALIDATION_VAL_PROFILE_UNKNOWN_NOT_POLICY, profile.primitiveValue());
                        } else {
                            try {
                                sd = (StructureDefinition) fetcher.fetchCanonicalResource(this, profile.primitiveValue());
                            } catch (Exception e) {
                                if (STACK_TRACE)
                                    e.printStackTrace();
                                warning(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath() + ".meta.profile[" + i + "]", false, I18nConstants.VALIDATION_VAL_PROFILE_UNKNOWN_ERROR, profile.primitiveValue(), e.getMessage());
                            }
                            if (sd != null) {
                                context.cacheResource(sd);
                            }
                        }
                    }
                    if (sd != null) {
                        if (crumbTrails) {
                            element.addMessage(signpost(errors, IssueType.INFORMATIONAL, element.line(), element.col(), stack.getLiteralPath(), I18nConstants.VALIDATION_VAL_PROFILE_SIGNPOST_META, sd.getUrl()));
                        }
                        stack.resetIds();
                        startInner(hostContext, errors, resource, element, sd, stack, false);
                    }
                }
            }
            i++;
        }
    }
    String rt = element.fhirType();
    for (ImplementationGuide ig : igs) {
        for (ImplementationGuideGlobalComponent gl : ig.getGlobal()) {
            if (rt.equals(gl.getType())) {
                StructureDefinition sd = context.fetchResource(StructureDefinition.class, gl.getProfile());
                if (warning(errors, IssueType.STRUCTURE, element.line(), element.col(), stack.getLiteralPath(), sd != null, I18nConstants.VALIDATION_VAL_GLOBAL_PROFILE_UNKNOWN, gl.getProfile())) {
                    if (crumbTrails) {
                        element.addMessage(signpost(errors, IssueType.INFORMATIONAL, element.line(), element.col(), stack.getLiteralPath(), I18nConstants.VALIDATION_VAL_PROFILE_SIGNPOST_GLOBAL, sd.getUrl(), ig.getUrl()));
                    }
                    stack.resetIds();
                    startInner(hostContext, errors, resource, element, sd, stack, false);
                }
            }
        }
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) ImplementationGuideGlobalComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideGlobalComponent) ImplementationGuide(org.hl7.fhir.r5.model.ImplementationGuide) NamedElement(org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement) IndexedElement(org.hl7.fhir.validation.instance.utils.IndexedElement) SpecialElement(org.hl7.fhir.r5.elementmodel.Element.SpecialElement) Element(org.hl7.fhir.r5.elementmodel.Element) ArrayList(java.util.ArrayList) VersionURLInfo(org.hl7.fhir.utilities.VersionUtilities.VersionURLInfo) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) FHIRLexerException(org.hl7.fhir.r5.utils.FHIRLexer.FHIRLexerException)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)1 FHIRException (org.hl7.fhir.exceptions.FHIRException)1 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)1 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)1 Element (org.hl7.fhir.r5.elementmodel.Element)1 SpecialElement (org.hl7.fhir.r5.elementmodel.Element.SpecialElement)1 NamedElement (org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement)1 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)1 ImplementationGuide (org.hl7.fhir.r5.model.ImplementationGuide)1 ImplementationGuideGlobalComponent (org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideGlobalComponent)1 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)1 FHIRLexerException (org.hl7.fhir.r5.utils.FHIRLexer.FHIRLexerException)1 VersionURLInfo (org.hl7.fhir.utilities.VersionUtilities.VersionURLInfo)1 IndexedElement (org.hl7.fhir.validation.instance.utils.IndexedElement)1