(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:
Anthony Sute 2019-11-05 17:46:33 -05:00
parent 9e7efa9db4
commit 619a21032b
3 changed files with 46 additions and 4 deletions

View File

@ -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,

View File

@ -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();

View File

@ -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;