Merge branch 'master' of github.com:jamesagnew/hapi-fhir into hl7org_structs

This commit is contained in:
James Agnew 2015-05-08 18:59:00 -04:00
commit 2ce921f39b
7 changed files with 820 additions and 14 deletions

View File

@ -98,7 +98,9 @@ class TransactionParamBinder implements IParameter {
@Override @Override
public Object translateQueryParametersIntoServerArgument(Request theRequest, Object theRequestContents) throws InternalErrorException, InvalidRequestException { public Object translateQueryParametersIntoServerArgument(Request theRequest, Object theRequestContents) throws InternalErrorException, InvalidRequestException {
EncodingEnum encoding = RestfulServerUtils.determineResponseEncodingWithDefault(theRequest.getServer(), theRequest.getServletRequest()); // TODO: don't use a default encoding, just fail!
EncodingEnum encoding = RestfulServerUtils.determineRequestEncoding(theRequest);
IParser parser = encoding.newParser(myContext); IParser parser = encoding.newParser(myContext);
BufferedReader reader; BufferedReader reader;

View File

@ -3,11 +3,17 @@ package ca.uhn.fhir.jpa.provider;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -280,26 +286,32 @@ public class ResourceProviderDstu2Test {
* but we want to make sure that works too.. * but we want to make sure that works too..
*/ */
Socket sock = new Socket(); Socket sock = new Socket();
sock.setSoTimeout(3000);
try { try {
sock.connect(new InetSocketAddress("localhost", ourPort)); sock.connect(new InetSocketAddress("localhost", ourPort));
sock.getOutputStream().write(("DELETE " + "/fhir/context/Patient?identifier=" + ("http://ghh.org/patient|" + methodName)).getBytes("UTF-8")); sock.getOutputStream().write(("DELETE /fhir/context/Patient?identifier=http://ghh.org/patient|" + methodName + " HTTP/1.1\n").getBytes("UTF-8"));
sock.getOutputStream().write("\n\n".getBytes("UTF-8")); sock.getOutputStream().write("Host: localhost\n".getBytes("UTF-8"));
sock.getOutputStream().flush(); sock.getOutputStream().write("\n".getBytes("UTF-8"));
InputStream inputStream = sock.getInputStream(); BufferedReader socketInput = new BufferedReader(new InputStreamReader(sock.getInputStream()));
byte[] buf = new byte[10000]; //String response = "";
int count; StringBuilder b = new StringBuilder();
StringBuilder b = new StringBuilder(); char[] buf = new char[1000];
while ((count = inputStream.read(buf)) != -1) { while(socketInput.read(buf) != -1){
b.append(new String(buf, 0, count, Charset.forName("UTF-8"))); b.append(buf);
} }
String resp = b.toString(); String resp = b.toString();
ourLog.info("Resp: {}", resp); ourLog.info("Resp: {}", resp);
} catch (SocketTimeoutException e) {
e.printStackTrace();
} finally { } finally {
sock.close(); sock.close();
} }
Thread.sleep(1000);
HttpGet read = new HttpGet(ourServerBase + "/Patient/" + id.getIdPart()); HttpGet read = new HttpGet(ourServerBase + "/Patient/" + id.getIdPart());
response = ourHttpClient.execute(read); response = ourHttpClient.execute(read);
try { try {

View File

@ -46,6 +46,16 @@ public class SystemProviderTest {
ourLog.info(response); ourLog.info(response);
} }
// TODO: enable!
// @Test
public void testTransactionFromBundle3() throws Exception {
InputStream bundleRes = SystemProviderTest.class.getResourceAsStream("/grahame-transaction.xml");
String bundle = IOUtils.toString(bundleRes);
String response = ourClient.transaction().withBundle(bundle).prettyPrint().execute();
ourLog.info(response);
}
@Test @Test
public void testTransactionFromBundle2() throws Exception { public void testTransactionFromBundle2() throws Exception {

View File

@ -0,0 +1,446 @@
<!-- transaction test case
This is intended to be aplied to a database that just contains a set of resources from the spec
In this transaction
- 1 create a resource (provenance, with both version and version independent references)
- 2 create a resource if nothing already exists (where nothing does)
- 3 create a resource if nothing already exists (where something does)
- 4 update an exising resource
- 4a delete a resource that doesn't exist
- 5 update an existing resource version dependently
- 6 update an existing resource conditionally (where nothing does)
- 7 update an existing resource conditionally (where something does)
- 8 delete an existing resource
- 9 delete an existing resource version dependently
- 10 delete an existing resource conditionally (where nothing does)
- 11 delete an existing resource conditionally (where something does)
- 12 read a resource
- 13 read a resource for something in the transaction
- 14 vread a resource
- 15 do a search
error conditions (comment out for success):
- 16 create a resource with multiple matches
- 17 update an existing resource that doesn't exist
- 18 update a duplicate resource
- 19 update a resource specifying a wrong version
- 20 update a resource conditionally with multiple matches
- 22 delete a duplicate resource
- 23 delete a duplicate with update
- 24 delete a resource specifying a wrong version
- 25 delete a resource conditionally with multiple matches
- 26 conditionally delete a resource created in the transaction
- 27 conditionally update a resource created in the transaction
-->
<Bundle xmlns="http://hl7.org/fhir" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://hl7.org/fhir file:///C:/work/org.hl7.fhir/build/schema/bundle.xsd">
<id value="e4f1c1b8-c7db-49c7-a891-f8a014e75911"/>
<type value="transaction"/>
<base value="http://hl7.org/fhir"/>
<!-- this is in the spec space -->
<!-- - 1 create a resource (provenance, with both version and version independent references) -->
<entry>
<resource>
<Provenance xmlns="http://hl7.org/fhir">
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Make sure links are updated: <a href="Patient/xdfsdsg">Patient</a>
</div>
</text>
<target>
<reference value="Patient/xdfsdsg/_history/1"/>
</target>
<target>
<reference value="Patient/patx1"/>
</target>
<recorded value="2015-04-30T12:00:00+05:00"/>
</Provenance>
</resource>
<transaction>
<method value="POST"/>
<url value="Provenance"/>
</transaction>
</entry>
<!-- - 2 create a resource if nothing already exists (where nothing does) -->
<entry>
<resource>
<Patient xmlns="http://hl7.org/fhir">
<id value="xdfsdsg"/>
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Snipped for brevity</div>
</text>
<identifier>
<system value="urn:oid:1.2.36.146.595.217.0.1"/>
<value value="xdfsdsg"/>
</identifier>
<!-- Peter James Chalmers, but called &quot;Jim&quot; -->
<name>
<family value="Chalmers"/>
<given value="Peter"/>
</name>
</Patient>
</resource>
<transaction>
<method value="POST"/>
<url value="Patient"/>
<ifNoneExist value="Patient?identifier=xdfsdsg"/>
</transaction>
</entry>
<!-- - 3 create a resource if nothing already exists (where something does) -->
<entry>
<resource>
<Patient xmlns="http://hl7.org/fhir">
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Snipped for brevity</div>
</text>
<identifier>
<system value="urn:oid:1.2.36.146.595.217.0.1"/>
<value value="12345"/>
</identifier>
<!-- Peter James Chalmers, but called &quot;Jim&quot; -->
<name>
<family value="Chalmers"/>
<given value="Peter"/>
</name>
</Patient>
</resource>
<transaction>
<method value="POST"/>
<url value="Patient"/>
<ifNoneExist value="Patient?identifier=urn:oid:1.2.36.146.595.217.0.1|12345"/>
</transaction>
</entry>
<!-- - 4 update an exising resource -->
<entry>
<resource>
<Patient>
<id value="xcda"/>
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Snipped</div>
</text>
<name>
<family value="Levin"/>
<given value="Henry"/>
</name>
</Patient>
</resource>
<transaction>
<method value="PUT"/>
<url value="Patient/xcda"/>
</transaction>
</entry>
<!-- - 4a update an existing resource that doesn't exist -->
<entry>
<resource>
<Patient>
<id value="xcda1"/>
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Snipped</div>
</text>
<name>
<family value="Levin"/>
<given value="Henry"/>
</name>
</Patient>
</resource>
<transaction>
<method value="PUT"/>
<url value="Patient/xcda"/>
</transaction>
</entry>
<!-- - 5 update an existing resource version dependently -->
<entry>
<resource>
<Patient xmlns="http://hl7.org/fhir">
<id value="xds"/>
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Snipped</div>
</text>
<name>
<family value="Doe"/>
<given value="John"/>
</name>
</Patient>
</resource>
<transaction>
<method value="PUT"/>
<url value="Patient/xds"/>
<ifMatch value="W/1"/>
</transaction>
</entry>
<!-- - 6 update an existing resource conditionally (where nothing does) -->
<entry>
<resource>
<Patient xmlns="http://hl7.org/fhir">
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Snipped</div>
</text>
<identifier>
<system value="urn:oid:0.1.2.3.4.5.6.7"/>
<value value="123456xx"/>
</identifier>
<name>
<family value="Donald"/>
<given value="Duck"/>
<given value="D"/>
</name>
</Patient>
</resource>
<transaction>
<method value="PUT"/>
<url value="Patient?identifier=urn:oid:0.1.2.3.4.5.6.7|123456xx"/>
</transaction>
</entry>
<!-- - 7 update an existing resource conditionally (where something does) -->
<entry>
<resource>
<Patient xmlns="http://hl7.org/fhir">
<id value="patx1"/>
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Snipped</div>
</text>
<identifier>
<system value="urn:oid:0.1.2.3.4.5.6.7"/>
<value value="654321"/>
</identifier>
<name>
<family value="Donald"/>
<given value="Duck"/>
</name>
</Patient>
</resource>
<transaction>
<method value="PUT"/>
<url value="Patient?identifier=urn:oid:0.1.2.3.4.5.6.7|654321"/>
</transaction>
</entry>
<!-- - 8 delete an existing resource -->
<entry>
<transaction>
<method value="DELETE"/>
<url value="Patient/glossy"/>
</transaction>
</entry>
<!-- - 9 delete an existing resource version dependently -->
<entry>
<transaction>
<method value="DELETE"/>
<url value="Patient/us01"/>
<ifMatch value="W/1"/>
</transaction>
</entry>
<!-- - 10 delete an existing resource conditionally (where nothing does) -->
<entry>
<transaction>
<method value="DELETE"/>
<url value="Patient?identifier=http://www.maroondah.vic.gov.au/AnimalRegFees.aspx|1234123x"/>
</transaction>
</entry>
<!-- - 11 delete an existing resource conditionally (where something does) -->
<entry>
<transaction>
<method value="DELETE"/>
<url value="Patient?identifier=http://www.maroondah.vic.gov.au/AnimalRegFees.aspx|1234123"/>
</transaction>
</entry>
<!-- - 12 read a resource -->
<entry>
<transaction>
<method value="GET"/>
<url value="Patient/dicom"/>
</transaction>
</entry>
<!-- - 13 read a resource for something in the transaction -->
<entry>
<transaction>
<method value="GET"/>
<url value="patient/xcda"/>
</transaction>
</entry>
<!-- - 14 vread a resource -->
<entry>
<transaction>
<method value="GET"/>
<url value="Patient/xcda/_history/1"/>
</transaction>
</entry>
<!-- - 15 do a search -->
<entry>
<transaction>
<method value="GET"/>
<url value="Patient?name=peter"/>
</transaction>
</entry>
<!-- error conditionas -->
<!-- - 16 create a resource with multiple matches -->
<entry>
<resource>
<Patient xmlns="http://hl7.org/fhir">
<id value="xdfsdsg"/>
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Snipped for brevity</div>
</text>
<identifier>
<system value="urn:oid:1.2.36.146.595.217.0.1"/>
<value value="xdfsdsg"/>
</identifier>
<!-- Peter James Chalmers, but called &quot;Jim&quot; -->
<name>
<family value="Chalmers"/>
<given value="Peter"/>
</name>
</Patient>
</resource>
<transaction>
<method value="POST"/>
<url value="Patient"/>
<ifNoneExist value="Patient?name=peter"/>
</transaction>
</entry>
<!-- - 18 update a duplicate resource -->
<entry>
<resource>
<Patient>
<id value="xcda"/>
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Snipped</div>
</text>
<name>
<family value="Levin1"/>
<given value="Henry"/>
</name>
</Patient>
</resource>
<transaction>
<method value="PUT"/>
<url value="Patient/xcda"/>
</transaction>
</entry>
<!-- - 19 update a resource specifying a wrong version -->
<entry>
<resource>
<Patient xmlns="http://hl7.org/fhir">
<id value="ihe-pcd"/>
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Snipped</div>
</text>
<name>
<family value="Doe"/>
<given value="John"/>
</name>
</Patient>
</resource>
<transaction>
<method value="PUT"/>
<url value="Patient/xds"/>
<ifMatch value="W/2"/>
</transaction>
</entry>
<!-- - 20 update a resource conditionally with multiple matches -->
<entry>
<resource>
<Patient xmlns="http://hl7.org/fhir">
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Snipped</div>
</text>
<identifier>
<system value="urn:oid:0.1.2.3.4.5.6.7"/>
<value value="123456xx"/>
</identifier>
<name>
<family value="Donald"/>
<given value="Duck"/>
<given value="D"/>
</name>
</Patient>
</resource>
<transaction>
<method value="PUT"/>
<url value="Patient?name=peter"/>
</transaction>
</entry>
<!-- - 21 delete a resource that doesn't exist -->
<entry>
<transaction>
<method value="DELETE"/>
<url value="Patient/xxxxxxxxxxxxxxxxxxxxxx"/>
</transaction>
</entry>
<!-- - 22 delete a duplicate resource -->
<entry>
<transaction>
<method value="DELETE"/>
<url value="Patient/us01"/>
</transaction>
</entry>
<!-- - 23 delete a duplicate with update -->
<entry>
<transaction>
<method value="DELETE"/>
<url value="Patient/xcda"/>
</transaction>
</entry>
<!-- - 24 delete a resource specifying a wrong version -->
<entry>
<transaction>
<method value="DELETE"/>
<url value="Patient/proband"/>
<ifMatch value="W/2"/>
</transaction>
</entry>
<!-- - 25 delete a resource conditionally with multiple matches -->
<entry>
<transaction>
<method value="DELETE"/>
<url value="Patient?name=peter"/>
</transaction>
</entry>
<!-- - 26 conditionally delete a resource created in the transaction -->
<entry>
<transaction>
<method value="DELETE"/>
<url value="Patient?identifier=urn:oid:1.2.36.146.595.217.0.1|xdfsdsg"/>
</transaction>
</entry>
<!-- - 27 conditionally update a resource created in the transaction -->
<entry>
<resource>
<Patient xmlns="http://hl7.org/fhir">
<id value="patx1"/>
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Snipped</div>
</text>
<identifier>
<system value="urn:oid:0.1.2.3.4.5.6.7"/>
<value value="654321"/>
</identifier>
<name>
<family value="Donald1"/>
<given value="Duck"/>
</name>
</Patient>
</resource>
<transaction>
<method value="PUT"/>
<url value="Patient?identifier=urn:oid:0.1.2.3.4.5.6.7|xdfsdsg"/>
</transaction>
</entry>
</Bundle>

View File

@ -0,0 +1,285 @@
<!-- transaction test case
This is intended to be aplied to a database that just contains a set of resources from the spec
In this transaction
- 1 create a resource (provenance, with both version and version independent references)
- 2 create a resource if nothing already exists (where nothing does)
- 3 create a resource if nothing already exists (where something does)
- 4 update an exising resource
- 4a delete a resource that doesn't exist
- 5 update an existing resource version dependently
- 6 update an existing resource conditionally (where nothing does)
- 7 update an existing resource conditionally (where something does)
- 8 delete an existing resource
- 9 delete an existing resource version dependently
- 10 delete an existing resource conditionally (where nothing does)
- 11 delete an existing resource conditionally (where something does)
- 12 read a resource
- 13 read a resource for something in the transaction
- 14 vread a resource
- 15 do a search
error conditions (comment out for success):
- 16 create a resource with multiple matches
- 17 update an existing resource that doesn't exist
- 18 update a duplicate resource
- 19 update a resource specifying a wrong version
- 20 update a resource conditionally with multiple matches
- 22 delete a duplicate resource
- 23 delete a duplicate with update
- 24 delete a resource specifying a wrong version
- 25 delete a resource conditionally with multiple matches
- 26 conditionally delete a resource created in the transaction
- 27 conditionally update a resource created in the transaction
-->
<Bundle xmlns="http://hl7.org/fhir" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://hl7.org/fhir file:///C:/work/org.hl7.fhir/build/schema/bundle.xsd">
<id value="e4f1c1b8-c7db-49c7-a891-f8a014e75911"/>
<type value="transaction"/>
<base value="http://hl7.org/fhir"/>
<!-- this is in the spec space -->
<!-- - 1 create a resource (provenance, with both version and version independent references) -->
<entry>
<resource>
<Provenance xmlns="http://hl7.org/fhir">
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Make sure links are updated: <a href="Patient/xdfsdsg">Patient</a>
</div>
</text>
<target>
<reference value="Patient/xdfsdsg/_history/1"/>
</target>
<target>
<reference value="Patient/patx1"/>
</target>
<recorded value="2015-04-30T12:00:00+05:00"/>
</Provenance>
</resource>
<transaction>
<method value="POST"/>
<url value="Provenance"/>
</transaction>
</entry>
<!-- - 2 create a resource if nothing already exists (where nothing does) -->
<entry>
<resource>
<Patient xmlns="http://hl7.org/fhir">
<id value="xdfsdsg"/>
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Snipped for brevity</div>
</text>
<identifier>
<system value="urn:oid:1.2.36.146.595.217.0.1"/>
<value value="xdfsdsg"/>
</identifier>
<!-- Peter James Chalmers, but called &quot;Jim&quot; -->
<name>
<family value="Chalmers"/>
<given value="Peter"/>
</name>
</Patient>
</resource>
<transaction>
<method value="POST"/>
<url value="Patient"/>
<ifNoneExist value="Patient?identifier=xdfsdsg"/>
</transaction>
</entry>
<!-- - 3 create a resource if nothing already exists (where something does) -->
<entry>
<resource>
<Patient xmlns="http://hl7.org/fhir">
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Snipped for brevity</div>
</text>
<identifier>
<system value="urn:oid:1.2.36.146.595.217.0.1"/>
<value value="12345"/>
</identifier>
<!-- Peter James Chalmers, but called &quot;Jim&quot; -->
<name>
<family value="Chalmers"/>
<given value="Peter"/>
</name>
</Patient>
</resource>
<transaction>
<method value="POST"/>
<url value="Patient"/>
<ifNoneExist value="Patient?identifier=urn:oid:1.2.36.146.595.217.0.1|12345"/>
</transaction>
</entry>
<!-- - 4 update an exising resource -->
<entry>
<resource>
<Patient>
<id value="xcda"/>
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Snipped</div>
</text>
<name>
<family value="Levin"/>
<given value="Henry"/>
</name>
</Patient>
</resource>
<transaction>
<method value="PUT"/>
<url value="Patient/xcda"/>
</transaction>
</entry>
<!-- - 4a update an existing resource that doesn't exist -->
<entry>
<resource>
<Patient>
<id value="xcda1"/>
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Snipped</div>
</text>
<name>
<family value="Levin"/>
<given value="Henry"/>
</name>
</Patient>
</resource>
<transaction>
<method value="PUT"/>
<url value="Patient/xcda"/>
</transaction>
</entry>
<!-- - 5 update an existing resource version dependently -->
<entry>
<resource>
<Patient xmlns="http://hl7.org/fhir">
<id value="xds"/>
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Snipped</div>
</text>
<name>
<family value="Doe"/>
<given value="John"/>
</name>
</Patient>
</resource>
<transaction>
<method value="PUT"/>
<url value="Patient/xds"/>
<ifMatch value="W/1"/>
</transaction>
</entry>
<!-- - 6 update an existing resource conditionally (where nothing does) -->
<entry>
<resource>
<Patient xmlns="http://hl7.org/fhir">
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Snipped</div>
</text>
<identifier>
<system value="urn:oid:0.1.2.3.4.5.6.7"/>
<value value="123456xx"/>
</identifier>
<name>
<family value="Donald"/>
<given value="Duck"/>
<given value="D"/>
</name>
</Patient>
</resource>
<transaction>
<method value="PUT"/>
<url value="Patient?identifier=urn:oid:0.1.2.3.4.5.6.7|123456xx"/>
</transaction>
</entry>
<!-- - 7 update an existing resource conditionally (where something does) -->
<entry>
<resource>
<Patient xmlns="http://hl7.org/fhir">
<id value="patx1"/>
<text>
<status value="generated"/>
<div xmlns="http://www.w3.org/1999/xhtml">Snipped</div>
</text>
<identifier>
<system value="urn:oid:0.1.2.3.4.5.6.7"/>
<value value="654321"/>
</identifier>
<name>
<family value="Donald"/>
<given value="Duck"/>
</name>
</Patient>
</resource>
<transaction>
<method value="PUT"/>
<url value="Patient?identifier=urn:oid:0.1.2.3.4.5.6.7|654321"/>
</transaction>
</entry>
<!-- - 8 delete an existing resource -->
<entry>
<transaction>
<method value="DELETE"/>
<url value="Patient/glossy"/>
</transaction>
</entry>
<!-- - 9 delete an existing resource version dependently -->
<entry>
<transaction>
<method value="DELETE"/>
<url value="Patient/us01"/>
<ifMatch value="W/1"/>
</transaction>
</entry>
<!-- - 10 delete an existing resource conditionally (where nothing does) -->
<entry>
<transaction>
<method value="DELETE"/>
<url value="Patient?identifier=http://www.maroondah.vic.gov.au/AnimalRegFees.aspx|1234123x"/>
</transaction>
</entry>
<!-- - 11 delete an existing resource conditionally (where something does) -->
<entry>
<transaction>
<method value="DELETE"/>
<url value="Patient?identifier=http://www.maroondah.vic.gov.au/AnimalRegFees.aspx|1234123"/>
</transaction>
</entry>
<!-- - 12 read a resource -->
<entry>
<transaction>
<method value="GET"/>
<url value="Patient/dicom"/>
</transaction>
</entry>
<!-- - 13 read a resource for something in the transaction -->
<entry>
<transaction>
<method value="GET"/>
<url value="patient/xcda"/>
</transaction>
</entry>
<!-- - 14 vread a resource -->
<entry>
<transaction>
<method value="GET"/>
<url value="Patient/xcda/_history/1"/>
</transaction>
</entry>
<!-- - 15 do a search -->
<entry>
<transaction>
<method value="GET"/>
<url value="Patient?name=peter"/>
</transaction>
</entry>
</Bundle>

View File

@ -55,7 +55,7 @@ public class TransactionWithBundleResourceParamTest {
} }
@Test @Test
public void testTransaction() throws Exception { public void testTransactionWithXmlRequest() throws Exception {
Bundle b = new Bundle(); Bundle b = new Bundle();
InstantDt nowInstant = InstantDt.withCurrentTime(); InstantDt nowInstant = InstantDt.withCurrentTime();
@ -79,8 +79,55 @@ public class TransactionWithBundleResourceParamTest {
ourLog.info(bundleString); ourLog.info(bundleString);
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/");
httpPost.addHeader("Accept", Constants.CT_ATOM_XML + "; pretty=true"); httpPost.setEntity(new StringEntity(bundleString, ContentType.create(Constants.CT_FHIR_XML, "UTF-8")));
httpPost.setEntity(new StringEntity(bundleString, ContentType.create(Constants.CT_ATOM_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost);
String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent());
assertEquals(200, status.getStatusLine().getStatusCode());
ourLog.info(responseContent);
Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent);
assertEquals(3, bundle.getEntry().size());
Entry entry0 = bundle.getEntry().get(0);
assertEquals("Patient/81/_history/91", entry0.getTransactionResponse().getLocation());
Entry entry1 = bundle.getEntry().get(1);
assertEquals( "Patient/82/_history/92", entry1.getTransactionResponse().getLocation());
Entry entry2 = bundle.getEntry().get(2);
assertEquals("Patient/123/_history/93", entry2.getTransactionResponse().getLocation());
}
@Test
public void testTransactionWithJsonRequest() throws Exception {
Bundle b = new Bundle();
InstantDt nowInstant = InstantDt.withCurrentTime();
Patient p1 = new Patient();
p1.addName().addFamily("Family1");
Entry entry = b.addEntry();
p1.getId().setValue("1");
entry.setResource(p1);
Patient p2 = new Patient();
p2.addName().addFamily("Family2");
entry = b.addEntry();
p2.getId().setValue("2");
entry.setResource(p2);
Entry deletedEntry = b.addEntry();
deletedEntry.getTransaction().setMethod(HTTPVerbEnum.DELETE);
deletedEntry.getTransaction().setUrl("http://base.com/Patient/123");
String bundleString = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(b);
ourLog.info(bundleString);
HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/");
// httpPost.addHeader("Accept", Constants.CT_ATOM_XML + "; pretty=true");
httpPost.setEntity(new StringEntity(bundleString, ContentType.create(Constants.CT_FHIR_JSON, "UTF-8")));
HttpResponse status = ourClient.execute(httpPost); HttpResponse status = ourClient.execute(httpPost);
String responseContent = IOUtils.toString(status.getEntity().getContent()); String responseContent = IOUtils.toString(status.getEntity().getContent());
IOUtils.closeQuietly(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent());

View File

@ -217,6 +217,10 @@
HTTP 403 Forbidden status code. Thanks to Joel Costigliola for HTTP 403 Forbidden status code. Thanks to Joel Costigliola for
the patch! the patch!
</action> </action>
<action type="fix">
Transaction server operations incorrectly used the "Accept" header instead of the "Content-Type" header to determine the
POST request encoding. Thanks to Rene Spronk for providing a test case!
</action>
</release> </release>
<release version="0.9" date="2015-Mar-14"> <release version="0.9" date="2015-Mar-14">
<action type="add"> <action type="add">