Fixes issue (#2958) where Procedure?patient caused inconsistent results and ensured that such requests gave http 400

This commit is contained in:
Justin Dar 2021-09-09 16:10:09 -07:00
parent 2dcc4f534f
commit 836948010f
4 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,6 @@
---
type: fix
issue: 2958
jira: SMILE-643
title: "Fixed issue where the processing of queries like Procedure?patient= before a cache search would cause the parameter key to be removed.
Additionally, ensured that requests like Procedure?patient cause HTTP 400 Bad Request instead of HTTP 500 Internal Error."

View File

@ -1014,6 +1014,9 @@ public class SearchCoordinatorSvcImpl implements ISearchCoordinatorSvc {
logged = true;
ourLog.warn("Failed during search due to invalid request: {}", t.toString());
}
}else if (t instanceof java.lang.IllegalArgumentException && t.getMessage().contentEquals("The validated expression is false")) {
logged = true;
ourLog.warn("Failed during search due to invalid request: {}", t.toString());
}
if (!logged) {
@ -1028,6 +1031,8 @@ public class SearchCoordinatorSvcImpl implements ISearchCoordinatorSvc {
int failureCode = InternalErrorException.STATUS_CODE;
if (t instanceof BaseServerResponseException) {
failureCode = ((BaseServerResponseException) t).getStatusCode();
}else if(t instanceof java.lang.IllegalArgumentException && t.getMessage().contentEquals("The validated expression is false")) {
failureCode = Constants.STATUS_HTTP_400_BAD_REQUEST;
}
if (System.getProperty(UNIT_TEST_CAPTURE_STACK) != null) {

View File

@ -7,7 +7,11 @@ import ca.uhn.fhir.parser.StrictErrorHandler;
import ca.uhn.fhir.rest.api.CacheControlDirective;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.client.interceptor.CapturingInterceptor;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import com.ctc.wstx.shaded.msv_core.verifier.jarv.Const;
import org.hl7.fhir.r4.model.Base;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Patient;
@ -27,6 +31,7 @@ import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.core.IsNot.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
public class ResourceProviderR4CacheTest extends BaseResourceProviderR4Test {
@ -227,5 +232,32 @@ public class ResourceProviderR4CacheTest extends BaseResourceProviderR4Test {
assertEquals(1, resp2.getEntry().size());
}
@Test
public void testProcedurePatient(){
Bundle resp2 = myClient
.search()
.byUrl("Procedure")
.returnBundle(Bundle.class)
.execute();
BaseServerResponseException exception = assertThrows(BaseServerResponseException.class, () -> {myClient
.search()
.byUrl("Procedure?patient=")
.returnBundle(Bundle.class)
.execute();});
assertEquals(Constants.STATUS_HTTP_400_BAD_REQUEST, exception.getStatusCode());
}
@Test
public void testPatient(){
BaseServerResponseException exception = assertThrows(BaseServerResponseException.class, () -> {myClient
.search()
.byUrl("Procedure?patient=")
.returnBundle(Bundle.class)
.execute();});
assertEquals(Constants.STATUS_HTTP_400_BAD_REQUEST, exception.getStatusCode());
}
}

View File

@ -396,11 +396,15 @@ public class SearchParameterMap implements Serializable {
for (List<? extends IQueryParameterType> nextValuesAndIn : nextValuesAndsIn) {
List<IQueryParameterType> nextValuesOrsOut = new ArrayList<>();
/*
for (IQueryParameterType nextValueOrIn : nextValuesAndIn) {
if (nextValueOrIn.getMissing() != null || isNotBlank(nextValueOrIn.getValueAsQueryToken(theCtx))) {
nextValuesOrsOut.add(nextValueOrIn);
}
}
*/
nextValuesOrsOut.addAll(nextValuesAndIn);
nextValuesOrsOut.sort(new QueryParameterTypeComparator(theCtx));