(1) Fixes to address _filter-based _id retrievals not being restricted to the specified resource type
(2) Import fix for FhirServerConfig.java in hapi-fhir-jpaserver-example
This commit is contained in:
parent
37cc5a4a72
commit
3cf8254625
|
@ -834,13 +834,18 @@ public class SearchBuilder implements ISearchBuilder {
|
|||
|
||||
SearchFilterParser.CompareOperation operation = defaultIfNull(theOperation, SearchFilterParser.CompareOperation.eq);
|
||||
assert operation == SearchFilterParser.CompareOperation.eq || operation == SearchFilterParser.CompareOperation.ne;
|
||||
List<Predicate> codePredicates = new ArrayList<>();
|
||||
switch (operation) {
|
||||
default:
|
||||
case eq:
|
||||
nextPredicate = theRoot.get("myId").as(Long.class).in(allOrPids);
|
||||
codePredicates.add(theRoot.get("myId").as(Long.class).in(allOrPids));
|
||||
codePredicates.add(myBuilder.equal(myResourceTableRoot.get("myResourceType"), theResourceName));
|
||||
nextPredicate = myBuilder.and(toArray(codePredicates));
|
||||
break;
|
||||
case ne:
|
||||
nextPredicate = theRoot.get("myId").as(Long.class).in(allOrPids).not();
|
||||
codePredicates.add(theRoot.get("myId").as(Long.class).in(allOrPids).not());
|
||||
codePredicates.add(myBuilder.equal(myResourceTableRoot.get("myResourceType"), theResourceName));
|
||||
nextPredicate = myBuilder.and(toArray(codePredicates));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2718,7 +2723,9 @@ public class SearchBuilder implements ISearchBuilder {
|
|||
|
||||
RuntimeSearchParam searchParam = mySearchParamRegistry.getActiveSearchParam(theResourceName, theFilter.getParamPath().getName());
|
||||
|
||||
if (searchParam.getName().equals(IAnyResource.SP_RES_ID)) {
|
||||
if (searchParam == null) {
|
||||
throw new InvalidRequestException("Invalid search parameter specified, " + theFilter.getParamPath().getName() + ", for resource type " + theResourceName);
|
||||
} else if (searchParam.getName().equals(IAnyResource.SP_RES_ID)) {
|
||||
if (searchParam.getParamType() == RestSearchParameterTypeEnum.TOKEN) {
|
||||
TokenParam param = new TokenParam();
|
||||
param.setValueAsQueryToken(null,
|
||||
|
|
|
@ -169,6 +169,41 @@ public class FhirResourceDaoR4FilterTest extends BaseJpaR4Test {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetrieveDifferentTypeEq() {
|
||||
|
||||
Patient p = new Patient();
|
||||
p.addName().setFamily("Smith").addGiven("John");
|
||||
p.setActive(true);
|
||||
String id1 = myPatientDao.create(p).getId().toUnqualifiedVersionless().getValue();
|
||||
String idVal = id1.split("/")[1];
|
||||
|
||||
SearchParameterMap map;
|
||||
List<String> found;
|
||||
|
||||
map = new SearchParameterMap();
|
||||
map.setLoadSynchronous(true);
|
||||
map.add(Constants.PARAM_FILTER, new StringParam(String.format("status eq active or _id eq %s",
|
||||
idVal)));
|
||||
found = toUnqualifiedVersionlessIdValues(myEncounterDao.search(map));
|
||||
assertThat(found, Matchers.empty());
|
||||
|
||||
map = new SearchParameterMap();
|
||||
map.setLoadSynchronous(true);
|
||||
map.add(Constants.PARAM_FILTER, new StringParam(String.format("_id eq %s",
|
||||
idVal)));
|
||||
found = toUnqualifiedVersionlessIdValues(myEncounterDao.search(map));
|
||||
assertThat(found, Matchers.empty());
|
||||
|
||||
map = new SearchParameterMap();
|
||||
map.setLoadSynchronous(true);
|
||||
map.add(Constants.PARAM_FILTER, new StringParam(String.format("_id eq %s",
|
||||
idVal)));
|
||||
found = toUnqualifiedVersionlessIdValues(myPatientDao.search(map));
|
||||
assertThat(found, containsInAnyOrder(id1));
|
||||
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
|
|
|
@ -6,7 +6,7 @@ import javax.sql.DataSource;
|
|||
|
||||
import ca.uhn.fhir.jpa.config.BaseJavaConfigDstu3;
|
||||
import ca.uhn.fhir.jpa.dao.DaoConfig;
|
||||
import ca.uhn.fhir.jpa.search.elastic.ElasticsearchMappingProvider;
|
||||
import ca.uhn.fhir.jpa.search.ElasticsearchMappingProvider;
|
||||
import ca.uhn.fhir.jpa.util.SubscriptionsRequireManualActivationInterceptorDstu3;
|
||||
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
|
||||
import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
|
||||
|
|
Loading…
Reference in New Issue