From 31764fc0169ed2917a2991d4369b702698418235 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Tue, 5 Nov 2024 20:58:26 +1030 Subject: [PATCH] Fix to use derived element cardinality not element base cardinality when elementdefinition-json-name is present --- .../org/hl7/fhir/r5/elementmodel/JsonParser.java | 4 ++-- .../java/org/hl7/fhir/r5/elementmodel/Property.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java index c9ad7c052..94e28b8af 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/elementmodel/JsonParser.java @@ -504,7 +504,7 @@ public class JsonParser extends ParserBase { } } } else { - if (property.isList()) { + if (property.isJsonList()) { logError(errors, ValidationMessage.NO_RULE_DATE, line(e), col(e), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE_AN_ARRAY_NOT_, describe(e), name, path), IssueSeverity.ERROR); } parseChildComplexInstance(errors, npath, fpath, element, property, name, e, null, null, null); @@ -611,7 +611,7 @@ public class JsonParser extends ParserBase { logError(errors, "2022-11-26", line(main.getValue()), col(main.getValue()), path, IssueType.INVALID, context.formatMessage(I18nConstants.JSON_PROPERTY_VALUE_NO_QUOTES, main.getName(), main.getValue().asString()), IssueSeverity.ERROR); } if (main != null || fork != null) { - if (property.isList()) { + if (property.isJsonList()) { boolean ok = true; if (!(main == null || main.getValue() instanceof JsonArray)) { logError(errors, ValidationMessage.NO_RULE_DATE, line(main.getValue()), col(main.getValue()), npath, IssueType.INVALID, context.formatMessage(I18nConstants.THIS_PROPERTY_MUST_BE_AN_ARRAY_NOT_, describe(main.getValue()), name, path), IssueSeverity.ERROR); 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 84b23476a..ec7cf72d0 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 @@ -304,6 +304,19 @@ public class Property { return !"1".equals(definition.getBase().hasMax() ? definition.getBase().getMax() : definition.getMax()); } + /** + * This handles a very special case: An extension used with json extensions in CDS hooks, + * where the extension definition, not the base, decides whether it's an array or not + * @return + */ + public boolean isJsonList() { + if (definition.hasExtension("http://hl7.org/fhir/tools/StructureDefinition/elementdefinition-json-name")) { + return !"1".equals(definition.getMax()); + } else { + return !"1".equals(definition.getBase().hasMax() ? definition.getBase().getMax() : definition.getMax()); + } + } + public boolean isBaseList() { return !"1".equals(definition.getBase().getMax()); }