Skip to content

Commit 22fe942

Browse files
committed
Add tests
1 parent ce1caee commit 22fe942

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/search/builder/SearchBuilder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,8 @@ public HashSet<ResourcePersistentId> loadIncludes(FhirContext theContext, Entity
705705
List<Long> results = q.getResultList();
706706
for (Long resourceLink : results) {
707707
if (resourceLink == null) {
708+
// This can happen if there are outgoing references which are canonical or point to
709+
// other servers
708710
continue;
709711
}
710712
if (theReverseMode) {

hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/PatientEverythingR4Test.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import ca.uhn.fhir.jpa.api.config.DaoConfig;
1111
import ca.uhn.fhir.parser.StrictErrorHandler;
12+
import ca.uhn.fhir.rest.api.Constants;
1213
import ca.uhn.fhir.rest.api.EncodingEnum;
1314
import com.google.common.base.Charsets;
1415
import org.apache.commons.io.IOUtils;
@@ -23,6 +24,7 @@
2324
import org.hl7.fhir.r4.model.Observation.ObservationStatus;
2425
import org.hl7.fhir.r4.model.Organization;
2526
import org.hl7.fhir.r4.model.Patient;
27+
import org.hl7.fhir.r4.model.Reference;
2628
import org.junit.jupiter.api.*;
2729

2830
import org.junit.jupiter.api.BeforeEach;
@@ -52,6 +54,7 @@ public void after() throws Exception {
5254
myDaoConfig.setReuseCachedSearchResultsForMillis(new DaoConfig().getReuseCachedSearchResultsForMillis());
5355
myDaoConfig.setEverythingIncludesFetchPageSize(new DaoConfig().getEverythingIncludesFetchPageSize());
5456
myDaoConfig.setSearchPreFetchThresholds(new DaoConfig().getSearchPreFetchThresholds());
57+
myDaoConfig.setAllowExternalReferences(new DaoConfig().isAllowExternalReferences());
5558
}
5659

5760
@Override
@@ -104,6 +107,44 @@ public void before() throws Exception {
104107

105108
}
106109

110+
@Test
111+
public void testEverythingWithCanonicalReferences() throws Exception {
112+
myDaoConfig.setAllowExternalReferences(true);
113+
114+
Patient p = new Patient();
115+
p.setManagingOrganization(new Reference("http://example.com/Organization/123"));
116+
String patientId = myPatientDao.create(p).getId().toUnqualifiedVersionless().getValue();
117+
118+
Observation obs = new Observation();
119+
obs.getSubject().setReference(patientId);
120+
obs.getEncounter().setReference("http://example.com/Encounter/999");
121+
String observationId = myObservationDao.create(obs).getId().toUnqualifiedVersionless().getValue();
122+
123+
// Normal call
124+
Bundle bundle = fetchBundle(ourServerBase + "/" + patientId + "/$everything?_format=json&_count=100", EncodingEnum.JSON);
125+
assertNull(bundle.getLink("next"));
126+
Set<String> actual = new TreeSet<>();
127+
for (BundleEntryComponent nextEntry : bundle.getEntry()) {
128+
actual.add(nextEntry.getResource().getIdElement().toUnqualifiedVersionless().getValue());
129+
}
130+
assertThat(actual, containsInAnyOrder(patientId, observationId));
131+
132+
// Synchronous call
133+
HttpGet get = new HttpGet(ourServerBase + "/" + patientId + "/$everything?_format=json&_count=100");
134+
get.addHeader(Constants.HEADER_CACHE_CONTROL, Constants.CACHE_CONTROL_NO_CACHE);
135+
try (CloseableHttpResponse resp = ourHttpClient.execute(get)) {
136+
assertEquals(EncodingEnum.JSON.getResourceContentTypeNonLegacy(), resp.getFirstHeader(ca.uhn.fhir.rest.api.Constants.HEADER_CONTENT_TYPE).getValue().replaceAll(";.*", ""));
137+
bundle = EncodingEnum.JSON.newParser(myFhirCtx).parseResource(Bundle.class, IOUtils.toString(resp.getEntity().getContent(), Charsets.UTF_8));
138+
}
139+
assertNull(bundle.getLink("next"));
140+
actual = new TreeSet<>();
141+
for (BundleEntryComponent nextEntry : bundle.getEntry()) {
142+
actual.add(nextEntry.getResource().getIdElement().toUnqualifiedVersionless().getValue());
143+
}
144+
assertThat(actual, containsInAnyOrder(patientId, observationId));
145+
}
146+
147+
107148
/**
108149
* See #674
109150
*/
@@ -114,7 +155,7 @@ public void testEverythingReturnsCorrectResources() throws Exception {
114155

115156
assertNull(bundle.getLink("next"));
116157

117-
Set<String> actual = new TreeSet<String>();
158+
Set<String> actual = new TreeSet<>();
118159
for (BundleEntryComponent nextEntry : bundle.getEntry()) {
119160
actual.add(nextEntry.getResource().getIdElement().toUnqualifiedVersionless().getValue());
120161
}

0 commit comments

Comments
 (0)