Work on porting STU1 tests
This commit is contained in:
parent
1ae37b0db3
commit
b02fbb6804
|
@ -19,13 +19,10 @@ package ca.uhn.fhir.rest.annotation;
|
|||
* limitations under the License.
|
||||
* #L%
|
||||
*/
|
||||
import java.lang.annotation.*;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.rest.api.ValidationModeEnum;
|
||||
|
||||
/**
|
||||
|
@ -54,7 +51,7 @@ public @interface Validate {
|
|||
* but generally does need to be populated for client implementations.
|
||||
*/
|
||||
// NB: Read, Search (maybe others) share this annotation, so update the javadocs everywhere
|
||||
Class<? extends IResource> type() default IResource.class;
|
||||
Class<? extends IBaseResource> type() default IBaseResource.class;
|
||||
|
||||
/**
|
||||
* Validation mode parameter annotation for the validation mode parameter (only supported
|
||||
|
|
|
@ -3,39 +3,12 @@ package ca.uhn.fhir.rest.client;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.api.Include;
|
||||
import ca.uhn.fhir.model.dstu.resource.DiagnosticReport;
|
||||
import ca.uhn.fhir.model.dstu.resource.Observation;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import ca.uhn.fhir.model.primitive.IntegerDt;
|
||||
import ca.uhn.fhir.rest.annotation.Count;
|
||||
import ca.uhn.fhir.rest.annotation.Create;
|
||||
import ca.uhn.fhir.rest.annotation.Delete;
|
||||
import ca.uhn.fhir.rest.annotation.History;
|
||||
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||
import ca.uhn.fhir.rest.annotation.IncludeParam;
|
||||
import ca.uhn.fhir.rest.annotation.OptionalParam;
|
||||
import ca.uhn.fhir.rest.annotation.Read;
|
||||
import ca.uhn.fhir.rest.annotation.RequiredParam;
|
||||
import ca.uhn.fhir.rest.annotation.ResourceParam;
|
||||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.rest.annotation.Since;
|
||||
import ca.uhn.fhir.rest.annotation.Update;
|
||||
import ca.uhn.fhir.rest.annotation.Validate;
|
||||
import ca.uhn.fhir.model.primitive.*;
|
||||
import ca.uhn.fhir.rest.annotation.*;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.client.api.IBasicClient;
|
||||
import ca.uhn.fhir.rest.param.CompositeParam;
|
||||
import ca.uhn.fhir.rest.param.DateParam;
|
||||
import ca.uhn.fhir.rest.param.DateRangeParam;
|
||||
import ca.uhn.fhir.rest.param.QuantityParam;
|
||||
import ca.uhn.fhir.rest.param.StringAndListParam;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.rest.param.TokenOrListParam;
|
||||
import ca.uhn.fhir.rest.param.TokenParam;
|
||||
import ca.uhn.fhir.rest.param.*;
|
||||
|
||||
public interface ITestClient extends IBasicClient {
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,301 +0,0 @@
|
|||
package ca.uhn.fhir.rest.client;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.io.input.ReaderInputStream;
|
||||
import org.apache.http.HeaderElement;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Tag;
|
||||
import ca.uhn.fhir.model.api.TagList;
|
||||
import ca.uhn.fhir.model.dstu.resource.Conformance;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.annotation.AddTags;
|
||||
import ca.uhn.fhir.rest.annotation.DeleteTags;
|
||||
import ca.uhn.fhir.rest.annotation.GetTags;
|
||||
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||
import ca.uhn.fhir.rest.annotation.TagListParam;
|
||||
import ca.uhn.fhir.rest.annotation.VersionIdParam;
|
||||
import ca.uhn.fhir.rest.client.api.IBasicClient;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class TagsClientTest {
|
||||
|
||||
private FhirContext ctx;
|
||||
private HttpClient httpClient;
|
||||
private HttpResponse httpResponse;
|
||||
|
||||
// atom-document-large.xml
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
ctx = new FhirContext(Patient.class, Conformance.class);
|
||||
|
||||
httpClient = mock(HttpClient.class, new ReturnsDeepStubs());
|
||||
ctx.getRestfulClientFactory().setHttpClient(httpClient);
|
||||
ctx.getRestfulClientFactory().setServerValidationModeEnum(ServerValidationModeEnum.NEVER);
|
||||
|
||||
httpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllTags() throws Exception {
|
||||
|
||||
TagList tagList = new TagList();
|
||||
tagList.add(new Tag("CCC", "AAA", "BBB"));
|
||||
String ser = ctx.newXmlParser().encodeTagListToString(tagList);
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
|
||||
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
|
||||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(ser), Charset.forName("UTF-8")));
|
||||
|
||||
IClient client = ctx.newRestfulClient(IClient.class, "http://foo");
|
||||
TagList response = client.getAllTags();
|
||||
assertEquals(tagList, response);
|
||||
|
||||
assertEquals(HttpGet.class, capt.getValue().getClass());
|
||||
HttpGet get = (HttpGet) capt.getValue();
|
||||
assertEquals("http://foo/_tags", get.getURI().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllTagsPatient() throws Exception {
|
||||
|
||||
TagList tagList = new TagList();
|
||||
tagList.add(new Tag("CCC", "AAA", "BBB"));
|
||||
String ser = ctx.newXmlParser().encodeTagListToString(tagList);
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
|
||||
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
|
||||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(ser), Charset.forName("UTF-8")));
|
||||
|
||||
IClient client = ctx.newRestfulClient(IClient.class, "http://foo");
|
||||
TagList response = client.getAllTagsPatient();
|
||||
assertEquals(tagList, response);
|
||||
|
||||
assertEquals(HttpGet.class, capt.getValue().getClass());
|
||||
HttpGet get = (HttpGet) capt.getValue();
|
||||
assertEquals("http://foo/Patient/_tags", get.getURI().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteTagsPatient() throws Exception {
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
|
||||
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||
when(httpResponse.getEntity().getContentType().getElements()).thenReturn(new HeaderElement[0]);
|
||||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
|
||||
|
||||
TagList tagList = new TagList();
|
||||
tagList.add(new Tag("CCC", "AAA", "BBB"));
|
||||
|
||||
IClient client = ctx.newRestfulClient(IClient.class, "http://foo");
|
||||
client.deleteTags(new IdDt("111"), tagList);
|
||||
|
||||
assertEquals(HttpPost.class, capt.getValue().getClass());
|
||||
HttpPost post = (HttpPost) capt.getValue();
|
||||
assertEquals("http://foo/Patient/111/_tags/_delete", post.getURI().toString());
|
||||
|
||||
String ser = IOUtils.toString(post.getEntity().getContent());
|
||||
TagList actualTagList = ctx.newXmlParser().parseTagList(ser);
|
||||
assertEquals(tagList, actualTagList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteTagsPatientVersion() throws Exception {
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
|
||||
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||
when(httpResponse.getEntity().getContentType().getElements()).thenReturn(new HeaderElement[0]);
|
||||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
|
||||
|
||||
TagList tagList = new TagList();
|
||||
tagList.add(new Tag("CCC", "AAA", "BBB"));
|
||||
|
||||
IClient client = ctx.newRestfulClient(IClient.class, "http://foo");
|
||||
client.deleteTags(new IdDt("111"), new IdDt("222"),tagList);
|
||||
|
||||
assertEquals(HttpPost.class, capt.getValue().getClass());
|
||||
HttpPost post = (HttpPost) capt.getValue();
|
||||
assertEquals("http://foo/Patient/111/_history/222/_tags/_delete", post.getURI().toString());
|
||||
|
||||
String ser = IOUtils.toString(post.getEntity().getContent());
|
||||
TagList actualTagList = ctx.newXmlParser().parseTagList(ser);
|
||||
assertEquals(tagList, actualTagList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddTagsPatient() throws Exception {
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
|
||||
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||
when(httpResponse.getEntity().getContentType().getElements()).thenReturn(new HeaderElement[0]);
|
||||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
|
||||
|
||||
TagList tagList = new TagList();
|
||||
tagList.add(new Tag("CCC", "AAA", "BBB"));
|
||||
|
||||
IClient client = ctx.newRestfulClient(IClient.class, "http://foo");
|
||||
client.addTags(new IdDt("111"), tagList);
|
||||
|
||||
assertEquals(HttpPost.class, capt.getValue().getClass());
|
||||
HttpPost post = (HttpPost) capt.getValue();
|
||||
assertEquals("http://foo/Patient/111/_tags", post.getURI().toString());
|
||||
|
||||
String ser = IOUtils.toString(post.getEntity().getContent());
|
||||
TagList actualTagList = ctx.newXmlParser().parseTagList(ser);
|
||||
assertEquals(tagList, actualTagList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddTagsPatientVersion() throws Exception {
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
|
||||
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||
when(httpResponse.getEntity().getContentType().getElements()).thenReturn(new HeaderElement[0]);
|
||||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
|
||||
|
||||
TagList tagList = new TagList();
|
||||
tagList.add(new Tag("CCC", "AAA", "BBB"));
|
||||
|
||||
IClient client = ctx.newRestfulClient(IClient.class, "http://foo");
|
||||
client.addTags(new IdDt("111"), new IdDt("222"),tagList);
|
||||
|
||||
assertEquals(HttpPost.class, capt.getValue().getClass());
|
||||
HttpPost post = (HttpPost) capt.getValue();
|
||||
assertEquals("http://foo/Patient/111/_history/222/_tags", post.getURI().toString());
|
||||
|
||||
String ser = IOUtils.toString(post.getEntity().getContent());
|
||||
TagList actualTagList = ctx.newXmlParser().parseTagList(ser);
|
||||
assertEquals(tagList, actualTagList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllTagsPatientId() throws Exception {
|
||||
|
||||
TagList tagList = new TagList();
|
||||
tagList.add(new Tag("CCC", "AAA", "BBB"));
|
||||
String ser = ctx.newXmlParser().encodeTagListToString(tagList);
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
|
||||
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
|
||||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(ser), Charset.forName("UTF-8")));
|
||||
|
||||
IClient client = ctx.newRestfulClient(IClient.class, "http://foo");
|
||||
TagList response = client.getAllTagsPatientId(new IdDt("111"));
|
||||
assertEquals(tagList, response);
|
||||
|
||||
assertEquals(HttpGet.class, capt.getValue().getClass());
|
||||
HttpGet get = (HttpGet) capt.getValue();
|
||||
assertEquals("http://foo/Patient/111/_tags", get.getURI().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllTagsPatientIdVersion() throws Exception {
|
||||
|
||||
TagList tagList = new TagList();
|
||||
tagList.add(new Tag("CCC", "AAA", "BBB"));
|
||||
String ser = ctx.newXmlParser().encodeTagListToString(tagList);
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
|
||||
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
|
||||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(ser), Charset.forName("UTF-8")));
|
||||
|
||||
IClient client = ctx.newRestfulClient(IClient.class, "http://foo");
|
||||
TagList response = client.getAllTagsPatientId(new IdDt("Patient", "111", "222"));
|
||||
assertEquals(tagList, response);
|
||||
|
||||
assertEquals(HttpGet.class, capt.getValue().getClass());
|
||||
HttpGet get = (HttpGet) capt.getValue();
|
||||
assertEquals("http://foo/Patient/111/_history/222/_tags", get.getURI().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllTagsPatientIdVersionOld() throws Exception {
|
||||
|
||||
TagList tagList = new TagList();
|
||||
tagList.add(new Tag("CCC", "AAA", "BBB"));
|
||||
String ser = ctx.newXmlParser().encodeTagListToString(tagList);
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
|
||||
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
|
||||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(ser), Charset.forName("UTF-8")));
|
||||
|
||||
IClient client = ctx.newRestfulClient(IClient.class, "http://foo");
|
||||
TagList response = client.getAllTagsPatientIdVersion(new IdDt("111"), new IdDt("222"));
|
||||
assertEquals(tagList, response);
|
||||
|
||||
assertEquals(HttpGet.class, capt.getValue().getClass());
|
||||
HttpGet get = (HttpGet) capt.getValue();
|
||||
assertEquals("http://foo/Patient/111/_history/222/_tags", get.getURI().toString());
|
||||
}
|
||||
|
||||
private interface IClient extends IBasicClient {
|
||||
|
||||
@GetTags
|
||||
public TagList getAllTags();
|
||||
|
||||
@GetTags(type = Patient.class)
|
||||
public TagList getAllTagsPatient();
|
||||
|
||||
@GetTags(type = Patient.class)
|
||||
public TagList getAllTagsPatientId(@IdParam IdDt theId);
|
||||
|
||||
@GetTags(type = Patient.class)
|
||||
public TagList getAllTagsPatientIdVersion(@IdParam IdDt theId, @VersionIdParam IdDt theVersion);
|
||||
|
||||
@AddTags(type = Patient.class)
|
||||
public void addTags(@IdParam IdDt theId, @TagListParam TagList theTagList);
|
||||
|
||||
@AddTags(type = Patient.class)
|
||||
public void addTags(@IdParam IdDt theId, @VersionIdParam IdDt theVersionId, @TagListParam TagList theTagList);
|
||||
|
||||
@DeleteTags(type = Patient.class)
|
||||
public void deleteTags(@IdParam IdDt theId, @TagListParam TagList theTagList);
|
||||
|
||||
@DeleteTags(type = Patient.class)
|
||||
public void deleteTags(@IdParam IdDt theId, @VersionIdParam IdDt theVersionId, @TagListParam TagList theTagList);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,166 +0,0 @@
|
|||
package ca.uhn.fhir.rest.client;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.input.ReaderInputStream;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
|
||||
import ca.uhn.fhir.model.dstu.resource.Conformance;
|
||||
import ca.uhn.fhir.model.dstu.resource.Observation;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.annotation.Transaction;
|
||||
import ca.uhn.fhir.rest.annotation.TransactionParam;
|
||||
import ca.uhn.fhir.rest.client.api.IBasicClient;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class TransactionClientTest {
|
||||
|
||||
private FhirContext ctx;
|
||||
private HttpClient httpClient;
|
||||
private HttpResponse httpResponse;
|
||||
|
||||
// atom-document-large.xml
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
ctx = new FhirContext(Patient.class, Conformance.class);
|
||||
|
||||
httpClient = mock(HttpClient.class, new ReturnsDeepStubs());
|
||||
ctx.getRestfulClientFactory().setHttpClient(httpClient);
|
||||
ctx.getRestfulClientFactory().setServerValidationModeEnum(ServerValidationModeEnum.NEVER);
|
||||
|
||||
httpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimpleTransaction() throws Exception {
|
||||
Patient patient = new Patient();
|
||||
patient.setId(new IdDt("Patient/testPersistWithSimpleLinkP01"));
|
||||
patient.addIdentifier("urn:system", "testPersistWithSimpleLinkP01");
|
||||
patient.addName().addFamily("Tester").addGiven("Joe");
|
||||
|
||||
Observation obs = new Observation();
|
||||
obs.getName().addCoding().setSystem("urn:system").setCode("testPersistWithSimpleLinkO01");
|
||||
obs.setSubject(new ResourceReferenceDt("Patient/testPersistWithSimpleLinkP01"));
|
||||
|
||||
List<IResource> resources = Arrays.asList((IResource)patient, obs);
|
||||
|
||||
IClient client = ctx.newRestfulClient(IClient.class, "http://foo");
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
|
||||
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_ATOM_XML + "; charset=UTF-8"));
|
||||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(createBundle()), Charset.forName("UTF-8")));
|
||||
|
||||
client.transaction(resources);
|
||||
|
||||
assertEquals(HttpPost.class, capt.getValue().getClass());
|
||||
HttpPost post = (HttpPost) capt.getValue();
|
||||
assertEquals("http://foo", post.getURI().toString());
|
||||
|
||||
Bundle bundle = ctx.newXmlParser().parseBundle(new InputStreamReader(post.getEntity().getContent()));
|
||||
ourLog.info(ctx.newXmlParser().setPrettyPrint(true).encodeBundleToString(bundle));
|
||||
|
||||
assertEquals(2, bundle.size());
|
||||
assertEquals("Patient/testPersistWithSimpleLinkP01", bundle.getEntries().get(0).getId().getValue());
|
||||
assertEquals("Patient/testPersistWithSimpleLinkP01", bundle.getEntries().get(0).getLinkSelf().getValue());
|
||||
assertEquals(null, bundle.getEntries().get(0).getLinkAlternate().getValue());
|
||||
|
||||
assertTrue(bundle.getEntries().get(1).getId().isEmpty());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimpleTransactionWithBundleParam() throws Exception {
|
||||
Patient patient = new Patient();
|
||||
patient.setId(new IdDt("Patient/testPersistWithSimpleLinkP01"));
|
||||
patient.addIdentifier("urn:system", "testPersistWithSimpleLinkP01");
|
||||
patient.addName().addFamily("Tester").addGiven("Joe");
|
||||
|
||||
Observation obs = new Observation();
|
||||
obs.getName().addCoding().setSystem("urn:system").setCode("testPersistWithSimpleLinkO01");
|
||||
obs.setSubject(new ResourceReferenceDt("Patient/testPersistWithSimpleLinkP01"));
|
||||
|
||||
Bundle transactionBundle = Bundle.withResources(Arrays.asList((IResource)patient, obs), ctx, "http://foo");
|
||||
|
||||
IBundleClient client = ctx.newRestfulClient(IBundleClient.class, "http://foo");
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
|
||||
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_ATOM_XML + "; charset=UTF-8"));
|
||||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(createBundle()), Charset.forName("UTF-8")));
|
||||
|
||||
client.transaction(transactionBundle);
|
||||
|
||||
assertEquals(HttpPost.class, capt.getValue().getClass());
|
||||
HttpPost post = (HttpPost) capt.getValue();
|
||||
assertEquals("http://foo", post.getURI().toString());
|
||||
|
||||
Bundle bundle = ctx.newXmlParser().parseBundle(new InputStreamReader(post.getEntity().getContent()));
|
||||
ourLog.info(ctx.newXmlParser().setPrettyPrint(true).encodeBundleToString(bundle));
|
||||
|
||||
assertEquals(2, bundle.size());
|
||||
assertEquals("http://foo/Patient/testPersistWithSimpleLinkP01", bundle.getEntries().get(0).getId().getValue());
|
||||
assertEquals("http://foo/Patient/testPersistWithSimpleLinkP01", bundle.getEntries().get(0).getLinkSelf().getValue());
|
||||
assertEquals(null, bundle.getEntries().get(0).getLinkAlternate().getValue());
|
||||
|
||||
assertTrue(bundle.getEntries().get(1).getId().isEmpty());
|
||||
|
||||
}
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TransactionClientTest.class);
|
||||
private String createBundle() {
|
||||
return ctx.newXmlParser().encodeBundleToString(new Bundle());
|
||||
}
|
||||
|
||||
private interface IClient extends IBasicClient {
|
||||
|
||||
@Transaction
|
||||
public List<IResource> transaction(@TransactionParam List<IResource> theResources);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private interface IBundleClient extends IBasicClient {
|
||||
|
||||
@Transaction
|
||||
public List<IResource> transaction(@TransactionParam Bundle theResources);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
|
@ -8,29 +8,22 @@ import java.io.StringReader;
|
|||
import java.nio.charset.Charset;
|
||||
|
||||
import org.apache.commons.io.input.ReaderInputStream;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.*;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.hl7.fhir.r4.model.IdType;
|
||||
import org.junit.*;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||
import ca.uhn.fhir.rest.client.interceptor.BasicAuthInterceptor;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
*/
|
||||
public class BasicAuthInterceptorTest {
|
||||
|
||||
private static FhirContext ourCtx;
|
||||
|
@ -41,7 +34,7 @@ public class BasicAuthInterceptorTest {
|
|||
public void before() {
|
||||
myHttpClient = mock(HttpClient.class, new ReturnsDeepStubs());
|
||||
ourCtx.getRestfulClientFactory().setHttpClient(myHttpClient);
|
||||
ourCtx.getRestfulClientFactory().setServerValidationModeEnum(ServerValidationModeEnum.NEVER);
|
||||
ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
|
||||
myHttpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
|
||||
}
|
||||
|
@ -76,7 +69,7 @@ public class BasicAuthInterceptorTest {
|
|||
|
||||
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
|
||||
client.registerInterceptor(new BasicAuthInterceptor("myuser", "mypass"));
|
||||
client.getPatientById(new IdDt("111"));
|
||||
client.getPatientById(new IdType("111"));
|
||||
|
||||
assertEquals(1, capt.getAllValues().size());
|
||||
HttpUriRequest req = capt.getAllValues().get(0);
|
||||
|
@ -88,7 +81,7 @@ public class BasicAuthInterceptorTest {
|
|||
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
|
||||
client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
|
||||
client.registerInterceptor(new BasicAuthInterceptor("myuser", "mypass"));
|
||||
client.getPatientById(new IdDt("111"));
|
||||
client.getPatientById(new IdType("111"));
|
||||
|
||||
assertEquals(2, capt.getAllValues().size());
|
||||
req = capt.getAllValues().get(1);
|
||||
|
@ -99,7 +92,7 @@ public class BasicAuthInterceptorTest {
|
|||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
ourCtx = FhirContext.forDstu1();
|
||||
ourCtx = FhirContext.forR4();
|
||||
}
|
||||
|
||||
|
|
@ -8,24 +8,20 @@ import java.io.StringReader;
|
|||
import java.nio.charset.Charset;
|
||||
|
||||
import org.apache.commons.io.input.ReaderInputStream;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.*;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.hl7.fhir.r4.model.IdType;
|
||||
import org.junit.*;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||
import ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
/**
|
||||
|
@ -76,7 +72,7 @@ public class BearerTokenAuthInterceptorTest {
|
|||
|
||||
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
|
||||
client.registerInterceptor(new BearerTokenAuthInterceptor("mytoken"));
|
||||
client.getPatientById(new IdDt("111"));
|
||||
client.getPatientById(new IdType("111"));
|
||||
|
||||
HttpUriRequest req = capt.getValue();
|
||||
assertEquals("Bearer mytoken", req.getFirstHeader("Authorization").getValue());
|
||||
|
@ -84,7 +80,7 @@ public class BearerTokenAuthInterceptorTest {
|
|||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
ourCtx = FhirContext.forDstu1();
|
||||
ourCtx = FhirContext.forR4();
|
||||
}
|
||||
|
||||
|
|
@ -11,29 +11,21 @@ import org.apache.commons.io.IOUtils;
|
|||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.client.methods.*;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.hl7.fhir.r4.model.Binary;
|
||||
import org.junit.*;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.resource.Binary;
|
||||
import ca.uhn.fhir.model.dstu.resource.Conformance;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.annotation.Create;
|
||||
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||
import ca.uhn.fhir.rest.annotation.Read;
|
||||
import ca.uhn.fhir.rest.annotation.ResourceParam;
|
||||
import ca.uhn.fhir.model.primitive.IdType;
|
||||
import ca.uhn.fhir.rest.annotation.*;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.client.api.IBasicClient;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class BinaryClientTest {
|
||||
|
@ -46,7 +38,7 @@ public class BinaryClientTest {
|
|||
|
||||
@Before
|
||||
public void before() {
|
||||
mtCtx = FhirContext.forDstu1();
|
||||
mtCtx = FhirContext.forR4();
|
||||
|
||||
myHttpClient = mock(HttpClient.class, new ReturnsDeepStubs());
|
||||
mtCtx.getRestfulClientFactory().setHttpClient(myHttpClient);
|
||||
|
@ -64,7 +56,7 @@ public class BinaryClientTest {
|
|||
when(httpResponse.getEntity().getContent()).thenReturn(new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 }));
|
||||
|
||||
IClient client = mtCtx.newRestfulClient(IClient.class, "http://foo");
|
||||
Binary resp = client.read(new IdDt("http://foo/Patient/123"));
|
||||
Binary resp = client.read(new IdType("http://foo/Patient/123"));
|
||||
|
||||
assertEquals(HttpGet.class, capt.getValue().getClass());
|
||||
HttpGet get = (HttpGet) capt.getValue();
|
||||
|
@ -101,7 +93,7 @@ public class BinaryClientTest {
|
|||
private interface IClient extends IBasicClient {
|
||||
|
||||
@Read(type = Binary.class)
|
||||
public Binary read(@IdParam IdDt theBinary);
|
||||
public Binary read(@IdParam IdType theBinary);
|
||||
|
||||
@Create(type = Binary.class)
|
||||
public MethodOutcome create(@ResourceParam Binary theBinary);
|
|
@ -55,7 +55,7 @@ import ca.uhn.fhir.model.dstu.resource.OperationOutcome;
|
|||
import ca.uhn.fhir.model.dstu.resource.Organization;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.dstu.valueset.QuantityCompararatorEnum;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.IdType;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import ca.uhn.fhir.model.primitive.IntegerDt;
|
||||
import ca.uhn.fhir.rest.annotation.Elements;
|
||||
|
@ -246,7 +246,7 @@ public class ClientDstu1Test {
|
|||
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(resp), Charset.forName("UTF-8")));
|
||||
|
||||
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
|
||||
MethodOutcome response = client.deletePatient(new IdDt("1234"));
|
||||
MethodOutcome response = client.deletePatient(new IdType("1234"));
|
||||
|
||||
assertEquals(HttpDelete.class, capt.getValue().getClass());
|
||||
assertEquals("http://foo/Patient/1234", capt.getValue().getURI().toString());
|
||||
|
@ -263,7 +263,7 @@ public class ClientDstu1Test {
|
|||
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
|
||||
|
||||
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
|
||||
client.deleteDiagnosticReport(new IdDt("1234"));
|
||||
client.deleteDiagnosticReport(new IdType("1234"));
|
||||
|
||||
assertEquals(HttpDelete.class, capt.getValue().getClass());
|
||||
assertEquals("http://foo/DiagnosticReport/1234", capt.getValue().getURI().toString());
|
||||
|
@ -321,7 +321,7 @@ public class ClientDstu1Test {
|
|||
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
|
||||
|
||||
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
|
||||
Bundle response = client.getHistoryPatientInstance(new IdDt("111"));
|
||||
Bundle response = client.getHistoryPatientInstance(new IdType("111"));
|
||||
|
||||
assertEquals("http://foo/Patient/111/_history", capt.getValue().getURI().toString());
|
||||
|
||||
|
@ -530,26 +530,26 @@ public class ClientDstu1Test {
|
|||
String expectedDateString = new InstantDt(new InstantDt("2012-01-02T12:01:02").getValue()).getValueAsString();
|
||||
expectedDateString = expectedDateString.replace(":", "%3A").replace("+", "%2B");
|
||||
|
||||
client.getHistoryPatientInstance(new IdDt("111"), new InstantDt("2012-01-02T12:01:02"), new IntegerDt(12));
|
||||
client.getHistoryPatientInstance(new IdType("111"), new InstantDt("2012-01-02T12:01:02"), new IntegerDt(12));
|
||||
assertThat(capt.getAllValues().get(0).getURI().toString(), containsString("http://foo/Patient/111/_history?"));
|
||||
assertThat(capt.getAllValues().get(0).getURI().toString(), containsString("_since=" + expectedDateString.replaceAll("\\..*", "")));
|
||||
assertThat(capt.getAllValues().get(0).getURI().toString(), containsString("_count=12"));
|
||||
|
||||
client.getHistoryPatientInstance(new IdDt("111"), new InstantDt("2012-01-02T12:01:02").getValue(), new IntegerDt(12).getValue());
|
||||
client.getHistoryPatientInstance(new IdType("111"), new InstantDt("2012-01-02T12:01:02").getValue(), new IntegerDt(12).getValue());
|
||||
assertThat(capt.getAllValues().get(1).getURI().toString(), containsString("http://foo/Patient/111/_history?"));
|
||||
assertThat(capt.getAllValues().get(1).getURI().toString(), containsString("_since=" + expectedDateString));
|
||||
assertThat(capt.getAllValues().get(1).getURI().toString(), containsString("_count=12"));
|
||||
|
||||
client.getHistoryPatientInstance(new IdDt("111"), null, new IntegerDt(12));
|
||||
client.getHistoryPatientInstance(new IdType("111"), null, new IntegerDt(12));
|
||||
assertEquals("http://foo/Patient/111/_history?_count=12", capt.getAllValues().get(2).getURI().toString());
|
||||
|
||||
client.getHistoryPatientInstance(new IdDt("111"), new InstantDt("2012-01-02T00:01:02"), null);
|
||||
client.getHistoryPatientInstance(new IdType("111"), new InstantDt("2012-01-02T00:01:02"), null);
|
||||
assertEquals("http://foo/Patient/111/_history?_since=2012-01-02T00%3A01%3A02", capt.getAllValues().get(3).getURI().toString());
|
||||
|
||||
client.getHistoryPatientInstance(new IdDt("111"), new InstantDt(), new IntegerDt(12));
|
||||
client.getHistoryPatientInstance(new IdType("111"), new InstantDt(), new IntegerDt(12));
|
||||
assertEquals("http://foo/Patient/111/_history?_count=12", capt.getAllValues().get(4).getURI().toString());
|
||||
|
||||
client.getHistoryPatientInstance(new IdDt("111"), new InstantDt("2012-01-02T00:01:02"), new IntegerDt());
|
||||
client.getHistoryPatientInstance(new IdType("111"), new InstantDt("2012-01-02T00:01:02"), new IntegerDt());
|
||||
assertEquals("http://foo/Patient/111/_history?_since=2012-01-02T00%3A01%3A02", capt.getAllValues().get(5).getURI().toString());
|
||||
|
||||
}
|
||||
|
@ -565,7 +565,7 @@ public class ClientDstu1Test {
|
|||
ClientWithoutAnnotation client = ctx.newRestfulClient(ClientWithoutAnnotation.class, "http://wildfhir.aegis.net/fhir");
|
||||
|
||||
try {
|
||||
client.read(new IdDt("8"));
|
||||
client.read(new IdType("8"));
|
||||
fail();
|
||||
} catch (UnsupportedOperationException e) {
|
||||
assertThat(e.getMessage(), containsString("annotation"));
|
||||
|
@ -601,7 +601,7 @@ public class ClientDstu1Test {
|
|||
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
|
||||
// Patient response = client.findPatientByMrn(new
|
||||
// IdentifierDt("urn:foo", "123"));
|
||||
Patient response = client.getPatientById(new IdDt("111"));
|
||||
Patient response = client.getPatientById(new IdType("111"));
|
||||
|
||||
assertEquals("http://foo/Patient/111", capt.getValue().getURI().toString());
|
||||
assertEquals("PRP1660", response.getIdentifier().get(0).getValue().getValue());
|
||||
|
@ -645,7 +645,7 @@ public class ClientDstu1Test {
|
|||
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
|
||||
// Patient response = client.findPatientByMrn(new
|
||||
// IdentifierDt("urn:foo", "123"));
|
||||
Patient response = client.getPatientById(new IdDt("111"));
|
||||
Patient response = client.getPatientById(new IdType("111"));
|
||||
|
||||
assertEquals("http://foo/Patient/111", capt.getValue().getURI().toString());
|
||||
assertEquals("PRP1660", response.getIdentifier().get(0).getValue().getValue());
|
||||
|
@ -666,7 +666,7 @@ public class ClientDstu1Test {
|
|||
|
||||
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
|
||||
try {
|
||||
client.getPatientById(new IdDt("111"));
|
||||
client.getPatientById(new IdType("111"));
|
||||
fail();
|
||||
} catch (InternalErrorException e) {
|
||||
assertThat(e.getMessage(), containsString("INTERNAL"));
|
||||
|
@ -693,7 +693,7 @@ public class ClientDstu1Test {
|
|||
|
||||
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
|
||||
try {
|
||||
client.getPatientById(new IdDt("111"));
|
||||
client.getPatientById(new IdType("111"));
|
||||
fail();
|
||||
} catch (ResourceNotFoundException e) {
|
||||
// good
|
||||
|
@ -728,7 +728,7 @@ public class ClientDstu1Test {
|
|||
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
|
||||
// Patient response = client.findPatientByMrn(new
|
||||
// IdentifierDt("urn:foo", "123"));
|
||||
Patient response = client.getPatientById(new IdDt("111"));
|
||||
Patient response = client.getPatientById(new IdType("111"));
|
||||
|
||||
assertEquals("http://foo/Patient/111", capt.getValue().getURI().toString());
|
||||
assertEquals("PRP1660", response.getIdentifier().get(0).getValue().getValue());
|
||||
|
@ -922,13 +922,13 @@ public class ClientDstu1Test {
|
|||
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
||||
|
||||
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
|
||||
List<Patient> response = client.getPatientByCompartmentAndDob(new IdDt("123"), new DateParam(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, "2011-01-02"));
|
||||
List<Patient> response = client.getPatientByCompartmentAndDob(new IdType("123"), new DateParam(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, "2011-01-02"));
|
||||
|
||||
assertEquals("http://foo/Patient/123/compartmentName?birthdate=%3E%3D2011-01-02", capt.getValue().getURI().toString());
|
||||
assertEquals("PRP1660", response.get(0).getIdentifier().get(0).getValue().getValue());
|
||||
|
||||
try {
|
||||
client.getPatientByCompartmentAndDob(new IdDt(""), new DateParam(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, "2011-01-02"));
|
||||
client.getPatientByCompartmentAndDob(new IdType(""), new DateParam(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, "2011-01-02"));
|
||||
fail();
|
||||
} catch (InvalidRequestException e) {
|
||||
assertThat(e.toString(), containsString("null or empty for compartment"));
|
||||
|
@ -1246,7 +1246,7 @@ public class ClientDstu1Test {
|
|||
when(myHttpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200"));
|
||||
|
||||
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
|
||||
MethodOutcome response = client.updatePatient(new IdDt("100"), patient);
|
||||
MethodOutcome response = client.updatePatient(new IdType("100"), patient);
|
||||
|
||||
assertEquals(HttpPut.class, capt.getValue().getClass());
|
||||
HttpPut post = (HttpPut) capt.getValue();
|
||||
|
@ -1274,7 +1274,7 @@ public class ClientDstu1Test {
|
|||
when(myHttpResponse.getAllHeaders()).thenReturn(toHeaderArray("Content-Location", "http://example.com/fhir/Patient/100/_history/200"));
|
||||
|
||||
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
|
||||
client.updatePatient(new IdDt("Patient/100/_history/200"), patient);
|
||||
client.updatePatient(new IdType("Patient/100/_history/200"), patient);
|
||||
|
||||
assertEquals(HttpPut.class, capt.getValue().getClass());
|
||||
HttpPut post = (HttpPut) capt.getValue();
|
||||
|
@ -1298,7 +1298,7 @@ public class ClientDstu1Test {
|
|||
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), Constants.STATUS_HTTP_409_CONFLICT, "Conflict"));
|
||||
|
||||
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
|
||||
client.updatePatient(new IdDt("Patient/100/_history/200"), patient);
|
||||
client.updatePatient(new IdType("Patient/100/_history/200"), patient);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1315,7 +1315,7 @@ public class ClientDstu1Test {
|
|||
when(myHttpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200"));
|
||||
|
||||
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
|
||||
MethodOutcome response = client.updatePatient(new IdDt("Patient/100/_history/200"), patient);
|
||||
MethodOutcome response = client.updatePatient(new IdType("Patient/100/_history/200"), patient);
|
||||
|
||||
assertEquals(HttpPut.class, capt.getValue().getClass());
|
||||
HttpPut post = (HttpPut) capt.getValue();
|
||||
|
@ -1375,7 +1375,7 @@ public class ClientDstu1Test {
|
|||
ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo");
|
||||
// Patient response = client.findPatientByMrn(new
|
||||
// IdentifierDt("urn:foo", "123"));
|
||||
Patient response = client.getPatientById(new IdDt("Patient/111/_history/999"));
|
||||
Patient response = client.getPatientById(new IdType("Patient/111/_history/999"));
|
||||
|
||||
assertEquals("http://foo/Patient/111/_history/999", capt.getValue().getURI().toString());
|
||||
assertEquals("PRP1660", response.getIdentifier().get(0).getValue().getValue());
|
||||
|
@ -1387,7 +1387,7 @@ public class ClientDstu1Test {
|
|||
}
|
||||
|
||||
private interface ClientWithoutAnnotation extends IBasicClient {
|
||||
Patient read(@IdParam IdDt theId);
|
||||
Patient read(@IdParam IdType theId);
|
||||
}
|
||||
|
||||
@ResourceDef(name = "Patient")
|
|
@ -25,7 +25,7 @@ import ca.uhn.fhir.context.FhirContext;
|
|||
import ca.uhn.fhir.model.base.resource.BaseOperationOutcome;
|
||||
import ca.uhn.fhir.model.dstu.resource.OperationOutcome;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.IdType;
|
||||
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||
import ca.uhn.fhir.rest.annotation.Read;
|
||||
import ca.uhn.fhir.rest.client.api.IRestfulClient;
|
||||
|
@ -68,7 +68,7 @@ public class ExceptionHandlingTest {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
try {
|
||||
client.read(Patient.class, new IdDt("Patient/1234"));
|
||||
client.read(Patient.class, new IdType("Patient/1234"));
|
||||
fail();
|
||||
} catch (InternalErrorException e) {
|
||||
assertThat(e.getMessage(), StringContains.containsString("HTTP 500 Internal Error"));
|
||||
|
@ -93,7 +93,7 @@ public class ExceptionHandlingTest {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
try {
|
||||
client.read(Patient.class, new IdDt("Patient/1234"));
|
||||
client.read(Patient.class, new IdType("Patient/1234"));
|
||||
fail();
|
||||
} catch (InternalErrorException e) {
|
||||
assertThat(e.getMessage(), StringContains.containsString("HTTP 500 Internal Error"));
|
||||
|
@ -118,7 +118,7 @@ public class ExceptionHandlingTest {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
try {
|
||||
client.read(Patient.class, new IdDt("Patient/1234"));
|
||||
client.read(Patient.class, new IdType("Patient/1234"));
|
||||
fail();
|
||||
} catch (InternalErrorException e) {
|
||||
assertEquals("HTTP 500 Internal Error", e.getMessage());
|
||||
|
@ -142,7 +142,7 @@ public class ExceptionHandlingTest {
|
|||
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
try {
|
||||
client.read(Patient.class, new IdDt("Patient/1234"));
|
||||
client.read(Patient.class, new IdType("Patient/1234"));
|
||||
fail();
|
||||
} catch (InternalErrorException e) {
|
||||
assertThat(e.getMessage(), StringContains.containsString("HTTP 500 Internal Error"));
|
||||
|
@ -168,7 +168,7 @@ public class ExceptionHandlingTest {
|
|||
|
||||
IMyClient client = ourCtx.newRestfulClient(IMyClient.class, "http://example.com/fhir");
|
||||
try {
|
||||
client.read(new IdDt("Patient/1234"));
|
||||
client.read(new IdType("Patient/1234"));
|
||||
fail();
|
||||
} catch (InternalErrorException e) {
|
||||
assertThat(e.getMessage(), StringContains.containsString("HTTP 500 Internal Error"));
|
||||
|
@ -181,7 +181,7 @@ public class ExceptionHandlingTest {
|
|||
|
||||
public interface IMyClient extends IRestfulClient {
|
||||
@Read
|
||||
Patient read(@IdParam IdDt theId);
|
||||
Patient read(@IdParam IdType theId);
|
||||
}
|
||||
|
||||
|
|
@ -10,60 +10,41 @@ import static org.junit.Assert.fail;
|
|||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.io.input.ReaderInputStream;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.*;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.client.methods.*;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.hamcrest.core.StringContains;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.hl7.fhir.r4.model.*;
|
||||
import org.junit.*;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum;
|
||||
import ca.uhn.fhir.model.api.Tag;
|
||||
import ca.uhn.fhir.model.api.TagList;
|
||||
import ca.uhn.fhir.model.dstu.resource.Encounter;
|
||||
import ca.uhn.fhir.model.dstu.resource.Observation;
|
||||
import ca.uhn.fhir.model.dstu.resource.OperationOutcome;
|
||||
import ca.uhn.fhir.model.dstu.resource.Organization;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.dstu.resource.Provenance;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.api.*;
|
||||
import ca.uhn.fhir.model.primitive.InstantDt;
|
||||
import ca.uhn.fhir.model.primitive.UriDt;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.api.*;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||
import ca.uhn.fhir.rest.client.exceptions.NonFhirResponseException;
|
||||
import ca.uhn.fhir.rest.method.SearchStyleEnum;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.rest.server.EncodingEnum;
|
||||
import ca.uhn.fhir.rest.client.impl.BaseClient;
|
||||
import ca.uhn.fhir.rest.client.impl.GenericClient;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
@ -368,7 +349,7 @@ public class GenericClientTest {
|
|||
assertEquals("testDelete01", outcome.getIssueFirstRep().getLocationFirstRep().getValue());
|
||||
|
||||
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader("LKJHLKJGLKJKLL"), Charset.forName("UTF-8")));
|
||||
outcome = (OperationOutcome) client.delete().resourceById(new IdDt("Location", "123", "456")).prettyPrint().encodedJson().execute();
|
||||
outcome = (OperationOutcome) client.delete().resourceById(new IdType("Location", "123", "456")).prettyPrint().encodedJson().execute();
|
||||
|
||||
assertEquals("http://example.com/fhir/Location/123?_pretty=true", capt.getAllValues().get(1).getURI().toString());
|
||||
assertEquals("DELETE", capt.getValue().getMethod());
|
||||
|
@ -460,7 +441,7 @@ public class GenericClientTest {
|
|||
//@formatter:off
|
||||
response = client
|
||||
.history()
|
||||
.onInstance(new IdDt("Patient", "123"))
|
||||
.onInstance(new IdType("Patient", "123"))
|
||||
.andReturnDstu1Bundle()
|
||||
.execute();
|
||||
//@formatter:on
|
||||
|
@ -511,7 +492,7 @@ public class GenericClientTest {
|
|||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
//@formatter:off
|
||||
Patient response = client.read(Patient.class, new IdDt("Patient/1234"));
|
||||
Patient response = client.read(Patient.class, new IdType("Patient/1234"));
|
||||
//@formatter:on
|
||||
|
||||
assertThat(response.getNameFirstRep().getFamilyAsSingleString(), StringContains.containsString("Cardinal"));
|
||||
|
@ -549,7 +530,7 @@ public class GenericClientTest {
|
|||
|
||||
int count = 0;
|
||||
|
||||
Patient response = client.read().resource(Patient.class).withId(new IdDt("Patient/1234")).execute();
|
||||
Patient response = client.read().resource(Patient.class).withId(new IdType("Patient/1234")).execute();
|
||||
assertThat(response.getNameFirstRep().getFamilyAsSingleString(), StringContains.containsString("Cardinal"));
|
||||
assertEquals("http://example.com/fhir/Patient/1234", capt.getAllValues().get(count++).getURI().toString());
|
||||
|
||||
|
@ -591,12 +572,12 @@ public class GenericClientTest {
|
|||
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
Patient response = client.read(Patient.class, new IdDt("http://somebase.com/path/to/base/Patient/1234"));
|
||||
Patient response = client.read(Patient.class, new IdType("http://somebase.com/path/to/base/Patient/1234"));
|
||||
assertThat(response.getNameFirstRep().getFamilyAsSingleString(), StringContains.containsString("Cardinal"));
|
||||
assertEquals("http://somebase.com/path/to/base/Patient/1234", capt.getAllValues().get(0).getURI().toString());
|
||||
|
||||
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
|
||||
response = client.read(Patient.class, new IdDt("http://somebase.com/path/to/base/Patient/1234/_history/2222"));
|
||||
response = client.read(Patient.class, new IdType("http://somebase.com/path/to/base/Patient/1234/_history/2222"));
|
||||
assertThat(response.getNameFirstRep().getFamilyAsSingleString(), StringContains.containsString("Cardinal"));
|
||||
assertEquals("http://somebase.com/path/to/base/Patient/1234", capt.getAllValues().get(1).getURI().toString());
|
||||
|
||||
|
@ -1478,7 +1459,7 @@ public class GenericClientTest {
|
|||
(client).setEncoding(EncodingEnum.JSON);
|
||||
int count = 0;
|
||||
|
||||
client.read(Patient.class, new IdDt("Patient/1234"));
|
||||
client.read(Patient.class, new IdType("Patient/1234"));
|
||||
assertEquals("http://example.com/fhir/Patient/1234?_format=json", capt.getAllValues().get(count).getURI().toString());
|
||||
count++;
|
||||
|
||||
|
@ -1716,12 +1697,12 @@ public class GenericClientTest {
|
|||
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
|
||||
|
||||
Patient response = client.vread(Patient.class, new IdDt("http://somebase.com/path/to/base/Patient/1234/_history/2222"));
|
||||
Patient response = client.vread(Patient.class, new IdType("http://somebase.com/path/to/base/Patient/1234/_history/2222"));
|
||||
assertThat(response.getNameFirstRep().getFamilyAsSingleString(), StringContains.containsString("Cardinal"));
|
||||
assertEquals("http://somebase.com/path/to/base/Patient/1234/_history/2222", capt.getAllValues().get(0).getURI().toString());
|
||||
|
||||
try {
|
||||
client.vread(Patient.class, new IdDt("http://somebase.com/path/to/base/Patient/1234"));
|
||||
client.vread(Patient.class, new IdType("http://somebase.com/path/to/base/Patient/1234"));
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertThat(e.getMessage(), containsString("No version specified in URL"));
|
|
@ -28,7 +28,7 @@ import org.junit.Test;
|
|||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.IdType;
|
||||
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||
import ca.uhn.fhir.rest.annotation.Read;
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
|
@ -111,7 +111,7 @@ public class HttpProxyTest {
|
|||
String baseUri = "http://99.99.99.99:" + port + "/rootctx/rcp2/fhirctx/fcp2";
|
||||
IGenericClient client = ourCtx.newRestfulGenericClient(baseUri);
|
||||
|
||||
IdDt id = new IdDt("Patient", "123");
|
||||
IdType id = new IdType("Patient", "123");
|
||||
client.read(Patient.class, id);
|
||||
|
||||
assertEquals("Basic dXNlcm5hbWU6cGFzc3dvcmQ=", myAuthHeader);
|
||||
|
@ -135,7 +135,7 @@ public class HttpProxyTest {
|
|||
}
|
||||
|
||||
@Read
|
||||
public Patient read(@IdParam IdDt theId, HttpServletRequest theRequest) {
|
||||
public Patient read(@IdParam IdType theId, HttpServletRequest theRequest) {
|
||||
Patient retVal = new Patient();
|
||||
retVal.setId(theId);
|
||||
ourRequest = theRequest;
|
|
@ -1,22 +1,92 @@
|
|||
package ca.uhn.fhir.rest.client;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.hl7.fhir.instance.model.api.IAnyResource;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.r4.model.Patient;
|
||||
import org.hl7.fhir.r4.model.*;
|
||||
|
||||
import ca.uhn.fhir.rest.annotation.RequiredParam;
|
||||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.api.Include;
|
||||
import ca.uhn.fhir.model.primitive.*;
|
||||
import ca.uhn.fhir.rest.annotation.*;
|
||||
import ca.uhn.fhir.rest.annotation.Count;
|
||||
import ca.uhn.fhir.rest.api.MethodOutcome;
|
||||
import ca.uhn.fhir.rest.client.api.IBasicClient;
|
||||
import ca.uhn.fhir.rest.param.DateParam;
|
||||
import ca.uhn.fhir.rest.param.*;
|
||||
|
||||
public interface ITestClient extends IBasicClient {
|
||||
|
||||
@Search(type=ExtendedPatient.class)
|
||||
public List<IBaseResource> getPatientByDobWithGenericResourceReturnType(@RequiredParam(name=Patient.SP_BIRTHDATE) DateParam theBirthDate);
|
||||
@Create
|
||||
public MethodOutcome createPatient(@ResourceParam Patient thePatient);
|
||||
|
||||
@Search()
|
||||
public List<Patient> getPatientByDateRange(@RequiredParam(name = "dateRange") DateRangeParam theIdentifiers);
|
||||
|
||||
@Search(type=Observation.class)
|
||||
public Bundle getObservationByNameValueDate(@RequiredParam(name = Observation.SP_CODE_VALUE_DATE, compositeTypes= {StringParam.class,DateParam.class}) CompositeParam<StringParam, DateParam> theIdentifiers);
|
||||
|
||||
@Search()
|
||||
public List<Patient> getPatientByDob(@RequiredParam(name=Patient.SP_BIRTHDATE) DateParam theBirthDate);
|
||||
|
||||
@Search(type=ExtendedPatient.class)
|
||||
public List<IResource> getPatientByDobWithGenericResourceReturnType(@RequiredParam(name=Patient.SP_BIRTHDATE) DateParam theBirthDate);
|
||||
|
||||
@Search()
|
||||
public List<Patient> getPatientMultipleIdentifiers(@RequiredParam(name = "ids") TokenOrListParam theIdentifiers);
|
||||
|
||||
@Search(queryName="someQueryNoParams")
|
||||
public Patient getPatientNoParams();
|
||||
|
||||
@Search(queryName="someQueryOneParam")
|
||||
public Patient getPatientOneParam(@RequiredParam(name="param1") StringParam theParam);
|
||||
|
||||
@Search(type=Patient.class)
|
||||
public Bundle findPatient(@RequiredParam(name = "param") StringAndListParam theStrings);
|
||||
|
||||
@Search()
|
||||
public Patient getPatientWithIncludes(@RequiredParam(name = "withIncludes") StringParam theString, @IncludeParam List<Include> theIncludes);
|
||||
|
||||
@Update
|
||||
public MethodOutcome updatePatient(@IdParam IdType theId, @ResourceParam Patient thePatient);
|
||||
|
||||
@Delete(type=DiagnosticReport.class)
|
||||
void deleteDiagnosticReport(@IdParam IdType theId);
|
||||
|
||||
@Delete(type=Patient.class)
|
||||
MethodOutcome deletePatient(@IdParam IdType theId);
|
||||
|
||||
@Search(type=Patient.class)
|
||||
Patient findPatientByMrn(@RequiredParam(name = Patient.SP_IDENTIFIER) TokenParam theId);
|
||||
|
||||
@Search(type=Patient.class)
|
||||
Bundle findPatientByName(@RequiredParam(name = Patient.SP_FAMILY) StringParam theId, @OptionalParam(name=Patient.SP_GIVEN) StringParam theGiven);
|
||||
|
||||
@History(type=Patient.class)
|
||||
Bundle getHistoryPatientInstance(@IdParam IdType theId);
|
||||
|
||||
@History(type=Patient.class)
|
||||
Bundle getHistoryPatientInstance(@IdParam IdType theId, @Since InstantDt theSince, @Count IntegerDt theCount);
|
||||
|
||||
@History(type=Patient.class)
|
||||
Bundle getHistoryPatientInstance(@IdParam IdType theId, @Since Date theSince, @Count Integer theCount);
|
||||
|
||||
@History(type=Patient.class)
|
||||
Bundle getHistoryPatientType();
|
||||
|
||||
@History
|
||||
Bundle getHistoryServer();
|
||||
|
||||
@Read(type=Patient.class)
|
||||
Patient getPatientById(@IdParam IdType theId);
|
||||
|
||||
@Validate(type=Patient.class)
|
||||
MethodOutcome validatePatient(@ResourceParam Patient thePatient);
|
||||
|
||||
@Search(type=Patient.class)
|
||||
Patient findPatientQuantity(@RequiredParam(name="quantityParam") QuantityParam theQuantityDt);
|
||||
|
||||
@Search(compartmentName="compartmentName")
|
||||
public List<Patient> getPatientByCompartmentAndDob(@IdParam IdType theIdType, @RequiredParam(name=Patient.SP_BIRTHDATE) DateParam theBirthDate);
|
||||
|
||||
@Search(type=ExtendedPatient.class)
|
||||
public List<IAnyResource> getPatientByDobWithGenericResourceReturnType2(@RequiredParam(name=Patient.SP_BIRTHDATE) DateParam theBirthDate);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package ca.uhn.fhir.rest.client;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.Charset;
|
||||
|
@ -15,20 +17,17 @@ import org.apache.http.client.methods.HttpGet;
|
|||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.hl7.fhir.r4.model.*;
|
||||
import org.junit.*;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.ExtensionDt;
|
||||
import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt;
|
||||
import ca.uhn.fhir.model.dstu.resource.Conformance;
|
||||
import ca.uhn.fhir.model.dstu.resource.Organization;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||
import ca.uhn.fhir.rest.server.IncludeTest;
|
||||
import ca.uhn.fhir.rest.server.IncludeTest.ExtPatient;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
@ -43,11 +42,11 @@ public class IncludedResourceStitchingClientTest {
|
|||
|
||||
@Before
|
||||
public void before() {
|
||||
ctx = new FhirContext(Patient.class, Conformance.class);
|
||||
ctx = FhirContext.forR4();
|
||||
|
||||
httpClient = mock(HttpClient.class, new ReturnsDeepStubs());
|
||||
ctx.getRestfulClientFactory().setHttpClient(httpClient);
|
||||
ctx.getRestfulClientFactory().setServerValidationModeEnum(ServerValidationModeEnum.NEVER);
|
||||
ctx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
|
||||
httpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
|
||||
}
|
||||
|
@ -61,20 +60,24 @@ public class IncludedResourceStitchingClientTest {
|
|||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(createBundle()), Charset.forName("UTF-8")));
|
||||
|
||||
IGenericClient client = ctx.newRestfulGenericClient( "http://foo");
|
||||
Bundle bundle = client.search().forResource("Patient").execute();
|
||||
Bundle bundle = client
|
||||
.search()
|
||||
.forResource("Patient")
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
|
||||
assertEquals(HttpGet.class, capt.getValue().getClass());
|
||||
HttpGet get = (HttpGet) capt.getValue();
|
||||
assertEquals("http://foo/Patient", get.getURI().toString());
|
||||
|
||||
assertEquals(3, bundle.size());
|
||||
assertEquals(3, bundle.getEntry().size());
|
||||
|
||||
Patient p = (Patient) bundle.getEntries().get(0).getResource();
|
||||
List<ExtensionDt> exts = p.getUndeclaredExtensionsByUrl("http://foo");
|
||||
Patient p = (Patient) bundle.getEntry().get(0).getResource();
|
||||
List<Extension> exts = p.getExtensionsByUrl("http://foo");
|
||||
assertEquals(1,exts.size());
|
||||
ExtensionDt ext = exts.get(0);
|
||||
ResourceReferenceDt ref = (ResourceReferenceDt) ext.getValue();
|
||||
assertEquals("Organization/o1", ref.getReference().getValue());
|
||||
Extension ext = exts.get(0);
|
||||
Reference ref = (Reference) ext.getValue();
|
||||
assertEquals("Organization/o1", ref.getReferenceElement().getValue());
|
||||
assertNotNull(ref.getResource());
|
||||
|
||||
}
|
||||
|
@ -97,7 +100,7 @@ public class IncludedResourceStitchingClientTest {
|
|||
|
||||
assertEquals(4, bundle.size());
|
||||
|
||||
ExtPatient p = (ExtPatient) bundle.getEntries().get(0).getResource();
|
||||
ExtPatient p = (ExtPatient) bundle.getEntry().get(0).getResource();
|
||||
ResourceReferenceDt ref = (ResourceReferenceDt) p.getSecondOrg();
|
||||
assertEquals("Organization/o1", ref.getReference().getValue());
|
||||
assertNotNull(ref.getResource());
|
|
@ -13,16 +13,17 @@ import java.net.URL;
|
|||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.servlet.ServletHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
import org.hl7.fhir.r4.model.IdType;
|
||||
import org.hl7.fhir.r4.model.Patient;
|
||||
import org.junit.*;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.annotation.IdParam;
|
||||
import ca.uhn.fhir.rest.annotation.Read;
|
||||
import ca.uhn.fhir.rest.client.api.IGenericClient;
|
||||
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||
|
@ -37,7 +38,7 @@ import ch.qos.logback.core.Appender;
|
|||
|
||||
public class LoggingInterceptorTest {
|
||||
|
||||
private static FhirContext ourCtx = FhirContext.forDstu1();
|
||||
private static FhirContext ourCtx = FhirContext.forR4();
|
||||
private static int ourPort;
|
||||
private static Server ourServer;
|
||||
private Logger myLoggerRoot;
|
||||
|
@ -135,21 +136,18 @@ public class LoggingInterceptorTest {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
*/
|
||||
public static class DummyProvider implements IResourceProvider {
|
||||
|
||||
@Read(version = true)
|
||||
public Patient findPatient(@IdParam IdDt theId) {
|
||||
public Patient findPatient(@IdParam IdType theId) {
|
||||
Patient patient = new Patient();
|
||||
patient.addIdentifier(theId.getIdPart(), theId.getVersionIdPart());
|
||||
patient.addIdentifier().setSystem(theId.getIdPart()).setValue(theId.getVersionIdPart());
|
||||
patient.setId("Patient/1/_history/1");
|
||||
return patient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends IResource> getResourceType() {
|
||||
public Class<Patient> getResourceType() {
|
||||
return Patient.class;
|
||||
}
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
package ca.uhn.fhir.rest.client;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.Charset;
|
||||
|
@ -15,21 +16,19 @@ import org.apache.http.client.methods.HttpGet;
|
|||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.hl7.fhir.r4.model.Bundle;
|
||||
import org.hl7.fhir.r4.model.Patient;
|
||||
import org.junit.*;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.dstu.resource.Conformance;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
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.client.api.IBasicClient;
|
||||
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||
import ca.uhn.fhir.rest.param.ReferenceParam;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class ReferenceClientTest {
|
||||
|
@ -42,11 +41,11 @@ public class ReferenceClientTest {
|
|||
|
||||
@Before
|
||||
public void before() {
|
||||
ctx = new FhirContext(Patient.class, Conformance.class);
|
||||
ctx = FhirContext.forR4();
|
||||
|
||||
httpClient = mock(HttpClient.class, new ReturnsDeepStubs());
|
||||
ctx.getRestfulClientFactory().setHttpClient(httpClient);
|
||||
ctx.getRestfulClientFactory().setServerValidationModeEnum(ServerValidationModeEnum.NEVER);
|
||||
ctx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
|
||||
httpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
|
||||
}
|
||||
|
@ -64,7 +63,7 @@ public class ReferenceClientTest {
|
|||
|
||||
assertEquals(HttpGet.class, capt.getValue().getClass());
|
||||
HttpGet get = (HttpGet) capt.getValue();
|
||||
assertEquals("http://foo/Patient?provider=123", get.getURI().toString());
|
||||
assertEquals("http://foo/Patient?general-practitioner=123", get.getURI().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -80,7 +79,7 @@ public class ReferenceClientTest {
|
|||
|
||||
assertEquals(HttpGet.class, capt.getValue().getClass());
|
||||
HttpGet get = (HttpGet) capt.getValue();
|
||||
assertEquals("http://foo/Patient?provider.chain=123", get.getURI().toString());
|
||||
assertEquals("http://foo/Patient?general-practitioner.chain=123", get.getURI().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -96,7 +95,7 @@ public class ReferenceClientTest {
|
|||
|
||||
assertEquals(HttpGet.class, capt.getValue().getClass());
|
||||
HttpGet get = (HttpGet) capt.getValue();
|
||||
assertEquals("http://foo/Patient?provider%3AOrganization.chain=123", get.getURI().toString());
|
||||
assertEquals("http://foo/Patient?general-practitioner%3AOrganization.chain=123", get.getURI().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -112,18 +111,18 @@ public class ReferenceClientTest {
|
|||
|
||||
assertEquals(HttpGet.class, capt.getValue().getClass());
|
||||
HttpGet get = (HttpGet) capt.getValue();
|
||||
assertEquals("http://foo/Patient?provider%3AOrganization=123", get.getURI().toString());
|
||||
assertEquals("http://foo/Patient?general-practitioner%3AOrganization=123", get.getURI().toString());
|
||||
}
|
||||
|
||||
private String createBundle() {
|
||||
return ctx.newXmlParser().encodeBundleToString(new Bundle());
|
||||
return ctx.newXmlParser().encodeResourceToString(new Bundle());
|
||||
}
|
||||
|
||||
|
||||
private interface IClient extends IBasicClient {
|
||||
|
||||
@Search(type=Patient.class)
|
||||
public List<Patient> search(@RequiredParam(name=Patient.SP_PROVIDER) ReferenceParam theString);
|
||||
public List<Patient> search(@RequiredParam(name=Patient.SP_GENERAL_PRACTITIONER) ReferenceParam theString);
|
||||
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
|
@ -1,7 +1,8 @@
|
|||
package ca.uhn.fhir.rest.client;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.Charset;
|
||||
|
@ -15,24 +16,18 @@ import org.apache.http.client.methods.HttpGet;
|
|||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.hl7.fhir.r4.model.Bundle;
|
||||
import org.hl7.fhir.r4.model.Patient;
|
||||
import org.junit.*;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.dstu.resource.Conformance;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.rest.annotation.RequiredParam;
|
||||
import ca.uhn.fhir.rest.annotation.Search;
|
||||
import ca.uhn.fhir.rest.annotation.Sort;
|
||||
import ca.uhn.fhir.rest.api.SortOrderEnum;
|
||||
import ca.uhn.fhir.rest.api.SortSpec;
|
||||
import ca.uhn.fhir.rest.annotation.*;
|
||||
import ca.uhn.fhir.rest.api.*;
|
||||
import ca.uhn.fhir.rest.client.api.IBasicClient;
|
||||
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class SortClientTest {
|
||||
|
@ -45,11 +40,11 @@ public class SortClientTest {
|
|||
|
||||
@Before
|
||||
public void before() {
|
||||
ctx = new FhirContext(Patient.class, Conformance.class);
|
||||
ctx = FhirContext.forR4();
|
||||
|
||||
httpClient = mock(HttpClient.class, new ReturnsDeepStubs());
|
||||
ctx.getRestfulClientFactory().setHttpClient(httpClient);
|
||||
ctx.getRestfulClientFactory().setServerValidationModeEnum(ServerValidationModeEnum.NEVER);
|
||||
ctx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
|
||||
httpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
|
||||
}
|
||||
|
@ -89,7 +84,7 @@ public class SortClientTest {
|
|||
}
|
||||
|
||||
private String createBundle() {
|
||||
return ctx.newXmlParser().encodeBundleToString(new Bundle());
|
||||
return ctx.newXmlParser().encodeResourceToString(new Bundle());
|
||||
}
|
||||
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
package ca.uhn.fhir.rest.client;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.Charset;
|
||||
|
@ -15,21 +16,19 @@ import org.apache.http.client.methods.HttpGet;
|
|||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.hl7.fhir.r4.model.Bundle;
|
||||
import org.hl7.fhir.r4.model.Patient;
|
||||
import org.junit.*;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.dstu.resource.Conformance;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
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.client.api.IBasicClient;
|
||||
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||
import ca.uhn.fhir.rest.param.StringParam;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class StringClientTest {
|
||||
|
@ -42,11 +41,11 @@ public class StringClientTest {
|
|||
|
||||
@Before
|
||||
public void before() {
|
||||
ctx = new FhirContext(Patient.class, Conformance.class);
|
||||
ctx = FhirContext.forR4();
|
||||
|
||||
httpClient = mock(HttpClient.class, new ReturnsDeepStubs());
|
||||
ctx.getRestfulClientFactory().setHttpClient(httpClient);
|
||||
ctx.getRestfulClientFactory().setServerValidationModeEnum(ServerValidationModeEnum.NEVER);
|
||||
ctx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
|
||||
httpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
|
||||
}
|
||||
|
@ -101,7 +100,7 @@ public class StringClientTest {
|
|||
|
||||
|
||||
private String createBundle() {
|
||||
return ctx.newXmlParser().encodeBundleToString(new Bundle());
|
||||
return ctx.newXmlParser().encodeResourceToString(new Bundle());
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,157 @@
|
|||
package ca.uhn.fhir.rest.client;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.input.ReaderInputStream;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpUriRequest;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.apache.http.message.BasicStatusLine;
|
||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||
import org.hl7.fhir.r4.model.*;
|
||||
import org.junit.*;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.rest.annotation.Transaction;
|
||||
import ca.uhn.fhir.rest.annotation.TransactionParam;
|
||||
import ca.uhn.fhir.rest.api.Constants;
|
||||
import ca.uhn.fhir.rest.client.api.IBasicClient;
|
||||
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
|
||||
public class TransactionClientTest {
|
||||
|
||||
private FhirContext ctx;
|
||||
private HttpClient httpClient;
|
||||
private HttpResponse httpResponse;
|
||||
|
||||
// atom-document-large.xml
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
ctx = FhirContext.forR4();
|
||||
|
||||
httpClient = mock(HttpClient.class, new ReturnsDeepStubs());
|
||||
ctx.getRestfulClientFactory().setHttpClient(httpClient);
|
||||
ctx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER);
|
||||
|
||||
httpResponse = mock(HttpResponse.class, new ReturnsDeepStubs());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleTransaction() throws Exception {
|
||||
Patient patient = new Patient();
|
||||
patient.setId(new IdType("Patient/testPersistWithSimpleLinkP01"));
|
||||
patient.addIdentifier().setSystem("urn:system").setValue("testPersistWithSimpleLinkP01");
|
||||
patient.addName().setFamily("Tester").addGiven("Joe");
|
||||
|
||||
Observation obs = new Observation();
|
||||
obs.getCode().addCoding().setSystem("urn:system").setCode("testPersistWithSimpleLinkO01");
|
||||
obs.setSubject(new Reference("Patient/testPersistWithSimpleLinkP01"));
|
||||
|
||||
List<IBaseResource> resources = Arrays.asList((IResource) patient, obs);
|
||||
|
||||
IClient client = ctx.newRestfulClient(IClient.class, "http://foo");
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
|
||||
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_ATOM_XML + "; charset=UTF-8"));
|
||||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(createBundle()), Charset.forName("UTF-8")));
|
||||
|
||||
client.transaction(resources);
|
||||
|
||||
assertEquals(HttpPost.class, capt.getValue().getClass());
|
||||
HttpPost post = (HttpPost) capt.getValue();
|
||||
assertEquals("http://foo", post.getURI().toString());
|
||||
|
||||
Bundle bundle = ctx.newXmlParser().parseResource(Bundle.class, new InputStreamReader(post.getEntity().getContent()));
|
||||
ourLog.info(ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(bundle));
|
||||
|
||||
assertEquals(2, bundle.getEntry().size());
|
||||
assertEquals("Patient/testPersistWithSimpleLinkP01", bundle.getEntry().get(0).getIdElement().getValue());
|
||||
|
||||
assertTrue(bundle.getEntry().get(1).getId().isEmpty());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleTransactionWithBundleParam() throws Exception {
|
||||
Patient patient = new Patient();
|
||||
patient.setId(new IdType("Patient/testPersistWithSimpleLinkP01"));
|
||||
patient.addIdentifier().setSystem("urn:system").setValue("testPersistWithSimpleLinkP01");
|
||||
patient.addName().setFamily("Tester").addGiven("Joe");
|
||||
|
||||
Observation obs = new Observation();
|
||||
obs.getCode().addCoding().setSystem("urn:system").setCode("testPersistWithSimpleLinkO01");
|
||||
obs.setSubject(new Reference("Patient/testPersistWithSimpleLinkP01"));
|
||||
|
||||
Bundle transactionBundle = new Bundle();
|
||||
transactionBundle.addEntry().setResource(patient);
|
||||
transactionBundle.addEntry().setResource(obs);
|
||||
|
||||
IBundleClient client = ctx.newRestfulClient(IBundleClient.class, "http://foo");
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
|
||||
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
|
||||
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_ATOM_XML + "; charset=UTF-8"));
|
||||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(createBundle()), Charset.forName("UTF-8")));
|
||||
|
||||
client.transaction(transactionBundle);
|
||||
|
||||
assertEquals(HttpPost.class, capt.getValue().getClass());
|
||||
HttpPost post = (HttpPost) capt.getValue();
|
||||
assertEquals("http://foo", post.getURI().toString());
|
||||
|
||||
Bundle bundle = ctx.newXmlParser().parseResource(Bundle.class, new InputStreamReader(post.getEntity().getContent()));
|
||||
ourLog.info(ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(bundle));
|
||||
|
||||
assertEquals(2, bundle.getEntry().size());
|
||||
assertEquals("http://foo/Patient/testPersistWithSimpleLinkP01", bundle.getEntry().get(0).getIdElement().getValue());
|
||||
|
||||
assertTrue(bundle.getEntry().get(1).getId().isEmpty());
|
||||
|
||||
}
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TransactionClientTest.class);
|
||||
|
||||
private String createBundle() {
|
||||
return ctx.newXmlParser().encodeResourceToString(new Bundle());
|
||||
}
|
||||
|
||||
private interface IClient extends IBasicClient {
|
||||
|
||||
@Transaction
|
||||
public List<IBaseResource> transaction(@TransactionParam List<IBaseResource> theResources);
|
||||
|
||||
}
|
||||
|
||||
private interface IBundleClient extends IBasicClient {
|
||||
|
||||
@Transaction
|
||||
public List<IBaseResource> transaction(@TransactionParam Bundle theResources);
|
||||
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassClearContext() {
|
||||
TestUtil.clearAllStaticFieldsForUnitTest();
|
||||
}
|
||||
|
||||
}
|
|
@ -6,12 +6,7 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
@ -23,35 +18,20 @@ 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.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.hl7.fhir.r4.model.*;
|
||||
import org.junit.*;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.context.api.BundleInclusionRule;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.api.Include;
|
||||
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.dstu.composite.ResourceReferenceDt;
|
||||
import ca.uhn.fhir.model.dstu.resource.DiagnosticReport;
|
||||
import ca.uhn.fhir.model.dstu.resource.Observation;
|
||||
import ca.uhn.fhir.model.dstu.resource.Organization;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.dstu.resource.Practitioner;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
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.util.ElementUtil;
|
||||
import ca.uhn.fhir.util.PortUtil;
|
||||
import ca.uhn.fhir.util.TestUtil;
|
||||
import ca.uhn.fhir.rest.annotation.*;
|
||||
import ca.uhn.fhir.util.*;
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
*/
|
||||
public class IncludeTest {
|
||||
|
||||
private static CloseableHttpClient ourClient;
|
||||
|
@ -80,20 +60,21 @@ public class IncludeTest {
|
|||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
assertEquals(3, bundle.size());
|
||||
assertEquals(new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless());
|
||||
assertEquals(new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless());
|
||||
assertEquals(new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless());
|
||||
assertEquals(3, bundle.getEntry().size());
|
||||
|
||||
assertEquals(new IdType("Patient/p1"), bundle.getEntry().get(0).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
||||
assertEquals(new IdType("Patient/p2"), bundle.getEntry().get(1).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
||||
assertEquals(new IdType("Organization/o1"), bundle.getEntry().get(2).getResource().getIdElement().toUnqualifiedVersionless().getValue());
|
||||
|
||||
Patient p1 = (Patient) bundle.toListOfResources().get(0);
|
||||
assertEquals(0, p1.getContained().getContainedResources().size());
|
||||
Patient p1 = (Patient) bundle.getEntry().get(0).getResource();
|
||||
assertEquals(0, p1.getContained().size());
|
||||
|
||||
Patient p2 = (Patient) bundle.toListOfResources().get(1);
|
||||
assertEquals(0, p2.getContained().getContainedResources().size());
|
||||
Patient p2 = (Patient) bundle.getEntry().get(1).getResource();
|
||||
assertEquals(0, p2.getContained().size());
|
||||
|
||||
}
|
||||
|
||||
|
@ -105,21 +86,21 @@ public class IncludeTest {
|
|||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
assertEquals(4, bundle.size());
|
||||
assertEquals(new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless());
|
||||
assertEquals(new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless());
|
||||
assertEquals(new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless());
|
||||
assertEquals(new IdDt("Organization/o2"), bundle.toListOfResources().get(3).getId().toUnqualifiedVersionless());
|
||||
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.toListOfResources().get(0);
|
||||
assertEquals(0, p1.getContained().getContainedResources().size());
|
||||
Patient p1 = (Patient) bundle.getEntry().get(0).getResource();
|
||||
assertEquals(0, p1.getContained().size());
|
||||
|
||||
Patient p2 = (Patient) bundle.toListOfResources().get(1);
|
||||
assertEquals(0, p2.getContained().getContainedResources().size());
|
||||
Patient p2 = (Patient) bundle.getEntry().get(1).getResource();
|
||||
assertEquals(0, p2.getContained().size());
|
||||
|
||||
}
|
||||
|
||||
|
@ -131,20 +112,20 @@ public class IncludeTest {
|
|||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
assertEquals(3, bundle.size());
|
||||
assertEquals(new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless());
|
||||
assertEquals(new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless());
|
||||
assertEquals(new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless());
|
||||
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.toListOfResources().get(0);
|
||||
assertEquals(0, p1.getContained().getContainedResources().size());
|
||||
Patient p1 = (Patient) bundle.getEntry().get(0).getResource();
|
||||
assertEquals(0, p1.getContained().size());
|
||||
|
||||
Patient p2 = (Patient) bundle.toListOfResources().get(1);
|
||||
assertEquals(0, p2.getContained().getContainedResources().size());
|
||||
Patient p2 = (Patient) bundle.getEntry().get(1).getResource();
|
||||
assertEquals(0, p2.getContained().size());
|
||||
|
||||
}
|
||||
|
||||
|
@ -156,20 +137,20 @@ public class IncludeTest {
|
|||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newJsonParser().parseBundle(responseContent);
|
||||
Bundle bundle = ourCtx.newJsonParser().parseResource(Bundle.class, responseContent);
|
||||
|
||||
ourLog.info(responseContent);
|
||||
|
||||
assertEquals(3, bundle.size());
|
||||
assertEquals(new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless());
|
||||
assertEquals(new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless());
|
||||
assertEquals(new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless());
|
||||
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.toListOfResources().get(0);
|
||||
assertEquals(0, p1.getContained().getContainedResources().size());
|
||||
Patient p1 = (Patient) bundle.getEntry().get(0).getResource();
|
||||
assertEquals(0, p1.getContained().size());
|
||||
|
||||
Patient p2 = (Patient) bundle.toListOfResources().get(1);
|
||||
assertEquals(0, p2.getContained().getContainedResources().size());
|
||||
Patient p2 = (Patient) bundle.getEntry().get(1).getResource();
|
||||
assertEquals(0, p2.getContained().size());
|
||||
|
||||
}
|
||||
|
||||
|
@ -214,8 +195,8 @@ public class IncludeTest {
|
|||
ourLog.info(responseContent);
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
assertEquals(4, bundle.size());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||
assertEquals(4, bundle.getEntry().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -226,12 +207,12 @@ public class IncludeTest {
|
|||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
assertEquals(1, bundle.size());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||
assertEquals(1, bundle.getEntry().size());
|
||||
|
||||
Patient p = bundle.getResources(Patient.class).get(0);
|
||||
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||
assertEquals(0, p.getName().size());
|
||||
assertEquals("Hello", p.getId().getIdPart());
|
||||
assertEquals("Hello", p.getIdElement().getIdPart());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -242,13 +223,13 @@ public class IncludeTest {
|
|||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
assertEquals(1, bundle.size());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||
assertEquals(1, bundle.getEntry().size());
|
||||
|
||||
Patient p = bundle.getResources(Patient.class).get(0);
|
||||
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||
assertEquals(1, p.getName().size());
|
||||
assertEquals("Hello", p.getId().getIdPart());
|
||||
assertEquals("foo", p.getName().get(0).getFamilyFirstRep().getValue());
|
||||
assertEquals("Hello", p.getIdElement().getIdPart());
|
||||
assertEquals("foo", p.getName().get(0).getFamily());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -259,16 +240,16 @@ public class IncludeTest {
|
|||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
assertEquals(200, status.getStatusLine().getStatusCode());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent);
|
||||
assertEquals(1, bundle.size());
|
||||
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
|
||||
assertEquals(1, bundle.getEntry().size());
|
||||
|
||||
Patient p = bundle.getResources(Patient.class).get(0);
|
||||
Patient p = BundleUtil.toListOfResourcesOfType(ourCtx, bundle, Patient.class).get(0);
|
||||
assertEquals(2, p.getName().size());
|
||||
assertEquals("Hello", p.getId().getIdPart());
|
||||
assertEquals("Hello", p.getIdElement().getIdPart());
|
||||
|
||||
Set<String> values = new HashSet<String>();
|
||||
values.add(p.getName().get(0).getFamilyFirstRep().getValue());
|
||||
values.add(p.getName().get(1).getFamilyFirstRep().getValue());
|
||||
values.add(p.getName().get(0).getFamily());
|
||||
values.add(p.getName().get(1).getFamily());
|
||||
assertThat(values, containsInAnyOrder("foo", "bar"));
|
||||
|
||||
}
|
||||
|
@ -283,7 +264,7 @@ public class IncludeTest {
|
|||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
|
||||
ourCtx = FhirContext.forDstu1();
|
||||
ourCtx = FhirContext.forR4();
|
||||
ourPort = PortUtil.findFreePort();
|
||||
ourServer = new Server(ourPort);
|
||||
|
||||
|
@ -309,14 +290,14 @@ public class IncludeTest {
|
|||
|
||||
Organization org = new Organization();
|
||||
org.setId("Organization/65546");
|
||||
org.getName().setValue("Contained Test Organization");
|
||||
org.getNameElement().setValue("Contained Test Organization");
|
||||
|
||||
Patient patient = new Patient();
|
||||
patient.setId("Patient/1333");
|
||||
patient.addIdentifier("urn:mrns", "253345");
|
||||
patient.addIdentifier().setSystem("urn:mrns").setValue("253345");
|
||||
patient.getManagingOrganization().setResource(patient);
|
||||
|
||||
System.out.println(FhirContext.forDstu1().newXmlParser().setPrettyPrint(true).encodeResourceToString(patient));
|
||||
System.out.println(FhirContext.forR4().newXmlParser().setPrettyPrint(true).encodeResourceToString(patient));
|
||||
|
||||
patient.getManagingOrganization().getReference();
|
||||
|
||||
|
@ -328,7 +309,7 @@ public class IncludeTest {
|
|||
public static class DummyDiagnosticReportResourceProvider implements IResourceProvider {
|
||||
|
||||
@Override
|
||||
public Class<? extends IResource> getResourceType() {
|
||||
public Class<DiagnosticReport> getResourceType() {
|
||||
return DiagnosticReport.class;
|
||||
}
|
||||
|
||||
|
@ -336,31 +317,31 @@ public class IncludeTest {
|
|||
public List<DiagnosticReport> stitchedInclude() {
|
||||
Practitioner pr1 = new Practitioner();
|
||||
pr1.setId("Practitioner/001");
|
||||
pr1.getName().addFamily("Pract1");
|
||||
pr1.addName().setFamily("Pract1");
|
||||
|
||||
Practitioner pr2 = new Practitioner();
|
||||
pr2.setId("Practitioner/002");
|
||||
pr2.getName().addFamily("Pract2");
|
||||
pr2.addName().setFamily("Pract2");
|
||||
|
||||
Practitioner pr3 = new Practitioner();
|
||||
pr3.setId("Practitioner/003");
|
||||
pr3.getName().addFamily("Pract3");
|
||||
pr3.addName().setFamily("Pract3");
|
||||
|
||||
Observation o1 = new Observation();
|
||||
o1.getName().setText("Obs1");
|
||||
o1.getCode().setText("Obs1");
|
||||
o1.addPerformer().setResource(pr1);
|
||||
|
||||
Observation o2 = new Observation();
|
||||
o2.getName().setText("Obs2");
|
||||
o2.getCode().setText("Obs2");
|
||||
o2.addPerformer().setResource(pr2);
|
||||
|
||||
Observation o3 = new Observation();
|
||||
o3.getName().setText("Obs3");
|
||||
o3.getCode().setText("Obs3");
|
||||
o3.addPerformer().setResource(pr3);
|
||||
|
||||
DiagnosticReport rep = new DiagnosticReport();
|
||||
rep.setId("DiagnosticReport/999");
|
||||
rep.getName().setText("Rep");
|
||||
rep.getCode().setText("Rep");
|
||||
rep.addResult().setResource(o1);
|
||||
rep.addResult().setResource(o2);
|
||||
rep.addResult().setResource(o3);
|
||||
|
@ -370,24 +351,21 @@ public class IncludeTest {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Created by dsotnikov on 2/25/2014.
|
||||
*/
|
||||
public static class DummyPatientResourceProvider implements IResourceProvider {
|
||||
|
||||
@Search(queryName = "containedInclude")
|
||||
public List<Patient> containedInclude() {
|
||||
Organization o1 = new Organization();
|
||||
o1.getName().setValue("o1");
|
||||
o1.getNameElement().setValue("o1");
|
||||
|
||||
Patient p1 = new Patient();
|
||||
p1.setId("p1");
|
||||
p1.addIdentifier().setLabel("p1");
|
||||
p1.addIdentifier().setValue("p1");
|
||||
p1.getManagingOrganization().setResource(o1);
|
||||
|
||||
Patient p2 = new Patient();
|
||||
p2.setId("p2");
|
||||
p2.addIdentifier().setLabel("p2");
|
||||
p2.addIdentifier().setValue("p2");
|
||||
p2.getManagingOrganization().setResource(o1);
|
||||
|
||||
return Arrays.asList(p1, p2);
|
||||
|
@ -396,22 +374,22 @@ public class IncludeTest {
|
|||
@Search(queryName = "declaredExtInclude")
|
||||
public List<ExtPatient> declaredExtInclude() {
|
||||
Organization o1 = new Organization();
|
||||
o1.getName().setValue("o1");
|
||||
o1.getNameElement().setValue("o1");
|
||||
o1.setId("o1");
|
||||
|
||||
Organization o2 = new Organization();
|
||||
o2.getName().setValue("o2");
|
||||
o2.getNameElement().setValue("o2");
|
||||
o2.setId("o2");
|
||||
o1.getPartOf().setResource(o2);
|
||||
|
||||
ExtPatient p1 = new ExtPatient();
|
||||
p1.setId("p1");
|
||||
p1.addIdentifier().setLabel("p1");
|
||||
p1.addIdentifier().setValue("p1");
|
||||
p1.getSecondOrg().setResource(o1);
|
||||
|
||||
ExtPatient p2 = new ExtPatient();
|
||||
p2.setId("p2");
|
||||
p2.addIdentifier().setLabel("p2");
|
||||
p2.addIdentifier().setValue("p2");
|
||||
p2.getSecondOrg().setResource(o1);
|
||||
|
||||
return Arrays.asList(p1, p2);
|
||||
|
@ -420,18 +398,18 @@ public class IncludeTest {
|
|||
@Search(queryName = "extInclude")
|
||||
public List<Patient> extInclude() {
|
||||
Organization o1 = new Organization();
|
||||
o1.getName().setValue("o1");
|
||||
o1.getNameElement().setValue("o1");
|
||||
o1.setId("o1");
|
||||
|
||||
Patient p1 = new Patient();
|
||||
p1.setId("p1");
|
||||
p1.addIdentifier().setLabel("p1");
|
||||
p1.addUndeclaredExtension(false, "http://foo", new ResourceReferenceDt(o1));
|
||||
p1.addIdentifier().setValue("p1");
|
||||
p1.addUndeclaredExtension(false, "http://foo", new Reference(o1));
|
||||
|
||||
Patient p2 = new Patient();
|
||||
p2.setId("p2");
|
||||
p2.addIdentifier().setLabel("p2");
|
||||
p2.addUndeclaredExtension(false, "http://foo", new ResourceReferenceDt(o1));
|
||||
p2.addIdentifier().setValue("p2");
|
||||
p2.addUndeclaredExtension(false, "http://foo", new Reference(o1));
|
||||
|
||||
return Arrays.asList(p1, p2);
|
||||
}
|
||||
|
@ -447,7 +425,7 @@ public class IncludeTest {
|
|||
|
||||
if (theIncludes != null) {
|
||||
for (Include next : theIncludes) {
|
||||
p.addName().addFamily().setValue(next.getValue());
|
||||
p.addName().setFamily().setValue(next.getValue());
|
||||
}
|
||||
}
|
||||
retVal.add(p);
|
||||
|
@ -463,17 +441,17 @@ public class IncludeTest {
|
|||
@Search(queryName = "normalInclude")
|
||||
public List<Patient> normalInclude() {
|
||||
Organization o1 = new Organization();
|
||||
o1.getName().setValue("o1");
|
||||
o1.getNameElement().setValue("o1");
|
||||
o1.setId("o1");
|
||||
|
||||
Patient p1 = new Patient();
|
||||
p1.setId("p1");
|
||||
p1.addIdentifier().setLabel("p1");
|
||||
p1.addIdentifier().setValue("p1");
|
||||
p1.getManagingOrganization().setResource(o1);
|
||||
|
||||
Patient p2 = new Patient();
|
||||
p2.setId("p2");
|
||||
p2.addIdentifier().setLabel("p2");
|
||||
p2.addIdentifier().setValue("p2");
|
||||
p2.getManagingOrganization().setResource(o1);
|
||||
|
||||
return Arrays.asList(p1, p2);
|
||||
|
@ -484,13 +462,15 @@ 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 ResourceReferenceDt mySecondOrg;
|
||||
private Reference mySecondOrg;
|
||||
|
||||
public ResourceReferenceDt getSecondOrg() {
|
||||
public Reference getSecondOrg() {
|
||||
if (mySecondOrg == null) {
|
||||
mySecondOrg = new ResourceReferenceDt();
|
||||
mySecondOrg = new Reference();
|
||||
}
|
||||
return mySecondOrg;
|
||||
}
|
||||
|
@ -500,7 +480,7 @@ public class IncludeTest {
|
|||
return super.isEmpty() && ElementUtil.isEmpty(mySecondOrg);
|
||||
}
|
||||
|
||||
public void setSecondOrg(ResourceReferenceDt theSecondOrg) {
|
||||
public void setSecondOrg(Reference theSecondOrg) {
|
||||
mySecondOrg = theSecondOrg;
|
||||
}
|
||||
|
Loading…
Reference in New Issue