Merge pull request #45 from lmckenzi/bad-bundle-reference-types

Bad bundle reference types
This commit is contained in:
Grahame Grieve 2019-06-08 05:26:50 +10:00 committed by GitHub
commit 299014c606
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 5 deletions

View File

@ -1810,10 +1810,10 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
if (we == null) { if (we == null) {
refType = "remote"; refType = "remote";
} else { } 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 (pol.checkExists()) {
if (we == null) { if (we == null) {
@ -2182,6 +2182,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
private Element getFromBundle(Element bundle, String ref, String fullUrl, List<ValidationMessage> errors, String path, String type) { private Element getFromBundle(Element bundle, String ref, String fullUrl, List<ValidationMessage> errors, String path, String type) {
String targetUrl = null; String targetUrl = null;
String version = ""; String version = "";
String resourceType = null;
if (ref.startsWith("http") || ref.startsWith("urn")) { if (ref.startsWith("http") || ref.startsWith("urn")) {
// We've got an absolute reference, no need to calculate // We've got an absolute reference, no need to calculate
if (ref.contains("/_history/")) { if (ref.contains("/_history/")) {
@ -2218,10 +2219,13 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat
String id = null; String id = null;
if (ref.contains("/_history/")) { if (ref.contains("/_history/")) {
version = ref.substring(ref.indexOf("/_history/") + 10); version = ref.substring(ref.indexOf("/_history/") + 10);
id = ref.substring(0, ref.indexOf("/_history/")).split("/")[1]; String[] refBaseParts = ref.substring(0, ref.indexOf("/_history/")).split("/");
} else if (base.startsWith("urn")) resourceType = refBaseParts[0];
id = refBaseParts[1];
} else if (base.startsWith("urn")) {
resourceType = ref.split("/")[0];
id = ref.split("/")[1]; id = ref.split("/")[1];
else } else
id = ref; id = ref;
targetUrl = base + id; 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) if (match == null)
warning(errors, IssueType.REQUIRED, -1, -1, path, !ref.startsWith("urn"), "URN reference is not locally contained within the bundle " + ref); warning(errors, IssueType.REQUIRED, -1, -1, path, !ref.startsWith("urn"), "URN reference is not locally contained within the bundle " + ref);
return match; return match;

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bundle xmlns="http://hl7.org/fhir">
<type value="collection"/>
<entry>
<fullUrl value="urn:uuid:54fc3e09-e279-4b74-a8ff-2649ec968642"/>
<resource>
<Patient>
<generalPractitioner>
<reference value="Practitioner/5d9588d8-3cd6-4b32-8fb7-ad13694e069d"/>
</generalPractitioner>
</Patient>
</resource>
</entry>
<entry>
<fullUrl value="urn:uuid:5d9588d8-3cd6-4b32-8fb7-ad13694e069d"/>
<resource>
<Organization>
<name value="foo"/>
</Organization>
</resource>
</entry>
</Bundle>

View File

@ -746,6 +746,9 @@
"source": "multi-profile-same-resource-profile.xml", "source": "multi-profile-same-resource-profile.xml",
"errorCount": 0 "errorCount": 0
} }
},
"bad-bundle-reference-type.xml": {
"errorCount": 1
} }
} }
} }