SearchBuilder NPE (#2726)
* Add failing test first. * Fixed the NPE and enhanced the test. * Update hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java Co-authored-by: Ken Stevens <khstevens@gmail.com> Co-authored-by: Ken Stevens <khstevens@gmail.com>
This commit is contained in:
parent
134631fdee
commit
6f680af3ce
|
@ -796,7 +796,7 @@ public class SearchBuilder implements ISearchBuilder {
|
||||||
// Account for _include=[resourceType]:*
|
// Account for _include=[resourceType]:*
|
||||||
String wantResourceType = null;
|
String wantResourceType = null;
|
||||||
if (!matchAll) {
|
if (!matchAll) {
|
||||||
if (nextInclude.getParamName().equals("*")) {
|
if ("*".equals(nextInclude.getParamName())) {
|
||||||
wantResourceType = nextInclude.getParamType();
|
wantResourceType = nextInclude.getParamType();
|
||||||
matchAll = true;
|
matchAll = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,10 @@ import ca.uhn.fhir.rest.api.server.IBundleProvider;
|
||||||
import ca.uhn.fhir.rest.param.TokenParam;
|
import ca.uhn.fhir.rest.param.TokenParam;
|
||||||
import org.hamcrest.Matcher;
|
import org.hamcrest.Matcher;
|
||||||
import org.hamcrest.collection.IsIterableContainingInAnyOrder;
|
import org.hamcrest.collection.IsIterableContainingInAnyOrder;
|
||||||
|
import org.hl7.fhir.r4.model.CarePlan;
|
||||||
import org.hl7.fhir.r4.model.EpisodeOfCare;
|
import org.hl7.fhir.r4.model.EpisodeOfCare;
|
||||||
import org.hl7.fhir.r4.model.Organization;
|
import org.hl7.fhir.r4.model.Organization;
|
||||||
|
import org.hl7.fhir.r4.model.Patient;
|
||||||
import org.hl7.fhir.r4.model.Reference;
|
import org.hl7.fhir.r4.model.Reference;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -21,6 +23,8 @@ import java.util.stream.IntStream;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.hl7.fhir.r4.model.ResourceType.Patient;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked", "Duplicates"})
|
@SuppressWarnings({"unchecked", "Duplicates"})
|
||||||
public class FhirResourceDaoR4SearchIncludeTest extends BaseJpaR4Test {
|
public class FhirResourceDaoR4SearchIncludeTest extends BaseJpaR4Test {
|
||||||
|
@ -83,6 +87,33 @@ public class FhirResourceDaoR4SearchIncludeTest extends BaseJpaR4Test {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSearchWithIncludeSpecDoesNotCauseNPE() {
|
||||||
|
createPatientWithReferencingCarePlan(1);
|
||||||
|
|
||||||
|
// First verify it with the "." syntax
|
||||||
|
SearchParameterMap map = SearchParameterMap.newSynchronous()
|
||||||
|
.addInclude(new Include("CarePlan.patient"));
|
||||||
|
try {
|
||||||
|
IBundleProvider results = myCarePlanDao.search(map);
|
||||||
|
List<String> ids = toUnqualifiedVersionlessIdValues(results);
|
||||||
|
assertThat(ids.toString(), ids, containsInAnyOrder("CarePlan/CP-1"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next verify it with the ":" syntax
|
||||||
|
SearchParameterMap map2 = SearchParameterMap.newSynchronous()
|
||||||
|
.addInclude(new Include("CarePlan:patient"));
|
||||||
|
try {
|
||||||
|
IBundleProvider results = myCarePlanDao.search(map2);
|
||||||
|
List<String> ids = toUnqualifiedVersionlessIdValues(results);
|
||||||
|
assertThat(ids.toString(), ids, containsInAnyOrder("CarePlan/CP-1", "Patient/PAT-1"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRevIncludesPaged_AsyncSearch() {
|
public void testRevIncludesPaged_AsyncSearch() {
|
||||||
int eocCount = 10;
|
int eocCount = 10;
|
||||||
|
@ -158,4 +189,17 @@ public class FhirResourceDaoR4SearchIncludeTest extends BaseJpaR4Test {
|
||||||
myEpisodeOfCareDao.update(eoc);
|
myEpisodeOfCareDao.update(eoc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createPatientWithReferencingCarePlan(int theCount) {
|
||||||
|
org.hl7.fhir.r4.model.Patient patient = new Patient();
|
||||||
|
patient.setId("Patient/PAT-1");
|
||||||
|
myPatientDao.update(patient);
|
||||||
|
|
||||||
|
for (int i = 1; i <= theCount; i++) {
|
||||||
|
CarePlan carePlan = new CarePlan();
|
||||||
|
carePlan.setId("CarePlan/CP-" + i);
|
||||||
|
carePlan.getSubject().setReference("Patient/PAT-1");
|
||||||
|
myCarePlanDao.update(carePlan);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue