@@ -678,14 +678,14 @@ public void testValidateCode_InMemoryExpansionAgainstHugeValueSet() throws Excep
678
678
obs .getCode ().getCoding ().clear ();
679
679
obs .getCategory ().clear ();
680
680
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 " );
682
682
oo = validateAndReturnOutcome (obs );
683
683
assertEquals ("No issues detected during validation" , oo .getIssueFirstRep ().getDiagnostics (), encode (oo ));
684
684
myCaptureQueriesListener .logSelectQueriesForCurrentThread ();
685
685
686
686
myCaptureQueriesListener .clear ();
687
687
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 " );
689
689
oo = validateAndReturnOutcome (obs );
690
690
assertEquals ("No issues detected during validation" , oo .getIssueFirstRep ().getDiagnostics (), encode (oo ));
691
691
myCaptureQueriesListener .logSelectQueriesForCurrentThread ();
@@ -737,7 +737,7 @@ public void testValidateProfileTargetType_PolicyCheckValid() throws IOException
737
737
obs .setStatus (ObservationStatus .FINAL );
738
738
obs .setValue (new StringType ("This is the value" ));
739
739
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 " );
741
741
742
742
OperationOutcome oo ;
743
743
@@ -807,7 +807,7 @@ public void testValidateProfileTargetType_PolicyCheckExistsAndType() throws IOEx
807
807
obs .setStatus (ObservationStatus .FINAL );
808
808
obs .setValue (new StringType ("This is the value" ));
809
809
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 " );
811
811
812
812
OperationOutcome oo ;
813
813
@@ -878,7 +878,7 @@ public void testValidateProfileTargetType_PolicyCheckExists() throws IOException
878
878
obs .setStatus (ObservationStatus .FINAL );
879
879
obs .setValue (new StringType ("This is the value" ));
880
880
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 " );
882
882
883
883
// Non-existent target
884
884
obs .setSubject (new Reference ("Group/123" ));
@@ -1381,6 +1381,43 @@ public void testValidateUsingExternallyDefinedCode() {
1381
1381
1382
1382
}
1383
1383
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
+
1384
1421
private OperationOutcome doTestValidateResourceContainingProfileDeclaration (String methodName , EncodingEnum enc ) throws IOException {
1385
1422
Bundle vss = loadResourceFromClasspath (Bundle .class , "/org/hl7/fhir/r4/model/valueset/valuesets.xml" );
1386
1423
myValueSetDao .update ((ValueSet ) findResourceByIdInBundle (vss , "observation-status" ), mySrd );
0 commit comments