Update to use GSON
This commit is contained in:
parent
040c098742
commit
ed941a116b
|
@ -26,6 +26,13 @@
|
|||
<version>1.6.0</version>
|
||||
</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
|
||||
StAX version that's bundled with the JDK. The hapi-fhir-base-testmindeps-server
|
||||
|
|
|
@ -38,6 +38,13 @@
|
|||
<version>3.2</version><!--$NO-MVN-MAN-VER$-->
|
||||
</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
|
||||
StAX version that's bundled with the JDK. The hapi-fhir-base-testmindeps-server
|
||||
|
|
|
@ -20,12 +20,9 @@
|
|||
|
||||
<!-- JSON -->
|
||||
<dependency>
|
||||
<groupId>javax.json</groupId>
|
||||
<artifactId>javax.json-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish</groupId>
|
||||
<artifactId>javax.json</artifactId>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.7</version>
|
||||
</dependency>
|
||||
|
||||
<!-- XML -->
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1333,7 +1333,7 @@ public class GenericJaxRsClientDstu2Test {
|
|||
|
||||
@Test
|
||||
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();
|
||||
assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$validate?_format=json&_pretty=true", ourRequestUri);
|
||||
assertEquals("POST", ourRequestMethod);
|
||||
assertThat(ourRequestBodyString, containsString("\"resourceType\":\"Parameters\",\n"));
|
||||
assertThat(ourRequestBodyString, containsString("\"resourceType\": \"Parameters\",\n"));
|
||||
assertNotNull(response.getOperationOutcome());
|
||||
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue());
|
||||
|
||||
|
|
|
@ -1335,7 +1335,7 @@ public class GenericJaxRsClientDstu3Test {
|
|||
|
||||
@Test
|
||||
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();
|
||||
assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$validate?_format=json&_pretty=true", ourRequestUri);
|
||||
assertEquals("POST", ourRequestMethod);
|
||||
assertThat(ourRequestBodyString, containsString("\"resourceType\":\"Parameters\",\n"));
|
||||
assertThat(ourRequestBodyString, containsString("\"resourceType\": \"Parameters\",\n"));
|
||||
assertNotNull(response.getOperationOutcome());
|
||||
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssue().get(0).getDiagnosticsElement().getValue());
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ public class AbstractJaxRsConformanceProviderDstu3Test {
|
|||
providers.put(TestJaxRsMockPatientRestProviderDstu3.class, new TestJaxRsMockPatientRestProviderDstu3());
|
||||
Response response = createConformanceProvider(providers).conformance();
|
||||
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"));
|
||||
System.out.println(response);
|
||||
System.out.println(response.getEntity());
|
||||
|
|
|
@ -68,7 +68,7 @@ public class AbstractJaxRsConformanceProviderTest {
|
|||
providers.put(TestJaxRsMockPatientRestProvider.class, new TestJaxRsMockPatientRestProvider());
|
||||
Response response = createConformanceProvider(providers).conformance();
|
||||
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"));
|
||||
System.out.println(response);
|
||||
System.out.println(response.getEntity());
|
||||
|
|
|
@ -109,7 +109,7 @@ public class JaxRsResponseDstu3Test {
|
|||
Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), createPatient(), theSummaryMode, 200, addContentLocationHeader, respondGzip, this.request);
|
||||
assertEquals(200, result.getStatus());
|
||||
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"));
|
||||
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ public class JaxRsResponseTest {
|
|||
assertEquals(200, result.getStatus());
|
||||
assertEquals("application/json+fhir; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE));
|
||||
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"));
|
||||
|
||||
}
|
||||
|
|
|
@ -1635,28 +1635,29 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test {
|
|||
public void testOrganizationName() {
|
||||
|
||||
//@formatter:off
|
||||
String inputStr = "{\"resourceType\":\"Organization\",\n" +
|
||||
" \"extension\":[\n" +
|
||||
" {\n" +
|
||||
" \"url\":\"http://fhir.connectinggta.ca/Profile/organization#providerIdPool\",\n" +
|
||||
" \"valueUri\":\"urn:oid:2.16.840.1.113883.3.239.23.21.1\"\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"text\":{\n" +
|
||||
" \"status\":\"empty\",\n" +
|
||||
" \"div\":\"<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">No narrative template available for resource profile: http://fhir.connectinggta.ca/Profile/organization</div>\"\n" +
|
||||
" },\n" +
|
||||
" \"identifier\":[\n" +
|
||||
" {\n" +
|
||||
" \"use\":\"official\",\n" +
|
||||
" \"label\":\"HSP 2.16.840.1.113883.3.239.23.21\",\n" +
|
||||
" \"system\":\"urn:cgta:hsp_ids\",\n" +
|
||||
" \"value\":\"urn:oid:2.16.840.1.113883.3.239.23.21\"\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"name\":\"Peterborough Regional Health Centre\"\n" +
|
||||
" }\n" +
|
||||
" }";
|
||||
String inputStr =
|
||||
"{" +
|
||||
" \"resourceType\":\"Organization\",\n" +
|
||||
" \"extension\":[\n" +
|
||||
" {\n" +
|
||||
" \"url\":\"http://fhir.connectinggta.ca/Profile/organization#providerIdPool\",\n" +
|
||||
" \"valueUri\":\"urn:oid:2.16.840.1.113883.3.239.23.21.1\"\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"text\":{\n" +
|
||||
" \"status\":\"empty\",\n" +
|
||||
" \"div\":\"<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">No narrative template available for resource profile: http://fhir.connectinggta.ca/Profile/organization</div>\"\n" +
|
||||
" },\n" +
|
||||
" \"identifier\":[\n" +
|
||||
" {\n" +
|
||||
" \"use\":\"official\",\n" +
|
||||
" \"label\":\"HSP 2.16.840.1.113883.3.239.23.21\",\n" +
|
||||
" \"system\":\"urn:cgta:hsp_ids\",\n" +
|
||||
" \"value\":\"urn:oid:2.16.840.1.113883.3.239.23.21\"\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"name\":\"Peterborough Regional Health Centre\"\n" +
|
||||
"}\n";
|
||||
//@formatter:on
|
||||
|
||||
Set<Long> val = myOrganizationDao.searchForIds("name", new StringParam("P"));
|
||||
|
|
|
@ -2044,28 +2044,29 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test {
|
|||
public void testOrganizationName() {
|
||||
|
||||
//@formatter:off
|
||||
String inputStr = "{\"resourceType\":\"Organization\",\n" +
|
||||
" \"extension\":[\n" +
|
||||
" {\n" +
|
||||
" \"url\":\"http://fhir.connectinggta.ca/Profile/organization#providerIdPool\",\n" +
|
||||
" \"valueUri\":\"urn:oid:2.16.840.1.113883.3.239.23.21.1\"\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"text\":{\n" +
|
||||
" \"status\":\"empty\",\n" +
|
||||
" \"div\":\"<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">No narrative template available for resource profile: http://fhir.connectinggta.ca/Profile/organization</div>\"\n" +
|
||||
" },\n" +
|
||||
" \"identifier\":[\n" +
|
||||
" {\n" +
|
||||
" \"use\":\"official\",\n" +
|
||||
" \"label\":\"HSP 2.16.840.1.113883.3.239.23.21\",\n" +
|
||||
" \"system\":\"urn:cgta:hsp_ids\",\n" +
|
||||
" \"value\":\"urn:oid:2.16.840.1.113883.3.239.23.21\"\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"name\":\"Peterborough Regional Health Centre\"\n" +
|
||||
" }\n" +
|
||||
" }";
|
||||
String inputStr =
|
||||
"{" +
|
||||
" \"resourceType\":\"Organization\",\n" +
|
||||
" \"extension\":[\n" +
|
||||
" {\n" +
|
||||
" \"url\":\"http://fhir.connectinggta.ca/Profile/organization#providerIdPool\",\n" +
|
||||
" \"valueUri\":\"urn:oid:2.16.840.1.113883.3.239.23.21.1\"\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"text\":{\n" +
|
||||
" \"status\":\"empty\",\n" +
|
||||
" \"div\":\"<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">No narrative template available for resource profile: http://fhir.connectinggta.ca/Profile/organization</div>\"\n" +
|
||||
" },\n" +
|
||||
" \"identifier\":[\n" +
|
||||
" {\n" +
|
||||
" \"use\":\"official\",\n" +
|
||||
" \"label\":\"HSP 2.16.840.1.113883.3.239.23.21\",\n" +
|
||||
" \"system\":\"urn:cgta:hsp_ids\",\n" +
|
||||
" \"value\":\"urn:oid:2.16.840.1.113883.3.239.23.21\"\n" +
|
||||
" }\n" +
|
||||
" ],\n" +
|
||||
" \"name\":\"Peterborough Regional Health Centre\"\n" +
|
||||
"}\n";
|
||||
//@formatter:on
|
||||
|
||||
Set<Long> val = myOrganizationDao.searchForIds("name", new StringParam("P"));
|
||||
|
|
|
@ -294,10 +294,10 @@ public class JsonParserTest {
|
|||
ourLog.info(bundleString);
|
||||
|
||||
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("\"id\":\"2\"", "\"rel\":\"alternate\"", "\"href\":\"http://foo/bar\""));
|
||||
strings.addAll(Arrays.asList("\"deleted\":\"" + nowDt.getValueAsString() + "\"", "\"id\":\"Patient/3\""));
|
||||
strings.addAll(Arrays.asList("\"id\": \"2\"", "\"rel\": \"alternate\"", "\"href\": \"http://foo/bar\""));
|
||||
strings.addAll(Arrays.asList("\"deleted\": \"" + nowDt.getValueAsString() + "\"", "\"id\": \"Patient/3\""));
|
||||
assertThat(bundleString, StringContainsInOrder.stringContainsInOrder(strings));
|
||||
|
||||
b.getEntries().remove(2);
|
||||
|
@ -372,7 +372,7 @@ public class JsonParserTest {
|
|||
|
||||
String encoded = xmlParser.encodeResourceToString(patient);
|
||||
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
|
||||
List<IResource> resources = new ArrayList<IResource>();
|
||||
|
@ -382,7 +382,7 @@ public class JsonParserTest {
|
|||
// Encode the bundle
|
||||
encoded = xmlParser.encodeBundleToString(b);
|
||||
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
|
||||
patient = (Patient) xmlParser.parseResource(xmlParser.encodeResourceToString(patient));
|
||||
|
@ -396,7 +396,7 @@ public class JsonParserTest {
|
|||
// And re-encode a second time
|
||||
encoded = xmlParser.encodeResourceToString(patient);
|
||||
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\":"))));
|
||||
|
||||
// And re-encode once more, with the references cleared
|
||||
|
@ -404,7 +404,7 @@ public class JsonParserTest {
|
|||
patient.getManagingOrganization().setReference((IdDt) null);
|
||||
encoded = xmlParser.encodeResourceToString(patient);
|
||||
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\":"))));
|
||||
|
||||
// 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"));
|
||||
encoded = xmlParser.encodeResourceToString(patient);
|
||||
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\":"))));
|
||||
|
||||
}
|
||||
|
@ -438,13 +438,13 @@ public class JsonParserTest {
|
|||
// Encode the buntdle
|
||||
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(b);
|
||||
ourLog.info(encoded);
|
||||
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\"", "resourceType\":\"Organization", "id\":\"1\"")));
|
||||
assertThat(encoded, containsString("reference\":\"#1\""));
|
||||
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\"", "resourceType\": \"Organization", "id\": \"1\"")));
|
||||
assertThat(encoded, containsString("reference\": \"#1\""));
|
||||
|
||||
encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient);
|
||||
ourLog.info(encoded);
|
||||
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\"", "resourceType\":\"Organization", "id\":\"1\"")));
|
||||
assertThat(encoded, containsString("reference\":\"#1\""));
|
||||
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\"", "resourceType\": \"Organization", "id\": \"1\"")));
|
||||
assertThat(encoded, containsString("reference\": \"#1\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -472,13 +472,13 @@ public class JsonParserTest {
|
|||
|
||||
ourLog.info(str);
|
||||
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));
|
||||
|
||||
int idx = str.indexOf(substring) + substring.length();
|
||||
int idx2 = str.indexOf('"', idx + 1);
|
||||
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'?>")));
|
||||
|
||||
}
|
||||
|
@ -737,12 +737,12 @@ public class JsonParserTest {
|
|||
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeBundleToString(b);
|
||||
ourLog.info(encoded);
|
||||
assertThat(encoded, not(containsString("contained")));
|
||||
assertThat(encoded, containsString("\"reference\":\"Organization/65546\""));
|
||||
assertThat(encoded, containsString("\"reference\": \"Organization/65546\""));
|
||||
|
||||
encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient);
|
||||
ourLog.info(encoded);
|
||||
assertThat(encoded, not(containsString("contained")));
|
||||
assertThat(encoded, containsString("\"reference\":\"Organization/65546\""));
|
||||
assertThat(encoded, containsString("\"reference\": \"Organization/65546\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -936,7 +936,7 @@ public class JsonParserTest {
|
|||
|
||||
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(parsed);
|
||||
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);
|
||||
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
|
||||
int idx0 = str.indexOf("\"contained\"");
|
||||
|
@ -1232,13 +1232,7 @@ public class JsonParserTest {
|
|||
|
||||
@Test
|
||||
public void testParseSingleQuotes() {
|
||||
try {
|
||||
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"));
|
||||
}
|
||||
assertEquals("1", ourCtx.newJsonParser().parseBundle("{ 'resourceType': 'Bundle', 'id':'1' }").getBundleId().getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -222,7 +222,7 @@ public class CreateTest {
|
|||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
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: '<' (must be '{')"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -775,7 +775,4 @@
|
|||
"title" : "HTML Report"
|
||||
}
|
||||
]
|
||||
},
|
||||
"summary" : "\r\n<div xmlns=\"http://www.w3.org/1999/xhtml\"> 
 
 \r\n <h3>CBC Report for Wile. E. COYOTE (MRN: 23453) issued 3-Mar 2011 11:45</h3> 

 \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... -->
 
 \r\n <pre>
Test Units Value Reference Range
Haemoglobin g/L 176 135 - 180
Red Cell Count x10*12/L 5.9 4.2 - 6.0
Haematocrit 0.55+ 0.38 - 0.52
Mean Cell Volume fL 99+ 80 - 98
Mean Cell Haemoglobin pg 36+ 27 - 35
Platelet Count x10*9/L 444 150 - 450
White Cell Count x10*9/L 4.6 4.0 - 11.0
Neutrophils % 20 
Neutrophils x10*9/L 0.9--- 2.0 - 7.5
Lymphocytes % 20 
Lymphocytes x10*9/L 0.9- 1.1 - 4.0
Monocytes % 20 
Monocytes x10*9/L 0.9 0.2 - 1.0
Eosinophils % 20 
Eosinophils x10*9/L 0.92++ 0.04 - 0.40
Basophils % 20 
Basophils x10*9/L 0.92+++ <0.21
 </pre>
 
 \r\n <p>Acme Laboratory, Inc signed: Dr Pete Pathologist</p>
 </div>"
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ public class JsonParserDstu2Test {
|
|||
|
||||
String output = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p);
|
||||
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);
|
||||
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
|
||||
|
@ -267,21 +267,21 @@ public class JsonParserDstu2Test {
|
|||
ourLog.info(enc);
|
||||
|
||||
//@formatter:off
|
||||
assertThat(enc, stringContainsInOrder("\"meta\":{",
|
||||
"\"profile\":[",
|
||||
assertThat(enc, stringContainsInOrder("\"meta\": {",
|
||||
"\"profile\": [",
|
||||
"\"http://foo/Profile1\",",
|
||||
"\"http://foo/Profile2\"",
|
||||
"],",
|
||||
"\"tag\":[",
|
||||
"\"tag\": [",
|
||||
"{",
|
||||
"\"system\":\"scheme1\",",
|
||||
"\"code\":\"term1\",",
|
||||
"\"display\":\"label1\"",
|
||||
"\"system\": \"scheme1\",",
|
||||
"\"code\": \"term1\",",
|
||||
"\"display\": \"label1\"",
|
||||
"},",
|
||||
"{",
|
||||
"\"system\":\"scheme2\",",
|
||||
"\"code\":\"term2\",",
|
||||
"\"display\":\"label2\"",
|
||||
"\"system\": \"scheme2\",",
|
||||
"\"code\": \"term2\",",
|
||||
"\"display\": \"label2\"",
|
||||
"}",
|
||||
"]",
|
||||
"},"));
|
||||
|
@ -377,32 +377,35 @@ public class JsonParserDstu2Test {
|
|||
ourLog.info(enc);
|
||||
|
||||
//@formatter:off
|
||||
String actual = enc.trim();
|
||||
ourLog.info("Actual:\n{}", actual);
|
||||
|
||||
assertEquals("{\n" +
|
||||
" \"resourceType\":\"Patient\",\n" +
|
||||
" \"meta\":{\n" +
|
||||
" \"security\":[\n" +
|
||||
" {\n" +
|
||||
" \"system\":\"SYSTEM1\",\n" +
|
||||
" \"version\":\"VERSION1\",\n" +
|
||||
" \"code\":\"CODE1\",\n" +
|
||||
" \"display\":\"DISPLAY1\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"system\":\"SYSTEM2\",\n" +
|
||||
" \"version\":\"VERSION2\",\n" +
|
||||
" \"code\":\"CODE2\",\n" +
|
||||
" \"display\":\"DISPLAY2\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" },\n" +
|
||||
" \"name\":[\n" +
|
||||
" {\n" +
|
||||
" \"family\":[\n" +
|
||||
" \"FAMILY\"\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
" \"resourceType\": \"Patient\",\n" +
|
||||
" \"meta\": {\n" +
|
||||
" \"security\": [\n" +
|
||||
" {\n" +
|
||||
" \"system\": \"SYSTEM1\",\n" +
|
||||
" \"version\": \"VERSION1\",\n" +
|
||||
" \"code\": \"CODE1\",\n" +
|
||||
" \"display\": \"DISPLAY1\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"system\": \"SYSTEM2\",\n" +
|
||||
" \"version\": \"VERSION2\",\n" +
|
||||
" \"code\": \"CODE2\",\n" +
|
||||
" \"display\": \"DISPLAY2\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
"}", enc.trim());
|
||||
" },\n" +
|
||||
" \"name\": [\n" +
|
||||
" {\n" +
|
||||
" \"family\": [\n" +
|
||||
" \"FAMILY\"\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
"}", actual);
|
||||
//@formatter:on
|
||||
|
||||
Patient parsed = ourCtx.newJsonParser().parseResource(Patient.class, enc);
|
||||
|
@ -597,17 +600,17 @@ public class JsonParserDstu2Test {
|
|||
|
||||
//@formatter:off
|
||||
assertThat(output, stringContainsInOrder(
|
||||
"\"id\":\"1\"",
|
||||
"\"id\": \"1\"",
|
||||
"\"meta\"",
|
||||
"\"extension\"",
|
||||
"\"url\":\"http://exturl\"",
|
||||
"\"valueString\":\"ext_url_value\"",
|
||||
"\"url\": \"http://exturl\"",
|
||||
"\"valueString\": \"ext_url_value\"",
|
||||
"\"code\":"
|
||||
));
|
||||
assertThat(output, not(stringContainsInOrder(
|
||||
"\"url\":\"http://exturl\"",
|
||||
"\"url\": \"http://exturl\"",
|
||||
",",
|
||||
"\"url\":\"http://exturl\""
|
||||
"\"url\": \"http://exturl\""
|
||||
)));
|
||||
//@formatter:on
|
||||
|
||||
|
@ -637,19 +640,19 @@ public class JsonParserDstu2Test {
|
|||
|
||||
//@formatter:off
|
||||
assertThat(output, stringContainsInOrder(
|
||||
"\"id\":\"1\"",
|
||||
"\"id\": \"1\"",
|
||||
"\"meta\"",
|
||||
"\"extension\"",
|
||||
"\"url\":\"http://exturl\"",
|
||||
"\"url\": \"http://exturl\"",
|
||||
"\"extension\"",
|
||||
"\"url\":\"http://subext\"",
|
||||
"\"valueString\":\"sub_ext_value\"",
|
||||
"\"url\": \"http://subext\"",
|
||||
"\"valueString\": \"sub_ext_value\"",
|
||||
"\"code\":"
|
||||
));
|
||||
assertThat(output, not(stringContainsInOrder(
|
||||
"\"url\":\"http://exturl\"",
|
||||
"\"url\": \"http://exturl\"",
|
||||
",",
|
||||
"\"url\":\"http://exturl\""
|
||||
"\"url\": \"http://exturl\""
|
||||
)));
|
||||
//@formatter:on
|
||||
|
||||
|
@ -708,7 +711,7 @@ public class JsonParserDstu2Test {
|
|||
ourLog.info(encoded);
|
||||
|
||||
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, containsString("family"));
|
||||
assertThat(encoded, not(containsString("maritalStatus")));
|
||||
|
@ -730,7 +733,7 @@ public class JsonParserDstu2Test {
|
|||
ourLog.info(encoded);
|
||||
|
||||
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, containsString("family"));
|
||||
assertThat(encoded, not(containsString("maritalStatus")));
|
||||
|
@ -1246,7 +1249,7 @@ public class JsonParserDstu2Test {
|
|||
|
||||
//@formatter:off
|
||||
assertThat(encoded, stringContainsInOrder(
|
||||
"\"identifier\":[",
|
||||
"\"identifier\": [",
|
||||
"{",
|
||||
"\"fhir_comments\":",
|
||||
"[",
|
||||
|
@ -1254,8 +1257,8 @@ public class JsonParserDstu2Test {
|
|||
",",
|
||||
"\"identifier comment 2\"",
|
||||
"]",
|
||||
"\"use\":\"usual\",",
|
||||
"\"_use\":{",
|
||||
"\"use\": \"usual\",",
|
||||
"\"_use\": {",
|
||||
"\"fhir_comments\":",
|
||||
"[",
|
||||
"\"use comment 1\"",
|
||||
|
@ -1316,11 +1319,11 @@ public class JsonParserDstu2Test {
|
|||
|
||||
//@formatter:off
|
||||
assertThat(enc, stringContainsInOrder(
|
||||
"\"resourceType\":\"Observation\"",
|
||||
"\"contained\":[",
|
||||
"\"resourceType\":\"Patient\",",
|
||||
"\"id\":\"1\"",
|
||||
"\"reference\":\"#1\""
|
||||
"\"resourceType\": \"Observation\"",
|
||||
"\"contained\": [",
|
||||
"\"resourceType\": \"Patient\",",
|
||||
"\"id\": \"1\"",
|
||||
"\"reference\": \"#1\""
|
||||
));
|
||||
//@formatter:on
|
||||
|
||||
|
@ -1547,7 +1550,16 @@ public class JsonParserDstu2Test {
|
|||
*/
|
||||
@Test
|
||||
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);
|
||||
try {
|
||||
|
@ -1589,7 +1601,7 @@ public class JsonParserDstu2Test {
|
|||
ourCtx.newJsonParser().parseResource(Conformance.class, input);
|
||||
fail();
|
||||
} 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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1767,7 +1767,7 @@ public class XmlParserDstu2Test {
|
|||
|
||||
//@formatter:off
|
||||
assertThat(encoded, stringContainsInOrder(
|
||||
"\"identifier\":[",
|
||||
"\"identifier\": [",
|
||||
"{",
|
||||
"\"fhir_comments\":",
|
||||
"[",
|
||||
|
@ -1775,8 +1775,8 @@ public class XmlParserDstu2Test {
|
|||
",",
|
||||
"\"identifier comment 2\"",
|
||||
"]",
|
||||
"\"use\":\"usual\",",
|
||||
"\"_use\":{",
|
||||
"\"use\": \"usual\",",
|
||||
"\"_use\": {",
|
||||
"\"fhir_comments\":",
|
||||
"[",
|
||||
"\"use comment 1\"",
|
||||
|
|
|
@ -1724,7 +1724,7 @@ public class GenericClientDstu2Test {
|
|||
|
||||
@Test
|
||||
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);
|
||||
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
|
||||
|
@ -2595,7 +2595,7 @@ public class GenericClientDstu2Test {
|
|||
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("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());
|
||||
assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue());
|
||||
idx++;
|
||||
|
|
|
@ -53,12 +53,6 @@
|
|||
<version>9.6.0-4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Testing -->
|
||||
<dependency>
|
||||
<groupId>xmlunit</groupId>
|
||||
|
|
|
@ -97,7 +97,7 @@ public class JsonParserDstu3Test {
|
|||
|
||||
String output = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p);
|
||||
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
|
||||
|
@ -108,7 +108,7 @@ public class JsonParserDstu3Test {
|
|||
|
||||
String output = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p);
|
||||
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>\""));
|
||||
}
|
||||
|
||||
|
||||
|
@ -130,7 +130,7 @@ public class JsonParserDstu3Test {
|
|||
String encode = p.encodeResourceToString(bundle);
|
||||
ourLog.info(encode);
|
||||
|
||||
assertThat(encode, containsString("\"value\":\"APPID\""));
|
||||
assertThat(encode, containsString("\"value\": \"APPID\""));
|
||||
}
|
||||
|
||||
|
||||
|
@ -271,33 +271,33 @@ public class JsonParserDstu3Test {
|
|||
ourLog.info(enc);
|
||||
|
||||
//@formatter:off
|
||||
assertThat(enc, stringContainsInOrder("\"meta\":{",
|
||||
"\"profile\":[",
|
||||
assertThat(enc, stringContainsInOrder("\"meta\": {",
|
||||
"\"profile\": [",
|
||||
"\"http://foo/Profile1\",",
|
||||
"\"http://foo/Profile2\"",
|
||||
"],",
|
||||
"\"security\":[",
|
||||
"\"security\": [",
|
||||
"{",
|
||||
"\"system\":\"sec_scheme1\",",
|
||||
"\"code\":\"sec_term1\",",
|
||||
"\"display\":\"sec_label1\"",
|
||||
"\"system\": \"sec_scheme1\",",
|
||||
"\"code\": \"sec_term1\",",
|
||||
"\"display\": \"sec_label1\"",
|
||||
"},",
|
||||
"{",
|
||||
"\"system\":\"sec_scheme2\",",
|
||||
"\"code\":\"sec_term2\",",
|
||||
"\"display\":\"sec_label2\"",
|
||||
"\"system\": \"sec_scheme2\",",
|
||||
"\"code\": \"sec_term2\",",
|
||||
"\"display\": \"sec_label2\"",
|
||||
"}",
|
||||
"],",
|
||||
"\"tag\":[",
|
||||
"\"tag\": [",
|
||||
"{",
|
||||
"\"system\":\"scheme1\",",
|
||||
"\"code\":\"term1\",",
|
||||
"\"display\":\"label1\"",
|
||||
"\"system\": \"scheme1\",",
|
||||
"\"code\": \"term1\",",
|
||||
"\"display\": \"label1\"",
|
||||
"},",
|
||||
"{",
|
||||
"\"system\":\"scheme2\",",
|
||||
"\"code\":\"term2\",",
|
||||
"\"display\":\"label2\"",
|
||||
"\"system\": \"scheme2\",",
|
||||
"\"code\": \"term2\",",
|
||||
"\"display\": \"label2\"",
|
||||
"}",
|
||||
"]",
|
||||
"},"));
|
||||
|
@ -400,30 +400,30 @@ public class JsonParserDstu3Test {
|
|||
|
||||
//@formatter:off
|
||||
assertEquals("{\n" +
|
||||
" \"resourceType\":\"Patient\",\n" +
|
||||
" \"meta\":{\n" +
|
||||
" \"security\":[\n" +
|
||||
" {\n" +
|
||||
" \"system\":\"SYSTEM1\",\n" +
|
||||
" \"version\":\"VERSION1\",\n" +
|
||||
" \"code\":\"CODE1\",\n" +
|
||||
" \"display\":\"DISPLAY1\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"system\":\"SYSTEM2\",\n" +
|
||||
" \"version\":\"VERSION2\",\n" +
|
||||
" \"code\":\"CODE2\",\n" +
|
||||
" \"display\":\"DISPLAY2\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" },\n" +
|
||||
" \"name\":[\n" +
|
||||
" {\n" +
|
||||
" \"family\":[\n" +
|
||||
" \"FAMILY\"\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
" \"resourceType\": \"Patient\",\n" +
|
||||
" \"meta\": {\n" +
|
||||
" \"security\": [\n" +
|
||||
" {\n" +
|
||||
" \"system\": \"SYSTEM1\",\n" +
|
||||
" \"version\": \"VERSION1\",\n" +
|
||||
" \"code\": \"CODE1\",\n" +
|
||||
" \"display\": \"DISPLAY1\"\n" +
|
||||
" },\n" +
|
||||
" {\n" +
|
||||
" \"system\": \"SYSTEM2\",\n" +
|
||||
" \"version\": \"VERSION2\",\n" +
|
||||
" \"code\": \"CODE2\",\n" +
|
||||
" \"display\": \"DISPLAY2\"\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" },\n" +
|
||||
" \"name\": [\n" +
|
||||
" {\n" +
|
||||
" \"family\": [\n" +
|
||||
" \"FAMILY\"\n" +
|
||||
" ]\n" +
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
"}", enc.trim());
|
||||
//@formatter:on
|
||||
|
||||
|
@ -478,22 +478,22 @@ public class JsonParserDstu3Test {
|
|||
//@formatter:off
|
||||
assertThat(encoded, stringContainsInOrder(
|
||||
"{",
|
||||
"\"resourceType\":\"Patient\",",
|
||||
"\"contained\":[",
|
||||
"\"resourceType\": \"Patient\",",
|
||||
"\"contained\": [",
|
||||
"{",
|
||||
"\"resourceType\":\"Condition\",",
|
||||
"\"id\":\"1\"",
|
||||
"\"resourceType\": \"Condition\",",
|
||||
"\"id\": \"1\"",
|
||||
"}",
|
||||
"],",
|
||||
"\"extension\":[",
|
||||
"\"extension\": [",
|
||||
"{",
|
||||
"\"url\":\"test\",",
|
||||
"\"valueReference\":{",
|
||||
"\"reference\":\"#1\"",
|
||||
"\"url\": \"test\",",
|
||||
"\"valueReference\": {",
|
||||
"\"reference\": \"#1\"",
|
||||
"}",
|
||||
"}",
|
||||
"],",
|
||||
"\"birthDate\":\"2016-04-05\"",
|
||||
"\"birthDate\": \"2016-04-05\"",
|
||||
"}"
|
||||
));
|
||||
//@formatter:on
|
||||
|
@ -595,17 +595,17 @@ public class JsonParserDstu3Test {
|
|||
|
||||
//@formatter:off
|
||||
assertThat(output, stringContainsInOrder(
|
||||
"\"id\":\"1\"",
|
||||
"\"id\": \"1\"",
|
||||
"\"meta\"",
|
||||
"\"extension\"",
|
||||
"\"url\":\"http://exturl\"",
|
||||
"\"valueString\":\"ext_url_value\"",
|
||||
"\"url\": \"http://exturl\"",
|
||||
"\"valueString\": \"ext_url_value\"",
|
||||
"\"code\":"
|
||||
));
|
||||
assertThat(output, not(stringContainsInOrder(
|
||||
"\"url\":\"http://exturl\"",
|
||||
"\"url\": \"http://exturl\"",
|
||||
",",
|
||||
"\"url\":\"http://exturl\""
|
||||
"\"url\": \"http://exturl\""
|
||||
)));
|
||||
//@formatter:on
|
||||
|
||||
|
@ -635,19 +635,19 @@ public class JsonParserDstu3Test {
|
|||
|
||||
//@formatter:off
|
||||
assertThat(output, stringContainsInOrder(
|
||||
"\"id\":\"1\"",
|
||||
"\"id\": \"1\"",
|
||||
"\"meta\"",
|
||||
"\"extension\"",
|
||||
"\"url\":\"http://exturl\"",
|
||||
"\"url\": \"http://exturl\"",
|
||||
"\"extension\"",
|
||||
"\"url\":\"http://subext\"",
|
||||
"\"valueString\":\"sub_ext_value\"",
|
||||
"\"url\": \"http://subext\"",
|
||||
"\"valueString\": \"sub_ext_value\"",
|
||||
"\"code\":"
|
||||
));
|
||||
assertThat(output, not(stringContainsInOrder(
|
||||
"\"url\":\"http://exturl\"",
|
||||
"\"url\": \"http://exturl\"",
|
||||
",",
|
||||
"\"url\":\"http://exturl\""
|
||||
"\"url\": \"http://exturl\""
|
||||
)));
|
||||
//@formatter:on
|
||||
|
||||
|
@ -687,7 +687,7 @@ public class JsonParserDstu3Test {
|
|||
String enc = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(reqParms);
|
||||
ourLog.info(enc);
|
||||
|
||||
assertThat(enc, containsString("\"valueId\":\"1\""));
|
||||
assertThat(enc, containsString("\"valueId\": \"1\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -705,7 +705,7 @@ public class JsonParserDstu3Test {
|
|||
ourLog.info(encoded);
|
||||
|
||||
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, containsString("family"));
|
||||
assertThat(encoded, not(containsString("maritalStatus")));
|
||||
|
@ -726,7 +726,7 @@ public class JsonParserDstu3Test {
|
|||
|
||||
assertThat(encoded, containsString("Patient"));
|
||||
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, containsString("family"));
|
||||
assertThat(encoded, not(containsString("maritalStatus")));
|
||||
|
@ -924,9 +924,22 @@ public class JsonParserDstu3Test {
|
|||
*/
|
||||
@Test
|
||||
public void testExplanationOfBenefit() {
|
||||
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:off
|
||||
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);
|
||||
assertEquals(Reference.class, eob.getCoverage().getCoverage().getClass());
|
||||
|
||||
|
@ -1281,7 +1294,7 @@ public class JsonParserDstu3Test {
|
|||
|
||||
//@formatter:off
|
||||
assertThat(encoded, stringContainsInOrder(
|
||||
"\"identifier\":[",
|
||||
"\"identifier\": [",
|
||||
"{",
|
||||
"\"fhir_comments\":",
|
||||
"[",
|
||||
|
@ -1289,8 +1302,8 @@ public class JsonParserDstu3Test {
|
|||
",",
|
||||
"\"identifier comment 2\"",
|
||||
"]",
|
||||
"\"use\":\"usual\",",
|
||||
"\"_use\":{",
|
||||
"\"use\": \"usual\",",
|
||||
"\"_use\": {",
|
||||
"\"fhir_comments\":",
|
||||
"[",
|
||||
"\"use comment 1\"",
|
||||
|
@ -1372,9 +1385,24 @@ public class JsonParserDstu3Test {
|
|||
/**
|
||||
* See #342
|
||||
*/
|
||||
@Test(expected = DataFormatException.class)
|
||||
@Test()
|
||||
public void testParseInvalid() {
|
||||
ourCtx.newJsonParser().parseResource("FOO");
|
||||
try {
|
||||
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
|
||||
|
@ -1440,6 +1468,18 @@ public class JsonParserDstu3Test {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
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
|
||||
*/
|
||||
|
|
|
@ -1893,7 +1893,7 @@ public class XmlParserDstu3Test {
|
|||
|
||||
//@formatter:off
|
||||
assertThat(encoded, stringContainsInOrder(
|
||||
"\"identifier\":[",
|
||||
"\"identifier\": [",
|
||||
"{",
|
||||
"\"fhir_comments\":",
|
||||
"[",
|
||||
|
@ -1901,8 +1901,8 @@ public class XmlParserDstu3Test {
|
|||
",",
|
||||
"\"identifier comment 2\"",
|
||||
"]",
|
||||
"\"use\":\"usual\",",
|
||||
"\"_use\":{",
|
||||
"\"use\": \"usual\",",
|
||||
"\"_use\": {",
|
||||
"\"fhir_comments\":",
|
||||
"[",
|
||||
"\"use comment 1\"",
|
||||
|
@ -1998,34 +1998,34 @@ public class XmlParserDstu3Test {
|
|||
|
||||
assertThat(output, stringContainsInOrder(
|
||||
"{",
|
||||
" \"resourceType\":\"Patient\",",
|
||||
" \"id\":\"someid\",",
|
||||
" \"_id\":{",
|
||||
" \"fhir_comments\":[",
|
||||
" \"resourceType\": \"Patient\",",
|
||||
" \"id\": \"someid\",",
|
||||
" \"_id\": {",
|
||||
" \"fhir_comments\": [",
|
||||
" \" comment 1 \"",
|
||||
" ]",
|
||||
" },",
|
||||
" \"extension\":[",
|
||||
" \"extension\": [",
|
||||
" {",
|
||||
" \"fhir_comments\":[",
|
||||
" \"fhir_comments\": [",
|
||||
" \" comment 2 \",",
|
||||
" \" comment 7 \"",
|
||||
" ],",
|
||||
" \"url\":\"urn:patientext:att\",",
|
||||
" \"valueAttachment\":{",
|
||||
" \"fhir_comments\":[",
|
||||
" \"url\": \"urn:patientext:att\",",
|
||||
" \"valueAttachment\": {",
|
||||
" \"fhir_comments\": [",
|
||||
" \" comment 3 \",",
|
||||
" \" comment 6 \"",
|
||||
" ],",
|
||||
" \"contentType\":\"aaaa\",",
|
||||
" \"_contentType\":{",
|
||||
" \"fhir_comments\":[",
|
||||
" \"contentType\": \"aaaa\",",
|
||||
" \"_contentType\": {",
|
||||
" \"fhir_comments\": [",
|
||||
" \" comment 4 \"",
|
||||
" ]",
|
||||
" },",
|
||||
" \"data\":\"AAAA\",",
|
||||
" \"_data\":{",
|
||||
" \"fhir_comments\":[",
|
||||
" \"data\": \"AAAA\",",
|
||||
" \"_data\": {",
|
||||
" \"fhir_comments\": [",
|
||||
" \" comment 5 \"",
|
||||
" ]",
|
||||
" }",
|
||||
|
|
|
@ -52,12 +52,6 @@
|
|||
<version>9.6.0-4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Testing -->
|
||||
<dependency>
|
||||
<groupId>xmlunit</groupId>
|
||||
|
|
|
@ -259,17 +259,17 @@ public class JsonParserHl7OrgDstu2Test {
|
|||
|
||||
//@formatter:off
|
||||
String[] strings = new String[] {
|
||||
"\"resourceType\":\"Bundle\",",
|
||||
"\"lastUpdated\":\"" + pub.getValueAsString() + "\"",
|
||||
"\"entry\":[",
|
||||
"\"resource\":{",
|
||||
"\"id\":\"1\"",
|
||||
"\"resource\":{",
|
||||
"\"id\":\"2\"",
|
||||
"\"resource\":{",
|
||||
"\"id\":\"3\"",
|
||||
"\"meta\":{",
|
||||
"\"lastUpdated\":\"" + nowDt.getValueAsString() + "\""
|
||||
"\"resourceType\": \"Bundle\",",
|
||||
"\"lastUpdated\": \"" + pub.getValueAsString() + "\"",
|
||||
"\"entry\": [",
|
||||
"\"resource\": {",
|
||||
"\"id\": \"1\"",
|
||||
"\"resource\": {",
|
||||
"\"id\": \"2\"",
|
||||
"\"resource\": {",
|
||||
"\"id\": \"3\"",
|
||||
"\"meta\": {",
|
||||
"\"lastUpdated\": \"" + nowDt.getValueAsString() + "\""
|
||||
};
|
||||
//@formatter:off
|
||||
assertThat(bundleString, StringContainsInOrder.stringContainsInOrder(strings));
|
||||
|
@ -351,7 +351,7 @@ public class JsonParserHl7OrgDstu2Test {
|
|||
|
||||
String encoded = jsonParser.encodeResourceToString(patient);
|
||||
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
|
||||
Bundle b = new Bundle();
|
||||
|
@ -360,7 +360,7 @@ public class JsonParserHl7OrgDstu2Test {
|
|||
// Encode the bundle
|
||||
encoded = jsonParser.encodeResourceToString(b);
|
||||
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
|
||||
patient = (Patient) jsonParser.parseResource(jsonParser.encodeResourceToString(patient));
|
||||
|
@ -374,7 +374,7 @@ public class JsonParserHl7OrgDstu2Test {
|
|||
// And re-encode a second time
|
||||
encoded = jsonParser.encodeResourceToString(patient);
|
||||
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\":"))));
|
||||
|
||||
// And re-encode once more, with the references cleared
|
||||
|
@ -382,7 +382,7 @@ public class JsonParserHl7OrgDstu2Test {
|
|||
patient.getManagingOrganization().setReference(null);
|
||||
encoded = jsonParser.encodeResourceToString(patient);
|
||||
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\":"))));
|
||||
|
||||
// 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"));
|
||||
encoded = jsonParser.encodeResourceToString(patient);
|
||||
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\":"))));
|
||||
|
||||
}
|
||||
|
@ -415,13 +415,13 @@ public class JsonParserHl7OrgDstu2Test {
|
|||
// Encode the buntdle
|
||||
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(b);
|
||||
ourLog.info(encoded);
|
||||
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\"", "resourceType\":\"Organization", "id\":\"1\"")));
|
||||
assertThat(encoded, containsString("reference\":\"#1\""));
|
||||
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\"", "resourceType\": \"Organization", "id\": \"1\"")));
|
||||
assertThat(encoded, containsString("reference\": \"#1\""));
|
||||
|
||||
encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient);
|
||||
ourLog.info(encoded);
|
||||
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\"", "resourceType\":\"Organization", "id\":\"1\"")));
|
||||
assertThat(encoded, containsString("reference\":\"#1\""));
|
||||
assertThat(encoded, stringContainsInOrder(Arrays.asList("\"contained\"", "resourceType\": \"Organization", "id\": \"1\"")));
|
||||
assertThat(encoded, containsString("reference\": \"#1\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -437,13 +437,13 @@ public class JsonParserHl7OrgDstu2Test {
|
|||
|
||||
ourLog.info(str);
|
||||
assertThat(str, StringContains.containsString("<div>AAA</div>"));
|
||||
String substring = "\"reference\":\"#";
|
||||
String substring = "\"reference\": \"#";
|
||||
assertThat(str, StringContains.containsString(substring));
|
||||
|
||||
int idx = str.indexOf(substring) + substring.length();
|
||||
int idx2 = str.indexOf('"', idx + 1);
|
||||
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'?>")));
|
||||
|
||||
}
|
||||
|
@ -641,7 +641,7 @@ public class JsonParserHl7OrgDstu2Test {
|
|||
String enc = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(list);
|
||||
ourLog.info(enc);
|
||||
|
||||
assertThat(enc, containsString("\"id\":\"1\""));
|
||||
assertThat(enc, containsString("\"id\": \"1\""));
|
||||
|
||||
List_ parsed = ourCtx.newJsonParser().parseResource(List_.class,enc);
|
||||
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);
|
||||
ourLog.info(encoded);
|
||||
assertThat(encoded, not(containsString("contained")));
|
||||
assertThat(encoded, containsString("\"reference\":\"Organization/65546\""));
|
||||
assertThat(encoded, containsString("\"reference\": \"Organization/65546\""));
|
||||
|
||||
encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient);
|
||||
ourLog.info(encoded);
|
||||
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, 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, containsString("family"));
|
||||
assertThat(encoded, not(containsString("maritalStatus")));
|
||||
|
@ -768,8 +768,8 @@ public class JsonParserHl7OrgDstu2Test {
|
|||
|
||||
assertThat(encoded, containsString("Patient"));
|
||||
assertThat(encoded, stringContainsInOrder("\"tag\"",
|
||||
"\"system\":\"foo\",", "\"code\":\"bar\"",
|
||||
"\"system\":\"" + Constants.TAG_SUBSETTED_SYSTEM + "\",", "\"code\":\"" + Constants.TAG_SUBSETTED_CODE+"\","));
|
||||
"\"system\": \"foo\",", "\"code\": \"bar\"",
|
||||
"\"system\": \"" + Constants.TAG_SUBSETTED_SYSTEM + "\",", "\"code\": \"" + Constants.TAG_SUBSETTED_CODE+"\","));
|
||||
assertThat(encoded, not(containsString("THE DIV")));
|
||||
assertThat(encoded, containsString("family"));
|
||||
assertThat(encoded, not(containsString("maritalStatus")));
|
||||
|
@ -1036,7 +1036,7 @@ public class JsonParserHl7OrgDstu2Test {
|
|||
String str = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(A);
|
||||
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
|
||||
int idx0 = str.indexOf("\"contained\"");
|
||||
|
@ -1104,13 +1104,7 @@ public class JsonParserHl7OrgDstu2Test {
|
|||
@Test
|
||||
public void testParseSingleQuotes() {
|
||||
ourCtx.newJsonParser().parseResource(Bundle.class, "{ \"resourceType\": \"Bundle\" }");
|
||||
|
||||
try {
|
||||
ourCtx.newJsonParser().parseResource(Bundle.class, "{ 'resourceType': 'Bundle' }");
|
||||
fail();
|
||||
} catch (DataFormatException e) {
|
||||
// good
|
||||
}
|
||||
ourCtx.newJsonParser().parseResource(Bundle.class, "{ 'resourceType': 'Bundle' }");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.isNotBlank;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.stream.JsonGenerator;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
|
@ -29,6 +28,8 @@ import org.springframework.ui.ModelMap;
|
|||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.context.FhirVersionEnum;
|
||||
import ca.uhn.fhir.context.RuntimeResourceDefinition;
|
||||
|
@ -375,14 +376,14 @@ public class Controller extends BaseController {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
@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);
|
||||
|
||||
StringWriter clientCodeJsonStringWriter = new StringWriter();
|
||||
JsonGenerator clientCodeJsonWriter = Json.createGenerator(clientCodeJsonStringWriter);
|
||||
clientCodeJsonWriter.writeStartObject();
|
||||
clientCodeJsonWriter.write("action", "search");
|
||||
clientCodeJsonWriter.write("base", (String) theModel.get("base"));
|
||||
JsonWriter clientCodeJsonWriter = new JsonWriter(clientCodeJsonStringWriter);
|
||||
clientCodeJsonWriter.beginObject();
|
||||
clientCodeJsonWriter.name("action");clientCodeJsonWriter.value("search");
|
||||
clientCodeJsonWriter.name("base");clientCodeJsonWriter.value((String) theModel.get("base"));
|
||||
|
||||
CaptureInterceptor interceptor = new CaptureInterceptor();
|
||||
GenericClient client = theRequest.newClient(theReq, getContext(theRequest), myConfig, interceptor);
|
||||
|
@ -396,27 +397,28 @@ public class Controller extends BaseController {
|
|||
theModel.put("errorMsg", e.toString());
|
||||
return "resource";
|
||||
}
|
||||
clientCodeJsonWriter.write("resource", theReq.getParameter("resource"));
|
||||
clientCodeJsonWriter.name("resource");clientCodeJsonWriter.value(theReq.getParameter("resource"));
|
||||
} else {
|
||||
query = search.forAllResources();
|
||||
clientCodeJsonWriter.writeNull("resource");
|
||||
clientCodeJsonWriter.name("resource");clientCodeJsonWriter.nullValue();
|
||||
}
|
||||
|
||||
if (client.getPrettyPrint() != null) {
|
||||
clientCodeJsonWriter.write("pretty", client.getPrettyPrint().toString());
|
||||
clientCodeJsonWriter.name("pretty");clientCodeJsonWriter.value( client.getPrettyPrint().toString());
|
||||
} else {
|
||||
clientCodeJsonWriter.writeNull("pretty");
|
||||
clientCodeJsonWriter.name("pretty");clientCodeJsonWriter.nullValue();
|
||||
}
|
||||
|
||||
if (client.getEncoding() != null) {
|
||||
clientCodeJsonWriter.write("format", client.getEncoding().getRequestContentType());
|
||||
clientCodeJsonWriter.name("format");clientCodeJsonWriter.value(client.getEncoding().getRequestContentType());
|
||||
} else {
|
||||
clientCodeJsonWriter.writeNull("format");
|
||||
clientCodeJsonWriter.name("format");clientCodeJsonWriter.nullValue();
|
||||
}
|
||||
|
||||
String outcomeDescription = "Search for Resources";
|
||||
|
||||
clientCodeJsonWriter.writeStartArray("params");
|
||||
clientCodeJsonWriter.name("params");
|
||||
clientCodeJsonWriter.beginArray();
|
||||
int paramIdx = -1;
|
||||
while (true) {
|
||||
paramIdx++;
|
||||
|
@ -427,31 +429,33 @@ public class Controller extends BaseController {
|
|||
break;
|
||||
}
|
||||
}
|
||||
clientCodeJsonWriter.writeEnd();
|
||||
clientCodeJsonWriter.endArray();
|
||||
|
||||
clientCodeJsonWriter.writeStartArray("includes");
|
||||
clientCodeJsonWriter.name("includes");
|
||||
clientCodeJsonWriter.beginArray();
|
||||
String[] incValues = theReq.getParameterValues(Constants.PARAM_INCLUDE);
|
||||
if (incValues != null) {
|
||||
for (String next : incValues) {
|
||||
if (isNotBlank(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);
|
||||
if (revIncValues != null) {
|
||||
for (String next : revIncValues) {
|
||||
if (isNotBlank(next)) {
|
||||
query.revInclude(new Include(next));
|
||||
clientCodeJsonWriter.write(next);
|
||||
clientCodeJsonWriter.value(next);
|
||||
}
|
||||
}
|
||||
}
|
||||
clientCodeJsonWriter.writeEnd();
|
||||
clientCodeJsonWriter.endArray();
|
||||
|
||||
String limit = theReq.getParameter("resource-search-limit");
|
||||
if (isNotBlank(limit)) {
|
||||
|
@ -461,9 +465,9 @@ public class Controller extends BaseController {
|
|||
}
|
||||
int limitInt = Integer.parseInt(limit);
|
||||
query.limitTo(limitInt);
|
||||
clientCodeJsonWriter.write("limit", limit);
|
||||
clientCodeJsonWriter.name("limit");clientCodeJsonWriter.value(limit);
|
||||
} else {
|
||||
clientCodeJsonWriter.writeNull("limit");
|
||||
clientCodeJsonWriter.name("limit");clientCodeJsonWriter.nullValue();
|
||||
}
|
||||
|
||||
String[] sort = theReq.getParameterValues("sort_by");
|
||||
|
@ -501,7 +505,7 @@ public class Controller extends BaseController {
|
|||
|
||||
processAndAddLastClientInvocation(client, returnsResource, theModel, delay, outcomeDescription, interceptor, theRequest);
|
||||
|
||||
clientCodeJsonWriter.writeEnd();
|
||||
clientCodeJsonWriter.endObject();
|
||||
clientCodeJsonWriter.close();
|
||||
String clientCodeJson = clientCodeJsonStringWriter.toString();
|
||||
theModel.put("clientCodeJson", clientCodeJson);
|
||||
|
@ -837,7 +841,7 @@ public class Controller extends BaseController {
|
|||
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");
|
||||
if (isBlank(nextName)) {
|
||||
return false;
|
||||
|
@ -921,12 +925,12 @@ public class Controller extends BaseController {
|
|||
|
||||
for (String nextValue : values) {
|
||||
|
||||
theClientCodeJsonWriter.writeStartObject();
|
||||
theClientCodeJsonWriter.write("type", nextType);
|
||||
theClientCodeJsonWriter.write("name", nextName);
|
||||
theClientCodeJsonWriter.write("qualifier", nextQualifier);
|
||||
theClientCodeJsonWriter.write("value", nextValue);
|
||||
theClientCodeJsonWriter.writeEnd();
|
||||
theClientCodeJsonWriter.beginObject();
|
||||
theClientCodeJsonWriter.name("type");theClientCodeJsonWriter.value(nextType);
|
||||
theClientCodeJsonWriter.name("name");theClientCodeJsonWriter.value(nextName);
|
||||
theClientCodeJsonWriter.name("qualifier");theClientCodeJsonWriter.value(nextQualifier);
|
||||
theClientCodeJsonWriter.name("value");theClientCodeJsonWriter.value(nextValue);
|
||||
theClientCodeJsonWriter.endObject();
|
||||
if (addToWhere) {
|
||||
theQuery.where(new StringClientParam(nextName + nextQualifier).matches().value(nextValue));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue