From 532aba2485f585226d41ee330ab27c1c4b0bfd6e Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Thu, 3 Dec 2020 12:52:43 +1100 Subject: [PATCH] cache xversion extension manager, and use it in any place accessing extension definitions --- .../fhir/r5/context/SimpleWorkerContext.java | 20 +++- .../fhir/r5/utils/XVerExtensionManager.java | 1 + .../hl7/fhir/validation/BaseValidator.java | 91 +++++++++++++++++-- .../hl7/fhir/validation/ValidationEngine.java | 2 +- .../codesystem/CodeSystemValidator.java | 5 +- .../instance/InstanceValidator.java | 54 ++++------- .../instance/InstanceValidatorFactory.java | 8 +- .../instance/type/BundleValidator.java | 5 +- .../instance/type/CodeSystemValidator.java | 5 +- .../instance/type/MeasureValidator.java | 5 +- .../instance/type/QuestionnaireValidator.java | 5 +- .../type/SearchParameterValidator.java | 5 +- .../type/StructureDefinitionValidator.java | 9 +- .../instance/type/ValueSetValidator.java | 5 +- .../validation/profile/ProfileValidator.java | 11 ++- 15 files changed, 165 insertions(+), 66 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java index 14cb75b2a..8c2890026 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/context/SimpleWorkerContext.java @@ -76,6 +76,7 @@ import org.hl7.fhir.r5.model.StructureMap.StructureMapModelMode; import org.hl7.fhir.r5.model.StructureMap.StructureMapStructureComponent; import org.hl7.fhir.r5.terminologies.TerminologyClient; import org.hl7.fhir.r5.utils.IResourceValidator; +import org.hl7.fhir.r5.utils.XVerExtensionManager; import org.hl7.fhir.utilities.CSFileInputStream; import org.hl7.fhir.utilities.TextFile; import org.hl7.fhir.utilities.TimeTracker; @@ -138,7 +139,8 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon } public interface IValidatorFactory { - IResourceValidator makeValidator(IWorkerContext ctxts) throws FHIRException; +// IResourceValidator makeValidator(IWorkerContext ctxt) throws FHIRException; + IResourceValidator makeValidator(IWorkerContext ctxts, XVerExtensionManager xverManager) throws FHIRException; } private Questionnaire questionnaire; @@ -149,6 +151,7 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon private boolean progress; private List loadedPackages = new ArrayList(); private boolean canNoTS; + private XVerExtensionManager xverManager; public SimpleWorkerContext() throws FileNotFoundException, IOException, FHIRException { super(); @@ -539,7 +542,7 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon public IResourceValidator newValidator() throws FHIRException { if (validatorFactory == null) throw new Error(formatMessage(I18nConstants.NO_VALIDATOR_CONFIGURED)); - return validatorFactory.makeValidator(this); + return validatorFactory.makeValidator(this, xverManager); } @@ -770,6 +773,10 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon ProfileUtilities pu = new ProfileUtilities(this, msgs, this); pu.setAutoFixSliceNames(true); pu.setThrowException(false); + if (xverManager == null) { + xverManager = new XVerExtensionManager(this); + } + pu.setXver(xverManager); if (sd.getDerivation() == TypeDerivationRule.CONSTRAINT) { pu.sortDifferential(sd, p, p.getUrl(), errors, true); } @@ -827,6 +834,13 @@ public class SimpleWorkerContext extends BaseWorkerContext implements IWorkerCon public void setCanNoTS(boolean canNoTS) { this.canNoTS = canNoTS; } + + public XVerExtensionManager getXVer() { + if (xverManager == null) { + xverManager = new XVerExtensionManager(this); + } + return xverManager; + } - + } \ No newline at end of file diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/XVerExtensionManager.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/XVerExtensionManager.java index 116752a74..fd682d128 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/XVerExtensionManager.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/XVerExtensionManager.java @@ -84,6 +84,7 @@ public class XVerExtensionManager { StructureDefinition sd = new StructureDefinition(); sd.setUserData(XVER_EXT_MARKER, "true"); + sd.setUserData("path", "http://hl7.org/fhir/versions.html#extensions"); sd.setUrl(url); sd.setVersion(context.getVersion()); sd.setFhirVersion(FHIRVersion.fromCode(context.getVersion())); diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/BaseValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/BaseValidator.java index 4ea182bbe..2c4391d0a 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/BaseValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/BaseValidator.java @@ -73,8 +73,11 @@ import org.hl7.fhir.r5.elementmodel.Element; import org.hl7.fhir.r5.model.Base; import org.hl7.fhir.r5.model.DomainResource; import org.hl7.fhir.r5.model.Resource; +import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.terminologies.ValueSetUtilities; +import org.hl7.fhir.r5.utils.XVerExtensionManager; +import org.hl7.fhir.r5.utils.XVerExtensionManager.XVerExtensionStatus; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.validation.ValidationMessage; @@ -118,7 +121,18 @@ public class BaseValidator { protected Source source; protected IWorkerContext context; protected TimeTracker timeTracker = new TimeTracker(); - + protected XVerExtensionManager xverManager; + + public BaseValidator(IWorkerContext context, XVerExtensionManager xverManager) { + super(); + this.context = context; + this.xverManager = xverManager; + if (this.xverManager == null) { + this.xverManager = new XVerExtensionManager(context); + } + + } + /** * Use to control what validation the validator performs. * Using this, you can turn particular kinds of validation on and off @@ -129,11 +143,7 @@ public class BaseValidator { */ private Map validationControl = new HashMap<>(); - public BaseValidator(IWorkerContext context){ - this.context = context; - } - - /** + /** * Test a rule and add a {@link IssueSeverity#FATAL} validation message if the validation fails * * @param thePass @@ -873,5 +883,74 @@ public class BaseValidator { return validationControl; } + public XVerExtensionStatus xverStatus(String url) { + return xverManager.status(url); + } + public boolean isXverUrl(String url) { + return xverManager.matchingUrl(url); + } + + public StructureDefinition xverDefn(String url) { + return xverManager.makeDefinition(url); + } + + public String xverVersion(String url) { + return xverManager.getVersion(url); + } + + public String xverElementId(String url) { + return xverManager.getElementId(url); + } + + public StructureDefinition getXverExt(StructureDefinition profile, List errors, String url) { + if (isXverUrl(url)) { + switch (xverStatus(url)) { + case BadVersion: + rule(errors, IssueType.BUSINESSRULE, profile.getId(), false, I18nConstants.EXTENSION_EXT_VERSION_INVALID, url, xverVersion(url)); + return null; + case Unknown: + rule(errors, IssueType.BUSINESSRULE, profile.getId(), false, I18nConstants.EXTENSION_EXT_VERSION_INVALIDID, url, xverElementId(url)); + return null; + case Invalid: + rule(errors, IssueType.BUSINESSRULE, profile.getId(), false, I18nConstants.EXTENSION_EXT_VERSION_NOCHANGE, url, xverElementId(url)); + return null; + case Valid: + StructureDefinition defn = xverDefn(url); + context.generateSnapshot(defn); + context.cacheResource(defn); + return defn; + default: + rule(errors, IssueType.INVALID, profile.getId(), false, I18nConstants.EXTENSION_EXT_VERSION_INTERNAL, url); + return null; + } + } else { + return null; + } + } + + public StructureDefinition getXverExt(List errors, String path, Element element, String url) { + if (isXverUrl(url)) { + switch (xverStatus(url)) { + case BadVersion: + rule(errors, IssueType.INVALID, element.line(), element.col(), path + "[url='" + url + "']", false, I18nConstants.EXTENSION_EXT_VERSION_INVALID, url, xverVersion(url)); + break; + case Unknown: + rule(errors, IssueType.INVALID, element.line(), element.col(), path + "[url='" + url + "']", false, I18nConstants.EXTENSION_EXT_VERSION_INVALIDID, url, xverElementId(url)); + break; + case Invalid: + rule(errors, IssueType.INVALID, element.line(), element.col(), path + "[url='" + url + "']", false, I18nConstants.EXTENSION_EXT_VERSION_NOCHANGE, url, xverElementId(url)); + break; + case Valid: + StructureDefinition ex = xverDefn(url); + context.generateSnapshot(ex); + context.cacheResource(ex); + return ex; + default: + rule(errors, IssueType.INVALID, element.line(), element.col(), path + "[url='" + url + "']", false, I18nConstants.EXTENSION_EXT_VERSION_INTERNAL, url); + break; + } + } + return null; + } } \ No newline at end of file diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java index 73252e246..b64e79031 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/ValidationEngine.java @@ -1564,7 +1564,7 @@ public class ValidationEngine implements IValidatorResourceFetcher, IPackageInst } public InstanceValidator getValidator() { - InstanceValidator validator = new InstanceValidator(context, null); + InstanceValidator validator = new InstanceValidator(context, null, null); validator.setHintAboutNonMustSupport(hintAboutNonMustSupport); validator.setAnyExtensionsAllowed(anyExtensionsAllowed); validator.setNoInvariantChecks(isNoInvariantChecks()); diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/codesystem/CodeSystemValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/codesystem/CodeSystemValidator.java index 92c2a953e..ed17a1208 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/codesystem/CodeSystemValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/codesystem/CodeSystemValidator.java @@ -39,14 +39,15 @@ import java.util.Set; import org.hl7.fhir.r5.context.IWorkerContext; import org.hl7.fhir.r5.model.CodeSystem; import org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent; +import org.hl7.fhir.r5.utils.XVerExtensionManager; import org.hl7.fhir.utilities.validation.ValidationMessage; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType; import org.hl7.fhir.validation.BaseValidator; public class CodeSystemValidator extends BaseValidator { - public CodeSystemValidator(IWorkerContext context) { - super(context); + public CodeSystemValidator(IWorkerContext context, XVerExtensionManager xverManager) { + super(context, xverManager); } public List validate(CodeSystem cs, boolean forBuild) { diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java index cab9910dd..0b4c397ab 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidator.java @@ -368,7 +368,6 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat private EnableWhenEvaluator myEnableWhenEvaluator = new EnableWhenEvaluator(); private String executionId; - private XVerExtensionManager xverManager; private IValidationProfileUsageTracker tracker; private ValidatorHostServices validatorServices; private boolean assumeValidRestReferences; @@ -380,8 +379,8 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat private boolean validateValueSetCodesOnTxServer = true; private QuestionnaireMode questionnaireMode; - public InstanceValidator(IWorkerContext theContext, IEvaluationContext hostServices) { - super(theContext); + public InstanceValidator(IWorkerContext theContext, IEvaluationContext hostServices, XVerExtensionManager xverManager) { + super(theContext, xverManager); this.externalHostServices = hostServices; this.profileUtilities = new ProfileUtilities(theContext, null, null); fpe = new FHIRPathEngine(context); @@ -1504,30 +1503,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat StructureDefinition ex = Utilities.isAbsoluteUrl(url) ? context.fetchResource(StructureDefinition.class, url) : null; timeTracker.sd(t); if (ex == null) { - if (xverManager == null) { - xverManager = new XVerExtensionManager(context); - } - if (xverManager.matchingUrl(url)) { - switch (xverManager.status(url)) { - case BadVersion: - rule(errors, IssueType.INVALID, element.line(), element.col(), path + "[url='" + url + "']", false, I18nConstants.EXTENSION_EXT_VERSION_INVALID, url, xverManager.getVersion(url)); - break; - case Unknown: - rule(errors, IssueType.INVALID, element.line(), element.col(), path + "[url='" + url + "']", false, I18nConstants.EXTENSION_EXT_VERSION_INVALIDID, url, xverManager.getElementId(url)); - break; - case Invalid: - rule(errors, IssueType.INVALID, element.line(), element.col(), path + "[url='" + url + "']", false, I18nConstants.EXTENSION_EXT_VERSION_NOCHANGE, url, xverManager.getElementId(url)); - break; - case Valid: - ex = xverManager.makeDefinition(url); - context.generateSnapshot(ex); - context.cacheResource(ex); - break; - default: - rule(errors, IssueType.INVALID, element.line(), element.col(), path + "[url='" + url + "']", false, I18nConstants.EXTENSION_EXT_VERSION_INTERNAL, url); - break; - } - } else if (extensionUrl != null && !isAbsolute(url)) { + ex = getXverExt(errors, path, element, url); + } + if (ex == null) { + if (extensionUrl != null && !isAbsolute(url)) { if (extensionUrl.equals(profile.getUrl())) { rule(errors, IssueType.INVALID, element.line(), element.col(), path + "[url='" + url + "']", hasExtensionSlice(profile, url), I18nConstants.EXTENSION_EXT_SUBEXTENSION_INVALID, url, profile.getUrl()); } @@ -1568,6 +1547,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat return ex; } + private boolean hasExtensionSlice(StructureDefinition profile, String sliceName) { for (ElementDefinition ed : profile.getSnapshot().getElement()) { @@ -1951,7 +1931,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat boolean found; try { found = isDefinitionURL(url) || (allowExamples && (url.contains("example.org") || url.contains("acme.com")) || url.contains("acme.org")) || (url.startsWith("http://hl7.org/fhir/tools")) || fetcher.resolveURL(appContext, path, url) || - SpecialExtensions.isKnownExtension(url); + SpecialExtensions.isKnownExtension(url) || isXverUrl(url); } catch (IOException e1) { found = false; } @@ -3889,27 +3869,27 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat public void checkSpecials(ValidatorHostContext hostContext, List errors, Element element, NodeStack stack, boolean checkSpecials) { // specific known special validations if (element.getType().equals(BUNDLE)) { - new BundleValidator(context, serverBase, this).validateBundle(errors, element, stack, checkSpecials, hostContext); + new BundleValidator(context, serverBase, this, xverManager).validateBundle(errors, element, stack, checkSpecials, hostContext); } else if (element.getType().equals("Observation")) { validateObservation(errors, element, stack); } else if (element.getType().equals("Questionnaire")) { - new QuestionnaireValidator(context, myEnableWhenEvaluator, fpe, timeTracker, questionnaireMode).validateQuestionannaire(errors, element, element, stack); + new QuestionnaireValidator(context, myEnableWhenEvaluator, fpe, timeTracker, questionnaireMode, xverManager).validateQuestionannaire(errors, element, element, stack); } else if (element.getType().equals("QuestionnaireResponse")) { - new QuestionnaireValidator(context, myEnableWhenEvaluator, fpe, timeTracker, questionnaireMode).validateQuestionannaireResponse(hostContext, errors, element, stack); + new QuestionnaireValidator(context, myEnableWhenEvaluator, fpe, timeTracker, questionnaireMode, xverManager).validateQuestionannaireResponse(hostContext, errors, element, stack); } else if (element.getType().equals("Measure")) { - new MeasureValidator(context, timeTracker).validateMeasure(hostContext, errors, element, stack); + new MeasureValidator(context, timeTracker, xverManager).validateMeasure(hostContext, errors, element, stack); } else if (element.getType().equals("MeasureReport")) { - new MeasureValidator(context, timeTracker).validateMeasureReport(hostContext, errors, element, stack); + new MeasureValidator(context, timeTracker, xverManager).validateMeasureReport(hostContext, errors, element, stack); } else if (element.getType().equals("CapabilityStatement")) { validateCapabilityStatement(errors, element, stack); } else if (element.getType().equals("CodeSystem")) { - new CodeSystemValidator(context, timeTracker).validateCodeSystem(errors, element, stack); + new CodeSystemValidator(context, timeTracker, xverManager).validateCodeSystem(errors, element, stack); } else if (element.getType().equals("SearchParameter")) { - new SearchParameterValidator(context, timeTracker, fpe).validateSearchParameter(errors, element, stack); + new SearchParameterValidator(context, timeTracker, fpe, xverManager).validateSearchParameter(errors, element, stack); } else if (element.getType().equals("StructureDefinition")) { - new StructureDefinitionValidator(context, timeTracker, fpe, wantCheckSnapshotUnchanged).validateStructureDefinition(errors, element, stack); + new StructureDefinitionValidator(context, timeTracker, fpe, wantCheckSnapshotUnchanged, xverManager).validateStructureDefinition(errors, element, stack); } else if (element.getType().equals("ValueSet")) { - new ValueSetValidator(context, timeTracker, this).validateValueSet(errors, element, stack); + new ValueSetValidator(context, timeTracker, this, xverManager).validateValueSet(errors, element, stack); } } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidatorFactory.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidatorFactory.java index 518a0dc1c..d51487f6e 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidatorFactory.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/InstanceValidatorFactory.java @@ -36,12 +36,18 @@ import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r5.context.IWorkerContext; import org.hl7.fhir.r5.context.SimpleWorkerContext.IValidatorFactory; import org.hl7.fhir.r5.utils.IResourceValidator; +import org.hl7.fhir.r5.utils.XVerExtensionManager; public class InstanceValidatorFactory implements IValidatorFactory { + @Override + public IResourceValidator makeValidator(IWorkerContext ctxt, XVerExtensionManager xverManager) throws FHIRException { + return new InstanceValidator(ctxt, null, xverManager); + } + @Override public IResourceValidator makeValidator(IWorkerContext ctxt) throws FHIRException { - return new InstanceValidator(ctxt, null); + return new InstanceValidator(ctxt, null, null); } } \ No newline at end of file diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/BundleValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/BundleValidator.java index 7794339d1..187c3a632 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/BundleValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/BundleValidator.java @@ -13,6 +13,7 @@ import org.hl7.fhir.r5.elementmodel.Element; import org.hl7.fhir.r5.model.Constants; import org.hl7.fhir.r5.model.Enumerations.FHIRVersion; import org.hl7.fhir.r5.model.StructureDefinition; +import org.hl7.fhir.r5.utils.XVerExtensionManager; import org.hl7.fhir.r5.utils.IResourceValidator.BundleValidationRule; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.VersionUtilities; @@ -31,8 +32,8 @@ public class BundleValidator extends BaseValidator{ private String serverBase; private InstanceValidator validator; - public BundleValidator(IWorkerContext context, String serverBase, InstanceValidator validator) { - super(context); + public BundleValidator(IWorkerContext context, String serverBase, InstanceValidator validator, XVerExtensionManager xverManager) { + super(context, xverManager); this.serverBase = serverBase; this.validator = validator; } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/CodeSystemValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/CodeSystemValidator.java index 06d5b5d2a..2a1a750fc 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/CodeSystemValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/CodeSystemValidator.java @@ -6,6 +6,7 @@ import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r5.context.IWorkerContext; import org.hl7.fhir.r5.elementmodel.Element; import org.hl7.fhir.r5.model.ValueSet; +import org.hl7.fhir.r5.utils.XVerExtensionManager; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.validation.ValidationMessage; @@ -17,8 +18,8 @@ import org.hl7.fhir.validation.instance.utils.NodeStack; public class CodeSystemValidator extends BaseValidator { - public CodeSystemValidator(IWorkerContext context, TimeTracker timeTracker) { - super(context); + public CodeSystemValidator(IWorkerContext context, TimeTracker timeTracker, XVerExtensionManager xverManager) { + super(context, xverManager); source = Source.InstanceValidator; this.timeTracker = timeTracker; } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/MeasureValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/MeasureValidator.java index ad12b1f2f..20280b917 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/MeasureValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/MeasureValidator.java @@ -26,6 +26,7 @@ import org.hl7.fhir.r5.model.Measure.MeasureGroupPopulationComponent; import org.hl7.fhir.r5.model.Measure.MeasureGroupStratifierComponent; import org.hl7.fhir.r5.model.Resource; import org.hl7.fhir.r5.renderers.DataRenderer; +import org.hl7.fhir.r5.utils.XVerExtensionManager; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.validation.ValidationMessage; @@ -40,8 +41,8 @@ import org.w3c.dom.Document; public class MeasureValidator extends BaseValidator { - public MeasureValidator(IWorkerContext context, TimeTracker timeTracker) { - super(context); + public MeasureValidator(IWorkerContext context, TimeTracker timeTracker, XVerExtensionManager xverManager) { + super(context, xverManager); source = Source.InstanceValidator; this.timeTracker = timeTracker; } diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/QuestionnaireValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/QuestionnaireValidator.java index 88f0521bf..5d28a4f52 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/QuestionnaireValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/QuestionnaireValidator.java @@ -35,6 +35,7 @@ import org.hl7.fhir.r5.model.StringType; import org.hl7.fhir.r5.model.TimeType; import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.utils.FHIRPathEngine; +import org.hl7.fhir.r5.utils.XVerExtensionManager; import org.hl7.fhir.utilities.CommaSeparatedStringBuilder; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.i18n.I18nConstants; @@ -58,8 +59,8 @@ public class QuestionnaireValidator extends BaseValidator { private FHIRPathEngine fpe; private QuestionnaireMode questionnaireMode; - public QuestionnaireValidator(IWorkerContext context, EnableWhenEvaluator myEnableWhenEvaluator, FHIRPathEngine fpe, TimeTracker timeTracker, QuestionnaireMode questionnaireMode) { - super(context); + public QuestionnaireValidator(IWorkerContext context, EnableWhenEvaluator myEnableWhenEvaluator, FHIRPathEngine fpe, TimeTracker timeTracker, QuestionnaireMode questionnaireMode, XVerExtensionManager xverManager) { + super(context, xverManager); source = Source.InstanceValidator; this.myEnableWhenEvaluator = myEnableWhenEvaluator; this.fpe = fpe; diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/SearchParameterValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/SearchParameterValidator.java index 669f9646e..b67e7a0a9 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/SearchParameterValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/SearchParameterValidator.java @@ -12,6 +12,7 @@ import org.hl7.fhir.r5.model.ExpressionNode.Kind; import org.hl7.fhir.r5.model.ExpressionNode.Operation; import org.hl7.fhir.r5.model.SearchParameter; import org.hl7.fhir.r5.utils.FHIRPathEngine; +import org.hl7.fhir.r5.utils.XVerExtensionManager; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.validation.ValidationMessage; @@ -34,8 +35,8 @@ public class SearchParameterValidator extends BaseValidator { private FHIRPathEngine fpe; - public SearchParameterValidator(IWorkerContext context, TimeTracker timeTracker, FHIRPathEngine fpe) { - super(context); + public SearchParameterValidator(IWorkerContext context, TimeTracker timeTracker, FHIRPathEngine fpe, XVerExtensionManager xverManager) { + super(context, xverManager); source = Source.InstanceValidator; this.fpe = fpe; this.timeTracker = timeTracker; diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java index 0f8de3f63..c26ab2078 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java @@ -23,6 +23,7 @@ import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule; import org.hl7.fhir.r5.utils.FHIRPathEngine; import org.hl7.fhir.r5.utils.ToolingExtensions; +import org.hl7.fhir.r5.utils.XVerExtensionManager; import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.validation.ValidationMessage; @@ -46,8 +47,8 @@ public class StructureDefinitionValidator extends BaseValidator { private FHIRPathEngine fpe; private boolean wantCheckSnapshotUnchanged; - public StructureDefinitionValidator(IWorkerContext context, TimeTracker timeTracker, FHIRPathEngine fpe, boolean wantCheckSnapshotUnchanged) { - super(context); + public StructureDefinitionValidator(IWorkerContext context, TimeTracker timeTracker, FHIRPathEngine fpe, boolean wantCheckSnapshotUnchanged, XVerExtensionManager xverManager) { + super(context, xverManager); source = Source.InstanceValidator; this.fpe = fpe; this.timeTracker = timeTracker; @@ -66,6 +67,7 @@ public class StructureDefinitionValidator extends BaseValidator { if (sd.getDerivation() == TypeDerivationRule.CONSTRAINT) { List msgs = new ArrayList<>(); ProfileUtilities pu = new ProfileUtilities(context, msgs, null); + pu.setXver(xverManager); pu.generateSnapshot(base, sd, sd.getUrl(), "http://hl7.org/fhir", sd.getName()); if (msgs.size() > 0) { for (ValidationMessage msg : msgs) { @@ -160,6 +162,9 @@ public class StructureDefinitionValidator extends BaseValidator { private void validateTypeProfile(List errors, Element profile, String code, NodeStack stack) { String p = profile.primitiveValue(); StructureDefinition sd = context.fetchResource(StructureDefinition.class, p); + if (sd == null ) { + sd = getXverExt(errors, stack.getLiteralPath(), profile, p); + } if (warning(errors, IssueType.EXCEPTION, stack.getLiteralPath(), sd != null, I18nConstants.SD_ED_TYPE_PROFILE_UNKNOWN, p)) { String t = determineBaseType(sd); if (t == null) { diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/ValueSetValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/ValueSetValidator.java index 7ce5a8f71..5a081dde6 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/ValueSetValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/ValueSetValidator.java @@ -11,6 +11,7 @@ import org.hl7.fhir.r5.model.Coding; import org.hl7.fhir.r5.model.Resource; import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.terminologies.ValueSetExpander.TerminologyServiceErrorClass; +import org.hl7.fhir.r5.utils.XVerExtensionManager; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.VersionUtilities; import org.hl7.fhir.utilities.i18n.I18nConstants; @@ -42,8 +43,8 @@ public class ValueSetValidator extends BaseValidator { private InstanceValidator parent; - public ValueSetValidator(IWorkerContext context, TimeTracker timeTracker, InstanceValidator parent) { - super(context); + public ValueSetValidator(IWorkerContext context, TimeTracker timeTracker, InstanceValidator parent, XVerExtensionManager xverManager) { + super(context, xverManager); source = Source.InstanceValidator; this.timeTracker = timeTracker; this.parent = parent; diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/profile/ProfileValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/profile/ProfileValidator.java index a804b5243..db156622d 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/profile/ProfileValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/profile/ProfileValidator.java @@ -40,7 +40,9 @@ import org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintCompon import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent; import org.hl7.fhir.r5.model.StructureDefinition; import org.hl7.fhir.r5.utils.FHIRPathEngine; +import org.hl7.fhir.r5.utils.XVerExtensionManager; import org.hl7.fhir.utilities.Utilities; +import org.hl7.fhir.utilities.i18n.I18nConstants; import org.hl7.fhir.utilities.validation.ValidationMessage; import org.hl7.fhir.utilities.validation.ValidationMessage.IssueType; import org.hl7.fhir.validation.BaseValidator; @@ -50,8 +52,8 @@ public class ProfileValidator extends BaseValidator { private boolean checkAggregation = false; private boolean checkMustSupport = false; - public ProfileValidator(IWorkerContext context) { - super(context); + public ProfileValidator(IWorkerContext context, XVerExtensionManager xverManager) { + super(context, xverManager); } public boolean isCheckAggregation() { @@ -138,7 +140,12 @@ public class ProfileValidator extends BaseValidator { if (!ec.getType().isEmpty() && "Extension".equals(ec.getType().get(0).getWorkingCode()) && ec.getType().get(0).hasProfile()) { String url = ec.getType().get(0).getProfile().get(0).getValue(); StructureDefinition defn = context.fetchResource(StructureDefinition.class, url); + if (defn == null) { + defn = getXverExt(profile, errors, url); + } rule(errors, IssueType.BUSINESSRULE, profile.getId(), defn != null, "Unable to find Extension '"+url+"' referenced at "+profile.getUrl()+" "+kind+" "+ec.getPath()+" ("+ec.getSliceName()+")"); } } + + } \ No newline at end of file