From 49bdff1862a58a52b4204442eafe450b7acf8ab1 Mon Sep 17 00:00:00 2001 From: patrick-werner Date: Tue, 5 Jun 2018 18:32:59 +0200 Subject: [PATCH] current state of $document --- .../dao/FhirResourceDaoCompositionDstu2.java | 3 +- .../jpa/dao/IFhirResourceDaoComposition.java | 6 +- .../FhirResourceDaoCompositionDstu3.java | 22 +-- .../dao/r4/FhirResourceDaoCompositionR4.java | 3 +- ...seJpaResourceProviderCompositionDstu2.java | 4 +- ...seJpaResourceProviderCompositionDstu3.java | 5 +- .../BaseJpaResourceProviderCompositionR4.java | 3 +- .../FhirResourceDaoDocumentDstu3Test.java | 9 -- .../dstu3/CompositionDocumentDstu3Test.java | 151 ++++++------------ 9 files changed, 71 insertions(+), 135 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoCompositionDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoCompositionDstu2.java index eabfdf27b53..554bd2e2a56 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoCompositionDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoCompositionDstu2.java @@ -22,7 +22,6 @@ package ca.uhn.fhir.jpa.dao; import ca.uhn.fhir.model.dstu2.resource.Composition; import ca.uhn.fhir.rest.api.SortSpec; -import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.server.exceptions.NotImplementedOperationException; @@ -38,7 +37,7 @@ public class FhirResourceDaoCompositionDstu2 extends FhirResourceDaoDstu2 theCount, DateRangeParam theLastUpdate, SortSpec theSort, RequestDetails theRequestDetails) { + public org.hl7.fhir.instance.model.Bundle getDocumentForComposition(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdate, SortSpec theSort, RequestDetails theRequestDetails) { throw new NotImplementedOperationException("$document in DSTU2 is not implemented "); } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoComposition.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoComposition.java index 75ca9f36997..7a466b9f885 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoComposition.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/IFhirResourceDaoComposition.java @@ -1,10 +1,10 @@ package ca.uhn.fhir.jpa.dao; import ca.uhn.fhir.rest.api.SortSpec; -import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.param.DateRangeParam; -import ca.uhn.fhir.rest.param.StringAndListParam; +import org.hl7.fhir.instance.model.Bundle; +import org.hl7.fhir.instance.model.api.IBaseBundle; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IPrimitiveType; @@ -33,6 +33,6 @@ import javax.servlet.http.HttpServletRequest; public interface IFhirResourceDaoComposition extends IFhirResourceDao { - IBundleProvider getDocumentForComposition(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdate, SortSpec theSort, RequestDetails theRequestDetails); + IBaseBundle getDocumentForComposition(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdate, SortSpec theSort, RequestDetails theRequestDetails); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCompositionDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCompositionDstu3.java index ce00f7cee12..5dce3ca4fca 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCompositionDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCompositionDstu3.java @@ -21,28 +21,26 @@ package ca.uhn.fhir.jpa.dao.dstu3; */ import ca.uhn.fhir.jpa.dao.IFhirResourceDaoComposition; -import ca.uhn.fhir.jpa.dao.IFhirResourceDaoPatient; import ca.uhn.fhir.jpa.dao.ISearchParamRegistry; import ca.uhn.fhir.jpa.dao.SearchParameterMap; -import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum; import ca.uhn.fhir.model.api.IResource; -import ca.uhn.fhir.rest.api.CacheControlDirective; -import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.param.CompositeParam; import ca.uhn.fhir.rest.param.DateRangeParam; -import ca.uhn.fhir.rest.param.StringAndListParam; import ca.uhn.fhir.rest.param.StringParam; +import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Composition; -import org.hl7.fhir.dstu3.model.Patient; +import org.hl7.fhir.dstu3.model.Resource; +import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.springframework.beans.factory.annotation.Autowired; import javax.servlet.http.HttpServletRequest; import java.util.Collections; +import java.util.Date; +import java.util.List; public class FhirResourceDaoCompositionDstu3 extends FhirResourceDaoDstu3 implements IFhirResourceDaoComposition { @@ -50,7 +48,7 @@ public class FhirResourceDaoCompositionDstu3 extends FhirResourceDaoDstu3 theCount, DateRangeParam theLastUpdate, SortSpec theSort, RequestDetails theRequestDetails) { + public Bundle getDocumentForComposition(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdate, SortSpec theSort, RequestDetails theRequestDetails) { SearchParameterMap paramMap = new SearchParameterMap(); if (theCount != null) { paramMap.setCount(theCount.getValue()); @@ -65,7 +63,13 @@ public class FhirResourceDaoCompositionDstu3 extends FhirResourceDaoDstu3 resourceList = retVal.getResources(0, retVal.size()); + + Bundle bundle = new Bundle().setType(Bundle.BundleType.DOCUMENT); + for (IBaseResource resource : resourceList) + bundle.addEntry(new Bundle.BundleEntryComponent().setResource((Resource) resource)); + + return bundle; } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoCompositionR4.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoCompositionR4.java index dac59427e15..72e6564d2ed 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoCompositionR4.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoCompositionR4.java @@ -23,7 +23,6 @@ package ca.uhn.fhir.jpa.dao.r4; import ca.uhn.fhir.jpa.dao.IFhirResourceDaoComposition; import ca.uhn.fhir.jpa.dao.ISearchParamRegistry; import ca.uhn.fhir.rest.api.SortSpec; -import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.param.DateRangeParam; import org.hl7.fhir.instance.model.api.IIdType; @@ -39,7 +38,7 @@ public class FhirResourceDaoCompositionR4 extends FhirResourceDaoR4 private ISearchParamRegistry mySearchParamRegistry; @Override - public IBundleProvider getDocumentForComposition(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdate, SortSpec theSort, RequestDetails theRequestDetails) { + public org.hl7.fhir.instance.model.Bundle getDocumentForComposition(HttpServletRequest theServletRequest, IIdType theId, IPrimitiveType theCount, DateRangeParam theLastUpdate, SortSpec theSort, RequestDetails theRequestDetails) { return null; } } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderCompositionDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderCompositionDstu2.java index d6e7260c211..b651176147b 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderCompositionDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/BaseJpaResourceProviderCompositionDstu2.java @@ -3,6 +3,7 @@ package ca.uhn.fhir.jpa.provider; import ca.uhn.fhir.jpa.dao.IFhirResourceDaoComposition; import ca.uhn.fhir.model.api.annotation.Description; +import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.dstu2.resource.Composition; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.annotation.IdParam; @@ -14,6 +15,7 @@ import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.param.DateRangeParam; +import org.hl7.fhir.instance.model.api.IBaseBundle; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -44,7 +46,7 @@ public class BaseJpaResourceProviderCompositionDstu2 extends JpaResourceProvider */ //@formatter:off @Operation(name = "document", idempotent = true, bundleType=BundleTypeEnum.SEARCHSET) - public IBundleProvider getDocumentForComposition( + public IBaseBundle getDocumentForComposition( javax.servlet.http.HttpServletRequest theServletRequest) { //@formatter:on diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderCompositionDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderCompositionDstu3.java index 2e129f85804..c66a8f4e59d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderCompositionDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/dstu3/BaseJpaResourceProviderCompositionDstu3.java @@ -14,6 +14,7 @@ import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import org.hl7.fhir.dstu3.model.*; +import org.hl7.fhir.instance.model.api.IBaseBundle; /* * #%L @@ -42,8 +43,8 @@ public class BaseJpaResourceProviderCompositionDstu3 extends JpaResourceProvider * @param theRequestDetails */ //@formatter:off - @Operation(name = "document", idempotent = true, bundleType=BundleTypeEnum.SEARCHSET) - public IBundleProvider getDocumentForComposition( + @Operation(name = "document", idempotent = true, bundleType=BundleTypeEnum.DOCUMENT) + public IBaseBundle getDocumentForComposition( javax.servlet.http.HttpServletRequest theServletRequest, diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/BaseJpaResourceProviderCompositionR4.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/BaseJpaResourceProviderCompositionR4.java index 9f60a1479c9..ab2808ee8b8 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/BaseJpaResourceProviderCompositionR4.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/provider/r4/BaseJpaResourceProviderCompositionR4.java @@ -13,6 +13,7 @@ import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.param.DateRangeParam; +import org.hl7.fhir.instance.model.api.IBaseBundle; import org.hl7.fhir.r4.model.Composition; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.UnsignedIntType; @@ -46,7 +47,7 @@ public class BaseJpaResourceProviderCompositionR4 extends JpaResourceProviderR4< */ //@formatter:off @Operation(name = "document", idempotent = true, bundleType=BundleTypeEnum.SEARCHSET) - public IBundleProvider getDocumentForComposition( + public IBaseBundle getDocumentForComposition( javax.servlet.http.HttpServletRequest theServletRequest, diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDocumentDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDocumentDstu3Test.java index c81060f78c4..ea21dc3fe45 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDocumentDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDocumentDstu3Test.java @@ -26,13 +26,4 @@ public class FhirResourceDaoDocumentDstu3Test extends BaseJpaDstu3Test { Bundle inputBundle = myFhirCtx.newXmlParser().parseResource(Bundle.class, input); DaoMethodOutcome responseBundle = myBundleDao.create(inputBundle, mySrd); } - - @Test - public void testGetDocument() throws Exception { - String input = IOUtils.toString(getClass().getResourceAsStream("/sample-document.xml"), StandardCharsets.UTF_8); - Bundle inputBundle = myFhirCtx.newXmlParser().parseResource(Bundle.class, input); - DaoMethodOutcome responseBundle = myBundleDao.create(inputBundle, mySrd); - - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/CompositionDocumentDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/CompositionDocumentDstu3Test.java index 72f1a323a45..c9422b7c117 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/CompositionDocumentDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/CompositionDocumentDstu3Test.java @@ -13,10 +13,7 @@ import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; import org.hl7.fhir.dstu3.model.Encounter.EncounterStatus; import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.*; import java.io.IOException; import java.util.ArrayList; @@ -31,11 +28,10 @@ public class CompositionDocumentDstu3Test extends BaseResourceProviderDstu3Test private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CompositionDocumentDstu3Test.class); private String orgId; private String patId; - private String encId1; - private String encId2; private ArrayList myObsIds; - private String myWrongPatId; - private String myWrongEnc1; + private String encId; + private String listId; + private String compId; @Before public void beforeDisableResultReuse() { @@ -56,7 +52,7 @@ public class CompositionDocumentDstu3Test extends BaseResourceProviderDstu3Test myFhirCtx.setParserErrorHandler(new StrictErrorHandler()); myDaoConfig.setAllowMultipleDelete(true); - + Organization org = new Organization(); org.setName("an org"); orgId = ourClient.create().resource(org).execute().getId().toUnqualifiedVersionless().getValue(); @@ -66,139 +62,82 @@ public class CompositionDocumentDstu3Test extends BaseResourceProviderDstu3Test patient.getManagingOrganization().setReference(orgId); patId = ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless().getValue(); - Patient patient2 = new Patient(); - patient2.getManagingOrganization().setReference(orgId); - myWrongPatId = ourClient.create().resource(patient2).execute().getId().toUnqualifiedVersionless().getValue(); + Encounter enc = new Encounter(); + enc.setStatus(EncounterStatus.ARRIVED); + enc.getSubject().setReference(patId); + enc.getServiceProvider().setReference(orgId); + encId = ourClient.create().resource(enc).execute().getId().toUnqualifiedVersionless().getValue(); - Encounter enc1 = new Encounter(); - enc1.setStatus(EncounterStatus.CANCELLED); - enc1.getSubject().setReference(patId); - enc1.getServiceProvider().setReference(orgId); - encId1 = ourClient.create().resource(enc1).execute().getId().toUnqualifiedVersionless().getValue(); - - Encounter enc2 = new Encounter(); - enc2.setStatus(EncounterStatus.ARRIVED); - enc2.getSubject().setReference(patId); - enc2.getServiceProvider().setReference(orgId); - encId2 = ourClient.create().resource(enc2).execute().getId().toUnqualifiedVersionless().getValue(); - - Encounter wrongEnc1 = new Encounter(); - wrongEnc1.setStatus(EncounterStatus.ARRIVED); - wrongEnc1.getSubject().setReference(myWrongPatId); - wrongEnc1.getServiceProvider().setReference(orgId); - myWrongEnc1 = ourClient.create().resource(wrongEnc1).execute().getId().toUnqualifiedVersionless().getValue(); + ListResource listResource = new ListResource(); + ArrayList myObs = new ArrayList<>(); myObsIds = new ArrayList(); - for (int i = 0; i < 20; i++) { + for (int i = 0; i < 5; i++) { Observation obs = new Observation(); obs.getSubject().setReference(patId); obs.setStatus(ObservationStatus.FINAL); String obsId = ourClient.create().resource(obs).execute().getId().toUnqualifiedVersionless().getValue(); + listResource.addEntry(new ListResource.ListEntryComponent().setItem(new Reference(obs))); + myObs.add(obs); myObsIds.add(obsId); } - } + listId = ourClient.create().resource(listResource).execute().getId().toUnqualifiedVersionless().getValue(); - /** - * See #674 - */ - @Test - public void testEverythingReturnsCorrectResources() throws Exception { - - Bundle bundle = fetchBundle(ourServerBase + "/" + patId + "/$everything?_format=json&_count=100", EncodingEnum.JSON); - - assertNull(bundle.getLink("next")); - - Set actual = new TreeSet(); - for (BundleEntryComponent nextEntry : bundle.getEntry()) { - actual.add(nextEntry.getResource().getIdElement().toUnqualifiedVersionless().getValue()); + Composition composition = new Composition(); + composition.setSubject(new Reference(patient)); + composition.addSection().addEntry(new Reference(patient)); + composition.addSection().addEntry(new Reference(org)); + composition.addSection().addEntry(new Reference(enc)); + composition.addSection().addEntry(new Reference(listResource)); + composition.addSection().addEntry(new Reference(listResource)); + + for (Observation obs : myObs) { + composition.addSection().addEntry(new Reference(obs)); } - - ourLog.info("Found IDs: {}", actual); - - assertThat(actual, hasItem(patId)); - assertThat(actual, hasItem(encId1)); - assertThat(actual, hasItem(encId2)); - assertThat(actual, hasItem(orgId)); - assertThat(actual, hasItems(myObsIds.toArray(new String[0]))); - assertThat(actual, not(hasItem(myWrongPatId))); - assertThat(actual, not(hasItem(myWrongEnc1))); + + compId = ourClient.create().resource(composition).execute().getId().toUnqualifiedVersionless().getValue(); } - /** - * See #674 - */ @Test - public void testEverythingReturnsCorrectResourcesSmallPage() throws Exception { + public void testDocumentBundleReturnedCorrect() throws Exception { myDaoConfig.setEverythingIncludesFetchPageSize(1); - - Bundle bundle = fetchBundle(ourServerBase + "/" + patId + "/$everything?_format=json&_count=100", EncodingEnum.JSON); - + + String theUrl = ourServerBase + "/" + compId + "/$document?_format=json&_count=100"; + System.out.println(theUrl); + Bundle bundle = fetchBundle(theUrl, EncodingEnum.JSON); + assertNull(bundle.getLink("next")); - + Set actual = new TreeSet(); for (BundleEntryComponent nextEntry : bundle.getEntry()) { actual.add(nextEntry.getResource().getIdElement().toUnqualifiedVersionless().getValue()); } - + ourLog.info("Found IDs: {}", actual); - + assertThat(actual, hasItem(patId)); - assertThat(actual, hasItem(encId1)); - assertThat(actual, hasItem(encId2)); + assertThat(actual, hasItem(encId)); + assertThat(actual, hasItem(encId)); assertThat(actual, hasItem(orgId)); assertThat(actual, hasItems(myObsIds.toArray(new String[0]))); - assertThat(actual, not(hasItem(myWrongPatId))); - assertThat(actual, not(hasItem(myWrongEnc1))); - } - - /** - * See #674 - */ - @Test - public void testEverythingPagesWithCorrectEncodingJson() throws Exception { - - Bundle bundle = fetchBundle(ourServerBase + "/" + patId + "/$everything?_format=json&_count=1", EncodingEnum.JSON); - - assertNotNull(bundle.getLink("next").getUrl()); - assertThat(bundle.getLink("next").getUrl(), containsString("_format=json")); - bundle = fetchBundle(bundle.getLink("next").getUrl(), EncodingEnum.JSON); - - assertNotNull(bundle.getLink("next").getUrl()); - assertThat(bundle.getLink("next").getUrl(), containsString("_format=json")); - bundle = fetchBundle(bundle.getLink("next").getUrl(), EncodingEnum.JSON); - } - - /** - * See #674 - */ - @Test - public void testEverythingPagesWithCorrectEncodingXml() throws Exception { - - Bundle bundle = fetchBundle(ourServerBase + "/" + patId + "/$everything?_format=xml&_count=1", EncodingEnum.XML); - - assertNotNull(bundle.getLink("next").getUrl()); - ourLog.info("Next link: {}", bundle.getLink("next").getUrl()); - assertThat(bundle.getLink("next").getUrl(), containsString("_format=xml")); - bundle = fetchBundle(bundle.getLink("next").getUrl(), EncodingEnum.XML); - - assertNotNull(bundle.getLink("next").getUrl()); - ourLog.info("Next link: {}", bundle.getLink("next").getUrl()); - assertThat(bundle.getLink("next").getUrl(), containsString("_format=xml")); - bundle = fetchBundle(bundle.getLink("next").getUrl(), EncodingEnum.XML); } private Bundle fetchBundle(String theUrl, EncodingEnum theEncoding) throws IOException, ClientProtocolException { Bundle bundle; HttpGet get = new HttpGet(theUrl); CloseableHttpResponse resp = ourHttpClient.execute(get); + try { + String test = IOUtils.toString(resp.getEntity().getContent(), Charsets.UTF_8); + System.out.println(test); + assertEquals(theEncoding.getResourceContentTypeNonLegacy(), resp.getFirstHeader(ca.uhn.fhir.rest.api.Constants.HEADER_CONTENT_TYPE).getValue().replaceAll(";.*", "")); - bundle = theEncoding.newParser(myFhirCtx).parseResource(Bundle.class, IOUtils.toString(resp.getEntity().getContent(), Charsets.UTF_8)); + bundle = theEncoding.newParser(myFhirCtx).parseResource(Bundle.class, test); } finally { IOUtils.closeQuietly(resp); } - + return bundle; }