99
1010import ca .uhn .fhir .jpa .api .config .DaoConfig ;
1111import ca .uhn .fhir .parser .StrictErrorHandler ;
12+ import ca .uhn .fhir .rest .api .Constants ;
1213import ca .uhn .fhir .rest .api .EncodingEnum ;
1314import com .google .common .base .Charsets ;
1415import org .apache .commons .io .IOUtils ;
2324import org .hl7 .fhir .r4 .model .Observation .ObservationStatus ;
2425import org .hl7 .fhir .r4 .model .Organization ;
2526import org .hl7 .fhir .r4 .model .Patient ;
27+ import org .hl7 .fhir .r4 .model .Reference ;
2628import org .junit .jupiter .api .*;
2729
2830import 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