Skip to content

Commit 07faa1f

Browse files
leif stawnyczyleif stawnyczy
authored andcommitted
Merge branch 'rel_6_6' into 4844-patient-everything-with-type-filter-fix
2 parents 6bba713 + 22c9a18 commit 07faa1f

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
type: fix
3+
issue: 4853
4+
title: "Previously, when validating resources that contain a display in a Coding/CodeableConcept different from the
5+
display defined in the CodeSystem that is used, no errors are returned in the outcome. This is now fixed."

hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/term/TermReadSvcImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,6 +2200,7 @@ public CodeValidationResult validateCodeInValueSet(ValidationSupportContext theV
22002200
public IValidationSupport.CodeValidationResult validateCode(@Nonnull ValidationSupportContext theValidationSupportContext, @Nonnull ConceptValidationOptions theOptions, String theCodeSystemUrl, String theCode, String theDisplay, String theValueSetUrl) {
22012201
//TODO GGG TRY TO JUST AUTO_PASS HERE AND SEE WHAT HAPPENS.
22022202
invokeRunnableForUnitTest();
2203+
theOptions.setValidateDisplay(isNotBlank(theDisplay));
22032204

22042205
if (isNotBlank(theValueSetUrl)) {
22052206
return validateCodeInValueSet(theValidationSupportContext, theOptions, theValueSetUrl, theCodeSystemUrl, theCode, theDisplay);

hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -678,14 +678,14 @@ public void testValidateCode_InMemoryExpansionAgainstHugeValueSet() throws Excep
678678
obs.getCode().getCoding().clear();
679679
obs.getCategory().clear();
680680
obs.getCategoryFirstRep().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/observation-category").setCode("vital-signs");
681-
obs.getCode().getCodingFirstRep().setSystem("http://loinc.org").setCode("CODE4").setDisplay("Display 3");
681+
obs.getCode().getCodingFirstRep().setSystem("http://loinc.org").setCode("CODE4").setDisplay("Display 4");
682682
oo = validateAndReturnOutcome(obs);
683683
assertEquals("No issues detected during validation", oo.getIssueFirstRep().getDiagnostics(), encode(oo));
684684
myCaptureQueriesListener.logSelectQueriesForCurrentThread();
685685

686686
myCaptureQueriesListener.clear();
687687
obs.getText().setStatus(Narrative.NarrativeStatus.GENERATED);
688-
obs.getCode().getCodingFirstRep().setSystem("http://loinc.org").setCode("CODE4").setDisplay("Display 3");
688+
obs.getCode().getCodingFirstRep().setSystem("http://loinc.org").setCode("CODE4").setDisplay("Display 4");
689689
oo = validateAndReturnOutcome(obs);
690690
assertEquals("No issues detected during validation", oo.getIssueFirstRep().getDiagnostics(), encode(oo));
691691
myCaptureQueriesListener.logSelectQueriesForCurrentThread();
@@ -737,7 +737,7 @@ public void testValidateProfileTargetType_PolicyCheckValid() throws IOException
737737
obs.setStatus(ObservationStatus.FINAL);
738738
obs.setValue(new StringType("This is the value"));
739739
obs.getText().setStatus(Narrative.NarrativeStatus.GENERATED);
740-
obs.getCode().getCodingFirstRep().setSystem("http://loinc.org").setCode("123-4").setDisplay("Display 3");
740+
obs.getCode().getCodingFirstRep().setSystem("http://loinc.org").setCode("123-4").setDisplay("Code 123 4");
741741

742742
OperationOutcome oo;
743743

@@ -807,7 +807,7 @@ public void testValidateProfileTargetType_PolicyCheckExistsAndType() throws IOEx
807807
obs.setStatus(ObservationStatus.FINAL);
808808
obs.setValue(new StringType("This is the value"));
809809
obs.getText().setStatus(Narrative.NarrativeStatus.GENERATED);
810-
obs.getCode().getCodingFirstRep().setSystem("http://loinc.org").setCode("123-4").setDisplay("Display 3");
810+
obs.getCode().getCodingFirstRep().setSystem("http://loinc.org").setCode("123-4").setDisplay("Code 123 4");
811811

812812
OperationOutcome oo;
813813

@@ -878,7 +878,7 @@ public void testValidateProfileTargetType_PolicyCheckExists() throws IOException
878878
obs.setStatus(ObservationStatus.FINAL);
879879
obs.setValue(new StringType("This is the value"));
880880
obs.getText().setStatus(Narrative.NarrativeStatus.GENERATED);
881-
obs.getCode().getCodingFirstRep().setSystem("http://loinc.org").setCode("123-4").setDisplay("Display 3");
881+
obs.getCode().getCodingFirstRep().setSystem("http://loinc.org").setCode("123-4").setDisplay("Code 123 4");
882882

883883
// Non-existent target
884884
obs.setSubject(new Reference("Group/123"));
@@ -1381,6 +1381,43 @@ public void testValidateUsingExternallyDefinedCode() {
13811381

13821382
}
13831383

1384+
@Test
1385+
public void testValidateUsingExternallyDefinedCodeMisMatchDisplay_ShouldError() {
1386+
CodeSystem codeSystem = new CodeSystem();
1387+
codeSystem.setUrl("http://foo");
1388+
codeSystem.setContent(CodeSystem.CodeSystemContentMode.NOTPRESENT);
1389+
IIdType csId = myCodeSystemDao.create(codeSystem).getId();
1390+
1391+
TermCodeSystemVersion csv = new TermCodeSystemVersion();
1392+
csv.addConcept().setCode("bar").setDisplay("Bar Code");
1393+
myTermCodeSystemStorageSvc.storeNewCodeSystemVersion(codeSystem, csv, mySrd, Collections.emptyList(), Collections.emptyList());
1394+
1395+
// Validate a resource containing this codesystem in a field with an extendable binding
1396+
Patient patient = new Patient();
1397+
patient.getText().setStatus(Narrative.NarrativeStatus.GENERATED).setDivAsString("<div>hello</div>");
1398+
patient
1399+
.addIdentifier()
1400+
.setSystem("http://example.com")
1401+
.setValue("12345")
1402+
.getType()
1403+
.addCoding()
1404+
.setSystem("http://foo")
1405+
.setCode("bar")
1406+
.setDisplay("not bar code");
1407+
MethodOutcome outcome = myPatientDao.validate(patient, null, encode(patient), EncodingEnum.JSON, ValidationModeEnum.CREATE, null, mySrd);
1408+
OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome();
1409+
ourLog.debug(myFhirContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(oo));
1410+
1411+
// It would be ok for this to produce 0 issues, or just an information message too
1412+
assertEquals(2, OperationOutcomeUtil.getIssueCount(myFhirContext, oo));
1413+
assertThat(OperationOutcomeUtil.getFirstIssueDetails(myFhirContext, oo),
1414+
containsString("None of the codings provided are in the value set 'IdentifierType'"));
1415+
assertThat(OperationOutcomeUtil.getFirstIssueDetails(myFhirContext, oo),
1416+
containsString("a coding should come from this value set unless it has no suitable code (note that the validator cannot judge what is suitable) (codes = http://foo#bar)"));
1417+
assertEquals(OperationOutcome.IssueSeverity.ERROR, oo.getIssue().get(1).getSeverity());
1418+
assertThat(oo.getIssue().get(1).getDiagnostics(), containsString("Unable to validate code http://foo#bar - Concept Display "));
1419+
}
1420+
13841421
private OperationOutcome doTestValidateResourceContainingProfileDeclaration(String methodName, EncodingEnum enc) throws IOException {
13851422
Bundle vss = loadResourceFromClasspath(Bundle.class, "/org/hl7/fhir/r4/model/valueset/valuesets.xml");
13861423
myValueSetDao.update((ValueSet) findResourceByIdInBundle(vss, "observation-status"), mySrd);

0 commit comments

Comments
 (0)