From f44bb526c276d5b2d96181086f6441735578a95f Mon Sep 17 00:00:00 2001 From: Lloyd McKenzie Date: Wed, 5 Jun 2019 20:38:00 -0400 Subject: [PATCH] Fixed problem with inconsistent values for refTypes Check that when referencing resources by type/id when the target has a urn:uuid fullUrl that the type matches as well as the id. --- .../fhir/r5/validation/InstanceValidator.java | 16 +++++++++----- .../bad-bundle-reference-type.xml | 22 +++++++++++++++++++ .../validation-examples/manifest.json | 3 +++ 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 org.hl7.fhir.validation/src/test/resources/validation-examples/bad-bundle-reference-type.xml diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/InstanceValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/InstanceValidator.java index cdca3461d..3c21ea9d3 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/InstanceValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/r5/validation/InstanceValidator.java @@ -1810,10 +1810,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat if (we == null) { refType = "remote"; } else { - refType = "bundle"; + refType = "bundled"; } } - ReferenceValidationPolicy pol = refType.equals("contained") || refType.equals("bundle") ? ReferenceValidationPolicy.CHECK_VALID : fetcher == null ? ReferenceValidationPolicy.IGNORE : fetcher.validationPolicy(hostContext.appContext, path, ref); + ReferenceValidationPolicy pol = refType.equals("contained") || refType.equals("bundled") ? ReferenceValidationPolicy.CHECK_VALID : fetcher == null ? ReferenceValidationPolicy.IGNORE : fetcher.validationPolicy(hostContext.appContext, path, ref); if (pol.checkExists()) { if (we == null) { @@ -2182,6 +2182,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat private Element getFromBundle(Element bundle, String ref, String fullUrl, List errors, String path, String type) { String targetUrl = null; String version = ""; + String resourceType = null; if (ref.startsWith("http") || ref.startsWith("urn")) { // We've got an absolute reference, no need to calculate if (ref.contains("/_history/")) { @@ -2218,10 +2219,13 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat String id = null; if (ref.contains("/_history/")) { version = ref.substring(ref.indexOf("/_history/") + 10); - id = ref.substring(0, ref.indexOf("/_history/")).split("/")[1]; - } else if (base.startsWith("urn")) + String[] refBaseParts = ref.substring(0, ref.indexOf("/_history/")).split("/"); + resourceType = refBaseParts[0]; + id = refBaseParts[1]; + } else if (base.startsWith("urn")) { + resourceType = ref.split("/")[0]; id = ref.split("/")[1]; - else + } else id = ref; targetUrl = base + id; @@ -2250,6 +2254,8 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat } } + if (match!=null && resourceType!=null) + rule(errors, IssueType.REQUIRED, -1, -1, path, match.getType().equals(resourceType), "Matching reference for reference " + ref + " has resourceType " + match.getType()); if (match == null) warning(errors, IssueType.REQUIRED, -1, -1, path, !ref.startsWith("urn"), "URN reference is not locally contained within the bundle " + ref); return match; diff --git a/org.hl7.fhir.validation/src/test/resources/validation-examples/bad-bundle-reference-type.xml b/org.hl7.fhir.validation/src/test/resources/validation-examples/bad-bundle-reference-type.xml new file mode 100644 index 000000000..9c4b97872 --- /dev/null +++ b/org.hl7.fhir.validation/src/test/resources/validation-examples/bad-bundle-reference-type.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.hl7.fhir.validation/src/test/resources/validation-examples/manifest.json b/org.hl7.fhir.validation/src/test/resources/validation-examples/manifest.json index d84f9a365..f53f1664e 100644 --- a/org.hl7.fhir.validation/src/test/resources/validation-examples/manifest.json +++ b/org.hl7.fhir.validation/src/test/resources/validation-examples/manifest.json @@ -746,6 +746,9 @@ "source": "multi-profile-same-resource-profile.xml", "errorCount": 0 } + }, + "bad-bundle-reference-type.xml": { + "errorCount": 1 } } }