diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java index 23426709440..f791b404272 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java @@ -2000,6 +2000,9 @@ public class SearchBuilder implements ISearchBuilder { } private static List filterResourceIdsByLastUpdated(EntityManager theEntityManager, final DateRangeParam theLastUpdated, Collection thePids) { + if (thePids.isEmpty()) { + return Collections.emptyList(); + } CriteriaBuilder builder = theEntityManager.getCriteriaBuilder(); CriteriaQuery cq = builder.createQuery(Long.class); Root from = cq.from(ResourceTable.class); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java index d3b04381029..eddaab5fbd0 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java @@ -2558,6 +2558,59 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } + /** + * https://chat.fhir.org/#narrow/stream/implementers/topic/Internal.20error.2C.20when.20executing.20the.20following.20query.20on.20HAPI + */ + @Test + public void testSearchByLastUpdatedGe() throws Exception { + Patient p2 = new Patient(); + p2.setId("P2"); + p2.addName().setFamily("P2"); + myClient.update().resource(p2).execute().getId().toUnqualifiedVersionless(); + + Practitioner pract = new Practitioner(); + pract.setId("PRAC"); + pract.addName().setFamily("PRACT"); + myClient.update().resource(pract).execute().getId().toUnqualifiedVersionless(); + + Encounter enc = new Encounter(); + enc.setId("E2"); + enc.setStatus(EncounterStatus.ARRIVED); + enc.setPeriod(new Period().setStart(new Date()).setEnd(new Date())); + enc.getSubject().setReference("Patient/P2"); + enc.addParticipant().getIndividual().setReference("Practitioner/PRAC"); + myClient.update().resource(enc).execute().getId().toUnqualifiedVersionless(); + + HttpGet get = new HttpGet(ourServerBase + "/Encounter?patient=P2&date=ge2017-01-01&_include:recurse=Encounter:practitioner&_lastUpdated=ge2017-11-10"); + CloseableHttpResponse response = ourHttpClient.execute(get); + try { + assertEquals(200, response.getStatusLine().getStatusCode()); + String output = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); + IOUtils.closeQuietly(response.getEntity().getContent()); + ourLog.info(output); + List ids = toUnqualifiedVersionlessIdValues(myFhirCtx.newXmlParser().parseResource(Bundle.class, output)); + ourLog.info(ids.toString()); + assertThat(ids, containsInAnyOrder("Practitioner/PRAC", "Encounter/E2")); + } finally { + response.close(); + } + + get = new HttpGet(ourServerBase + "/Encounter?patient=P2&date=ge2017-01-01&_include:recurse=Encounter:practitioner&_lastUpdated=ge2099-11-10"); + response = ourHttpClient.execute(get); + try { + assertEquals(200, response.getStatusLine().getStatusCode()); + String output = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8); + IOUtils.closeQuietly(response.getEntity().getContent()); + ourLog.info(output); + List ids = toUnqualifiedVersionlessIdValues(myFhirCtx.newXmlParser().parseResource(Bundle.class, output)); + ourLog.info(ids.toString()); + assertThat(ids, empty()); + } finally { + response.close(); + } + + } + @Test public void testSearchByReferenceIds() { Organization o1 = new Organization(); diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 6174e1c97ea..4cf2c689611 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -6,6 +6,12 @@ HAPI FHIR Changelog + + + Fix a crash in JPA server when performing a recursive + _include]]> which doesn't actually find any matches. + + The version of a few dependencies have been bumped to the