Merge pull request #2674 from hapifhir/2673-fix-npe-on-populate-display-interceptor
Add null check on code lookup result.
This commit is contained in:
commit
5c6ef2e247
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
type: fix
|
||||
issue: 2674
|
||||
title: "A null-pointer exception was fixed when a ResponseTerminologyDisplayInterceptor is registered and a search
|
||||
or read response returns a resource with code value that in turn returns a null code lookup."
|
|
@ -104,7 +104,7 @@ public class ResponseTerminologyDisplayPopulationInterceptor extends BaseRespons
|
|||
if (myValidationSupport.isCodeSystemSupported(validationSupportContext, system)) {
|
||||
|
||||
IValidationSupport.LookupCodeResult lookupCodeResult = myValidationSupport.lookupCode(validationSupportContext, system, code);
|
||||
if (lookupCodeResult.isFound()) {
|
||||
if (lookupCodeResult != null && lookupCodeResult.isFound()) {
|
||||
String newDisplay = lookupCodeResult.getCodeDisplay();
|
||||
IPrimitiveType<?> newString = myStringDefinition.newInstance(newDisplay);
|
||||
myCodingDisplayChild.getMutator().addValue(theElement, newString);
|
||||
|
|
|
@ -2,6 +2,8 @@ package ca.uhn.fhir.rest.server.interceptor;
|
|||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||
import ca.uhn.fhir.context.support.IValidationSupport;
|
||||
import ca.uhn.fhir.context.support.ValidationSupportContext;
|
||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||
import ca.uhn.fhir.test.utilities.server.HashMapResourceProviderExtension;
|
||||
import ca.uhn.fhir.test.utilities.server.RestfulServerExtension;
|
||||
|
@ -15,6 +17,7 @@ import org.junit.jupiter.api.Test;
|
|||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class ResponseTerminologyDisplayPopulationInterceptorTest {
|
||||
|
||||
|
@ -50,13 +53,26 @@ public class ResponseTerminologyDisplayPopulationInterceptorTest {
|
|||
assertEquals("Annulled", p.getMaritalStatus().getCoding().get(0).getDisplay());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDontPopulateCodingIfLookupReturnsNull_Read() {
|
||||
myServerExtension.getRestfulServer().registerInterceptor(new ResponseTerminologyDisplayPopulationInterceptor(new NullableValidationSupport(myCtx)));
|
||||
|
||||
Patient p = new Patient();
|
||||
p.getMaritalStatus().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/v3-MaritalStatus").setCode("zz");
|
||||
IIdType id = myClient.create().resource(p).execute().getId();
|
||||
|
||||
p = myClient.read().resource(Patient.class).withId(id).execute();
|
||||
assertEquals(1, p.getMaritalStatus().getCoding().size());
|
||||
assertNull(p.getMaritalStatus().getCoding().get(0).getDisplay());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPopulateCoding_Search() {
|
||||
myServerExtension.getRestfulServer().registerInterceptor(new ResponseTerminologyDisplayPopulationInterceptor(myCtx.getValidationSupport()));
|
||||
|
||||
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());
|
||||
|
@ -65,6 +81,21 @@ public class ResponseTerminologyDisplayPopulationInterceptorTest {
|
|||
assertEquals("Annulled", p.getMaritalStatus().getCoding().get(0).getDisplay());
|
||||
}
|
||||
|
||||
@Test
|
||||
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("zz");
|
||||
myClient.create().resource(p).execute();
|
||||
|
||||
Bundle bundle = myClient.search().forResource(Patient.class).returnBundle(Bundle.class).execute();
|
||||
assertEquals(1, bundle.getEntry().size());
|
||||
p = (Patient) bundle.getEntry().get(0).getResource();
|
||||
assertEquals(1, p.getMaritalStatus().getCoding().size());
|
||||
assertNull(p.getMaritalStatus().getCoding().get(0).getDisplay());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDontPopulateCodingIfAlreadyPopulated() {
|
||||
myServerExtension.getRestfulServer().registerInterceptor(new ResponseTerminologyDisplayPopulationInterceptor(myCtx.getValidationSupport()));
|
||||
|
@ -88,7 +119,31 @@ 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 {
|
||||
|
||||
private static FhirContext myStaticCtx;
|
||||
|
||||
NullableValidationSupport(FhirContext theCtx) {
|
||||
myStaticCtx = theCtx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FhirContext getFhirContext() {
|
||||
return myStaticCtx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCodeSystemSupported(ValidationSupportContext theValidationSupportContext, String theSystem) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LookupCodeResult lookupCode(ValidationSupportContext theValidationSupportContext, String theSystem, String theCode) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue