From 1478abac3ab3e95335648f77cf1f3ec934c47022 Mon Sep 17 00:00:00 2001 From: TipzCM Date: Fri, 12 Nov 2021 15:13:42 -0500 Subject: [PATCH] 3164 updating code review points (#3165) * 3164 updating code review points * 3164 updating code review points Co-authored-by: leif stawnyczy --- ...warnings-to-be-registered-as-warnings.yaml | 1 + .../dao/r4/FhirResourceDaoR4ValidateTest.java | 46 ++++++++++++++++++- ...ownCodeSystemWarningValidationSupport.java | 16 +++++-- 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_7_0/3153-updating-unknowncodesystem-to-allow-warnings-to-be-registered-as-warnings.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_7_0/3153-updating-unknowncodesystem-to-allow-warnings-to-be-registered-as-warnings.yaml index f7fe6c8f839..b1e0a1eaafd 100644 --- a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_7_0/3153-updating-unknowncodesystem-to-allow-warnings-to-be-registered-as-warnings.yaml +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_7_0/3153-updating-unknowncodesystem-to-allow-warnings-to-be-registered-as-warnings.yaml @@ -1,5 +1,6 @@ --- type: fix issue: 3153 +jira: SMILE-3289 title: "Updated UnknownCodeSystemWarningValidationSupport to allow the throwing of warnings if configured to do so." diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java index be1664f131e..a3ec4b90623 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java @@ -161,6 +161,20 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { } + private Observation createObservationForUnknownCodeSystemTest() { + Observation obs = new Observation(); + obs.getMeta().addProfile("http://sd"); + obs.getText().setDivAsString("
Hello
"); + obs.getText().setStatus(Narrative.NarrativeStatus.GENERATED); + obs.getCategoryFirstRep().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/observation-category").setCode("vital-signs"); + obs.getCode().setText("hello"); + obs.setSubject(new Reference("Patient/123")); + obs.addPerformer(new Reference("Practitioner/123")); + obs.setEffective(DateTimeType.now()); + obs.setStatus(ObservationStatus.FINAL); + return obs; + } + /** * By default, an unknown code system should fail validation */ @@ -171,6 +185,32 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { createStructureDefWithBindingToUnknownCs(); + Observation obs = createObservationForUnknownCodeSystemTest(); + + OperationOutcome oo; + String encoded; + + // Valid code + obs.setValue(new Quantity().setSystem("http://cs").setCode("code1").setValue(123)); + oo = validateAndReturnOutcome(obs); + encoded = encode(oo); + ourLog.info(encoded); + assertTrue(oo.getIssueFirstRep().getDiagnostics().contains("No issues detected during validation")); + + // Invalid code + obs.setValue(new Quantity().setSystem("http://cs").setCode("code99").setValue(123)); + oo = validateAndReturnOutcome(obs); + encoded = encode(oo); + ourLog.info(encoded); + assertTrue(oo.getIssueFirstRep().getDiagnostics().contains("No issues detected during validation")); + } + + @Test + public void testValidateCodeInValueSetWithUnknownCodeSystem_Error() { + myUnknownCodeSystemWarningValidationSupport.setNonExistentCodeSystemSeverity(IValidationSupport.IssueSeverity.ERROR); + + createStructureDefWithBindingToUnknownCs(); + Observation obs = new Observation(); obs.getMeta().addProfile("http://sd"); obs.getText().setDivAsString("
Hello
"); @@ -192,13 +232,15 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { ourLog.info(encoded); assertTrue(oo.getIssueFirstRep().getDiagnostics().contains("No issues detected during validation")); + // Invalid code obs.setValue(new Quantity().setSystem("http://cs").setCode("code99").setValue(123)); oo = validateAndReturnOutcome(obs); encoded = encode(oo); ourLog.info(encoded); - assertTrue(oo.getIssueFirstRep().getDiagnostics().contains("No issues detected during validation")); - + assertTrue(oo.getIssueFirstRep() + .getDiagnostics().contains("The code provided (http://cs#code99) is not in the value set http://vs, and a code from this value set is required: Unknown code 'http://cs#code99' for in-memory expansion of ValueSet 'http://vs'") + ); } public void createStructureDefWithBindingToUnknownCs() { diff --git a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/support/UnknownCodeSystemWarningValidationSupport.java b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/support/UnknownCodeSystemWarningValidationSupport.java index 6b9a0f02017..aaad4e9cd8b 100644 --- a/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/support/UnknownCodeSystemWarningValidationSupport.java +++ b/hapi-fhir-validation/src/main/java/org/hl7/fhir/common/hapi/validation/support/UnknownCodeSystemWarningValidationSupport.java @@ -45,12 +45,15 @@ public class UnknownCodeSystemWarningValidationSupport extends BaseValidationSup @Override public CodeValidationResult validateCode(ValidationSupportContext theValidationSupportContext, ConceptValidationOptions theOptions, String theCodeSystem, String theCode, String theDisplay, String theValueSetUrl) { // filters out error/fatal + // NB: this is a secondary check. isCodeSystemSupported + // should prevent this from ever calling validate code here + // ... but should it ever get called, we'll return null if (!canValidateCodeSystem(theValidationSupportContext, theCodeSystem)) { return null; } CodeValidationResult result = new CodeValidationResult() - .setSeverity(myNonExistentCodeSystemSeverity); // will be warning or info + .setSeverity(myNonExistentCodeSystemSeverity); // will be warning or info (error/fatal filtered out above) result.setMessage("No issues detected during validation"); @@ -89,15 +92,22 @@ public class UnknownCodeSystemWarningValidationSupport extends BaseValidationSup case ERROR: case FATAL: return false; + case WARNING: + case INFORMATION: + return true; default: ourLog.info("Unknown issue severity " + myNonExistentCodeSystemSeverity.name() + ". Treating as INFO/WARNING"); - case WARNING: - case INFORMATION: return true; } } + /** + * Determines if the code system can (and should) be validated. + * @param theValidationSupportContext + * @param theCodeSystem + * @return + */ private boolean canValidateCodeSystem(ValidationSupportContext theValidationSupportContext, String theCodeSystem) { if (!allowNonExistentCodeSystems()) {