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

This commit is contained in:
James Agnew 2016-07-13 09:22:19 -04:00
commit 0b69367b11
24 changed files with 760 additions and 665 deletions

View File

@ -26,6 +26,13 @@
<version>1.6.0</version> <version>1.6.0</version>
</dependency> </dependency>
<!-- Use an old version of Gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<!-- <!--
Woodstox note: The hapi-fhir-base-testmindeps-client project includes no Woodstox at all, so that we use the Woodstox note: The hapi-fhir-base-testmindeps-client project includes no Woodstox at all, so that we use the
StAX version that's bundled with the JDK. The hapi-fhir-base-testmindeps-server StAX version that's bundled with the JDK. The hapi-fhir-base-testmindeps-server

View File

@ -38,6 +38,13 @@
<version>3.2</version><!--$NO-MVN-MAN-VER$--> <version>3.2</version><!--$NO-MVN-MAN-VER$-->
</dependency> </dependency>
<!-- Use an old version of Gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<!-- <!--
Woodstox note: The hapi-fhir-base-testmindeps-client project includes no Woodstox at all, so that we use the Woodstox note: The hapi-fhir-base-testmindeps-client project includes no Woodstox at all, so that we use the
StAX version that's bundled with the JDK. The hapi-fhir-base-testmindeps-server StAX version that's bundled with the JDK. The hapi-fhir-base-testmindeps-server

View File

@ -20,12 +20,9 @@
<!-- JSON --> <!-- JSON -->
<dependency> <dependency>
<groupId>javax.json</groupId> <groupId>com.google.code.gson</groupId>
<artifactId>javax.json-api</artifactId> <artifactId>gson</artifactId>
</dependency> <version>2.7</version>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
</dependency> </dependency>
<!-- XML --> <!-- XML -->

View File

@ -1333,7 +1333,7 @@ public class GenericJaxRsClientDstu2Test {
@Test @Test
public void testReadWithElementsParam() throws Exception { public void testReadWithElementsParam() throws Exception {
String msg = "{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}"; String msg = "{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}";
@ -2071,7 +2071,7 @@ public class GenericJaxRsClientDstu2Test {
response = client.validate().resource(ourCtx.newJsonParser().encodeResourceToString(p)).prettyPrint().execute(); response = client.validate().resource(ourCtx.newJsonParser().encodeResourceToString(p)).prettyPrint().execute();
assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$validate?_format=json&_pretty=true", ourRequestUri); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$validate?_format=json&_pretty=true", ourRequestUri);
assertEquals("POST", ourRequestMethod); assertEquals("POST", ourRequestMethod);
assertThat(ourRequestBodyString, containsString("\"resourceType\":\"Parameters\",\n")); assertThat(ourRequestBodyString, containsString("\"resourceType\": \"Parameters\",\n"));
assertNotNull(response.getOperationOutcome()); assertNotNull(response.getOperationOutcome());
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue());

View File

@ -1335,7 +1335,7 @@ public class GenericJaxRsClientDstu3Test {
@Test @Test
public void testReadWithElementsParam() throws Exception { public void testReadWithElementsParam() throws Exception {
String msg = "{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}"; String msg = "{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}";
@ -2081,7 +2081,7 @@ public class GenericJaxRsClientDstu3Test {
response = client.validate().resource(ourCtx.newJsonParser().encodeResourceToString(p)).prettyPrint().execute(); response = client.validate().resource(ourCtx.newJsonParser().encodeResourceToString(p)).prettyPrint().execute();
assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$validate?_format=json&_pretty=true", ourRequestUri); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$validate?_format=json&_pretty=true", ourRequestUri);
assertEquals("POST", ourRequestMethod); assertEquals("POST", ourRequestMethod);
assertThat(ourRequestBodyString, containsString("\"resourceType\":\"Parameters\",\n")); assertThat(ourRequestBodyString, containsString("\"resourceType\": \"Parameters\",\n"));
assertNotNull(response.getOperationOutcome()); assertNotNull(response.getOperationOutcome());
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssue().get(0).getDiagnosticsElement().getValue()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssue().get(0).getDiagnosticsElement().getValue());

View File

@ -69,7 +69,7 @@ public class AbstractJaxRsConformanceProviderDstu3Test {
providers.put(TestJaxRsMockPatientRestProviderDstu3.class, new TestJaxRsMockPatientRestProviderDstu3()); providers.put(TestJaxRsMockPatientRestProviderDstu3.class, new TestJaxRsMockPatientRestProviderDstu3());
Response response = createConformanceProvider(providers).conformance(); Response response = createConformanceProvider(providers).conformance();
assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus()); assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus());
assertTrue(response.getEntity().toString().contains("\"type\":\"Patient\"")); assertTrue(response.getEntity().toString().contains("\"type\": \"Patient\""));
assertTrue(response.getEntity().toString().contains("\"someCustomOperation")); assertTrue(response.getEntity().toString().contains("\"someCustomOperation"));
System.out.println(response); System.out.println(response);
System.out.println(response.getEntity()); System.out.println(response.getEntity());

View File

@ -68,7 +68,7 @@ public class AbstractJaxRsConformanceProviderTest {
providers.put(TestJaxRsMockPatientRestProvider.class, new TestJaxRsMockPatientRestProvider()); providers.put(TestJaxRsMockPatientRestProvider.class, new TestJaxRsMockPatientRestProvider());
Response response = createConformanceProvider(providers).conformance(); Response response = createConformanceProvider(providers).conformance();
assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus()); assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus());
assertTrue(response.getEntity().toString().contains("\"type\":\"Patient\"")); assertTrue(response.getEntity().toString().contains("\"type\": \"Patient\""));
assertTrue(response.getEntity().toString().contains("\"someCustomOperation")); assertTrue(response.getEntity().toString().contains("\"someCustomOperation"));
System.out.println(response); System.out.println(response);
System.out.println(response.getEntity()); System.out.println(response.getEntity());

View File

@ -109,7 +109,7 @@ public class JaxRsResponseDstu3Test {
Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), createPatient(), theSummaryMode, 200, addContentLocationHeader, respondGzip, this.request); Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), createPatient(), theSummaryMode, 200, addContentLocationHeader, respondGzip, this.request);
assertEquals(200, result.getStatus()); assertEquals(200, result.getStatus());
assertEquals("application/json+fhir; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE)); assertEquals("application/json+fhir; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
assertTrue(result.getEntity().toString().contains("resourceType\":\"Patient")); assertTrue(result.getEntity().toString().contains("resourceType\": \"Patient"));
assertTrue(result.getEntity().toString().contains("15")); assertTrue(result.getEntity().toString().contains("15"));
} }

View File

@ -96,7 +96,7 @@ public class JaxRsResponseTest {
assertEquals(200, result.getStatus()); assertEquals(200, result.getStatus());
assertEquals("application/json+fhir; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE)); assertEquals("application/json+fhir; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
System.out.println(result.getEntity().toString()); System.out.println(result.getEntity().toString());
assertTrue(result.getEntity().toString().contains("resourceType\":\"Patient")); assertTrue(result.getEntity().toString().contains("resourceType\": \"Patient"));
assertTrue(result.getEntity().toString().contains("15")); assertTrue(result.getEntity().toString().contains("15"));
} }

View File

@ -1635,7 +1635,9 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test {
public void testOrganizationName() { public void testOrganizationName() {
//@formatter:off //@formatter:off
String inputStr = "{\"resourceType\":\"Organization\",\n" + String inputStr =
"{" +
" \"resourceType\":\"Organization\",\n" +
" \"extension\":[\n" + " \"extension\":[\n" +
" {\n" + " {\n" +
" \"url\":\"http://fhir.connectinggta.ca/Profile/organization#providerIdPool\",\n" + " \"url\":\"http://fhir.connectinggta.ca/Profile/organization#providerIdPool\",\n" +
@ -1655,8 +1657,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test {
" }\n" + " }\n" +
" ],\n" + " ],\n" +
" \"name\":\"Peterborough Regional Health Centre\"\n" + " \"name\":\"Peterborough Regional Health Centre\"\n" +
" }\n" + "}\n";
" }";
//@formatter:on //@formatter:on
Set<Long> val = myOrganizationDao.searchForIds("name", new StringParam("P")); Set<Long> val = myOrganizationDao.searchForIds("name", new StringParam("P"));

View File

@ -2044,7 +2044,9 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
public void testOrganizationName() { public void testOrganizationName() {
//@formatter:off //@formatter:off
String inputStr = "{\"resourceType\":\"Organization\",\n" + String inputStr =
"{" +
" \"resourceType\":\"Organization\",\n" +
" \"extension\":[\n" + " \"extension\":[\n" +
" {\n" + " {\n" +
" \"url\":\"http://fhir.connectinggta.ca/Profile/organization#providerIdPool\",\n" + " \"url\":\"http://fhir.connectinggta.ca/Profile/organization#providerIdPool\",\n" +
@ -2064,8 +2066,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
" }\n" + " }\n" +
" ],\n" + " ],\n" +
" \"name\":\"Peterborough Regional Health Centre\"\n" + " \"name\":\"Peterborough Regional Health Centre\"\n" +
" }\n" + "}\n";
" }";
//@formatter:on //@formatter:on
Set<Long> val = myOrganizationDao.searchForIds("name", new StringParam("P")); Set<Long> val = myOrganizationDao.searchForIds("name", new StringParam("P"));

View File

@ -294,10 +294,10 @@ public class JsonParserTest {
ourLog.info(bundleString); ourLog.info(bundleString);
List<String> strings = new ArrayList<String>(); List<String> strings = new ArrayList<String>();
strings.addAll(Arrays.asList("\"id\":\"1\"")); strings.addAll(Arrays.asList("\"id\": \"1\""));
strings.addAll(Arrays.asList("this is the summary")); strings.addAll(Arrays.asList("this is the summary"));
strings.addAll(Arrays.asList("\"id\":\"2\"", "\"rel\":\"alternate\"", "\"href\":\"http://foo/bar\"")); strings.addAll(Arrays.asList("\"id\": \"2\"", "\"rel\": \"alternate\"", "\"href\": \"http://foo/bar\""));
strings.addAll(Arrays.asList("\"deleted\":\"" + nowDt.getValueAsString() + "\"", "\"id\":\"Patient/3\"")); strings.addAll(Arrays.asList("\"deleted\": \"" + nowDt.getValueAsString() + "\"", "\"id\": \"Patient/3\""));
assertThat(bundleString, StringContainsInOrder.stringContainsInOrder(strings)); assertThat(bundleString, StringContainsInOrder.stringContainsInOrder(strings));
b.getEntries().remove(2); b.getEntries().remove(2);
@ -372,7 +372,7 @@ public class JsonParserTest {
String encoded = xmlParser.encodeResourceToString(patient); String encoded = xmlParser.encodeResourceToString(patient);
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\":[", "\"id\":\"1\"", "\"identifier\"", "\"reference\":\"#1\""))); assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\": [", "\"id\": \"1\"", "\"identifier\"", "\"reference\": \"#1\"")));
// Create a bundle with just the patient resource // Create a bundle with just the patient resource
List<IResource> resources = new ArrayList<IResource>(); List<IResource> resources = new ArrayList<IResource>();
@ -382,7 +382,7 @@ public class JsonParserTest {
// Encode the bundle // Encode the bundle
encoded = xmlParser.encodeBundleToString(b); encoded = xmlParser.encodeBundleToString(b);
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\":[", "\"id\":\"1\"", "\"identifier\"", "\"reference\":\"#1\""))); assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\": [", "\"id\": \"1\"", "\"identifier\"", "\"reference\": \"#1\"")));
// Re-parse the bundle // Re-parse the bundle
patient = (Patient) xmlParser.parseResource(xmlParser.encodeResourceToString(patient)); patient = (Patient) xmlParser.parseResource(xmlParser.encodeResourceToString(patient));
@ -396,7 +396,7 @@ public class JsonParserTest {
// And re-encode a second time // And re-encode a second time
encoded = xmlParser.encodeResourceToString(patient); encoded = xmlParser.encodeResourceToString(patient);
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\":[", "\"id\":\"1\"", "\"identifier\"", "\"reference\":\"#1\""))); assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\": [", "\"id\": \"1\"", "\"identifier\"", "\"reference\": \"#1\"")));
assertThat(encoded, not(stringContainsInOrder(Arrays.asList("\"contained\":", "[", "\"contained\":")))); assertThat(encoded, not(stringContainsInOrder(Arrays.asList("\"contained\":", "[", "\"contained\":"))));
// And re-encode once more, with the references cleared // And re-encode once more, with the references cleared
@ -404,7 +404,7 @@ public class JsonParserTest {
patient.getManagingOrganization().setReference((IdDt) null); patient.getManagingOrganization().setReference((IdDt) null);
encoded = xmlParser.encodeResourceToString(patient); encoded = xmlParser.encodeResourceToString(patient);
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\":[", "\"id\":\"1\"", "\"identifier\"", "\"reference\":\"#1\""))); assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\": [", "\"id\": \"1\"", "\"identifier\"", "\"reference\": \"#1\"")));
assertThat(encoded, not(stringContainsInOrder(Arrays.asList("\"contained\":", "[", "\"contained\":")))); assertThat(encoded, not(stringContainsInOrder(Arrays.asList("\"contained\":", "[", "\"contained\":"))));
// And re-encode once more, with the references cleared and a manually set local ID // And re-encode once more, with the references cleared and a manually set local ID
@ -413,7 +413,7 @@ public class JsonParserTest {
patient.getManagingOrganization().getResource().setId(new IdDt("#333")); patient.getManagingOrganization().getResource().setId(new IdDt("#333"));
encoded = xmlParser.encodeResourceToString(patient); encoded = xmlParser.encodeResourceToString(patient);
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\":[", "\"id\":\"333\"", "\"identifier\"", "\"reference\":\"#333\""))); assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\": [", "\"id\": \"333\"", "\"identifier\"", "\"reference\": \"#333\"")));
assertThat(encoded, not(stringContainsInOrder(Arrays.asList("\"contained\":", "[", "\"contained\":")))); assertThat(encoded, not(stringContainsInOrder(Arrays.asList("\"contained\":", "[", "\"contained\":"))));
} }
@ -438,13 +438,13 @@ public class JsonParserTest {
// Encode the buntdle // Encode the buntdle
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(b); String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(b);
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\"", "resourceType\":\"Organization", "id\":\"1\""))); assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\"", "resourceType\": \"Organization", "id\": \"1\"")));
assertThat(encoded, containsString("reference\":\"#1\"")); assertThat(encoded, containsString("reference\": \"#1\""));
encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient); encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient);
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\"", "resourceType\":\"Organization", "id\":\"1\""))); assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\"", "resourceType\": \"Organization", "id\": \"1\"")));
assertThat(encoded, containsString("reference\":\"#1\"")); assertThat(encoded, containsString("reference\": \"#1\""));
} }
@Test @Test
@ -472,13 +472,13 @@ public class JsonParserTest {
ourLog.info(str); ourLog.info(str);
assertThat(str, StringContains.containsString("<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">AAA</div>")); assertThat(str, StringContains.containsString("<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">AAA</div>"));
String substring = "\"reference\":\"#"; String substring = "\"reference\": \"#";
assertThat(str, StringContains.containsString(substring)); assertThat(str, StringContains.containsString(substring));
int idx = str.indexOf(substring) + substring.length(); int idx = str.indexOf(substring) + substring.length();
int idx2 = str.indexOf('"', idx + 1); int idx2 = str.indexOf('"', idx + 1);
String id = str.substring(idx, idx2); String id = str.substring(idx, idx2);
assertThat(str, StringContains.containsString("\"id\":\"" + id + "\"")); assertThat(str, StringContains.containsString("\"id\": \"" + id + "\""));
assertThat(str, IsNot.not(StringContains.containsString("<?xml version='1.0'?>"))); assertThat(str, IsNot.not(StringContains.containsString("<?xml version='1.0'?>")));
} }
@ -737,12 +737,12 @@ public class JsonParserTest {
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(b); String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(b);
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, not(containsString("contained"))); assertThat(encoded, not(containsString("contained")));
assertThat(encoded, containsString("\"reference\":\"Organization/65546\"")); assertThat(encoded, containsString("\"reference\": \"Organization/65546\""));
encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient); encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient);
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, not(containsString("contained"))); assertThat(encoded, not(containsString("contained")));
assertThat(encoded, containsString("\"reference\":\"Organization/65546\"")); assertThat(encoded, containsString("\"reference\": \"Organization/65546\""));
} }
@Test @Test
@ -936,7 +936,7 @@ public class JsonParserTest {
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(parsed); String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(parsed);
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, containsString("\"_header\":{")); assertThat(encoded, containsString("\"_header\": {"));
} }
@ -995,7 +995,7 @@ public class JsonParserTest {
String str = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(A); String str = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(A);
ourLog.info(str); ourLog.info(str);
assertThat(str, stringContainsInOrder(Arrays.asList("\"text\":\"B\"", "\"text\":\"C\"", "\"text\":\"A\""))); assertThat(str, stringContainsInOrder(Arrays.asList("\"text\": \"B\"", "\"text\": \"C\"", "\"text\": \"A\"")));
// Only one (outer) contained block // Only one (outer) contained block
int idx0 = str.indexOf("\"contained\""); int idx0 = str.indexOf("\"contained\"");
@ -1232,13 +1232,7 @@ public class JsonParserTest {
@Test @Test
public void testParseSingleQuotes() { public void testParseSingleQuotes() {
try { assertEquals("1", ourCtx.newJsonParser().parseBundle("{ 'resourceType': 'Bundle', 'id':'1' }").getBundleId().getValue());
ourCtx.newJsonParser().parseBundle("{ 'resourceType': 'Bundle' }");
fail();
} catch (DataFormatException e) {
// Should be an error message about how single quotes aren't valid JSON
assertThat(e.getMessage(), containsString("double quote"));
}
} }
@Test @Test

View File

@ -222,7 +222,7 @@ public class CreateTest {
ourLog.info("Response was:\n{}", responseContent); ourLog.info("Response was:\n{}", responseContent);
assertEquals(400, status.getStatusLine().getStatusCode()); assertEquals(400, status.getStatusLine().getStatusCode());
assertThat(responseContent, containsString("Unexpected char")); assertThat(responseContent, containsString("Content does not appear to be FHIR JSON, first non-whitespace character was: '&lt;' (must be '{')"));
} }
@Test @Test

View File

@ -775,7 +775,4 @@
"title" : "HTML Report" "title" : "HTML Report"
} }
] ]
},
"summary" : "\r\n<div xmlns=\"http://www.w3.org/1999/xhtml\"> &#x0A; &#x0A; \r\n <h3>CBC Report for Wile. E. COYOTE (MRN: 23453) issued 3-Mar 2011 11:45</h3> &#x0A;&#x0A; \r\n <!-- you could use ab html table here, but laboratories are still \n using fixed text tables, and this will take decades to change... -->&#x0A; &#x0A; \r\n <pre>&#x0A;Test Units Value Reference Range&#x0A;Haemoglobin g/L 176 135 - 180&#x0A;Red Cell Count x10*12/L 5.9 4.2 - 6.0&#x0A;Haematocrit 0.55+ 0.38 - 0.52&#x0A;Mean Cell Volume fL 99+ 80 - 98&#x0A;Mean Cell Haemoglobin pg 36+ 27 - 35&#x0A;Platelet Count x10*9/L 444 150 - 450&#x0A;White Cell Count x10*9/L 4.6 4.0 - 11.0&#x0A;Neutrophils % 20 &#x0A;Neutrophils x10*9/L 0.9--- 2.0 - 7.5&#x0A;Lymphocytes % 20 &#x0A;Lymphocytes x10*9/L 0.9- 1.1 - 4.0&#x0A;Monocytes % 20 &#x0A;Monocytes x10*9/L 0.9 0.2 - 1.0&#x0A;Eosinophils % 20 &#x0A;Eosinophils x10*9/L 0.92++ 0.04 - 0.40&#x0A;Basophils % 20 &#x0A;Basophils x10*9/L 0.92+++ &lt;0.21&#x0A; </pre>&#x0A; &#x0A; \r\n <p>Acme Laboratory, Inc signed: Dr Pete Pathologist</p>&#x0A; </div>"
} }

View File

@ -89,7 +89,7 @@ public class JsonParserDstu2Test {
String output = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p); String output = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p);
ourLog.info(output); ourLog.info(output);
assertThat(output, containsString("\"div\":\"<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">VALUE</div>\"")); assertThat(output, containsString("\"div\": \"<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">VALUE</div>\""));
} }
/** /**
@ -118,7 +118,7 @@ public class JsonParserDstu2Test {
String output = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p); String output = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p);
ourLog.info(output); ourLog.info(output);
assertThat(output, containsString("\"div\":\"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">VALUE</div>\"")); assertThat(output, containsString("\"div\": \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">VALUE</div>\""));
} }
@Test @Test
@ -267,21 +267,21 @@ public class JsonParserDstu2Test {
ourLog.info(enc); ourLog.info(enc);
//@formatter:off //@formatter:off
assertThat(enc, stringContainsInOrder("\"meta\":{", assertThat(enc, stringContainsInOrder("\"meta\": {",
"\"profile\":[", "\"profile\": [",
"\"http://foo/Profile1\",", "\"http://foo/Profile1\",",
"\"http://foo/Profile2\"", "\"http://foo/Profile2\"",
"],", "],",
"\"tag\":[", "\"tag\": [",
"{", "{",
"\"system\":\"scheme1\",", "\"system\": \"scheme1\",",
"\"code\":\"term1\",", "\"code\": \"term1\",",
"\"display\":\"label1\"", "\"display\": \"label1\"",
"},", "},",
"{", "{",
"\"system\":\"scheme2\",", "\"system\": \"scheme2\",",
"\"code\":\"term2\",", "\"code\": \"term2\",",
"\"display\":\"label2\"", "\"display\": \"label2\"",
"}", "}",
"]", "]",
"},")); "},"));
@ -377,32 +377,35 @@ public class JsonParserDstu2Test {
ourLog.info(enc); ourLog.info(enc);
//@formatter:off //@formatter:off
String actual = enc.trim();
ourLog.info("Actual:\n{}", actual);
assertEquals("{\n" + assertEquals("{\n" +
" \"resourceType\":\"Patient\",\n" + " \"resourceType\": \"Patient\",\n" +
" \"meta\":{\n" + " \"meta\": {\n" +
" \"security\":[\n" + " \"security\": [\n" +
" {\n" + " {\n" +
" \"system\":\"SYSTEM1\",\n" + " \"system\": \"SYSTEM1\",\n" +
" \"version\":\"VERSION1\",\n" + " \"version\": \"VERSION1\",\n" +
" \"code\":\"CODE1\",\n" + " \"code\": \"CODE1\",\n" +
" \"display\":\"DISPLAY1\"\n" + " \"display\": \"DISPLAY1\"\n" +
" },\n" + " },\n" +
" {\n" + " {\n" +
" \"system\":\"SYSTEM2\",\n" + " \"system\": \"SYSTEM2\",\n" +
" \"version\":\"VERSION2\",\n" + " \"version\": \"VERSION2\",\n" +
" \"code\":\"CODE2\",\n" + " \"code\": \"CODE2\",\n" +
" \"display\":\"DISPLAY2\"\n" + " \"display\": \"DISPLAY2\"\n" +
" }\n" + " }\n" +
" ]\n" + " ]\n" +
" },\n" + " },\n" +
" \"name\":[\n" + " \"name\": [\n" +
" {\n" + " {\n" +
" \"family\":[\n" + " \"family\": [\n" +
" \"FAMILY\"\n" + " \"FAMILY\"\n" +
" ]\n" + " ]\n" +
" }\n" + " }\n" +
" ]\n" + " ]\n" +
"}", enc.trim()); "}", actual);
//@formatter:on //@formatter:on
Patient parsed = ourCtx.newJsonParser().parseResource(Patient.class, enc); Patient parsed = ourCtx.newJsonParser().parseResource(Patient.class, enc);
@ -597,17 +600,17 @@ public class JsonParserDstu2Test {
//@formatter:off //@formatter:off
assertThat(output, stringContainsInOrder( assertThat(output, stringContainsInOrder(
"\"id\":\"1\"", "\"id\": \"1\"",
"\"meta\"", "\"meta\"",
"\"extension\"", "\"extension\"",
"\"url\":\"http://exturl\"", "\"url\": \"http://exturl\"",
"\"valueString\":\"ext_url_value\"", "\"valueString\": \"ext_url_value\"",
"\"code\":" "\"code\":"
)); ));
assertThat(output, not(stringContainsInOrder( assertThat(output, not(stringContainsInOrder(
"\"url\":\"http://exturl\"", "\"url\": \"http://exturl\"",
",", ",",
"\"url\":\"http://exturl\"" "\"url\": \"http://exturl\""
))); )));
//@formatter:on //@formatter:on
@ -637,19 +640,19 @@ public class JsonParserDstu2Test {
//@formatter:off //@formatter:off
assertThat(output, stringContainsInOrder( assertThat(output, stringContainsInOrder(
"\"id\":\"1\"", "\"id\": \"1\"",
"\"meta\"", "\"meta\"",
"\"extension\"", "\"extension\"",
"\"url\":\"http://exturl\"", "\"url\": \"http://exturl\"",
"\"extension\"", "\"extension\"",
"\"url\":\"http://subext\"", "\"url\": \"http://subext\"",
"\"valueString\":\"sub_ext_value\"", "\"valueString\": \"sub_ext_value\"",
"\"code\":" "\"code\":"
)); ));
assertThat(output, not(stringContainsInOrder( assertThat(output, not(stringContainsInOrder(
"\"url\":\"http://exturl\"", "\"url\": \"http://exturl\"",
",", ",",
"\"url\":\"http://exturl\"" "\"url\": \"http://exturl\""
))); )));
//@formatter:on //@formatter:on
@ -708,7 +711,7 @@ public class JsonParserDstu2Test {
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, containsString("Patient")); assertThat(encoded, containsString("Patient"));
assertThat(encoded, stringContainsInOrder("\"tag\"", "\"system\":\"" + Constants.TAG_SUBSETTED_SYSTEM + "\",", "\"code\":\"" + Constants.TAG_SUBSETTED_CODE + "\",")); assertThat(encoded, stringContainsInOrder("\"tag\"", "\"system\": \"" + Constants.TAG_SUBSETTED_SYSTEM + "\",", "\"code\": \"" + Constants.TAG_SUBSETTED_CODE + "\","));
assertThat(encoded, not(containsString("THE DIV"))); assertThat(encoded, not(containsString("THE DIV")));
assertThat(encoded, containsString("family")); assertThat(encoded, containsString("family"));
assertThat(encoded, not(containsString("maritalStatus"))); assertThat(encoded, not(containsString("maritalStatus")));
@ -730,7 +733,7 @@ public class JsonParserDstu2Test {
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, containsString("Patient")); assertThat(encoded, containsString("Patient"));
assertThat(encoded, stringContainsInOrder("\"tag\"", "\"system\":\"foo\",", "\"code\":\"bar\"", "\"system\":\"" + Constants.TAG_SUBSETTED_SYSTEM + "\",", "\"code\":\"" + Constants.TAG_SUBSETTED_CODE + "\",")); assertThat(encoded, stringContainsInOrder("\"tag\"", "\"system\": \"foo\",", "\"code\": \"bar\"", "\"system\": \"" + Constants.TAG_SUBSETTED_SYSTEM + "\",", "\"code\": \"" + Constants.TAG_SUBSETTED_CODE + "\","));
assertThat(encoded, not(containsString("THE DIV"))); assertThat(encoded, not(containsString("THE DIV")));
assertThat(encoded, containsString("family")); assertThat(encoded, containsString("family"));
assertThat(encoded, not(containsString("maritalStatus"))); assertThat(encoded, not(containsString("maritalStatus")));
@ -1246,7 +1249,7 @@ public class JsonParserDstu2Test {
//@formatter:off //@formatter:off
assertThat(encoded, stringContainsInOrder( assertThat(encoded, stringContainsInOrder(
"\"identifier\":[", "\"identifier\": [",
"{", "{",
"\"fhir_comments\":", "\"fhir_comments\":",
"[", "[",
@ -1254,8 +1257,8 @@ public class JsonParserDstu2Test {
",", ",",
"\"identifier comment 2\"", "\"identifier comment 2\"",
"]", "]",
"\"use\":\"usual\",", "\"use\": \"usual\",",
"\"_use\":{", "\"_use\": {",
"\"fhir_comments\":", "\"fhir_comments\":",
"[", "[",
"\"use comment 1\"", "\"use comment 1\"",
@ -1316,11 +1319,11 @@ public class JsonParserDstu2Test {
//@formatter:off //@formatter:off
assertThat(enc, stringContainsInOrder( assertThat(enc, stringContainsInOrder(
"\"resourceType\":\"Observation\"", "\"resourceType\": \"Observation\"",
"\"contained\":[", "\"contained\": [",
"\"resourceType\":\"Patient\",", "\"resourceType\": \"Patient\",",
"\"id\":\"1\"", "\"id\": \"1\"",
"\"reference\":\"#1\"" "\"reference\": \"#1\""
)); ));
//@formatter:on //@formatter:on
@ -1547,7 +1550,16 @@ public class JsonParserDstu2Test {
*/ */
@Test @Test
public void testParseResourceWithInvalidType() { public void testParseResourceWithInvalidType() {
String input = "{" + "\"resourceType\":\"Patient\"," + "\"contained\":[" + " {" + " \"rezType\":\"Organization\"" + " }" + " ]" + "}"; //@formatter:off
String input = "{" +
"\"resourceType\":\"Patient\"," +
"\"contained\":[" +
" {" +
" \"rezType\":\"Organization\"" +
" }" +
" ]" +
"}";
//@formatter:on
IParser jsonParser = ourCtx.newJsonParser().setPrettyPrint(true); IParser jsonParser = ourCtx.newJsonParser().setPrettyPrint(true);
try { try {
@ -1589,7 +1601,7 @@ public class JsonParserDstu2Test {
ourCtx.newJsonParser().parseResource(Conformance.class, input); ourCtx.newJsonParser().parseResource(Conformance.class, input);
fail(); fail();
} catch (DataFormatException e) { } catch (DataFormatException e) {
assertEquals("Syntax error parsing JSON FHIR structure: Expected ARRAY at element 'modifierExtension', found 'OBJECT'", e.getMessage()); assertEquals("Syntax error parsing JSON FHIR structure: Expected ARRAY at element 'modifierExtension', found 'JsonObject'", e.getMessage());
} }
} }

View File

@ -1767,7 +1767,7 @@ public class XmlParserDstu2Test {
//@formatter:off //@formatter:off
assertThat(encoded, stringContainsInOrder( assertThat(encoded, stringContainsInOrder(
"\"identifier\":[", "\"identifier\": [",
"{", "{",
"\"fhir_comments\":", "\"fhir_comments\":",
"[", "[",
@ -1775,8 +1775,8 @@ public class XmlParserDstu2Test {
",", ",",
"\"identifier comment 2\"", "\"identifier comment 2\"",
"]", "]",
"\"use\":\"usual\",", "\"use\": \"usual\",",
"\"_use\":{", "\"_use\": {",
"\"fhir_comments\":", "\"fhir_comments\":",
"[", "[",
"\"use comment 1\"", "\"use comment 1\"",

View File

@ -1724,7 +1724,7 @@ public class GenericClientDstu2Test {
@Test @Test
public void testReadWithElementsParam() throws Exception { public void testReadWithElementsParam() throws Exception {
String msg = "{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}"; String msg = "{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}";
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class); ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse); when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
@ -2595,7 +2595,7 @@ public class GenericClientDstu2Test {
response = client.validate().resource(ourCtx.newJsonParser().encodeResourceToString(p)).prettyPrint().execute(); response = client.validate().resource(ourCtx.newJsonParser().encodeResourceToString(p)).prettyPrint().execute();
assertEquals("http://example.com/fhir/Patient/$validate?_format=json&_pretty=true", capt.getAllValues().get(idx).getURI().toASCIIString()); assertEquals("http://example.com/fhir/Patient/$validate?_format=json&_pretty=true", capt.getAllValues().get(idx).getURI().toASCIIString());
assertEquals("POST", capt.getAllValues().get(idx).getRequestLine().getMethod()); assertEquals("POST", capt.getAllValues().get(idx).getRequestLine().getMethod());
assertThat(extractBody(capt, idx), containsString("\"resourceType\":\"Parameters\",\n")); assertThat(extractBody(capt, idx), containsString("\"resourceType\": \"Parameters\",\n"));
assertNotNull(response.getOperationOutcome()); assertNotNull(response.getOperationOutcome());
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue());
idx++; idx++;

View File

@ -53,12 +53,6 @@
<version>9.6.0-4</version> <version>9.6.0-4</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<!-- Testing --> <!-- Testing -->
<dependency> <dependency>
<groupId>xmlunit</groupId> <groupId>xmlunit</groupId>

View File

@ -99,7 +99,7 @@ public class JsonParserDstu3Test {
String output = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p); String output = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p);
ourLog.info(output); ourLog.info(output);
assertThat(output, containsString("\"div\":\"<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">VALUE</div>\"")); assertThat(output, containsString("\"div\": \"<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">VALUE</div>\""));
} }
@Test @Test
@ -110,7 +110,7 @@ public class JsonParserDstu3Test {
String output = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p); String output = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p);
ourLog.info(output); ourLog.info(output);
assertThat(output, containsString("\"div\":\"<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">VALUE</div>\"")); assertThat(output, containsString("\"div\": \"<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">VALUE</div>\""));
} }
@ -132,7 +132,7 @@ public class JsonParserDstu3Test {
String encode = p.encodeResourceToString(bundle); String encode = p.encodeResourceToString(bundle);
ourLog.info(encode); ourLog.info(encode);
assertThat(encode, containsString("\"value\":\"APPID\"")); assertThat(encode, containsString("\"value\": \"APPID\""));
} }
@ -273,33 +273,33 @@ public class JsonParserDstu3Test {
ourLog.info(enc); ourLog.info(enc);
//@formatter:off //@formatter:off
assertThat(enc, stringContainsInOrder("\"meta\":{", assertThat(enc, stringContainsInOrder("\"meta\": {",
"\"profile\":[", "\"profile\": [",
"\"http://foo/Profile1\",", "\"http://foo/Profile1\",",
"\"http://foo/Profile2\"", "\"http://foo/Profile2\"",
"],", "],",
"\"security\":[", "\"security\": [",
"{", "{",
"\"system\":\"sec_scheme1\",", "\"system\": \"sec_scheme1\",",
"\"code\":\"sec_term1\",", "\"code\": \"sec_term1\",",
"\"display\":\"sec_label1\"", "\"display\": \"sec_label1\"",
"},", "},",
"{", "{",
"\"system\":\"sec_scheme2\",", "\"system\": \"sec_scheme2\",",
"\"code\":\"sec_term2\",", "\"code\": \"sec_term2\",",
"\"display\":\"sec_label2\"", "\"display\": \"sec_label2\"",
"}", "}",
"],", "],",
"\"tag\":[", "\"tag\": [",
"{", "{",
"\"system\":\"scheme1\",", "\"system\": \"scheme1\",",
"\"code\":\"term1\",", "\"code\": \"term1\",",
"\"display\":\"label1\"", "\"display\": \"label1\"",
"},", "},",
"{", "{",
"\"system\":\"scheme2\",", "\"system\": \"scheme2\",",
"\"code\":\"term2\",", "\"code\": \"term2\",",
"\"display\":\"label2\"", "\"display\": \"label2\"",
"}", "}",
"]", "]",
"},")); "},"));
@ -402,26 +402,26 @@ public class JsonParserDstu3Test {
//@formatter:off //@formatter:off
assertEquals("{\n" + assertEquals("{\n" +
" \"resourceType\":\"Patient\",\n" + " \"resourceType\": \"Patient\",\n" +
" \"meta\":{\n" + " \"meta\": {\n" +
" \"security\":[\n" + " \"security\": [\n" +
" {\n" + " {\n" +
" \"system\":\"SYSTEM1\",\n" + " \"system\": \"SYSTEM1\",\n" +
" \"version\":\"VERSION1\",\n" + " \"version\": \"VERSION1\",\n" +
" \"code\":\"CODE1\",\n" + " \"code\": \"CODE1\",\n" +
" \"display\":\"DISPLAY1\"\n" + " \"display\": \"DISPLAY1\"\n" +
" },\n" + " },\n" +
" {\n" + " {\n" +
" \"system\":\"SYSTEM2\",\n" + " \"system\": \"SYSTEM2\",\n" +
" \"version\":\"VERSION2\",\n" + " \"version\": \"VERSION2\",\n" +
" \"code\":\"CODE2\",\n" + " \"code\": \"CODE2\",\n" +
" \"display\":\"DISPLAY2\"\n" + " \"display\": \"DISPLAY2\"\n" +
" }\n" + " }\n" +
" ]\n" + " ]\n" +
" },\n" + " },\n" +
" \"name\":[\n" + " \"name\": [\n" +
" {\n" + " {\n" +
" \"family\":[\n" + " \"family\": [\n" +
" \"FAMILY\"\n" + " \"FAMILY\"\n" +
" ]\n" + " ]\n" +
" }\n" + " }\n" +
@ -480,22 +480,22 @@ public class JsonParserDstu3Test {
//@formatter:off //@formatter:off
assertThat(encoded, stringContainsInOrder( assertThat(encoded, stringContainsInOrder(
"{", "{",
"\"resourceType\":\"Patient\",", "\"resourceType\": \"Patient\",",
"\"contained\":[", "\"contained\": [",
"{", "{",
"\"resourceType\":\"Condition\",", "\"resourceType\": \"Condition\",",
"\"id\":\"1\"", "\"id\": \"1\"",
"}", "}",
"],", "],",
"\"extension\":[", "\"extension\": [",
"{", "{",
"\"url\":\"test\",", "\"url\": \"test\",",
"\"valueReference\":{", "\"valueReference\": {",
"\"reference\":\"#1\"", "\"reference\": \"#1\"",
"}", "}",
"}", "}",
"],", "],",
"\"birthDate\":\"2016-04-05\"", "\"birthDate\": \"2016-04-05\"",
"}" "}"
)); ));
//@formatter:on //@formatter:on
@ -597,17 +597,17 @@ public class JsonParserDstu3Test {
//@formatter:off //@formatter:off
assertThat(output, stringContainsInOrder( assertThat(output, stringContainsInOrder(
"\"id\":\"1\"", "\"id\": \"1\"",
"\"meta\"", "\"meta\"",
"\"extension\"", "\"extension\"",
"\"url\":\"http://exturl\"", "\"url\": \"http://exturl\"",
"\"valueString\":\"ext_url_value\"", "\"valueString\": \"ext_url_value\"",
"\"code\":" "\"code\":"
)); ));
assertThat(output, not(stringContainsInOrder( assertThat(output, not(stringContainsInOrder(
"\"url\":\"http://exturl\"", "\"url\": \"http://exturl\"",
",", ",",
"\"url\":\"http://exturl\"" "\"url\": \"http://exturl\""
))); )));
//@formatter:on //@formatter:on
@ -637,19 +637,19 @@ public class JsonParserDstu3Test {
//@formatter:off //@formatter:off
assertThat(output, stringContainsInOrder( assertThat(output, stringContainsInOrder(
"\"id\":\"1\"", "\"id\": \"1\"",
"\"meta\"", "\"meta\"",
"\"extension\"", "\"extension\"",
"\"url\":\"http://exturl\"", "\"url\": \"http://exturl\"",
"\"extension\"", "\"extension\"",
"\"url\":\"http://subext\"", "\"url\": \"http://subext\"",
"\"valueString\":\"sub_ext_value\"", "\"valueString\": \"sub_ext_value\"",
"\"code\":" "\"code\":"
)); ));
assertThat(output, not(stringContainsInOrder( assertThat(output, not(stringContainsInOrder(
"\"url\":\"http://exturl\"", "\"url\": \"http://exturl\"",
",", ",",
"\"url\":\"http://exturl\"" "\"url\": \"http://exturl\""
))); )));
//@formatter:on //@formatter:on
@ -689,7 +689,7 @@ public class JsonParserDstu3Test {
String enc = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(reqParms); String enc = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(reqParms);
ourLog.info(enc); ourLog.info(enc);
assertThat(enc, containsString("\"valueId\":\"1\"")); assertThat(enc, containsString("\"valueId\": \"1\""));
} }
@Test @Test
@ -707,7 +707,7 @@ public class JsonParserDstu3Test {
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, containsString("Patient")); assertThat(encoded, containsString("Patient"));
assertThat(encoded, stringContainsInOrder("\"tag\"", "\"system\":\"" + Constants.TAG_SUBSETTED_SYSTEM + "\",", "\"code\":\"" + Constants.TAG_SUBSETTED_CODE + "\"")); assertThat(encoded, stringContainsInOrder("\"tag\"", "\"system\": \"" + Constants.TAG_SUBSETTED_SYSTEM + "\",", "\"code\": \"" + Constants.TAG_SUBSETTED_CODE + "\""));
assertThat(encoded, not(containsString("THE DIV"))); assertThat(encoded, not(containsString("THE DIV")));
assertThat(encoded, containsString("family")); assertThat(encoded, containsString("family"));
assertThat(encoded, not(containsString("maritalStatus"))); assertThat(encoded, not(containsString("maritalStatus")));
@ -728,7 +728,7 @@ public class JsonParserDstu3Test {
assertThat(encoded, containsString("Patient")); assertThat(encoded, containsString("Patient"));
assertThat(encoded, assertThat(encoded,
stringContainsInOrder("\"tag\"", "\"system\":\"foo\",", "\"code\":\"bar\"", "\"system\":\"" + Constants.TAG_SUBSETTED_SYSTEM + "\"", "\"code\":\"" + Constants.TAG_SUBSETTED_CODE + "\"")); stringContainsInOrder("\"tag\"", "\"system\": \"foo\",", "\"code\": \"bar\"", "\"system\": \"" + Constants.TAG_SUBSETTED_SYSTEM + "\"", "\"code\": \"" + Constants.TAG_SUBSETTED_CODE + "\""));
assertThat(encoded, not(containsString("THE DIV"))); assertThat(encoded, not(containsString("THE DIV")));
assertThat(encoded, containsString("family")); assertThat(encoded, containsString("family"));
assertThat(encoded, not(containsString("maritalStatus"))); assertThat(encoded, not(containsString("maritalStatus")));
@ -926,8 +926,21 @@ public class JsonParserDstu3Test {
*/ */
@Test @Test
public void testExplanationOfBenefit() { public void testExplanationOfBenefit() {
String input = "{" + " \"resourceType\":\"ExplanationOfBenefit\"," + " \"coverage\": {\n" + " \"coverageReference\": {\n" + " \"reference\": \"Coverage/123\"\n" + " }\n" + " },\n" //@formatter:off
+ " \"relationship\": {\n" + " \"system\": \"http://hl7.org/fhir/relationship\",\n" + " \"code\": \"1\",\n" + " \"display\": \"self\"\n" + " }\n" + "}"; String input = "{" +
" \"resourceType\": \"ExplanationOfBenefit\"," +
" \"coverage\": {\n" +
" \"coverageReference\": {\n" +
" \"reference\": \"Coverage/123\"\n" +
" }\n" +
" },\n" +
" \"relationship\": {\n" +
" \"system\": \"http://hl7.org/fhir/relationship\",\n" +
" \"code\": \"1\",\n" +
" \"display\": \"self\"\n" +
" }\n" +
"}";
//@formatter:on
ExplanationOfBenefit eob = ourCtx.newJsonParser().parseResource(ExplanationOfBenefit.class, input); ExplanationOfBenefit eob = ourCtx.newJsonParser().parseResource(ExplanationOfBenefit.class, input);
assertEquals(Reference.class, eob.getCoverage().getCoverage().getClass()); assertEquals(Reference.class, eob.getCoverage().getCoverage().getClass());
@ -1299,7 +1312,7 @@ public class JsonParserDstu3Test {
//@formatter:off //@formatter:off
assertThat(encoded, stringContainsInOrder( assertThat(encoded, stringContainsInOrder(
"\"identifier\":[", "\"identifier\": [",
"{", "{",
"\"fhir_comments\":", "\"fhir_comments\":",
"[", "[",
@ -1307,8 +1320,8 @@ public class JsonParserDstu3Test {
",", ",",
"\"identifier comment 2\"", "\"identifier comment 2\"",
"]", "]",
"\"use\":\"usual\",", "\"use\": \"usual\",",
"\"_use\":{", "\"_use\": {",
"\"fhir_comments\":", "\"fhir_comments\":",
"[", "[",
"\"use comment 1\"", "\"use comment 1\"",
@ -1390,9 +1403,24 @@ public class JsonParserDstu3Test {
/** /**
* See #342 * See #342
*/ */
@Test(expected = DataFormatException.class) @Test()
public void testParseInvalid() { public void testParseInvalid() {
try {
ourCtx.newJsonParser().parseResource("FOO"); ourCtx.newJsonParser().parseResource("FOO");
fail();
} catch (DataFormatException e) {
assertEquals("Failed to parse JSON content, error was: Content does not appear to be FHIR JSON, first non-whitespace character was: 'F' (must be '{')", e.getMessage());
}
try {
ourCtx.newJsonParser().parseResource("[\"aaa\"]");
fail();
} catch (DataFormatException e) {
assertEquals("Failed to parse JSON content, error was: Content does not appear to be FHIR JSON, first non-whitespace character was: '[' (must be '{')", e.getMessage());
}
assertEquals(Bundle.class, ourCtx.newJsonParser().parseResource(" {\"resourceType\" : \"Bundle\"}").getClass());
} }
@Test @Test
@ -1458,6 +1486,18 @@ public class JsonParserDstu3Test {
} }
@Test(expected=DataFormatException.class)
public void testParseWithTrailingContent() throws Exception {
//@formatter:off
String bundle = "{\n" +
" \"resourceType\" : \"Bundle\",\n" +
" \"total\" : 1\n" +
"}}";
//@formatter:on
Bundle b = ourCtx.newJsonParser().parseResource(Bundle.class, bundle);
}
/** /**
* See #163 * See #163
*/ */

View File

@ -1892,7 +1892,7 @@ public class XmlParserDstu3Test {
//@formatter:off //@formatter:off
assertThat(encoded, stringContainsInOrder( assertThat(encoded, stringContainsInOrder(
"\"identifier\":[", "\"identifier\": [",
"{", "{",
"\"fhir_comments\":", "\"fhir_comments\":",
"[", "[",
@ -1900,8 +1900,8 @@ public class XmlParserDstu3Test {
",", ",",
"\"identifier comment 2\"", "\"identifier comment 2\"",
"]", "]",
"\"use\":\"usual\",", "\"use\": \"usual\",",
"\"_use\":{", "\"_use\": {",
"\"fhir_comments\":", "\"fhir_comments\":",
"[", "[",
"\"use comment 1\"", "\"use comment 1\"",
@ -1997,34 +1997,34 @@ public class XmlParserDstu3Test {
assertThat(output, stringContainsInOrder( assertThat(output, stringContainsInOrder(
"{", "{",
" \"resourceType\":\"Patient\",", " \"resourceType\": \"Patient\",",
" \"id\":\"someid\",", " \"id\": \"someid\",",
" \"_id\":{", " \"_id\": {",
" \"fhir_comments\":[", " \"fhir_comments\": [",
" \" comment 1 \"", " \" comment 1 \"",
" ]", " ]",
" },", " },",
" \"extension\":[", " \"extension\": [",
" {", " {",
" \"fhir_comments\":[", " \"fhir_comments\": [",
" \" comment 2 \",", " \" comment 2 \",",
" \" comment 7 \"", " \" comment 7 \"",
" ],", " ],",
" \"url\":\"urn:patientext:att\",", " \"url\": \"urn:patientext:att\",",
" \"valueAttachment\":{", " \"valueAttachment\": {",
" \"fhir_comments\":[", " \"fhir_comments\": [",
" \" comment 3 \",", " \" comment 3 \",",
" \" comment 6 \"", " \" comment 6 \"",
" ],", " ],",
" \"contentType\":\"aaaa\",", " \"contentType\": \"aaaa\",",
" \"_contentType\":{", " \"_contentType\": {",
" \"fhir_comments\":[", " \"fhir_comments\": [",
" \" comment 4 \"", " \" comment 4 \"",
" ]", " ]",
" },", " },",
" \"data\":\"AAAA\",", " \"data\": \"AAAA\",",
" \"_data\":{", " \"_data\": {",
" \"fhir_comments\":[", " \"fhir_comments\": [",
" \" comment 5 \"", " \" comment 5 \"",
" ]", " ]",
" }", " }",

View File

@ -52,12 +52,6 @@
<version>9.6.0-4</version> <version>9.6.0-4</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<!-- Testing --> <!-- Testing -->
<dependency> <dependency>
<groupId>xmlunit</groupId> <groupId>xmlunit</groupId>

View File

@ -259,17 +259,17 @@ public class JsonParserHl7OrgDstu2Test {
//@formatter:off //@formatter:off
String[] strings = new String[] { String[] strings = new String[] {
"\"resourceType\":\"Bundle\",", "\"resourceType\": \"Bundle\",",
"\"lastUpdated\":\"" + pub.getValueAsString() + "\"", "\"lastUpdated\": \"" + pub.getValueAsString() + "\"",
"\"entry\":[", "\"entry\": [",
"\"resource\":{", "\"resource\": {",
"\"id\":\"1\"", "\"id\": \"1\"",
"\"resource\":{", "\"resource\": {",
"\"id\":\"2\"", "\"id\": \"2\"",
"\"resource\":{", "\"resource\": {",
"\"id\":\"3\"", "\"id\": \"3\"",
"\"meta\":{", "\"meta\": {",
"\"lastUpdated\":\"" + nowDt.getValueAsString() + "\"" "\"lastUpdated\": \"" + nowDt.getValueAsString() + "\""
}; };
//@formatter:off //@formatter:off
assertThat(bundleString, StringContainsInOrder.stringContainsInOrder(strings)); assertThat(bundleString, StringContainsInOrder.stringContainsInOrder(strings));
@ -351,7 +351,7 @@ public class JsonParserHl7OrgDstu2Test {
String encoded = jsonParser.encodeResourceToString(patient); String encoded = jsonParser.encodeResourceToString(patient);
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\":[", "\"id\":\"1\"", "\"identifier\"", "\"reference\":\"#1\""))); assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\": [", "\"id\": \"1\"", "\"identifier\"", "\"reference\": \"#1\"")));
// Create a bundle with just the patient resource // Create a bundle with just the patient resource
Bundle b = new Bundle(); Bundle b = new Bundle();
@ -360,7 +360,7 @@ public class JsonParserHl7OrgDstu2Test {
// Encode the bundle // Encode the bundle
encoded = jsonParser.encodeResourceToString(b); encoded = jsonParser.encodeResourceToString(b);
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\":[", "\"id\":\"1\"", "\"identifier\"", "\"reference\":\"#1\""))); assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\": [", "\"id\": \"1\"", "\"identifier\"", "\"reference\": \"#1\"")));
// Re-parse the bundle // Re-parse the bundle
patient = (Patient) jsonParser.parseResource(jsonParser.encodeResourceToString(patient)); patient = (Patient) jsonParser.parseResource(jsonParser.encodeResourceToString(patient));
@ -374,7 +374,7 @@ public class JsonParserHl7OrgDstu2Test {
// And re-encode a second time // And re-encode a second time
encoded = jsonParser.encodeResourceToString(patient); encoded = jsonParser.encodeResourceToString(patient);
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\":[", "\"id\":\"1\"", "\"identifier\"", "\"reference\":\"#1\""))); assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\": [", "\"id\": \"1\"", "\"identifier\"", "\"reference\": \"#1\"")));
assertThat(encoded, not(stringContainsInOrder(Arrays.asList("\"contained\":", "[", "\"contained\":")))); assertThat(encoded, not(stringContainsInOrder(Arrays.asList("\"contained\":", "[", "\"contained\":"))));
// And re-encode once more, with the references cleared // And re-encode once more, with the references cleared
@ -382,7 +382,7 @@ public class JsonParserHl7OrgDstu2Test {
patient.getManagingOrganization().setReference(null); patient.getManagingOrganization().setReference(null);
encoded = jsonParser.encodeResourceToString(patient); encoded = jsonParser.encodeResourceToString(patient);
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\":[", "\"id\":\"1\"", "\"identifier\"", "\"reference\":\"#1\""))); assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\": [", "\"id\": \"1\"", "\"identifier\"", "\"reference\": \"#1\"")));
assertThat(encoded, not(stringContainsInOrder(Arrays.asList("\"contained\":", "[", "\"contained\":")))); assertThat(encoded, not(stringContainsInOrder(Arrays.asList("\"contained\":", "[", "\"contained\":"))));
// And re-encode once more, with the references cleared and a manually set local ID // And re-encode once more, with the references cleared and a manually set local ID
@ -391,7 +391,7 @@ public class JsonParserHl7OrgDstu2Test {
patient.getManagingOrganization().getResource().setId(("#333")); patient.getManagingOrganization().getResource().setId(("#333"));
encoded = jsonParser.encodeResourceToString(patient); encoded = jsonParser.encodeResourceToString(patient);
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\":[", "\"id\":\"333\"", "\"identifier\"", "\"reference\":\"#333\""))); assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\": [", "\"id\": \"333\"", "\"identifier\"", "\"reference\": \"#333\"")));
assertThat(encoded, not(stringContainsInOrder(Arrays.asList("\"contained\":", "[", "\"contained\":")))); assertThat(encoded, not(stringContainsInOrder(Arrays.asList("\"contained\":", "[", "\"contained\":"))));
} }
@ -415,13 +415,13 @@ public class JsonParserHl7OrgDstu2Test {
// Encode the buntdle // Encode the buntdle
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(b); String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(b);
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\"", "resourceType\":\"Organization", "id\":\"1\""))); assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\"", "resourceType\": \"Organization", "id\": \"1\"")));
assertThat(encoded, containsString("reference\":\"#1\"")); assertThat(encoded, containsString("reference\": \"#1\""));
encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient); encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient);
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\"", "resourceType\":\"Organization", "id\":\"1\""))); assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\"", "resourceType\": \"Organization", "id\": \"1\"")));
assertThat(encoded, containsString("reference\":\"#1\"")); assertThat(encoded, containsString("reference\": \"#1\""));
} }
@Test @Test
@ -437,13 +437,13 @@ public class JsonParserHl7OrgDstu2Test {
ourLog.info(str); ourLog.info(str);
assertThat(str, StringContains.containsString("<div>AAA</div>")); assertThat(str, StringContains.containsString("<div>AAA</div>"));
String substring = "\"reference\":\"#"; String substring = "\"reference\": \"#";
assertThat(str, StringContains.containsString(substring)); assertThat(str, StringContains.containsString(substring));
int idx = str.indexOf(substring) + substring.length(); int idx = str.indexOf(substring) + substring.length();
int idx2 = str.indexOf('"', idx + 1); int idx2 = str.indexOf('"', idx + 1);
String id = str.substring(idx, idx2); String id = str.substring(idx, idx2);
assertThat(str, StringContains.containsString("\"id\":\"" + id + "\"")); assertThat(str, StringContains.containsString("\"id\": \"" + id + "\""));
assertThat(str, IsNot.not(StringContains.containsString("<?xml version='1.0'?>"))); assertThat(str, IsNot.not(StringContains.containsString("<?xml version='1.0'?>")));
} }
@ -641,7 +641,7 @@ public class JsonParserHl7OrgDstu2Test {
String enc = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(list); String enc = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(list);
ourLog.info(enc); ourLog.info(enc);
assertThat(enc, containsString("\"id\":\"1\"")); assertThat(enc, containsString("\"id\": \"1\""));
List_ parsed = ourCtx.newJsonParser().parseResource(List_.class,enc); List_ parsed = ourCtx.newJsonParser().parseResource(List_.class,enc);
assertEquals(Patient.class, parsed.getEntry().get(0).getItem().getResource().getClass()); assertEquals(Patient.class, parsed.getEntry().get(0).getItem().getResource().getClass());
@ -701,12 +701,12 @@ public class JsonParserHl7OrgDstu2Test {
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(b); String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(b);
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, not(containsString("contained"))); assertThat(encoded, not(containsString("contained")));
assertThat(encoded, containsString("\"reference\":\"Organization/65546\"")); assertThat(encoded, containsString("\"reference\": \"Organization/65546\""));
encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient); encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient);
ourLog.info(encoded); ourLog.info(encoded);
assertThat(encoded, not(containsString("contained"))); assertThat(encoded, not(containsString("contained")));
assertThat(encoded, containsString("\"reference\":\"Organization/65546\"")); assertThat(encoded, containsString("\"reference\": \"Organization/65546\""));
} }
@ -747,7 +747,7 @@ public class JsonParserHl7OrgDstu2Test {
assertThat(encoded, containsString("Patient")); assertThat(encoded, containsString("Patient"));
assertThat(encoded, stringContainsInOrder("\"tag\"", assertThat(encoded, stringContainsInOrder("\"tag\"",
"\"system\":\"" + Constants.TAG_SUBSETTED_SYSTEM + "\",", "\"code\":\"" + Constants.TAG_SUBSETTED_CODE+"\",")); "\"system\": \"" + Constants.TAG_SUBSETTED_SYSTEM + "\",", "\"code\": \"" + Constants.TAG_SUBSETTED_CODE+"\","));
assertThat(encoded, not(containsString("THE DIV"))); assertThat(encoded, not(containsString("THE DIV")));
assertThat(encoded, containsString("family")); assertThat(encoded, containsString("family"));
assertThat(encoded, not(containsString("maritalStatus"))); assertThat(encoded, not(containsString("maritalStatus")));
@ -768,8 +768,8 @@ public class JsonParserHl7OrgDstu2Test {
assertThat(encoded, containsString("Patient")); assertThat(encoded, containsString("Patient"));
assertThat(encoded, stringContainsInOrder("\"tag\"", assertThat(encoded, stringContainsInOrder("\"tag\"",
"\"system\":\"foo\",", "\"code\":\"bar\"", "\"system\": \"foo\",", "\"code\": \"bar\"",
"\"system\":\"" + Constants.TAG_SUBSETTED_SYSTEM + "\",", "\"code\":\"" + Constants.TAG_SUBSETTED_CODE+"\",")); "\"system\": \"" + Constants.TAG_SUBSETTED_SYSTEM + "\",", "\"code\": \"" + Constants.TAG_SUBSETTED_CODE+"\","));
assertThat(encoded, not(containsString("THE DIV"))); assertThat(encoded, not(containsString("THE DIV")));
assertThat(encoded, containsString("family")); assertThat(encoded, containsString("family"));
assertThat(encoded, not(containsString("maritalStatus"))); assertThat(encoded, not(containsString("maritalStatus")));
@ -1036,7 +1036,7 @@ public class JsonParserHl7OrgDstu2Test {
String str = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(A); String str = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(A);
ourLog.info(str); ourLog.info(str);
assertThat(str, stringContainsInOrder(Arrays.asList("\"text\":\"B\"", "\"text\":\"C\"", "\"text\":\"A\""))); assertThat(str, stringContainsInOrder(Arrays.asList("\"text\": \"B\"", "\"text\": \"C\"", "\"text\": \"A\"")));
// Only one (outer) contained block // Only one (outer) contained block
int idx0 = str.indexOf("\"contained\""); int idx0 = str.indexOf("\"contained\"");
@ -1104,13 +1104,7 @@ public class JsonParserHl7OrgDstu2Test {
@Test @Test
public void testParseSingleQuotes() { public void testParseSingleQuotes() {
ourCtx.newJsonParser().parseResource(Bundle.class, "{ \"resourceType\": \"Bundle\" }"); ourCtx.newJsonParser().parseResource(Bundle.class, "{ \"resourceType\": \"Bundle\" }");
try {
ourCtx.newJsonParser().parseResource(Bundle.class, "{ 'resourceType': 'Bundle' }"); ourCtx.newJsonParser().parseResource(Bundle.class, "{ 'resourceType': 'Bundle' }");
fail();
} catch (DataFormatException e) {
// good
}
} }
/** /**

View File

@ -5,14 +5,13 @@ import static org.apache.commons.lang3.StringUtils.defaultString;
import static org.apache.commons.lang3.StringUtils.isBlank; import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank; import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.io.IOException;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.TreeSet; import java.util.TreeSet;
import javax.json.Json;
import javax.json.stream.JsonGenerator;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -29,6 +28,8 @@ import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import com.google.gson.stream.JsonWriter;
import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeResourceDefinition;
@ -375,14 +376,16 @@ public class Controller extends BaseController {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@RequestMapping(value = { "/search" }) @RequestMapping(value = { "/search" })
public String actionSearch(HttpServletRequest theReq, HomeRequest theRequest, BindingResult theBindingResult, ModelMap theModel) { public String actionSearch(HttpServletRequest theReq, HomeRequest theRequest, BindingResult theBindingResult, ModelMap theModel) throws IOException {
addCommonParams(theReq, theRequest, theModel); addCommonParams(theReq, theRequest, theModel);
StringWriter clientCodeJsonStringWriter = new StringWriter(); StringWriter clientCodeJsonStringWriter = new StringWriter();
JsonGenerator clientCodeJsonWriter = Json.createGenerator(clientCodeJsonStringWriter); JsonWriter clientCodeJsonWriter = new JsonWriter(clientCodeJsonStringWriter);
clientCodeJsonWriter.writeStartObject(); clientCodeJsonWriter.beginObject();
clientCodeJsonWriter.write("action", "search"); clientCodeJsonWriter.name("action");
clientCodeJsonWriter.write("base", (String) theModel.get("base")); clientCodeJsonWriter.value("search");
clientCodeJsonWriter.name("base");
clientCodeJsonWriter.value((String) theModel.get("base"));
CaptureInterceptor interceptor = new CaptureInterceptor(); CaptureInterceptor interceptor = new CaptureInterceptor();
GenericClient client = theRequest.newClient(theReq, getContext(theRequest), myConfig, interceptor); GenericClient client = theRequest.newClient(theReq, getContext(theRequest), myConfig, interceptor);
@ -396,27 +399,34 @@ public class Controller extends BaseController {
theModel.put("errorMsg", e.toString()); theModel.put("errorMsg", e.toString());
return "resource"; return "resource";
} }
clientCodeJsonWriter.write("resource", theReq.getParameter("resource")); clientCodeJsonWriter.name("resource");
clientCodeJsonWriter.value(theReq.getParameter("resource"));
} else { } else {
query = search.forAllResources(); query = search.forAllResources();
clientCodeJsonWriter.writeNull("resource"); clientCodeJsonWriter.name("resource");
clientCodeJsonWriter.nullValue();
} }
if (client.getPrettyPrint() != null) { if (client.getPrettyPrint() != null) {
clientCodeJsonWriter.write("pretty", client.getPrettyPrint().toString()); clientCodeJsonWriter.name("pretty");
clientCodeJsonWriter.value(client.getPrettyPrint().toString());
} else { } else {
clientCodeJsonWriter.writeNull("pretty"); clientCodeJsonWriter.name("pretty");
clientCodeJsonWriter.nullValue();
} }
if (client.getEncoding() != null) { if (client.getEncoding() != null) {
clientCodeJsonWriter.write("format", client.getEncoding().getRequestContentType()); clientCodeJsonWriter.name("format");
clientCodeJsonWriter.value(client.getEncoding().getRequestContentType());
} else { } else {
clientCodeJsonWriter.writeNull("format"); clientCodeJsonWriter.name("format");
clientCodeJsonWriter.nullValue();
} }
String outcomeDescription = "Search for Resources"; String outcomeDescription = "Search for Resources";
clientCodeJsonWriter.writeStartArray("params"); clientCodeJsonWriter.name("params");
clientCodeJsonWriter.beginArray();
int paramIdx = -1; int paramIdx = -1;
while (true) { while (true) {
paramIdx++; paramIdx++;
@ -427,31 +437,33 @@ public class Controller extends BaseController {
break; break;
} }
} }
clientCodeJsonWriter.writeEnd(); clientCodeJsonWriter.endArray();
clientCodeJsonWriter.writeStartArray("includes"); clientCodeJsonWriter.name("includes");
clientCodeJsonWriter.beginArray();
String[] incValues = theReq.getParameterValues(Constants.PARAM_INCLUDE); String[] incValues = theReq.getParameterValues(Constants.PARAM_INCLUDE);
if (incValues != null) { if (incValues != null) {
for (String next : incValues) { for (String next : incValues) {
if (isNotBlank(next)) { if (isNotBlank(next)) {
query.include(new Include(next)); query.include(new Include(next));
clientCodeJsonWriter.write(next); clientCodeJsonWriter.value(next);
} }
} }
} }
clientCodeJsonWriter.writeEnd(); clientCodeJsonWriter.endArray();
clientCodeJsonWriter.writeStartArray("revincludes"); clientCodeJsonWriter.name("revincludes");
clientCodeJsonWriter.beginArray();
String[] revIncValues = theReq.getParameterValues(Constants.PARAM_REVINCLUDE); String[] revIncValues = theReq.getParameterValues(Constants.PARAM_REVINCLUDE);
if (revIncValues != null) { if (revIncValues != null) {
for (String next : revIncValues) { for (String next : revIncValues) {
if (isNotBlank(next)) { if (isNotBlank(next)) {
query.revInclude(new Include(next)); query.revInclude(new Include(next));
clientCodeJsonWriter.write(next); clientCodeJsonWriter.value(next);
} }
} }
} }
clientCodeJsonWriter.writeEnd(); clientCodeJsonWriter.endArray();
String limit = theReq.getParameter("resource-search-limit"); String limit = theReq.getParameter("resource-search-limit");
if (isNotBlank(limit)) { if (isNotBlank(limit)) {
@ -461,9 +473,11 @@ public class Controller extends BaseController {
} }
int limitInt = Integer.parseInt(limit); int limitInt = Integer.parseInt(limit);
query.limitTo(limitInt); query.limitTo(limitInt);
clientCodeJsonWriter.write("limit", limit); clientCodeJsonWriter.name("limit");
clientCodeJsonWriter.value(limit);
} else { } else {
clientCodeJsonWriter.writeNull("limit"); clientCodeJsonWriter.name("limit");
clientCodeJsonWriter.nullValue();
} }
String[] sort = theReq.getParameterValues("sort_by"); String[] sort = theReq.getParameterValues("sort_by");
@ -501,7 +515,7 @@ public class Controller extends BaseController {
processAndAddLastClientInvocation(client, returnsResource, theModel, delay, outcomeDescription, interceptor, theRequest); processAndAddLastClientInvocation(client, returnsResource, theModel, delay, outcomeDescription, interceptor, theRequest);
clientCodeJsonWriter.writeEnd(); clientCodeJsonWriter.endObject();
clientCodeJsonWriter.close(); clientCodeJsonWriter.close();
String clientCodeJson = clientCodeJsonStringWriter.toString(); String clientCodeJson = clientCodeJsonStringWriter.toString();
theModel.put("clientCodeJson", clientCodeJson); theModel.put("clientCodeJson", clientCodeJson);
@ -714,8 +728,7 @@ public class Controller extends BaseController {
} }
private boolean extractSearchParamsDstu1(IBaseResource theConformance, String resourceName, TreeSet<String> includes, TreeSet<String> sortParams, List<RestQuery> queries, boolean haveSearchParams, private boolean extractSearchParamsDstu1(IBaseResource theConformance, String resourceName, TreeSet<String> includes, TreeSet<String> sortParams, List<RestQuery> queries, boolean haveSearchParams, List<List<String>> queryIncludes) {
List<List<String>> queryIncludes) {
Conformance conformance = (Conformance) theConformance; Conformance conformance = (Conformance) theConformance;
for (Rest nextRest : conformance.getRest()) { for (Rest nextRest : conformance.getRest()) {
for (RestResource nextRes : nextRest.getResource()) { for (RestResource nextRes : nextRest.getResource()) {
@ -763,8 +776,7 @@ public class Controller extends BaseController {
return haveSearchParams; return haveSearchParams;
} }
private boolean extractSearchParamsDstu2(IBaseResource theConformance, String resourceName, TreeSet<String> includes, TreeSet<String> theRevIncludes, TreeSet<String> sortParams, List<RestQuery> queries, boolean haveSearchParams, private boolean extractSearchParamsDstu2(IBaseResource theConformance, String resourceName, TreeSet<String> includes, TreeSet<String> theRevIncludes, TreeSet<String> sortParams, List<RestQuery> queries, boolean haveSearchParams, List<List<String>> queryIncludes) {
List<List<String>> queryIncludes) {
ca.uhn.fhir.model.dstu2.resource.Conformance conformance = (ca.uhn.fhir.model.dstu2.resource.Conformance) theConformance; ca.uhn.fhir.model.dstu2.resource.Conformance conformance = (ca.uhn.fhir.model.dstu2.resource.Conformance) theConformance;
for (ca.uhn.fhir.model.dstu2.resource.Conformance.Rest nextRest : conformance.getRest()) { for (ca.uhn.fhir.model.dstu2.resource.Conformance.Rest nextRest : conformance.getRest()) {
for (ca.uhn.fhir.model.dstu2.resource.Conformance.RestResource nextRes : nextRest.getResource()) { for (ca.uhn.fhir.model.dstu2.resource.Conformance.RestResource nextRes : nextRest.getResource()) {
@ -800,8 +812,7 @@ public class Controller extends BaseController {
return haveSearchParams; return haveSearchParams;
} }
private boolean extractSearchParamsDstu3(IBaseResource theConformance, String resourceName, TreeSet<String> includes, TreeSet<String> theRevIncludes, TreeSet<String> sortParams, List<RestQuery> queries, boolean haveSearchParams, private boolean extractSearchParamsDstu3(IBaseResource theConformance, String resourceName, TreeSet<String> includes, TreeSet<String> theRevIncludes, TreeSet<String> sortParams, List<RestQuery> queries, boolean haveSearchParams, List<List<String>> queryIncludes) {
List<List<String>> queryIncludes) {
org.hl7.fhir.dstu3.model.Conformance conformance = (org.hl7.fhir.dstu3.model.Conformance) theConformance; org.hl7.fhir.dstu3.model.Conformance conformance = (org.hl7.fhir.dstu3.model.Conformance) theConformance;
for (ConformanceRestComponent nextRest : conformance.getRest()) { for (ConformanceRestComponent nextRest : conformance.getRest()) {
for (ConformanceRestResourceComponent nextRes : nextRest.getResource()) { for (ConformanceRestResourceComponent nextRes : nextRest.getResource()) {
@ -837,7 +848,7 @@ public class Controller extends BaseController {
return haveSearchParams; return haveSearchParams;
} }
private boolean handleSearchParam(String paramIdxString, HttpServletRequest theReq, IQuery<?> theQuery, JsonGenerator theClientCodeJsonWriter) { private boolean handleSearchParam(String paramIdxString, HttpServletRequest theReq, IQuery<?> theQuery, JsonWriter theClientCodeJsonWriter) throws IOException {
String nextName = theReq.getParameter("param." + paramIdxString + ".name"); String nextName = theReq.getParameter("param." + paramIdxString + ".name");
if (isBlank(nextName)) { if (isBlank(nextName)) {
return false; return false;
@ -921,12 +932,16 @@ public class Controller extends BaseController {
for (String nextValue : values) { for (String nextValue : values) {
theClientCodeJsonWriter.writeStartObject(); theClientCodeJsonWriter.beginObject();
theClientCodeJsonWriter.write("type", nextType); theClientCodeJsonWriter.name("type");
theClientCodeJsonWriter.write("name", nextName); theClientCodeJsonWriter.value(nextType);
theClientCodeJsonWriter.write("qualifier", nextQualifier); theClientCodeJsonWriter.name("name");
theClientCodeJsonWriter.write("value", nextValue); theClientCodeJsonWriter.value(nextName);
theClientCodeJsonWriter.writeEnd(); theClientCodeJsonWriter.name("qualifier");
theClientCodeJsonWriter.value(nextQualifier);
theClientCodeJsonWriter.name("value");
theClientCodeJsonWriter.value(nextValue);
theClientCodeJsonWriter.endObject();
if (addToWhere) { if (addToWhere) {
theQuery.where(new StringClientParam(nextName + nextQualifier).matches().value(nextValue)); theQuery.where(new StringClientParam(nextName + nextQualifier).matches().value(nextValue));
} }