From c6e68dc9c6dc41348d81ffee353107593a149f76 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 7 Jul 2023 09:38:55 +1000 Subject: [PATCH] Fixes to validator for new CDA package (proper handling of logical model types) --- .../java/org/hl7/fhir/r5/elementmodel/ParserBase.java | 9 +++++++-- .../main/java/org/hl7/fhir/r5/elementmodel/Property.java | 2 +- .../hl7/fhir/validation/instance/InstanceValidator.java | 4 ++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ParserBase.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ParserBase.java index 7b3d8ea55..1efa0984c 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ParserBase.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/ParserBase.java @@ -175,10 +175,11 @@ public abstract class ParserBase { } for (StructureDefinition sd : context.fetchResourcesByType(StructureDefinition.class)) { if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && !sd.getUrl().startsWith("http://hl7.org/fhir/StructureDefinition/de-")) { - if(name.equals(sd.getType()) && (ns == null || ns.equals(FormatUtilities.FHIR_NS)) && !ToolingExtensions.hasExtension(sd, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace")) + String type = urlTail(sd.getType()); + if(name.equals(type) && (ns == null || ns.equals(FormatUtilities.FHIR_NS)) && !ToolingExtensions.hasExtension(sd, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace")) return sd; String sns = ToolingExtensions.readStringExtension(sd, "http://hl7.org/fhir/StructureDefinition/elementdefinition-namespace"); - if ((name.equals(sd.getType()) || name.equals(sd.getName())) && ns != null && ns.equals(sns)) + if ((name.equals(type) || name.equals(sd.getName())) && ns != null && ns.equals(sns)) return sd; } } @@ -186,6 +187,10 @@ public abstract class ParserBase { return null; } + private String urlTail(String type) { + return type == null || !type.contains("/") ? type : type.substring(type.lastIndexOf("/")+1); + } + protected StructureDefinition getDefinition(int line, int col, String name) throws FHIRFormatError { if (name == null) { logError(ValidationMessage.NO_RULE_DATE, line, col, name, IssueType.STRUCTURE, context.formatMessage(I18nConstants.THIS_CANNOT_BE_PARSED_AS_A_FHIR_OBJECT_NO_NAME), IssueSeverity.FATAL); diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Property.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Property.java index f5dbd145a..2329daca8 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Property.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/Property.java @@ -373,7 +373,7 @@ public class Property { ok = true; if (Utilities.isAbsoluteUrl(tr.getWorkingCode())) { StructureDefinition sdt = context.fetchResource(StructureDefinition.class, tr.getWorkingCode()); - if (sdt != null && sdt.getType().equals(t)) { + if (sdt != null && sdt.getTypeTail().equals(t)) { url = tr.getWorkingCode(); ok = true; } 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 e5832ff08..088805293 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 @@ -3968,7 +3968,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat long t = System.nanoTime(); StructureDefinition sd = context.fetchResource(StructureDefinition.class, url, src); timeTracker.sd(t); - if (sd != null && (sd.getType().equals(type) || sd.getUrl().equals(type)) && sd.hasSnapshot()) { + if (sd != null && (sd.getTypeTail().equals(type) || sd.getUrl().equals(type)) && sd.hasSnapshot()) { return sd; } if (sd.getAbstract()) { @@ -6334,7 +6334,7 @@ public class InstanceValidator extends BaseValidator implements IResourceValidat } } // validate - if (rule(errors, NO_RULE_DATE, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), resourceName.equals(defn.getType()), I18nConstants.VALIDATION_VAL_PROFILE_WRONGTYPE, + if (rule(errors, NO_RULE_DATE, IssueType.INVALID, element.line(), element.col(), stack.getLiteralPath(), resourceName.equals(defn.getTypeTail()), I18nConstants.VALIDATION_VAL_PROFILE_WRONGTYPE, defn.getType(), resourceName, defn.getVersionedUrl())) { ok = start(hostContext, errors, element, element, defn, stack, pct, mode); // root is both definition and type } else {