Fix to use derived element cardinality not element base cardinality when elementdefinition-json-name is present

This commit is contained in:
Grahame Grieve 2024-11-05 20:58:26 +10:30
parent 6b0175ed38
commit 31764fc016
2 changed files with 15 additions and 2 deletions

View File

@ -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);

View File

@ -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());
}