|
|
|
@ -5,18 +5,13 @@ import static org.hamcrest.Matchers.containsString;
|
|
|
|
|
import static org.hamcrest.Matchers.empty;
|
|
|
|
|
import static org.hamcrest.Matchers.not;
|
|
|
|
|
import static org.hamcrest.Matchers.stringContainsInOrder;
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
|
import static org.junit.Assert.assertNull;
|
|
|
|
|
import static org.junit.Assert.assertSame;
|
|
|
|
|
import static org.junit.Assert.assertThat;
|
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
import static org.junit.Assert.fail;
|
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
@ -24,6 +19,7 @@ import java.util.UUID;
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
|
import org.hamcrest.Matchers;
|
|
|
|
|
import org.hamcrest.core.StringContains;
|
|
|
|
|
import org.hl7.fhir.dstu3.exceptions.FHIRException;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Address.AddressUse;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Address.AddressUseEnumFactory;
|
|
|
|
|
import org.hl7.fhir.dstu3.model.Attachment;
|
|
|
|
@ -79,6 +75,8 @@ import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
|
|
|
|
|
import ca.uhn.fhir.parser.PatientWithExtendedContactDstu3.CustomContactComponent;
|
|
|
|
|
import ca.uhn.fhir.rest.server.Constants;
|
|
|
|
|
import ca.uhn.fhir.util.TestUtil;
|
|
|
|
|
import ca.uhn.fhir.validation.FhirValidator;
|
|
|
|
|
import ca.uhn.fhir.validation.ValidationResult;
|
|
|
|
|
import net.sf.json.JSON;
|
|
|
|
|
import net.sf.json.JSONSerializer;
|
|
|
|
|
import net.sf.json.JsonConfig;
|
|
|
|
@ -113,30 +111,51 @@ public class JsonParserDstu3Test {
|
|
|
|
|
ourLog.info(output);
|
|
|
|
|
assertThat(output, containsString("\"div\": \"<div xmlns=\\\"http://www.w3.org/1999/xhtml\\\">VALUE</div>\""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testValidateCustomStructure() throws Exception {
|
|
|
|
|
|
|
|
|
|
FooMessageHeader.FooMessageSourceComponent source = new FooMessageHeader.FooMessageSourceComponent();
|
|
|
|
|
source.getMessageHeaderApplicationId().setValue("APPID");
|
|
|
|
|
source.setName("NAME");
|
|
|
|
|
source.setEndpoint("http://foo");
|
|
|
|
|
|
|
|
|
|
FooMessageHeader header = new FooMessageHeader();
|
|
|
|
|
header.setTimestamp(new Date());
|
|
|
|
|
header.getEvent().setSystem("http://system").setCode("value");
|
|
|
|
|
header.setSource(source);
|
|
|
|
|
|
|
|
|
|
FhirValidator val = ourCtx.newValidator();
|
|
|
|
|
val.setValidateAgainstStandardSchema(true);
|
|
|
|
|
val.setValidateAgainstStandardSchematron(true);
|
|
|
|
|
|
|
|
|
|
ValidationResult result = val.validateWithResult(header);
|
|
|
|
|
|
|
|
|
|
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome()));
|
|
|
|
|
assertTrue(result.isSuccessful());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testEncodeUndeclaredBlock() throws Exception {
|
|
|
|
|
FooMessageHeader.FooMessageSourceComponent source = new FooMessageHeader.FooMessageSourceComponent();
|
|
|
|
|
source.getMessageHeaderApplicationId().setValue("APPID");
|
|
|
|
|
source.setName("NAME");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FooMessageHeader header = new FooMessageHeader();
|
|
|
|
|
header.setSource(source);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
|
bundle.addEntry().setResource(header);
|
|
|
|
|
|
|
|
|
|
IParser p = ourCtx.newJsonParser();
|
|
|
|
|
p.setPrettyPrint(true);
|
|
|
|
|
|
|
|
|
|
String encode = p.encodeResourceToString(bundle);
|
|
|
|
|
ourLog.info(encode);
|
|
|
|
|
|
|
|
|
|
assertThat(encode, containsString("\"value\": \"APPID\""));
|
|
|
|
|
IParser p = ourCtx.newJsonParser();
|
|
|
|
|
p.setPrettyPrint(true);
|
|
|
|
|
|
|
|
|
|
String encode = p.encodeResourceToString(bundle);
|
|
|
|
|
ourLog.info(encode);
|
|
|
|
|
|
|
|
|
|
assertThat(encode, containsString("\"value\": \"APPID\""));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* See #344
|
|
|
|
|
*/
|
|
|
|
@ -728,8 +747,8 @@ public class JsonParserDstu3Test {
|
|
|
|
|
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")));
|
|
|
|
@ -947,7 +966,7 @@ public class JsonParserDstu3Test {
|
|
|
|
|
|
|
|
|
|
PatientWithExtendedContactDstu3 patient = new PatientWithExtendedContactDstu3();
|
|
|
|
|
patient.setId("123");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CustomContactComponent customContactComponent = new CustomContactComponent();
|
|
|
|
|
customContactComponent.getEyeColour().setValue("EYE");
|
|
|
|
|
customContactComponent.getName().addFamily("FAMILY");
|
|
|
|
@ -955,8 +974,10 @@ public class JsonParserDstu3Test {
|
|
|
|
|
|
|
|
|
|
String val = parser.encodeResourceToString(patient);
|
|
|
|
|
ourLog.info(val);
|
|
|
|
|
|
|
|
|
|
assertEquals("{\"resourceType\":\"Patient\",\"id\":\"123\",\"contact\":[{\"extension\":[{\"url\":\"http://foo.com/contact-eyecolour\",\"valueIdentifier\":{\"value\":\"EYE\"}}],\"name\":{\"family\":[\"FAMILY\"]}}]}", val);
|
|
|
|
|
|
|
|
|
|
assertEquals(
|
|
|
|
|
"{\"resourceType\":\"Patient\",\"id\":\"123\",\"contact\":[{\"extension\":[{\"url\":\"http://foo.com/contact-eyecolour\",\"valueIdentifier\":{\"value\":\"EYE\"}}],\"name\":{\"family\":[\"FAMILY\"]}}]}",
|
|
|
|
|
val);
|
|
|
|
|
|
|
|
|
|
FhirContext newCtx = FhirContext.forDstu3();
|
|
|
|
|
PatientWithExtendedContactDstu3 actual = newCtx.newJsonParser().parseResource(PatientWithExtendedContactDstu3.class, val);
|
|
|
|
@ -1087,7 +1108,7 @@ public class JsonParserDstu3Test {
|
|
|
|
|
" }\n" +
|
|
|
|
|
"}";
|
|
|
|
|
//@formatter:on
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ExplanationOfBenefit eob = ourCtx.newJsonParser().parseResource(ExplanationOfBenefit.class, input);
|
|
|
|
|
assertEquals(Reference.class, eob.getCoverage().getCoverage().getClass());
|
|
|
|
|
|
|
|
|
@ -1192,7 +1213,6 @@ public class JsonParserDstu3Test {
|
|
|
|
|
assertThat(ourCtx.newJsonParser().setOmitResourceId(true).encodeResourceToString(p), not(containsString("123")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@Ignore
|
|
|
|
|
public void testParseAndEncodeBundle() throws Exception {
|
|
|
|
@ -1410,7 +1430,6 @@ public class JsonParserDstu3Test {
|
|
|
|
|
assertEquals(StringType.class, comm.getPayload().get(2).getContent().getClass());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testParseAndEncodeComments() throws IOException {
|
|
|
|
|
//@formatter:off
|
|
|
|
@ -1563,10 +1582,9 @@ public class JsonParserDstu3Test {
|
|
|
|
|
} 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
|
|
|
|
@ -1632,7 +1650,7 @@ public class JsonParserDstu3Test {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test(expected=DataFormatException.class)
|
|
|
|
|
@Test(expected = DataFormatException.class)
|
|
|
|
|
public void testParseWithTrailingContent() throws Exception {
|
|
|
|
|
//@formatter:off
|
|
|
|
|
String bundle = "{\n" +
|
|
|
|
@ -1643,7 +1661,7 @@ public class JsonParserDstu3Test {
|
|
|
|
|
|
|
|
|
|
Bundle b = ourCtx.newJsonParser().parseResource(Bundle.class, bundle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* See #163
|
|
|
|
|
*/
|
|
|
|
|