Fix a crash on _include which doesnt find any matches

This commit is contained in:
James Agnew 2017-11-24 12:22:26 -05:00
parent 8a4182012d
commit 584ba1eec4
3 changed files with 62 additions and 0 deletions

View File

@ -2000,6 +2000,9 @@ public class SearchBuilder implements ISearchBuilder {
} }
private static List<Long> filterResourceIdsByLastUpdated(EntityManager theEntityManager, final DateRangeParam theLastUpdated, Collection<Long> thePids) { private static List<Long> filterResourceIdsByLastUpdated(EntityManager theEntityManager, final DateRangeParam theLastUpdated, Collection<Long> thePids) {
if (thePids.isEmpty()) {
return Collections.emptyList();
}
CriteriaBuilder builder = theEntityManager.getCriteriaBuilder(); CriteriaBuilder builder = theEntityManager.getCriteriaBuilder();
CriteriaQuery<Long> cq = builder.createQuery(Long.class); CriteriaQuery<Long> cq = builder.createQuery(Long.class);
Root<ResourceTable> from = cq.from(ResourceTable.class); Root<ResourceTable> from = cq.from(ResourceTable.class);

View File

@ -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<String> 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<String> ids = toUnqualifiedVersionlessIdValues(myFhirCtx.newXmlParser().parseResource(Bundle.class, output));
ourLog.info(ids.toString());
assertThat(ids, empty());
} finally {
response.close();
}
}
@Test @Test
public void testSearchByReferenceIds() { public void testSearchByReferenceIds() {
Organization o1 = new Organization(); Organization o1 = new Organization();

View File

@ -6,6 +6,12 @@
<title>HAPI FHIR Changelog</title> <title>HAPI FHIR Changelog</title>
</properties> </properties>
<body> <body>
<release version="3.2.0" date="TBD">
<action type="fix">
Fix a crash in JPA server when performing a recursive
<![CDATA[<code>_include</code>]]> which doesn't actually find any matches.
</action>
</release>
<release version="3.1.0" date="2017-11-23"> <release version="3.1.0" date="2017-11-23">
<action type="add"> <action type="add">
The version of a few dependencies have been bumped to the The version of a few dependencies have been bumped to the