|
|
|
@ -1,28 +1,5 @@
|
|
|
|
|
package ca.uhn.fhir.rest.server;
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.containsInAnyOrder;
|
|
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
import static org.junit.Assert.assertThat;
|
|
|
|
|
import static org.junit.Assert.fail;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import ca.uhn.fhir.rest.api.EncodingEnum;
|
|
|
|
|
import ca.uhn.fhir.test.utilities.JettyUtil;
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
|
import org.apache.http.HttpResponse;
|
|
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
|
|
import org.apache.http.impl.client.HttpClientBuilder;
|
|
|
|
|
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
|
|
|
|
import org.eclipse.jetty.server.Server;
|
|
|
|
|
import org.eclipse.jetty.servlet.ServletHandler;
|
|
|
|
|
import org.eclipse.jetty.servlet.ServletHolder;
|
|
|
|
|
import org.hl7.fhir.r4.model.*;
|
|
|
|
|
import org.junit.*;
|
|
|
|
|
|
|
|
|
|
import ca.uhn.fhir.context.FhirContext;
|
|
|
|
|
import ca.uhn.fhir.context.api.BundleInclusionRule;
|
|
|
|
|
import ca.uhn.fhir.model.api.Include;
|
|
|
|
@ -30,129 +7,156 @@ import ca.uhn.fhir.model.api.annotation.Child;
|
|
|
|
|
import ca.uhn.fhir.model.api.annotation.Extension;
|
|
|
|
|
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
|
|
|
|
import ca.uhn.fhir.model.primitive.StringDt;
|
|
|
|
|
import ca.uhn.fhir.rest.annotation.*;
|
|
|
|
|
import ca.uhn.fhir.util.*;
|
|
|
|
|
import ca.uhn.fhir.rest.annotation.IncludeParam;
|
|
|
|
|
import ca.uhn.fhir.rest.annotation.RequiredParam;
|
|
|
|
|
import ca.uhn.fhir.rest.annotation.Search;
|
|
|
|
|
import ca.uhn.fhir.rest.api.Constants;
|
|
|
|
|
import ca.uhn.fhir.rest.api.EncodingEnum;
|
|
|
|
|
import ca.uhn.fhir.test.utilities.JettyUtil;
|
|
|
|
|
import ca.uhn.fhir.util.BundleUtil;
|
|
|
|
|
import ca.uhn.fhir.util.ElementUtil;
|
|
|
|
|
import ca.uhn.fhir.util.TestUtil;
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
|
|
import org.apache.http.impl.client.HttpClientBuilder;
|
|
|
|
|
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
|
|
|
|
import org.eclipse.jetty.server.Server;
|
|
|
|
|
import org.eclipse.jetty.servlet.ServletHandler;
|
|
|
|
|
import org.eclipse.jetty.servlet.ServletHolder;
|
|
|
|
|
import org.hl7.fhir.r4.model.*;
|
|
|
|
|
import org.junit.AfterClass;
|
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.containsInAnyOrder;
|
|
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
|
|
|
|
public class IncludeTest {
|
|
|
|
|
|
|
|
|
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(IncludeTest.class);
|
|
|
|
|
private static CloseableHttpClient ourClient;
|
|
|
|
|
private static FhirContext ourCtx;
|
|
|
|
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(IncludeTest.class);
|
|
|
|
|
private static int ourPort;
|
|
|
|
|
private static Server ourServer;
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testBadInclude() throws Exception {
|
|
|
|
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo&_include=baz");
|
|
|
|
|
HttpResponse status = ourClient.execute(httpGet);
|
|
|
|
|
assertEquals(400, status.getStatusLine().getStatusCode());
|
|
|
|
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
|
|
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
|
|
|
try (CloseableHttpResponse status = ourClient.execute(httpGet)) {
|
|
|
|
|
assertEquals(400, status.getStatusLine().getStatusCode());
|
|
|
|
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
|
|
|
|
|
|
|
|
ourLog.info(responseContent);
|
|
|
|
|
assertThat(responseContent, containsString("Invalid _include parameter value"));
|
|
|
|
|
ourLog.info(responseContent);
|
|
|
|
|
assertThat(responseContent, containsString("Invalid _include parameter value"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testIIncludedResourcesNonContained() throws Exception {
|
|
|
|
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=normalInclude&_pretty=true");
|
|
|
|
|
HttpResponse status = ourClient.execute(httpGet);
|
|
|
|
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
|
|
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
|
|
|
try (CloseableHttpResponse status = ourClient.execute(httpGet)) {
|
|
|
|
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
|
|
|
|
|
|
|
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
|
|
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
|
|
|
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
|
|
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
|
|
|
|
|
|
|
|
|
ourLog.info(responseContent);
|
|
|
|
|
ourLog.info(responseContent);
|
|
|
|
|
|
|
|
|
|
assertEquals(3, bundle.getEntry().size());
|
|
|
|
|
|
|
|
|
|
assertEquals(("Patient/p1"), bundle.getEntry().get(0).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals(("Patient/p2"), bundle.getEntry().get(1).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals(("Organization/o1"), bundle.getEntry().get(2).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals(3, bundle.getEntry().size());
|
|
|
|
|
|
|
|
|
|
Patient p1 = (Patient) bundle.getEntry().get(0).getResource();
|
|
|
|
|
assertEquals(0, p1.getContained().size());
|
|
|
|
|
assertEquals(("Patient/p1"), bundle.getEntry().get(0).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals(("Patient/p2"), bundle.getEntry().get(1).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals(("Organization/o1"), bundle.getEntry().get(2).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
|
|
|
|
|
Patient p2 = (Patient) bundle.getEntry().get(1).getResource();
|
|
|
|
|
assertEquals(0, p2.getContained().size());
|
|
|
|
|
Patient p1 = (Patient) bundle.getEntry().get(0).getResource();
|
|
|
|
|
assertEquals(0, p1.getContained().size());
|
|
|
|
|
|
|
|
|
|
Patient p2 = (Patient) bundle.getEntry().get(1).getResource();
|
|
|
|
|
assertEquals(0, p2.getContained().size());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testIIncludedResourcesNonContainedInDeclaredExtension() throws Exception {
|
|
|
|
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=declaredExtInclude&_pretty=true");
|
|
|
|
|
HttpResponse status = ourClient.execute(httpGet);
|
|
|
|
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
|
|
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
|
|
|
try (CloseableHttpResponse status = ourClient.execute(httpGet)) {
|
|
|
|
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
|
|
|
|
|
|
|
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
|
|
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
|
|
|
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
|
|
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
|
|
|
|
|
|
|
|
|
ourLog.info(responseContent);
|
|
|
|
|
ourLog.info(responseContent);
|
|
|
|
|
|
|
|
|
|
assertEquals(4, bundle.getEntry().size());
|
|
|
|
|
assertEquals(("Patient/p1"), bundle.getEntry().get(0).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals(("Patient/p2"), bundle.getEntry().get(1).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals(("Organization/o1"), bundle.getEntry().get(2).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals(("Organization/o2"), bundle.getEntry().get(3).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals(4, bundle.getEntry().size());
|
|
|
|
|
assertEquals(("Patient/p1"), bundle.getEntry().get(0).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals(("Patient/p2"), bundle.getEntry().get(1).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals(("Organization/o1"), bundle.getEntry().get(2).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals(("Organization/o2"), bundle.getEntry().get(3).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
|
|
|
|
|
Patient p1 = (Patient) bundle.getEntry().get(0).getResource();
|
|
|
|
|
assertEquals(0, p1.getContained().size());
|
|
|
|
|
Patient p1 = (Patient) bundle.getEntry().get(0).getResource();
|
|
|
|
|
assertEquals(0, p1.getContained().size());
|
|
|
|
|
|
|
|
|
|
Patient p2 = (Patient) bundle.getEntry().get(1).getResource();
|
|
|
|
|
assertEquals(0, p2.getContained().size());
|
|
|
|
|
Patient p2 = (Patient) bundle.getEntry().get(1).getResource();
|
|
|
|
|
assertEquals(0, p2.getContained().size());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testIIncludedResourcesNonContainedInExtension() throws Exception {
|
|
|
|
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=extInclude&_pretty=true");
|
|
|
|
|
HttpResponse status = ourClient.execute(httpGet);
|
|
|
|
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
|
|
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
|
|
|
try (CloseableHttpResponse status = ourClient.execute(httpGet)) {
|
|
|
|
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
|
|
|
|
|
|
|
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
|
|
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
|
|
|
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
|
|
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
|
|
|
|
|
|
|
|
|
ourLog.info(responseContent);
|
|
|
|
|
ourLog.info(responseContent);
|
|
|
|
|
|
|
|
|
|
assertEquals(3, bundle.getEntry().size());
|
|
|
|
|
assertEquals(("Patient/p1"), bundle.getEntry().get(0).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals(("Patient/p2"), bundle.getEntry().get(1).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals(("Organization/o1"), bundle.getEntry().get(2).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals(3, bundle.getEntry().size());
|
|
|
|
|
assertEquals(("Patient/p1"), bundle.getEntry().get(0).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals(("Patient/p2"), bundle.getEntry().get(1).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals(("Organization/o1"), bundle.getEntry().get(2).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
|
|
|
|
|
Patient p1 = (Patient) bundle.getEntry().get(0).getResource();
|
|
|
|
|
assertEquals(0, p1.getContained().size());
|
|
|
|
|
Patient p1 = (Patient) bundle.getEntry().get(0).getResource();
|
|
|
|
|
assertEquals(0, p1.getContained().size());
|
|
|
|
|
|
|
|
|
|
Patient p2 = (Patient) bundle.getEntry().get(1).getResource();
|
|
|
|
|
assertEquals(0, p2.getContained().size());
|
|
|
|
|
Patient p2 = (Patient) bundle.getEntry().get(1).getResource();
|
|
|
|
|
assertEquals(0, p2.getContained().size());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testIIncludedResourcesNonContainedInExtensionJson() throws Exception {
|
|
|
|
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=extInclude&_pretty=true&_format=json");
|
|
|
|
|
HttpResponse status = ourClient.execute(httpGet);
|
|
|
|
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
|
|
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
|
|
|
try (CloseableHttpResponse status = ourClient.execute(httpGet)) {
|
|
|
|
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
|
|
|
|
|
|
|
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
|
|
|
Bundle bundle = ourCtx.newJsonParser().parseResource(Bundle.class, responseContent);
|
|
|
|
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
|
|
|
Bundle bundle = ourCtx.newJsonParser().parseResource(Bundle.class, responseContent);
|
|
|
|
|
|
|
|
|
|
ourLog.info(responseContent);
|
|
|
|
|
ourLog.info(responseContent);
|
|
|
|
|
|
|
|
|
|
assertEquals(3, bundle.getEntry().size());
|
|
|
|
|
assertEquals("Patient/p1", bundle.getEntry().get(0).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals("Patient/p2", bundle.getEntry().get(1).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals("Organization/o1", bundle.getEntry().get(2).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals(3, bundle.getEntry().size());
|
|
|
|
|
assertEquals("Patient/p1", bundle.getEntry().get(0).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals("Patient/p2", bundle.getEntry().get(1).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
assertEquals("Organization/o1", bundle.getEntry().get(2).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
|
|
|
|
|
|
|
|
|
Patient p1 = (Patient) bundle.getEntry().get(0).getResource();
|
|
|
|
|
assertEquals(0, p1.getContained().size());
|
|
|
|
|
Patient p1 = (Patient) bundle.getEntry().get(0).getResource();
|
|
|
|
|
assertEquals(0, p1.getContained().size());
|
|
|
|
|
|
|
|
|
|
Patient p2 = (Patient) bundle.getEntry().get(1).getResource();
|
|
|
|
|
assertEquals(0, p2.getContained().size());
|
|
|
|
|
Patient p2 = (Patient) bundle.getEntry().get(1).getResource();
|
|
|
|
|
assertEquals(0, p2.getContained().size());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -189,106 +193,73 @@ public class IncludeTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void testNoIncludes() throws Exception {
|
|
|
|
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello");
|
|
|
|
|
HttpResponse status = ourClient.execute(httpGet);
|
|
|
|
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
|
|
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
|
|
|
try (CloseableHttpResponse status = ourClient.execute(httpGet)) {
|
|
|
|
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
|
|
|
|
|
|
|
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
|
|
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
|
|
|
|
assertEquals(1, bundle.getEntry().size());
|
|
|
|
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
|
|
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
|
|
|
|
assertEquals(1, bundle.getEntry().size());
|
|
|
|
|
|
|
|
|
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
|
|
|
|
assertEquals(0, p.getName().size());
|
|
|
|
|
assertEquals("Hello", p.getIdElement().getIdPart());
|
|
|
|
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
|
|
|
|
assertEquals(0, p.getName().size());
|
|
|
|
|
assertEquals("Hello", p.getIdElement().getIdPart());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testOneInclude() throws Exception {
|
|
|
|
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo");
|
|
|
|
|
HttpResponse status = ourClient.execute(httpGet);
|
|
|
|
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
|
|
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
|
|
|
try (CloseableHttpResponse status = ourClient.execute(httpGet)) {
|
|
|
|
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
|
|
|
|
|
|
|
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
|
|
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
|
|
|
|
assertEquals(1, bundle.getEntry().size());
|
|
|
|
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
|
|
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
|
|
|
|
assertEquals(1, bundle.getEntry().size());
|
|
|
|
|
|
|
|
|
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
|
|
|
|
assertEquals(1, p.getName().size());
|
|
|
|
|
assertEquals("Hello", p.getIdElement().getIdPart());
|
|
|
|
|
assertEquals("foo", p.getName().get(0).getFamily());
|
|
|
|
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
|
|
|
|
assertEquals(1, p.getName().size());
|
|
|
|
|
assertEquals("Hello", p.getIdElement().getIdPart());
|
|
|
|
|
assertEquals("foo-false", p.getName().get(0).getFamily());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testOneIncludeIterate() throws Exception {
|
|
|
|
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&" + Constants.PARAM_INCLUDE_ITERATE + "=foo");
|
|
|
|
|
try (CloseableHttpResponse status = ourClient.execute(httpGet)) {
|
|
|
|
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
|
|
|
|
|
|
|
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
|
|
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
|
|
|
|
assertEquals(1, bundle.getEntry().size());
|
|
|
|
|
|
|
|
|
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
|
|
|
|
assertEquals(1, p.getName().size());
|
|
|
|
|
assertEquals("Hello", p.getIdElement().getIdPart());
|
|
|
|
|
assertEquals("foo-true", p.getName().get(0).getFamily());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testTwoInclude() throws Exception {
|
|
|
|
|
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo&_include=bar");
|
|
|
|
|
HttpResponse status = ourClient.execute(httpGet);
|
|
|
|
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
|
|
|
IOUtils.closeQuietly(status.getEntity().getContent());
|
|
|
|
|
try (CloseableHttpResponse status = ourClient.execute(httpGet)) {
|
|
|
|
|
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
|
|
|
|
|
|
|
|
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
|
|
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
|
|
|
|
assertEquals(1, bundle.getEntry().size());
|
|
|
|
|
assertEquals(200, status.getStatusLine().getStatusCode());
|
|
|
|
|
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
|
|
|
|
assertEquals(1, bundle.getEntry().size());
|
|
|
|
|
|
|
|
|
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
|
|
|
|
assertEquals(2, p.getName().size());
|
|
|
|
|
assertEquals("Hello", p.getIdElement().getIdPart());
|
|
|
|
|
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
|
|
|
|
assertEquals(2, p.getName().size());
|
|
|
|
|
assertEquals("Hello", p.getIdElement().getIdPart());
|
|
|
|
|
|
|
|
|
|
Set<String> values = new HashSet<String>();
|
|
|
|
|
values.add(p.getName().get(0).getFamily());
|
|
|
|
|
values.add(p.getName().get(1).getFamily());
|
|
|
|
|
assertThat(values, containsInAnyOrder("foo", "bar"));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@AfterClass
|
|
|
|
|
public static void afterClassClearContext() throws Exception {
|
|
|
|
|
JettyUtil.closeServer(ourServer);
|
|
|
|
|
TestUtil.clearAllStaticFieldsForUnitTest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
|
public static void beforeClass() throws Exception {
|
|
|
|
|
|
|
|
|
|
ourCtx = FhirContext.forR4();
|
|
|
|
|
ourServer = new Server(0);
|
|
|
|
|
|
|
|
|
|
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
|
|
|
|
|
|
|
|
|
|
ServletHandler proxyHandler = new ServletHandler();
|
|
|
|
|
RestfulServer servlet = new RestfulServer(ourCtx);
|
|
|
|
|
servlet.setDefaultResponseEncoding(EncodingEnum.XML);
|
|
|
|
|
servlet.setBundleInclusionRule(BundleInclusionRule.BASED_ON_RESOURCE_PRESENCE);
|
|
|
|
|
servlet.setResourceProviders(patientProvider, new DummyDiagnosticReportResourceProvider());
|
|
|
|
|
ServletHolder servletHolder = new ServletHolder(servlet);
|
|
|
|
|
proxyHandler.addServletWithMapping(servletHolder, "/*");
|
|
|
|
|
ourServer.setHandler(proxyHandler);
|
|
|
|
|
JettyUtil.startServer(ourServer);
|
|
|
|
|
ourPort = JettyUtil.getPortForStartedServer(ourServer);
|
|
|
|
|
|
|
|
|
|
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
|
|
|
|
|
HttpClientBuilder builder = HttpClientBuilder.create();
|
|
|
|
|
builder.setConnectionManager(connectionManager);
|
|
|
|
|
ourClient = builder.build();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
|
|
|
|
Organization org = new Organization();
|
|
|
|
|
org.setId("Organization/65546");
|
|
|
|
|
org.getNameElement().setValue("Contained Test Organization");
|
|
|
|
|
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.setId("Patient/1333");
|
|
|
|
|
patient.addIdentifier().setSystem("urn:mrns").setValue("253345");
|
|
|
|
|
patient.getManagingOrganization().setResource(patient);
|
|
|
|
|
|
|
|
|
|
System.out.println(FhirContext.forR4().newXmlParser().setPrettyPrint(true).encodeResourceToString(patient));
|
|
|
|
|
|
|
|
|
|
patient.getManagingOrganization().getReference();
|
|
|
|
|
Set<String> values = new HashSet<String>();
|
|
|
|
|
values.add(p.getName().get(0).getFamily());
|
|
|
|
|
values.add(p.getName().get(1).getFamily());
|
|
|
|
|
assertThat(values, containsInAnyOrder("foo-false", "bar-false"));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -397,13 +368,13 @@ public class IncludeTest {
|
|
|
|
|
Patient p2 = new Patient();
|
|
|
|
|
p2.setId("p2");
|
|
|
|
|
p2.addIdentifier().setValue("p2");
|
|
|
|
|
p2.addExtension(new org.hl7.fhir.r4.model.Extension( "http://foo", new Reference(o1)));
|
|
|
|
|
p2.addExtension(new org.hl7.fhir.r4.model.Extension("http://foo", new Reference(o1)));
|
|
|
|
|
|
|
|
|
|
return Arrays.asList(p1, p2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Search
|
|
|
|
|
public List<Patient> findPatientWithSimpleNames(@RequiredParam(name = Patient.SP_NAME) StringDt theName, @IncludeParam(allow = { "foo", "bar" }) Set<Include> theIncludes) {
|
|
|
|
|
public List<Patient> findPatientWithSimpleNames(@RequiredParam(name = Patient.SP_NAME) StringDt theName, @IncludeParam(allow = {"foo", "bar"}) Set<Include> theIncludes) {
|
|
|
|
|
ArrayList<Patient> retVal = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
Patient p = new Patient();
|
|
|
|
@ -413,7 +384,7 @@ public class IncludeTest {
|
|
|
|
|
|
|
|
|
|
if (theIncludes != null) {
|
|
|
|
|
for (Include next : theIncludes) {
|
|
|
|
|
p.addName().setFamily(next.getValue());
|
|
|
|
|
p.addName().setFamily(next.getValue() + "-" + next.isRecurse());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
retVal.add(p);
|
|
|
|
@ -447,11 +418,10 @@ public class IncludeTest {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ResourceDef(name = "Patient")
|
|
|
|
|
public static class ExtPatient extends Patient {
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Child(name = "secondOrg")
|
|
|
|
|
@Extension(url = "http://foo#secondOrg", definedLocally = false, isModifier = false)
|
|
|
|
|
private Reference mySecondOrg;
|
|
|
|
@ -470,4 +440,53 @@ public class IncludeTest {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AfterClass
|
|
|
|
|
public static void afterClassClearContext() throws Exception {
|
|
|
|
|
JettyUtil.closeServer(ourServer);
|
|
|
|
|
TestUtil.clearAllStaticFieldsForUnitTest();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
|
public static void beforeClass() throws Exception {
|
|
|
|
|
|
|
|
|
|
ourCtx = FhirContext.forR4();
|
|
|
|
|
ourServer = new Server(0);
|
|
|
|
|
|
|
|
|
|
DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider();
|
|
|
|
|
|
|
|
|
|
ServletHandler proxyHandler = new ServletHandler();
|
|
|
|
|
RestfulServer servlet = new RestfulServer(ourCtx);
|
|
|
|
|
servlet.setDefaultResponseEncoding(EncodingEnum.XML);
|
|
|
|
|
servlet.setBundleInclusionRule(BundleInclusionRule.BASED_ON_RESOURCE_PRESENCE);
|
|
|
|
|
servlet.setResourceProviders(patientProvider, new DummyDiagnosticReportResourceProvider());
|
|
|
|
|
ServletHolder servletHolder = new ServletHolder(servlet);
|
|
|
|
|
proxyHandler.addServletWithMapping(servletHolder, "/*");
|
|
|
|
|
ourServer.setHandler(proxyHandler);
|
|
|
|
|
JettyUtil.startServer(ourServer);
|
|
|
|
|
ourPort = JettyUtil.getPortForStartedServer(ourServer);
|
|
|
|
|
|
|
|
|
|
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
|
|
|
|
|
HttpClientBuilder builder = HttpClientBuilder.create();
|
|
|
|
|
builder.setConnectionManager(connectionManager);
|
|
|
|
|
ourClient = builder.build();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
|
|
|
|
Organization org = new Organization();
|
|
|
|
|
org.setId("Organization/65546");
|
|
|
|
|
org.getNameElement().setValue("Contained Test Organization");
|
|
|
|
|
|
|
|
|
|
Patient patient = new Patient();
|
|
|
|
|
patient.setId("Patient/1333");
|
|
|
|
|
patient.addIdentifier().setSystem("urn:mrns").setValue("253345");
|
|
|
|
|
patient.getManagingOrganization().setResource(patient);
|
|
|
|
|
|
|
|
|
|
System.out.println(FhirContext.forR4().newXmlParser().setPrettyPrint(true).encodeResourceToString(patient));
|
|
|
|
|
|
|
|
|
|
patient.getManagingOrganization().getReference();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|