From 8e552916ee5bb297194185d0c076a477f689f3b9 Mon Sep 17 00:00:00 2001 From: ianmarshall Date: Tue, 25 May 2021 09:07:28 -0400 Subject: [PATCH] Add null check on code lookup result. --- ...ologyDisplayPopulationInterceptorTest.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/interceptor/ResponseTerminologyDisplayPopulationInterceptorTest.java b/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/interceptor/ResponseTerminologyDisplayPopulationInterceptorTest.java index 52000ffacb6..2dd9ce074a0 100644 --- a/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/interceptor/ResponseTerminologyDisplayPopulationInterceptorTest.java +++ b/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/interceptor/ResponseTerminologyDisplayPopulationInterceptorTest.java @@ -54,7 +54,7 @@ public class ResponseTerminologyDisplayPopulationInterceptorTest { } @Test - public void testPopulateCoding_Read_NullableValidationSupport() { + public void testDontPopulateCodingIfLookupReturnsNull_Read() { myServerExtension.getRestfulServer().registerInterceptor(new ResponseTerminologyDisplayPopulationInterceptor(new NullableValidationSupport(myCtx))); Patient p = new Patient(); @@ -72,7 +72,7 @@ public class ResponseTerminologyDisplayPopulationInterceptorTest { Patient p = new Patient(); p.getMaritalStatus().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/v3-MaritalStatus").setCode("A"); - IIdType id = myClient.create().resource(p).execute().getId(); + myClient.create().resource(p).execute(); Bundle bundle = myClient.search().forResource(Patient.class).returnBundle(Bundle.class).execute(); assertEquals(1, bundle.getEntry().size()); @@ -82,12 +82,12 @@ public class ResponseTerminologyDisplayPopulationInterceptorTest { } @Test - public void testPopulateCoding_Search_NullableValidationSupport() { + public void testDontPopulateCodingIfLookupReturnsNull_Search() { myServerExtension.getRestfulServer().registerInterceptor(new ResponseTerminologyDisplayPopulationInterceptor(new NullableValidationSupport(myCtx))); Patient p = new Patient(); - p.getMaritalStatus().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/v3-MaritalStatus").setCode("A"); - IIdType id = myClient.create().resource(p).execute().getId(); + p.getMaritalStatus().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/v3-MaritalStatus").setCode("zz"); + myClient.create().resource(p).execute(); Bundle bundle = myClient.search().forResource(Patient.class).returnBundle(Bundle.class).execute(); assertEquals(1, bundle.getEntry().size()); @@ -101,7 +101,7 @@ public class ResponseTerminologyDisplayPopulationInterceptorTest { myServerExtension.getRestfulServer().registerInterceptor(new ResponseTerminologyDisplayPopulationInterceptor(myCtx.getValidationSupport())); Patient p = new Patient(); - p.getMaritalStatus().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/v3-MaritalStatus").setCode("A").setDisplay("FOO"); + p.getMaritalStatus().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/v3-MaritalStatus").setCode("zz").setDisplay("FOO"); IIdType id = myClient.create().resource(p).execute().getId(); p = myClient.read().resource(Patient.class).withId(id).execute(); @@ -119,7 +119,7 @@ public class ResponseTerminologyDisplayPopulationInterceptorTest { p = myClient.read().resource(Patient.class).withId(id).execute(); assertEquals(1, p.getMaritalStatus().getCoding().size()); - assertEquals(null, p.getMaritalStatus().getCoding().get(0).getDisplay()); + assertNull(p.getMaritalStatus().getCoding().get(0).getDisplay()); } private static class NullableValidationSupport implements IValidationSupport { @@ -139,6 +139,11 @@ public class ResponseTerminologyDisplayPopulationInterceptorTest { public boolean isCodeSystemSupported(ValidationSupportContext theValidationSupportContext, String theSystem) { return true; } + + @Override + public LookupCodeResult lookupCode(ValidationSupportContext theValidationSupportContext, String theSystem, String theCode) { + return null; + } } }