parent
74066a81b6
commit
db44244405
|
@ -38,6 +38,9 @@ public interface IBaseQuery<T extends IBaseQuery<?>> {
|
|||
|
||||
/**
|
||||
* Add a set of search parameters to the query.
|
||||
*
|
||||
* Note that the entries of the map are extracted immediately upon invoking this method. Changes made to the
|
||||
* map afterward will not be reflected in the actual search.
|
||||
*/
|
||||
T where(Map<String, List<IQueryParameterType>> theCriterion);
|
||||
|
||||
|
|
|
@ -631,7 +631,12 @@ public class GenericClient extends BaseClient implements IGenericClient {
|
|||
String nextKey = nextEntry.getKey();
|
||||
List<IQueryParameterType> nextValues = nextEntry.getValue();
|
||||
for (IQueryParameterType nextValue : nextValues) {
|
||||
addParam(myParams, nextKey, nextValue.getValueAsQueryToken(myContext));
|
||||
String value = nextValue.getValueAsQueryToken(myContext);
|
||||
String qualifier = nextValue.getQueryParameterQualifier();
|
||||
if (isNotBlank(qualifier)) {
|
||||
nextKey = nextKey + qualifier;
|
||||
}
|
||||
addParam(myParams, nextKey, value);
|
||||
}
|
||||
}
|
||||
return (QUERY) this;
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
type: fix
|
||||
issue: 2426
|
||||
title: "When using the Generic Client, search invocations where the parameters are supplied
|
||||
using `.where(Map)` did not include search modifiers such as `:exact` in the search
|
||||
URL. Thanks to GitHub user @granadacoder for reporting this issue!"
|
|
@ -23,6 +23,7 @@ import ca.uhn.fhir.rest.client.interceptor.UserInfoInterceptor;
|
|||
import ca.uhn.fhir.rest.param.DateParam;
|
||||
import ca.uhn.fhir.rest.param.DateRangeParam;
|
||||
import ca.uhn.fhir.rest.param.ParamPrefixEnum;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.rest.server.exceptions.NotImplementedOperationException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.UnclassifiedServerFailureException;
|
||||
import ca.uhn.fhir.util.BundleBuilder;
|
||||
|
@ -61,9 +62,11 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -1872,6 +1875,36 @@ public class GenericClientR4Test extends BaseGenericClientR4Test {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* See #2426
|
||||
*/
|
||||
@Test
|
||||
public void testSearchWithMap_StringModifier() throws Exception {
|
||||
String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}";
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
||||
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
|
||||
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), StandardCharsets.UTF_8));
|
||||
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
HashMap<String, List<IQueryParameterType>> params = new HashMap<>();
|
||||
params.put("foo", Collections.singletonList(new StringParam("Smith", true)));
|
||||
Bundle response = client
|
||||
.search()
|
||||
.forResource(Patient.class)
|
||||
.where(params)
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Patient?foo%3Aexact=Smith", capt.getValue().getURI().toString());
|
||||
assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSearchWithMultipleTokens() throws Exception {
|
||||
ArgumentCaptor<HttpUriRequest> capt = prepareClientForSearchResponse();
|
||||
|
|
Loading…
Reference in New Issue