Fix #872 - Include resource type in JPA uri search parameter criterias

This commit is contained in:
James Agnew 2018-03-01 08:31:41 -05:00
parent ecf570ced9
commit a18303f117
4 changed files with 44 additions and 15 deletions

View File

@ -770,12 +770,11 @@ public class SearchBuilder implements ISearchBuilder {
return;
}
List<Predicate> codePredicates = new ArrayList<Predicate>();
List<Predicate> codePredicates = new ArrayList<>();
for (IQueryParameterType nextOr : theList) {
IQueryParameterType params = nextOr;
if (params instanceof UriParam) {
UriParam param = (UriParam) params;
if (nextOr instanceof UriParam) {
UriParam param = (UriParam) nextOr;
String value = param.getValue();
if (value == null) {
@ -820,7 +819,7 @@ public class SearchBuilder implements ISearchBuilder {
}
codePredicates.add(predicate);
} else {
throw new IllegalArgumentException("Invalid URI type: " + params.getClass());
throw new IllegalArgumentException("Invalid URI type: " + nextOr.getClass());
}
}
@ -840,7 +839,9 @@ public class SearchBuilder implements ISearchBuilder {
Predicate paramNamePredicate = myBuilder.equal(join.get("myParamName"), theParamName);
Predicate outerPredicate = myBuilder.and(paramNamePredicate, orPredicate);
myPredicates.add(outerPredicate);
Predicate combinedOuterPredicate = combineParamIndexPredicateWithParamNamePredicate(theResourceName, theParamName, join, outerPredicate);
myPredicates.add(combinedOuterPredicate);
}
private Predicate combineParamIndexPredicateWithParamNamePredicate(String theResourceName, String theParamName, From<?, ? extends BaseResourceIndexedSearchParam> theFrom, Predicate thePredicate) {
@ -1195,7 +1196,7 @@ public class SearchBuilder implements ISearchBuilder {
for (VersionIndependentConcept nextCode : codes) {
List<VersionIndependentConcept> systemCodes = map.get(nextCode.getSystem());
if (null == systemCodes) {
systemCodes = new ArrayList<VersionIndependentConcept>();
systemCodes = new ArrayList<>();
map.put(nextCode.getSystem(), systemCodes);
}
systemCodes.add(nextCode);
@ -1342,7 +1343,7 @@ public class SearchBuilder implements ISearchBuilder {
}
myPredicates = new ArrayList<Predicate>();
myPredicates = new ArrayList<>();
if (myParams.getEverythingMode() != null) {
Join<ResourceTable, ResourceLink> join = myResourceTableRoot.join("myResourceLinks", JoinType.LEFT);
@ -1351,7 +1352,7 @@ public class SearchBuilder implements ISearchBuilder {
StringParam idParm = (StringParam) myParams.get(BaseResource.SP_RES_ID).get(0).get(0);
Long pid = BaseHapiFhirDao.translateForcedIdToPid(myResourceName, idParm.getValue(), myForcedIdDao);
if (myAlsoIncludePids == null) {
myAlsoIncludePids = new ArrayList<Long>(1);
myAlsoIncludePids = new ArrayList<>(1);
}
myAlsoIncludePids.add(pid);
myPredicates.add(myBuilder.equal(join.get("myTargetResourcePid").as(Long.class), pid));

View File

@ -681,6 +681,27 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test {
assertThat(actual, contains(id));
}
@Test
public void testReturnOnlyCorrectResourceType() {
ValueSet vsRes = new ValueSet();
vsRes.setUrl("http://foo");
String vsId = myValueSetDao.create(vsRes).getId().toUnqualifiedVersionless().getValue();
CodeSystem csRes = new CodeSystem();
csRes.setUrl("http://bar");
String csId = myCodeSystemDao.create(csRes).getId().toUnqualifiedVersionless().getValue();
SearchParameterMap map = new SearchParameterMap().setLoadSynchronous(true);
map.add(ValueSet.SP_URL, new UriParam("http://foo"));
List<String> actual = toUnqualifiedVersionlessIdValues(myValueSetDao.search(map));
assertThat(actual, contains(vsId));
map = new SearchParameterMap().setLoadSynchronous(true);
map.add(ValueSet.SP_URL, new UriParam("http://bar"));
actual = toUnqualifiedVersionlessIdValues(myCodeSystemDao.search(map));
assertThat(actual, contains(csId));
}
/**
* #454
*/

View File

@ -1569,7 +1569,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
* See #872
*/
@Test
public void testExtensionUrlWithHl7UrlPost() throws IOException {
public void testValidateExtensionUrlWithHl7UrlPost() throws IOException {
RequestValidatingInterceptor interceptor = new RequestValidatingInterceptor();
FhirInstanceValidator val = new FhirInstanceValidator(myValidationSupport);
interceptor.addValidatorModule(val);
@ -1577,8 +1577,9 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
ourRestServer.registerInterceptor(interceptor);
try {
String input = IOUtils.toString(ResourceProviderR4Test.class.getResourceAsStream("/bug872-ext-with-hl7-url.json"), Charsets.UTF_8);
assertThat(input, containsString("Unknown extension http://hl7.org/fhir/ValueSet/v3-ActInvoiceGroupCode"));
HttpPost post = new HttpPost(ourServerBase + "/Patient/aaa");
HttpPost post = new HttpPost(ourServerBase + "/Patient/$validate");
post.setEntity(new StringEntity(input, ContentType.APPLICATION_JSON));
CloseableHttpResponse resp = ourHttpClient.execute(post);
@ -1611,14 +1612,11 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
IIdType id2 = myObservationDao.create(obs2, mySrd).getId().toUnqualifiedVersionless();
HttpGet get = new HttpGet(ourServerBase + "/Observation?_content=systolic&_pretty=true");
CloseableHttpResponse response = ourHttpClient.execute(get);
try {
try (CloseableHttpResponse response = ourHttpClient.execute(get)) {
assertEquals(200, response.getStatusLine().getStatusCode());
String responseString = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
ourLog.info(responseString);
assertThat(responseString, containsString(id1.getIdPart()));
} finally {
response.close();
}
}

View File

@ -176,6 +176,15 @@
cam be useful for tests or for static servers with small amounts
of data.
</action>
<action type="fix" issue="872">
An issue in the JPA server was corrected where searching using
URI search parameters would sometimes not include the resource type in the
criteria. This meant, for example, that a search for
<![CDATA[<code>ValueSet?url=http://foo</code>]]> would also
match any CodeSystem resource that happened to also have
that URL as the value for the "url" search parameter. Thanks
to Josh Mandel for reporting and supplying a test case!
</action>
</release>
<release version="3.2.0" date="2018-01-13">
<action type="add">