made unknown code system error severity config work #7194
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#closes #7196
Description
This PR addresses a bug where validating a resource with an unknown CodeSystem fails to produce any validation issues, even when the UnknownCodeSystem issue severity is set to ERROR.
Root Cause
The main issue was that none of ValidationSupport classes were returning a validation result for unknown code systems. The UnknownCodeSystemWarningValidationSupport class, whose purpose is to generate these issues, was skipping the creation of an issue if the severity was set to ERROR, but would correctly produce an issue if the severity was set to WARNING.
It appears this feature may have never worked as intended. The existing validation tests were also not expecting any ERROR level issues and were, in fact, incorrectly asserting that no issues would be produced when the severity was set to ERROR.
Changes in this PR
This PR makes two key improvements: it corrects the behavior of UnknownCodeSystemWarningValidationSupport to properly handle error cases, and it refines the ValidationSupport interface to align with the unique role of UnknownCodeSystemWarningValidationSupport.
1. The
UnknownCodeSystemWarningValidationSupport
class now produces a validation issue with the configured severity if there's an unknown code system2. A new method,
canGenerateValidationResultForCodeSystem
, has been added to theValidationSupport
interface.The
UnknownCodeSystemWarningValidationSupport
class is not a true ValidationSupport class as it cannot actually validate a code system. However, to ensure it was called at the end of the validation chain, it was "abusing" theValidationSupport
interface by returningtrue
forisSupportedCodeSystem
, which would mislead the core validator.This had the unintended effect of causing the core library to follow a different code path for the same resource when validated through the CLI versus HAPI-FHIR because core validator also calls isSupportedCodeSystem itself in several places through
context.supportsSystem
, see for example src1, src2To improve this discrepancy, the new
canGenerateValidationResultForCodeSystem
method is now called in the validation chain.UnknownCodeSystemWarningValidationSupport
will returntrue
for this new method (since it can generate a result) but will now correctly returnfalse
forisSupportedCodeSystem
. This ensures the core validator is not misled while still allowing theUnknownCodeSystemWarningValidationSupport
to be properly invoked. For all the other existing ValidationSupport classescanGenerateValidationResultForCodeSystem
behaves the same asisSupportedCodeSystem
.Outstanding Issue
Even though this PR attempts to fix the issue on the HAPI-FHIR side, this is not enough to generate error level issues in all cases. There is still an outstanding question for the core validator. The core validator has its own logic (src) for determining the severity of an issue for an unknown CodeSystem, which is based on the binding strength. It will ignore the error severity set by HAPI-FHIR. It produces errors only when binding strength is REQUIRED. For any other binding strength, it assigns a warning severity be default. See the issue on the core validator: hapifhir/org.hl7.fhir.core#2129. So currently we are able to produce an error level issue only for a REQUIRED binding.
Future Work
I believe a better long-term solution would be to move the logic of
UnknownCodeSystemWarningValidationSupport
somewhere eles, maybe into the validation chain or to the wrapper, rather than trying to make it conform to theValidationSupport
interface. However, since this would require a larger refactoring, I am leaving that for a future PR.