From 1f6912d3a6adbcc4c162589625a1bc6034407fef Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sat, 8 Jul 2023 16:44:50 +1000 Subject: [PATCH] fix issue checking invariant expressions in R5 --- .../type/StructureDefinitionValidator.java | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java index 63b978c42..1f950a540 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/StructureDefinitionValidator.java @@ -485,23 +485,25 @@ public class StructureDefinitionValidator extends BaseValidator { String source = invariant.getNamedChildValue("source"); if (warning(errors, "2023-06-19", IssueType.INFORMATIONAL, stack, !Utilities.noString(key), I18nConstants.ED_INVARIANT_NO_KEY)) { if (hint(errors, "2023-06-19", IssueType.INFORMATIONAL, stack, !Utilities.noString(expression) || VersionUtilities.isR5Plus(context.getVersion()), I18nConstants.ED_INVARIANT_NO_EXPRESSION, key)) { // not for R5 - there's an invariant - if (invariantMap.containsKey(key)) { - // it's legal - and common - for a list of elemnts to contain the same invariant more than once, but it's not valid if it's not always the same - ok = rule(errors, "2023-06-19", IssueType.INVALID, stack, expression.equals(invariantMap.get(key)) || "ele-1".equals(key), I18nConstants.ED_INVARIANT_EXPRESSION_CONFLICT, key, expression, invariantMap.get(key)); - } else { - invariantMap.put(key, expression); + if (!Utilities.noString(expression)) { + if (invariantMap.containsKey(key)) { + // it's legal - and common - for a list of elemnts to contain the same invariant more than once, but it's not valid if it's not always the same + ok = rule(errors, "2023-06-19", IssueType.INVALID, stack, expression.equals(invariantMap.get(key)) || "ele-1".equals(key), I18nConstants.ED_INVARIANT_EXPRESSION_CONFLICT, key, expression, invariantMap.get(key)); + } else { + invariantMap.put(key, expression); + } + if (Utilities.noString(source) || (source.equals(profileUrl))) { // no need to revalidate FHIRPath from elsewhere + try { + // String upath = profileUrl+"#"+path; + fpe.check(invariant, rootPath, path, fpe.parse(expression)); + } catch (Exception e) { + if (debug) { + e.printStackTrace(); + } + ok = rule(errors, "2023-06-19", IssueType.INVALID, stack, false, I18nConstants.ED_INVARIANT_EXPRESSION_ERROR, key, expression, e.getMessage()) && ok; + } + } } - if (Utilities.noString(source) || (source.equals(profileUrl))) { // no need to revalidate FHIRPath from elsewhere - try { -// String upath = profileUrl+"#"+path; - fpe.check(invariant, rootPath, path, fpe.parse(expression)); - } catch (Exception e) { - if (debug) { - e.printStackTrace(); - } - ok = rule(errors, "2023-06-19", IssueType.INVALID, stack, false, I18nConstants.ED_INVARIANT_EXPRESSION_ERROR, key, expression, e.getMessage()) && ok; - } - } } } return ok;