From 28e7a191259aaeecc54ae1f8104d92295557347d Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Fri, 25 Sep 2020 15:00:10 +1000 Subject: [PATCH] Change warnings about invalid codes to hints in retired value sets --- .../org/hl7/fhir/validation/BaseValidator.java | 15 +++++++++++++++ .../instance/type/ValueSetValidator.java | 14 +++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/BaseValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/BaseValidator.java index c36db51d3..8e7b585a7 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/BaseValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/BaseValidator.java @@ -529,6 +529,21 @@ public class BaseValidator { return thePass; } + /** + * Test a rule and add a {@link IssueSeverity#WARNING} validation message if the validation fails + * + * @param thePass + * Set this parameter to false if the validation does not pass + * @return Returns thePass (in other words, returns true if the rule did not fail validation) + */ + protected boolean warningOrHint(List errors, IssueType type, String path, boolean thePass, boolean warning, String msg, Object... theMessageArguments) { + if (!thePass) { + String message = context.formatMessage(msg, theMessageArguments); + addValidationMessage(errors, type, -1, -1, path, message, warning ? IssueSeverity.WARNING : IssueSeverity.INFORMATION, null); + } + return thePass; + } + /** * Test a rule and add a {@link IssueSeverity#WARNING} validation message if the validation fails * diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/ValueSetValidator.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/ValueSetValidator.java index a10173f81..b3d4c0e3c 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/ValueSetValidator.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/instance/type/ValueSetValidator.java @@ -56,28 +56,28 @@ public class ValueSetValidator extends BaseValidator { List composes = vs.getChildrenByName("compose"); int cc = 0; for (Element compose : composes) { - validateValueSetCompose(errors, compose, stack.push(compose, cc, null, null), vs.getNamedChildValue("url")); + validateValueSetCompose(errors, compose, stack.push(compose, cc, null, null), vs.getNamedChildValue("url"), "retired".equals(vs.getNamedChildValue("url"))); cc++; } } } - private void validateValueSetCompose(List errors, Element compose, NodeStack stack, String vsid) { + private void validateValueSetCompose(List errors, Element compose, NodeStack stack, String vsid, boolean retired) { List includes = compose.getChildrenByName("include"); int ci = 0; for (Element include : includes) { - validateValueSetInclude(errors, include, stack.push(include, ci, null, null), vsid); + validateValueSetInclude(errors, include, stack.push(include, ci, null, null), vsid, retired); ci++; } List excludes = compose.getChildrenByName("exclude"); int ce = 0; for (Element exclude : excludes) { - validateValueSetInclude(errors, exclude, stack.push(exclude, ce, null, null), vsid); + validateValueSetInclude(errors, exclude, stack.push(exclude, ce, null, null), vsid, retired); ce++; } } - private void validateValueSetInclude(List errors, Element include, NodeStack stack, String vsid) { + private void validateValueSetInclude(List errors, Element include, NodeStack stack, String vsid, boolean retired) { String system = include.getChildValue("system"); String version = include.getChildValue("version"); List valuesets = include.getChildrenByName("valueSet"); @@ -125,9 +125,9 @@ public class ValueSetValidator extends BaseValidator { } for (VSCodingValidationRequest cv : batch) { if (version == null) { - warning(errors, IssueType.BUSINESSRULE, cv.getStack().getLiteralPath(), cv.getResult().isOk(), I18nConstants.VALUESET_INCLUDE_INVALID_CONCEPT_CODE, system, cv.getCoding().getCode()); + warningOrHint(errors, IssueType.BUSINESSRULE, cv.getStack().getLiteralPath(), cv.getResult().isOk(), !retired, I18nConstants.VALUESET_INCLUDE_INVALID_CONCEPT_CODE, system, cv.getCoding().getCode()); } else { - warning(errors, IssueType.BUSINESSRULE, cv.getStack().getLiteralPath(), cv.getResult().isOk(), I18nConstants.VALUESET_INCLUDE_INVALID_CONCEPT_CODE_VER, system, version, cv.getCoding().getCode()); + warningOrHint(errors, IssueType.BUSINESSRULE, cv.getStack().getLiteralPath(), cv.getResult().isOk(), !retired, I18nConstants.VALUESET_INCLUDE_INVALID_CONCEPT_CODE_VER, system, version, cv.getCoding().getCode()); } } }