From 3f9c87ab6355565f637610f3986b55858087c474 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sat, 5 Dec 2020 08:13:53 +1100 Subject: [PATCH] validation fixes (#397) * Fix validation issues for StructureDefinitions * Don't try to validate URLs outside HL7 space * Fix document rendering * fix failing tests --- .../hl7/fhir/r5/renderers/BundleRenderer.java | 2 +- .../services/StandAloneValidatorFetcher.java | 65 ++++++++++++++++++- pom.xml | 2 +- 3 files changed, 64 insertions(+), 5 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/BundleRenderer.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/BundleRenderer.java index 9d1a1f820..d27ee059a 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/BundleRenderer.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/renderers/BundleRenderer.java @@ -62,7 +62,7 @@ public class BundleRenderer extends ResourceRenderer { public boolean render(XhtmlNode x, ResourceWrapper b) throws FHIRFormatError, DefinitionException, IOException, FHIRException, EOperationOutcome { List entries = b.children("entry"); if ("document".equals(b.get("type").primitiveValue())) { - if (entries.isEmpty() || (entries.get(0).has("resource") && "Composition".equals(entries.get(0).get("resource").fhirType()))) + if (entries.isEmpty() || (entries.get(0).has("resource") && !"Composition".equals(entries.get(0).get("resource").fhirType()))) throw new FHIRException("Invalid document '"+b.getId()+"' - first entry is not a Composition ('"+entries.get(0).get("resource").fhirType()+"')"); return renderDocument(x, b, entries); } else if ("collection".equals(b.get("type").primitiveValue()) && allEntriesAreHistoryProvenance(entries)) { diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/StandAloneValidatorFetcher.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/StandAloneValidatorFetcher.java index a544230b8..a80b6789c 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/StandAloneValidatorFetcher.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/StandAloneValidatorFetcher.java @@ -78,7 +78,7 @@ public class StandAloneValidatorFetcher implements IValidatorResourceFetcher { String ver = null; String base = findBaseUrl(url); if (base == null) { - return false; + return !url.startsWith("http://hl7.org/fhir") && !type.equals("canonical"); } if (base.equals("http://terminology.hl7.org")) { @@ -89,7 +89,7 @@ public class StandAloneValidatorFetcher implements IValidatorResourceFetcher { pid = pcm.findCanonicalInLocalCache(base); } ver = url.contains("|") ? url.substring(url.indexOf("|")+1) : null; - if (pid == null) { + if (pid == null && Utilities.startsWithInList(url, "http://hl7.org/fhir", "http://terminology.hl7.org")) { return false; } @@ -113,7 +113,66 @@ public class StandAloneValidatorFetcher implements IValidatorResourceFetcher { // we don't bother with urls outside fhir space in the standalone validator - we assume they are valid - return !url.startsWith("http://hl7.org/fhir"); + return !url.startsWith("http://hl7.org/fhir") && !type.equals("canonical"); + } + + private boolean isMappingUri(String url) { + if (mappingsUris.isEmpty()) { + JsonObject json; + try { + json = JsonTrackingParser.fetchJson("http://hl7.org/fhir/mappingspaces.json"); + for (JsonObject ms : JSONUtil.objects(json, "spaces")) { + mappingsUris.add(JSONUtil.str(ms, "url")); + } + } catch (IOException e) { + // frozen R4 list + mappingsUris.add("http://hl7.org/fhir/fivews"); + mappingsUris.add("http://hl7.org/fhir/workflow"); + mappingsUris.add("http://hl7.org/fhir/interface"); + mappingsUris.add("http://hl7.org/v2"); + mappingsUris.add("http://loinc.org"); + mappingsUris.add("http://snomed.org/attributebinding"); + mappingsUris.add("http://snomed.info/conceptdomain"); + mappingsUris.add("http://hl7.org/v3/cda"); + mappingsUris.add("http://hl7.org/v3"); + mappingsUris.add("http://nema.org/dicom"); + mappingsUris.add("http://w3.org/vcard"); + mappingsUris.add("http://ihe.net/xds"); + mappingsUris.add("http://www.w3.org/ns/prov"); + mappingsUris.add("http://ietf.org/rfc/2445"); + mappingsUris.add("http://www.omg.org/spec/ServD/1.0/"); + mappingsUris.add("http://metadata-standards.org/11179/"); + mappingsUris.add("http://ihe.net/data-element-exchange"); + mappingsUris.add("http://openehr.org"); + mappingsUris.add("http://siframework.org/ihe-sdc-profile"); + mappingsUris.add("http://siframework.org/cqf"); + mappingsUris.add("http://www.cdisc.org/define-xml"); + mappingsUris.add("http://www.cda-adc.ca/en/services/cdanet/"); + mappingsUris.add("http://www.pharmacists.ca/"); + mappingsUris.add("http://www.healthit.gov/quality-data-model"); + mappingsUris.add("http://hl7.org/orim"); + mappingsUris.add("http://hl7.org/fhir/w5"); + mappingsUris.add("http://hl7.org/fhir/logical"); + mappingsUris.add("http://hl7.org/fhir/auditevent"); + mappingsUris.add("http://hl7.org/fhir/provenance"); + mappingsUris.add("http://hl7.org/qidam"); + mappingsUris.add("http://cap.org/ecc"); + mappingsUris.add("http://fda.gov/UDI"); + mappingsUris.add("http://hl7.org/fhir/object-implementation"); + mappingsUris.add("http://github.com/MDMI/ReferentIndexContent"); + mappingsUris.add("http://ncpdp.org/SCRIPT10_6"); + mappingsUris.add("http://clinicaltrials.gov"); + mappingsUris.add("http://hl7.org/fhir/rr"); + mappingsUris.add("http://www.hl7.org/v3/PORX_RM020070UV"); + mappingsUris.add("https://bridgmodel.nci.nih.gov"); + mappingsUris.add("http://hl7.org/fhir/composition"); + mappingsUris.add("http://hl7.org/fhir/documentreference"); + mappingsUris.add("https://en.wikipedia.org/wiki/Identification_of_medicinal_products"); + mappingsUris.add("urn:iso:std:iso:11073:10201"); + mappingsUris.add("urn:iso:std:iso:11073:10207"); + } + } + return mappingsUris.contains(url); } private boolean isMappingUri(String url) { diff --git a/pom.xml b/pom.xml index cb5180daf..dc140bec1 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ 5.1.0 - 1.1.55 + 1.1.56-SNAPSHOT 5.6.2 3.0.0-M4 0.8.5