From 3e5fadecb0ffc5214836bd7af3d2903e88bc7383 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Wed, 2 Oct 2019 14:51:43 +1000 Subject: [PATCH] fix issues validating resources with references --- .../fhir/r5/validation/ValidationEngine.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java index 6d9c1d4be..c49bc65bf 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/ValidationEngine.java @@ -103,6 +103,7 @@ import org.hl7.fhir.convertors.VersionConvertor_30_50; import org.hl7.fhir.convertors.VersionConvertor_40_50; import org.hl7.fhir.exceptions.DefinitionException; import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.exceptions.FHIRFormatError; import org.hl7.fhir.r5.conformance.ProfileUtilities; import org.hl7.fhir.r5.context.SimpleWorkerContext; import org.hl7.fhir.r5.context.SimpleWorkerContext.IContextResourceLoader; @@ -134,7 +135,9 @@ import org.hl7.fhir.r5.model.StructureMap; import org.hl7.fhir.r5.terminologies.ConceptMapEngine; import org.hl7.fhir.r5.utils.IResourceValidator.BestPracticeWarningLevel; import org.hl7.fhir.r5.utils.IResourceValidator.CheckDisplayOption; +import org.hl7.fhir.r5.utils.IResourceValidator.IValidatorResourceFetcher; import org.hl7.fhir.r5.utils.IResourceValidator.IdStatus; +import org.hl7.fhir.r5.utils.IResourceValidator.ReferenceValidationPolicy; import org.hl7.fhir.r5.utils.FHIRPathEngine; import org.hl7.fhir.r5.utils.NarrativeGenerator; import org.hl7.fhir.r5.utils.OperationOutcomeUtilities; @@ -201,7 +204,7 @@ import org.xml.sax.SAXException; * @author Grahame Grieve * */ -public class ValidationEngine { +public class ValidationEngine implements IValidatorResourceFetcher { public class ScanOutputItem { private String ref; @@ -1282,6 +1285,7 @@ public class ValidationEngine { validator.setAnyExtensionsAllowed(anyExtensionsAllowed); validator.setNoInvariantChecks(isNoInvariantChecks()); validator.setValidationLanguage(language); + validator.setFetcher(this); return validator; } @@ -1557,5 +1561,26 @@ public class ValidationEngine { return names; } + @Override + public Element fetch(Object appContext, String url) throws FHIRFormatError, DefinitionException, FHIRException, IOException { + return null; + } + + @Override + public ReferenceValidationPolicy validationPolicy(Object appContext, String path, String url) { + if (!url.startsWith("http://hl7.org/fhir")) + return ReferenceValidationPolicy.IGNORE; + throw new Error("Not done yet"); + } + + @Override + public boolean resolveURL(Object appContext, String path, String url) throws IOException, FHIRException { + if (!url.startsWith("http://hl7.org/fhir")) + return true; // we don't bother with those. + if (context.fetchResource(Resource.class, url) != null) + return true; + throw new Error("Not done yet - resolve "+url); + } + }