Add custom type test
This commit is contained in:
parent
d4baf38656
commit
d7fdaf7618
|
@ -73,6 +73,7 @@ import com.google.common.collect.Sets;
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
|
import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator;
|
||||||
|
import ca.uhn.fhir.parser.PatientWithExtendedContactDstu3.CustomContactComponent;
|
||||||
import ca.uhn.fhir.rest.server.Constants;
|
import ca.uhn.fhir.rest.server.Constants;
|
||||||
import ca.uhn.fhir.util.TestUtil;
|
import ca.uhn.fhir.util.TestUtil;
|
||||||
import net.sf.json.JSON;
|
import net.sf.json.JSON;
|
||||||
|
@ -87,30 +88,29 @@ public class JsonParserDstu3Test {
|
||||||
public void after() {
|
public void after() {
|
||||||
ourCtx.setNarrativeGenerator(null);
|
ourCtx.setNarrativeGenerator(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeNarrativeShouldIncludeNamespace() {
|
public void testEncodeNarrativeShouldIncludeNamespace() {
|
||||||
|
|
||||||
Patient p = new Patient();
|
Patient p = new Patient();
|
||||||
p.getText().setDivAsString("<div>VALUE</div>");
|
p.getText().setDivAsString("<div>VALUE</div>");
|
||||||
|
|
||||||
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
|
||||||
public void testEncodeNarrativeShouldIncludeNamespaceWithProcessingInstruction() {
|
public void testEncodeNarrativeShouldIncludeNamespaceWithProcessingInstruction() {
|
||||||
|
|
||||||
Patient p = new Patient();
|
Patient p = new Patient();
|
||||||
p.getText().setDivAsString("<?xml version=\"1.0\" encoding=\"UTF-8\"?><div>VALUE</div>");
|
p.getText().setDivAsString("<?xml version=\"1.0\" encoding=\"UTF-8\"?><div>VALUE</div>");
|
||||||
|
|
||||||
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>\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See #344
|
* See #344
|
||||||
*/
|
*/
|
||||||
|
@ -122,13 +122,13 @@ public class JsonParserDstu3Test {
|
||||||
data.setOrigin((SimpleQuantity) new SimpleQuantity().setValue(0L));
|
data.setOrigin((SimpleQuantity) new SimpleQuantity().setValue(0L));
|
||||||
data.setPeriod(1000L);
|
data.setPeriod(1000L);
|
||||||
obs.setValue(data);
|
obs.setValue(data);
|
||||||
|
|
||||||
IParser p = ourCtx.newJsonParser().setPrettyPrint(true).setParserErrorHandler(new StrictErrorHandler());
|
IParser p = ourCtx.newJsonParser().setPrettyPrint(true).setParserErrorHandler(new StrictErrorHandler());
|
||||||
String encoded = p.encodeResourceToString(obs);
|
String encoded = p.encodeResourceToString(obs);
|
||||||
ourLog.info(encoded);
|
ourLog.info(encoded);
|
||||||
|
|
||||||
p.parseResource(encoded);
|
p.parseResource(encoded);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
p.parseResource(encoded.replace("Observation", "observation"));
|
p.parseResource(encoded.replace("Observation", "observation"));
|
||||||
fail();
|
fail();
|
||||||
|
@ -143,9 +143,7 @@ public class JsonParserDstu3Test {
|
||||||
assertEquals("Unknown element 'valueSampleddata' found during parse", e.getMessage());
|
assertEquals("Unknown element 'valueSampleddata' found during parse", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeAndParseExtensions() throws Exception {
|
public void testEncodeAndParseExtensions() throws Exception {
|
||||||
|
|
||||||
|
@ -189,8 +187,10 @@ public class JsonParserDstu3Test {
|
||||||
assertThat(enc, Matchers.stringContainsInOrder("{\"resourceType\":\"Patient\",", "\"extension\":[{\"url\":\"http://example.com/extensions#someext\",\"valueDateTime\":\"2011-01-02T11:13:15\"}",
|
assertThat(enc, Matchers.stringContainsInOrder("{\"resourceType\":\"Patient\",", "\"extension\":[{\"url\":\"http://example.com/extensions#someext\",\"valueDateTime\":\"2011-01-02T11:13:15\"}",
|
||||||
"{\"url\":\"http://example.com#parent\",\"extension\":[{\"url\":\"http://example.com#child\",\"valueString\":\"value1\"},{\"url\":\"http://example.com#child\",\"valueString\":\"value2\"}]}"));
|
"{\"url\":\"http://example.com#parent\",\"extension\":[{\"url\":\"http://example.com#child\",\"valueString\":\"value1\"},{\"url\":\"http://example.com#child\",\"valueString\":\"value2\"}]}"));
|
||||||
assertThat(enc, Matchers.stringContainsInOrder("\"modifierExtension\":[" + "{" + "\"url\":\"http://example.com/extensions#modext\"," + "\"valueDate\":\"1995-01-02\"" + "}" + "],"));
|
assertThat(enc, Matchers.stringContainsInOrder("\"modifierExtension\":[" + "{" + "\"url\":\"http://example.com/extensions#modext\"," + "\"valueDate\":\"1995-01-02\"" + "}" + "],"));
|
||||||
assertThat(enc, containsString("\"_given\":[" + "{" + "\"extension\":[" + "{" + "\"url\":\"http://examples.com#givenext\"," + "\"valueString\":\"given\"" + "}" + "]" + "}," + "{" + "\"extension\":[" + "{" + "\"url\":\"http://examples.com#givenext_parent\"," + "\"extension\":[" + "{"
|
assertThat(enc,
|
||||||
+ "\"url\":\"http://examples.com#givenext_child\"," + "\"valueString\":\"CHILD\"" + "}" + "]" + "}" + "]" + "}"));
|
containsString("\"_given\":[" + "{" + "\"extension\":[" + "{" + "\"url\":\"http://examples.com#givenext\"," + "\"valueString\":\"given\"" + "}" + "]" + "}," + "{" + "\"extension\":[" + "{"
|
||||||
|
+ "\"url\":\"http://examples.com#givenext_parent\"," + "\"extension\":[" + "{" + "\"url\":\"http://examples.com#givenext_child\"," + "\"valueString\":\"CHILD\"" + "}" + "]" + "}"
|
||||||
|
+ "]" + "}"));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now parse this back
|
* Now parse this back
|
||||||
|
@ -229,7 +229,7 @@ public class JsonParserDstu3Test {
|
||||||
assertEquals("CHILD", ((StringType) given2ext2.getValue()).getValue());
|
assertEquals("CHILD", ((StringType) given2ext2.getValue()).getValue());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeAndParseMetaProfileAndTags() {
|
public void testEncodeAndParseMetaProfileAndTags() {
|
||||||
Patient p = new Patient();
|
Patient p = new Patient();
|
||||||
|
@ -313,7 +313,7 @@ public class JsonParserDstu3Test {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeAndParseNullPrimitiveWithExtensions() {
|
public void testEncodeAndParseNullPrimitiveWithExtensions() {
|
||||||
|
|
||||||
Patient p = new Patient();
|
Patient p = new Patient();
|
||||||
p.setId("patid");
|
p.setId("patid");
|
||||||
HumanName name = p.addName();
|
HumanName name = p.addName();
|
||||||
|
@ -325,43 +325,42 @@ 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);
|
||||||
|
|
||||||
output = ourCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(p);
|
output = ourCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(p);
|
||||||
String expected = "{\"resourceType\":\"Patient\",\"id\":\"patid\",\"name\":[{\"id\":\"nameid\",\"family\":[null,\"V1\",null],\"_family\":[{\"id\":\"f0\",\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"FOOEXT0\"}]},{\"id\":\"f1\",\"extension\":[{\"id\":\"ext1id\",\"url\":\"http://foo\",\"valueString\":\"FOOEXT1\"}]},{\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"FOOEXT3\"}]}]}]}";
|
String expected = "{\"resourceType\":\"Patient\",\"id\":\"patid\",\"name\":[{\"id\":\"nameid\",\"family\":[null,\"V1\",null],\"_family\":[{\"id\":\"f0\",\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"FOOEXT0\"}]},{\"id\":\"f1\",\"extension\":[{\"id\":\"ext1id\",\"url\":\"http://foo\",\"valueString\":\"FOOEXT1\"}]},{\"extension\":[{\"url\":\"http://foo\",\"valueString\":\"FOOEXT3\"}]}]}]}";
|
||||||
assertEquals(expected, output);
|
assertEquals(expected, output);
|
||||||
|
|
||||||
p = ourCtx.newJsonParser().parseResource(Patient.class, output);
|
p = ourCtx.newJsonParser().parseResource(Patient.class, output);
|
||||||
assertEquals("patid", p.getIdElement().getIdPart());
|
assertEquals("patid", p.getIdElement().getIdPart());
|
||||||
|
|
||||||
name = p.getName().get(0);
|
name = p.getName().get(0);
|
||||||
assertEquals("nameid", name.getId());
|
assertEquals("nameid", name.getId());
|
||||||
assertEquals(3, name.getFamily().size());
|
assertEquals(3, name.getFamily().size());
|
||||||
|
|
||||||
assertEquals(null, name.getFamily().get(0).getValue());
|
assertEquals(null, name.getFamily().get(0).getValue());
|
||||||
assertEquals("V1", name.getFamily().get(1).getValue());
|
assertEquals("V1", name.getFamily().get(1).getValue());
|
||||||
assertEquals(null, name.getFamily().get(2).getValue());
|
assertEquals(null, name.getFamily().get(2).getValue());
|
||||||
|
|
||||||
assertEquals("f0", name.getFamily().get(0).getId());
|
assertEquals("f0", name.getFamily().get(0).getId());
|
||||||
assertEquals("f1", name.getFamily().get(1).getId());
|
assertEquals("f1", name.getFamily().get(1).getId());
|
||||||
assertEquals(null, name.getFamily().get(2).getId());
|
assertEquals(null, name.getFamily().get(2).getId());
|
||||||
|
|
||||||
assertEquals(1, name.getFamily().get(0).getExtension().size());
|
assertEquals(1, name.getFamily().get(0).getExtension().size());
|
||||||
assertEquals("http://foo", name.getFamily().get(0).getExtension().get(0).getUrl());
|
assertEquals("http://foo", name.getFamily().get(0).getExtension().get(0).getUrl());
|
||||||
assertEquals("FOOEXT0", ((StringType)name.getFamily().get(0).getExtension().get(0).getValue()).getValue());
|
assertEquals("FOOEXT0", ((StringType) name.getFamily().get(0).getExtension().get(0).getValue()).getValue());
|
||||||
assertEquals(null, name.getFamily().get(0).getExtension().get(0).getId());
|
assertEquals(null, name.getFamily().get(0).getExtension().get(0).getId());
|
||||||
|
|
||||||
assertEquals(1, name.getFamily().get(1).getExtension().size());
|
assertEquals(1, name.getFamily().get(1).getExtension().size());
|
||||||
assertEquals("http://foo", name.getFamily().get(1).getExtension().get(0).getUrl());
|
assertEquals("http://foo", name.getFamily().get(1).getExtension().get(0).getUrl());
|
||||||
assertEquals("FOOEXT1", ((StringType)name.getFamily().get(1).getExtension().get(0).getValue()).getValue());
|
assertEquals("FOOEXT1", ((StringType) name.getFamily().get(1).getExtension().get(0).getValue()).getValue());
|
||||||
assertEquals("ext1id", name.getFamily().get(1).getExtension().get(0).getId());
|
assertEquals("ext1id", name.getFamily().get(1).getExtension().get(0).getId());
|
||||||
|
|
||||||
assertEquals(1, name.getFamily().get(2).getExtension().size());
|
assertEquals(1, name.getFamily().get(2).getExtension().size());
|
||||||
assertEquals("http://foo", name.getFamily().get(2).getExtension().get(0).getUrl());
|
assertEquals("http://foo", name.getFamily().get(2).getExtension().get(0).getUrl());
|
||||||
assertEquals("FOOEXT3", ((StringType)name.getFamily().get(2).getExtension().get(0).getValue()).getValue());
|
assertEquals("FOOEXT3", ((StringType) name.getFamily().get(2).getExtension().get(0).getValue()).getValue());
|
||||||
assertEquals(null, name.getFamily().get(2).getExtension().get(0).getId());
|
assertEquals(null, name.getFamily().get(2).getExtension().get(0).getId());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeAndParseSecurityLabels() {
|
public void testEncodeAndParseSecurityLabels() {
|
||||||
|
@ -449,10 +448,10 @@ public class JsonParserDstu3Test {
|
||||||
Patient patient = new Patient();
|
Patient patient = new Patient();
|
||||||
patient.getBirthDateElement().setValueAsString("2016-04-05");
|
patient.getBirthDateElement().setValueAsString("2016-04-05");
|
||||||
patient.addExtension().setUrl("test").setValue(new Reference(new Condition()));
|
patient.addExtension().setUrl("test").setValue(new Reference(new Condition()));
|
||||||
|
|
||||||
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient);
|
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient);
|
||||||
ourLog.info(encoded);
|
ourLog.info(encoded);
|
||||||
|
|
||||||
//@formatter:off
|
//@formatter:off
|
||||||
assertThat(encoded, stringContainsInOrder(
|
assertThat(encoded, stringContainsInOrder(
|
||||||
"{",
|
"{",
|
||||||
|
@ -476,7 +475,6 @@ public class JsonParserDstu3Test {
|
||||||
));
|
));
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeDoesntIncludeUuidId() {
|
public void testEncodeDoesntIncludeUuidId() {
|
||||||
|
@ -487,14 +485,13 @@ public class JsonParserDstu3Test {
|
||||||
String actual = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p);
|
String actual = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p);
|
||||||
assertThat(actual, not(containsString("78ef6f64c2f2")));
|
assertThat(actual, not(containsString("78ef6f64c2f2")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeEmptyBinary() {
|
public void testEncodeEmptyBinary() {
|
||||||
String output = ourCtx.newJsonParser().encodeResourceToString(new Binary());
|
String output = ourCtx.newJsonParser().encodeResourceToString(new Binary());
|
||||||
assertEquals("{\"resourceType\":\"Binary\"}", output);
|
assertEquals("{\"resourceType\":\"Binary\"}", output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* #158
|
* #158
|
||||||
*/
|
*/
|
||||||
|
@ -511,7 +508,6 @@ public class JsonParserDstu3Test {
|
||||||
assertThat(encoded, not(containsString("tag")));
|
assertThat(encoded, not(containsString("tag")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* #158
|
* #158
|
||||||
*/
|
*/
|
||||||
|
@ -529,7 +525,7 @@ public class JsonParserDstu3Test {
|
||||||
assertThat(encoded, containsString("scheme"));
|
assertThat(encoded, containsString("scheme"));
|
||||||
assertThat(encoded, not(containsString("Label")));
|
assertThat(encoded, not(containsString("Label")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeExtensionInPrimitiveElement() {
|
public void testEncodeExtensionInPrimitiveElement() {
|
||||||
|
|
||||||
|
@ -559,7 +555,6 @@ public class JsonParserDstu3Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeExtensionUndeclaredNonModifier() {
|
public void testEncodeExtensionUndeclaredNonModifier() {
|
||||||
Observation obs = new Observation();
|
Observation obs = new Observation();
|
||||||
|
@ -567,11 +562,11 @@ public class JsonParserDstu3Test {
|
||||||
obs.getMeta().addProfile("http://profile");
|
obs.getMeta().addProfile("http://profile");
|
||||||
Extension ext = obs.addExtension();
|
Extension ext = obs.addExtension();
|
||||||
ext.setUrl("http://exturl").setValue(new StringType("ext_url_value"));
|
ext.setUrl("http://exturl").setValue(new StringType("ext_url_value"));
|
||||||
|
|
||||||
obs.getCode().setText("CODE");
|
obs.getCode().setText("CODE");
|
||||||
|
|
||||||
IParser parser = ourCtx.newJsonParser();
|
IParser parser = ourCtx.newJsonParser();
|
||||||
|
|
||||||
String output = parser.setPrettyPrint(true).encodeResourceToString(obs);
|
String output = parser.setPrettyPrint(true).encodeResourceToString(obs);
|
||||||
ourLog.info(output);
|
ourLog.info(output);
|
||||||
|
|
||||||
|
@ -590,13 +585,13 @@ public class JsonParserDstu3Test {
|
||||||
"\"url\":\"http://exturl\""
|
"\"url\":\"http://exturl\""
|
||||||
)));
|
)));
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
|
|
||||||
obs = parser.parseResource(Observation.class, output);
|
obs = parser.parseResource(Observation.class, output);
|
||||||
assertEquals(1, obs.getExtension().size());
|
assertEquals(1, obs.getExtension().size());
|
||||||
assertEquals("http://exturl", obs.getExtension().get(0).getUrl());
|
assertEquals("http://exturl", obs.getExtension().get(0).getUrl());
|
||||||
assertEquals("ext_url_value", ((StringType)obs.getExtension().get(0).getValue()).getValue());
|
assertEquals("ext_url_value", ((StringType) obs.getExtension().get(0).getValue()).getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeExtensionUndeclaredNonModifierWithChildExtension() {
|
public void testEncodeExtensionUndeclaredNonModifierWithChildExtension() {
|
||||||
Observation obs = new Observation();
|
Observation obs = new Observation();
|
||||||
|
@ -604,14 +599,14 @@ public class JsonParserDstu3Test {
|
||||||
obs.getMeta().addProfile("http://profile");
|
obs.getMeta().addProfile("http://profile");
|
||||||
Extension ext = obs.addExtension();
|
Extension ext = obs.addExtension();
|
||||||
ext.setUrl("http://exturl");
|
ext.setUrl("http://exturl");
|
||||||
|
|
||||||
Extension subExt = ext.addExtension();
|
Extension subExt = ext.addExtension();
|
||||||
subExt.setUrl("http://subext").setValue(new StringType("sub_ext_value"));
|
subExt.setUrl("http://subext").setValue(new StringType("sub_ext_value"));
|
||||||
|
|
||||||
obs.getCode().setText("CODE");
|
obs.getCode().setText("CODE");
|
||||||
|
|
||||||
IParser parser = ourCtx.newJsonParser();
|
IParser parser = ourCtx.newJsonParser();
|
||||||
|
|
||||||
String output = parser.setPrettyPrint(true).encodeResourceToString(obs);
|
String output = parser.setPrettyPrint(true).encodeResourceToString(obs);
|
||||||
ourLog.info(output);
|
ourLog.info(output);
|
||||||
|
|
||||||
|
@ -632,13 +627,13 @@ public class JsonParserDstu3Test {
|
||||||
"\"url\":\"http://exturl\""
|
"\"url\":\"http://exturl\""
|
||||||
)));
|
)));
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
|
|
||||||
obs = parser.parseResource(Observation.class, output);
|
obs = parser.parseResource(Observation.class, output);
|
||||||
assertEquals(1, obs.getExtension().size());
|
assertEquals(1, obs.getExtension().size());
|
||||||
assertEquals("http://exturl", obs.getExtension().get(0).getUrl());
|
assertEquals("http://exturl", obs.getExtension().get(0).getUrl());
|
||||||
assertEquals(1, obs.getExtension().get(0).getExtension().size());
|
assertEquals(1, obs.getExtension().get(0).getExtension().size());
|
||||||
assertEquals("http://subext", obs.getExtension().get(0).getExtension().get(0).getUrl());
|
assertEquals("http://subext", obs.getExtension().get(0).getExtension().get(0).getUrl());
|
||||||
assertEquals("sub_ext_value", ((StringType)obs.getExtension().get(0).getExtension().get(0).getValue()).getValue());
|
assertEquals("sub_ext_value", ((StringType) obs.getExtension().get(0).getExtension().get(0).getValue()).getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -707,12 +702,13 @@ public class JsonParserDstu3Test {
|
||||||
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")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See #205
|
* See #205
|
||||||
*/
|
*/
|
||||||
|
@ -726,11 +722,11 @@ public class JsonParserDstu3Test {
|
||||||
String enc = ourCtx.newJsonParser().encodeResourceToString(pt);
|
String enc = ourCtx.newJsonParser().encodeResourceToString(pt);
|
||||||
ourLog.info(enc);
|
ourLog.info(enc);
|
||||||
|
|
||||||
assertEquals("{\"resourceType\":\"Patient\",\"meta\":{\"tag\":[{\"system\":\"scheme\",\"code\":\"term\",\"display\":\"display\"}]},\"identifier\":[{\"system\":\"sys\",\"value\":\"val\"}]}", enc);
|
assertEquals("{\"resourceType\":\"Patient\",\"meta\":{\"tag\":[{\"system\":\"scheme\",\"code\":\"term\",\"display\":\"display\"}]},\"identifier\":[{\"system\":\"sys\",\"value\":\"val\"}]}",
|
||||||
|
enc);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See #241
|
* See #241
|
||||||
*/
|
*/
|
||||||
|
@ -746,43 +742,66 @@ public class JsonParserDstu3Test {
|
||||||
String json = parser.encodeResourceToString(bundle);
|
String json = parser.encodeResourceToString(bundle);
|
||||||
ourLog.info(json);
|
ourLog.info(json);
|
||||||
bundle = (Bundle) parser.parseResource(json);
|
bundle = (Bundle) parser.parseResource(json);
|
||||||
|
|
||||||
assertEquals("123", bundle.getEntry().get(0).getId());
|
assertEquals("123", bundle.getEntry().get(0).getId());
|
||||||
|
|
||||||
condition = (Condition) bundle.getEntry().get(0).getResource();
|
condition = (Condition) bundle.getEntry().get(0).getResource();
|
||||||
assertEquals(null, condition.getId());
|
assertEquals(null, condition.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeUndeclaredExtensionWithEnumerationContent() {
|
public void testEncodeUndeclaredExtensionWithEnumerationContent() {
|
||||||
IParser parser = ourCtx.newJsonParser();
|
IParser parser = ourCtx.newJsonParser();
|
||||||
|
|
||||||
Patient patient = new Patient();
|
Patient patient = new Patient();
|
||||||
patient.addAddress().setUse(AddressUse.HOME);
|
patient.addAddress().setUse(AddressUse.HOME);
|
||||||
EnumFactory<AddressUse> fact = new AddressUseEnumFactory();
|
EnumFactory<AddressUse> fact = new AddressUseEnumFactory();
|
||||||
PrimitiveType<AddressUse> enumeration = new Enumeration<AddressUse>(fact).setValue(AddressUse.HOME);
|
PrimitiveType<AddressUse> enumeration = new Enumeration<AddressUse>(fact).setValue(AddressUse.HOME);
|
||||||
patient.addExtension().setUrl("urn:foo").setValue(enumeration);
|
patient.addExtension().setUrl("urn:foo").setValue(enumeration);
|
||||||
|
|
||||||
String val = parser.encodeResourceToString(patient);
|
String val = parser.encodeResourceToString(patient);
|
||||||
ourLog.info(val);
|
ourLog.info(val);
|
||||||
assertThat(val, StringContains.containsString("\"extension\":[{\"url\":\"urn:foo\",\"valueCode\":\"home\"}]"));
|
assertThat(val, StringContains.containsString("\"extension\":[{\"url\":\"urn:foo\",\"valueCode\":\"home\"}]"));
|
||||||
|
|
||||||
MyPatientWithOneDeclaredEnumerationExtensionDstu3 actual = parser.parseResource(MyPatientWithOneDeclaredEnumerationExtensionDstu3.class, val);
|
MyPatientWithOneDeclaredEnumerationExtensionDstu3 actual = parser.parseResource(MyPatientWithOneDeclaredEnumerationExtensionDstu3.class, val);
|
||||||
assertEquals(AddressUse.HOME, patient.getAddress().get(0).getUse());
|
assertEquals(AddressUse.HOME, patient.getAddress().get(0).getUse());
|
||||||
Enumeration<AddressUse> ref = actual.getFoo();
|
Enumeration<AddressUse> ref = actual.getFoo();
|
||||||
assertEquals("home", ref.getValue().toCode());
|
assertEquals("home", ref.getValue().toCode());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEncodeExtendedInfrastructureComponent() {
|
||||||
|
IParser parser = ourCtx.newJsonParser();
|
||||||
|
|
||||||
|
PatientWithExtendedContactDstu3 patient = new PatientWithExtendedContactDstu3();
|
||||||
|
patient.setId("123");
|
||||||
|
|
||||||
|
CustomContactComponent customContactComponent = new CustomContactComponent();
|
||||||
|
customContactComponent.getEyeColour().setValue("EYE");
|
||||||
|
customContactComponent.getName().addFamily("FAMILY");
|
||||||
|
patient.getCustomContact().add(customContactComponent);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
FhirContext newCtx = FhirContext.forDstu3();
|
||||||
|
PatientWithExtendedContactDstu3 actual = newCtx.newJsonParser().parseResource(PatientWithExtendedContactDstu3.class, val);
|
||||||
|
assertEquals("EYE", actual.getCustomContact().get(0).getEyeColour().getValue());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeWithDontEncodeElements() throws Exception {
|
public void testEncodeWithDontEncodeElements() throws Exception {
|
||||||
Patient patient = new Patient();
|
Patient patient = new Patient();
|
||||||
patient.setId("123");
|
patient.setId("123");
|
||||||
|
|
||||||
patient.getMeta().addProfile(("http://profile"));
|
patient.getMeta().addProfile(("http://profile"));
|
||||||
patient.addName().addFamily("FAMILY").addGiven("GIVEN");
|
patient.addName().addFamily("FAMILY").addGiven("GIVEN");
|
||||||
patient.addAddress().addLine("LINE1");
|
patient.addAddress().addLine("LINE1");
|
||||||
|
|
||||||
{
|
{
|
||||||
IParser p = ourCtx.newJsonParser();
|
IParser p = ourCtx.newJsonParser();
|
||||||
p.setDontEncodeElements(Sets.newHashSet("*.meta", "*.id"));
|
p.setDontEncodeElements(Sets.newHashSet("*.meta", "*.id"));
|
||||||
|
@ -882,24 +901,12 @@ public class JsonParserDstu3Test {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExplanationOfBenefit() {
|
public void testExplanationOfBenefit() {
|
||||||
String input =
|
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" + "}";
|
||||||
" \"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" +
|
|
||||||
"}";
|
|
||||||
|
|
||||||
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());
|
||||||
|
|
||||||
Reference coverage = (Reference) eob.getCoverage().getCoverage();
|
Reference coverage = (Reference) eob.getCoverage().getCoverage();
|
||||||
assertEquals("Coverage/123", coverage.getReference());
|
assertEquals("Coverage/123", coverage.getReference());
|
||||||
}
|
}
|
||||||
|
@ -1332,7 +1339,7 @@ public class JsonParserDstu3Test {
|
||||||
@Test
|
@Test
|
||||||
public void testParseExtensionWithId() throws Exception {
|
public void testParseExtensionWithId() throws Exception {
|
||||||
String input = IOUtils.toString(getClass().getResourceAsStream("/json-edge-case-modified-335.json"));
|
String input = IOUtils.toString(getClass().getResourceAsStream("/json-edge-case-modified-335.json"));
|
||||||
|
|
||||||
Patient p = ourCtx.newJsonParser().parseResource(Patient.class, input);
|
Patient p = ourCtx.newJsonParser().parseResource(Patient.class, input);
|
||||||
StringType family1 = p.getContact().get(0).getName().getFamily().get(1);
|
StringType family1 = p.getContact().get(0).getName().getFamily().get(1);
|
||||||
assertEquals("du", family1.getValue());
|
assertEquals("du", family1.getValue());
|
||||||
|
@ -1342,7 +1349,7 @@ public class JsonParserDstu3Test {
|
||||||
/**
|
/**
|
||||||
* See #342
|
* See #342
|
||||||
*/
|
*/
|
||||||
@Test(expected=DataFormatException.class)
|
@Test(expected = DataFormatException.class)
|
||||||
public void testParseInvalid() {
|
public void testParseInvalid() {
|
||||||
ourCtx.newJsonParser().parseResource("FOO");
|
ourCtx.newJsonParser().parseResource("FOO");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,20 @@
|
||||||
package ca.uhn.fhir.parser;
|
package ca.uhn.fhir.parser;
|
||||||
|
|
||||||
import org.hl7.fhir.dstu3.model.Address.AddressUse;
|
import org.hl7.fhir.dstu3.model.Address.AddressUse;
|
||||||
import org.hl7.fhir.dstu3.model.Enumeration;
|
import org.hl7.fhir.dstu3.model.Patient.ContactComponent;
|
||||||
import org.hl7.fhir.dstu3.model.Patient;
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hl7.fhir.dstu3.model.BackboneElement;
|
||||||
|
import org.hl7.fhir.dstu3.model.Enumeration;
|
||||||
|
import org.hl7.fhir.dstu3.model.Identifier;
|
||||||
|
import org.hl7.fhir.dstu3.model.Patient;
|
||||||
|
import org.hl7.fhir.dstu3.model.ResourceFactory;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.model.api.annotation.Block;
|
||||||
import ca.uhn.fhir.model.api.annotation.Child;
|
import ca.uhn.fhir.model.api.annotation.Child;
|
||||||
|
import ca.uhn.fhir.model.api.annotation.Description;
|
||||||
|
import ca.uhn.fhir.model.api.annotation.Extension;
|
||||||
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||||
|
|
||||||
@ResourceDef(name = "Patient")
|
@ResourceDef(name = "Patient")
|
||||||
|
@ -16,6 +26,13 @@ public class MyPatientWithOneDeclaredEnumerationExtensionDstu3 extends Patient {
|
||||||
@ca.uhn.fhir.model.api.annotation.Extension(url = "urn:foo", definedLocally = true, isModifier = false)
|
@ca.uhn.fhir.model.api.annotation.Extension(url = "urn:foo", definedLocally = true, isModifier = false)
|
||||||
private Enumeration<AddressUse> myFoo;
|
private Enumeration<AddressUse> myFoo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A contact party (e.g. guardian, partner, friend) for the patient.
|
||||||
|
*/
|
||||||
|
@Child(name = "contact", type = {}, order=Child.REPLACE_PARENT, min=0, max=Child.MAX_UNLIMITED, modifier=false, summary=false)
|
||||||
|
@Description(shortDefinition="A contact party (e.g. guardian, partner, friend) for the patient", formalDefinition="A contact party (e.g. guardian, partner, friend) for the patient." )
|
||||||
|
protected List<ContactComponent> contact;
|
||||||
|
|
||||||
public Enumeration<AddressUse> getFoo() {
|
public Enumeration<AddressUse> getFoo() {
|
||||||
return myFoo;
|
return myFoo;
|
||||||
}
|
}
|
||||||
|
@ -24,4 +41,32 @@ public class MyPatientWithOneDeclaredEnumerationExtensionDstu3 extends Patient {
|
||||||
myFoo = theFoo;
|
myFoo = theFoo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Block()
|
||||||
|
public static class MessageSourceComponent extends Patient.ContactComponent {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
@Child(name = "contact-eyecolour", type = { Identifier.class }, modifier = true)
|
||||||
|
@Description(shortDefinition = "Application ID")
|
||||||
|
@Extension(url = "http://foo.com/contact-eyecolour", definedLocally = false, isModifier = false)
|
||||||
|
private Identifier myEyeColour;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get messageHeaderApplicationId
|
||||||
|
*/
|
||||||
|
public Identifier getEyeColour() {
|
||||||
|
if (myEyeColour == null) {
|
||||||
|
myEyeColour = new Identifier();
|
||||||
|
}
|
||||||
|
return myEyeColour;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set messageHeaderApplicationId
|
||||||
|
*/
|
||||||
|
public void setEyeColour(Identifier messageHeaderApplicationId) {
|
||||||
|
this.myEyeColour = messageHeaderApplicationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
package ca.uhn.fhir.parser;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hl7.fhir.dstu3.model.Identifier;
|
||||||
|
import org.hl7.fhir.dstu3.model.Patient;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.model.api.annotation.Block;
|
||||||
|
import ca.uhn.fhir.model.api.annotation.Child;
|
||||||
|
import ca.uhn.fhir.model.api.annotation.Description;
|
||||||
|
import ca.uhn.fhir.model.api.annotation.Extension;
|
||||||
|
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||||
|
|
||||||
|
@ResourceDef(name = "Patient")
|
||||||
|
public class PatientWithExtendedContactDstu3 extends Patient {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A contact party (e.g. guardian, partner, friend) for the patient.
|
||||||
|
*/
|
||||||
|
@Child(name = "contact", type = {}, order = Child.REPLACE_PARENT, min = 0, max = Child.MAX_UNLIMITED, modifier = false, summary = false)
|
||||||
|
@Description(shortDefinition = "A contact party (e.g. guardian, partner, friend) for the patient", formalDefinition = "A contact party (e.g. guardian, partner, friend) for the patient.")
|
||||||
|
protected List<CustomContactComponent> customContact;
|
||||||
|
|
||||||
|
public List<CustomContactComponent> getCustomContact() {
|
||||||
|
if (customContact == null) {
|
||||||
|
customContact = new ArrayList<CustomContactComponent>();
|
||||||
|
}
|
||||||
|
return customContact;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Block()
|
||||||
|
public static class CustomContactComponent extends Patient.ContactComponent {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
@Child(name = "contact-eyecolour", type = { Identifier.class }, modifier = true)
|
||||||
|
@Description(shortDefinition = "Application ID")
|
||||||
|
@Extension(url = "http://foo.com/contact-eyecolour", definedLocally = false, isModifier = false)
|
||||||
|
private Identifier myEyeColour;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get messageHeaderApplicationId
|
||||||
|
*/
|
||||||
|
public Identifier getEyeColour() {
|
||||||
|
if (myEyeColour == null) {
|
||||||
|
myEyeColour = new Identifier();
|
||||||
|
}
|
||||||
|
return myEyeColour;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set messageHeaderApplicationId
|
||||||
|
*/
|
||||||
|
public void setEyeColour(Identifier messageHeaderApplicationId) {
|
||||||
|
this.myEyeColour = messageHeaderApplicationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue