Add test for #449
This commit is contained in:
parent
d159e44e52
commit
89e3021588
|
@ -0,0 +1,44 @@
|
||||||
|
package ca.uhn.fhir.parser;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.model.api.annotation.Child;
|
||||||
|
import ca.uhn.fhir.model.api.annotation.Extension;
|
||||||
|
import ca.uhn.fhir.model.api.annotation.ResourceDef;
|
||||||
|
import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt;
|
||||||
|
import ca.uhn.fhir.model.dstu2.resource.Device;
|
||||||
|
|
||||||
|
@ResourceDef(name="Device", id="ExtendedDevice")
|
||||||
|
public class ExtendedDevice extends Device {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Child(name="someOrg")
|
||||||
|
@Extension(url="http://extensionsBaseUrl/Device#someOrg", definedLocally=true, isModifier = false)
|
||||||
|
private ResourceReferenceDt someOrg;
|
||||||
|
|
||||||
|
@Child(name="someOtherOrg")
|
||||||
|
@Extension(url="http://extensionsBaseUrl/Device#someOtherOrg", definedLocally=true, isModifier = false)
|
||||||
|
private ResourceReferenceDt someOtherOrg;
|
||||||
|
|
||||||
|
public ResourceReferenceDt getSomeOrg() {
|
||||||
|
if (someOrg == null) {
|
||||||
|
someOrg = new ResourceReferenceDt();
|
||||||
|
}
|
||||||
|
return someOrg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSomeOrg(ResourceReferenceDt someOrg) {
|
||||||
|
this.someOrg = someOrg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceReferenceDt getSomeOtherOrg() {
|
||||||
|
if (someOtherOrg == null) {
|
||||||
|
someOtherOrg = new ResourceReferenceDt();
|
||||||
|
}
|
||||||
|
return someOtherOrg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSomeOtherOrg(ResourceReferenceDt someOtherOrg) {
|
||||||
|
this.someOtherOrg = someOtherOrg;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -144,7 +144,6 @@ public class JsonParserDstu2Test {
|
||||||
assertEquals(0, b.getEntry().size());
|
assertEquals(0, b.getEntry().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeAndParseExtensions() throws Exception {
|
public void testEncodeAndParseExtensions() throws Exception {
|
||||||
|
|
||||||
|
@ -230,6 +229,7 @@ public class JsonParserDstu2Test {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeAndParseLanguage() {
|
public void testEncodeAndParseLanguage() {
|
||||||
Patient p = new Patient();
|
Patient p = new Patient();
|
||||||
|
@ -424,7 +424,6 @@ public class JsonParserDstu2Test {
|
||||||
assertEquals("VERSION2", label.getVersion());
|
assertEquals("VERSION2", label.getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeBundleNewBundleNoText() {
|
public void testEncodeBundleNewBundleNoText() {
|
||||||
|
|
||||||
|
@ -486,6 +485,7 @@ public class JsonParserDstu2Test {
|
||||||
//@formatter:on
|
//@formatter:on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeDoesntIncludeUuidId() {
|
public void testEncodeDoesntIncludeUuidId() {
|
||||||
Patient p = new Patient();
|
Patient p = new Patient();
|
||||||
|
@ -602,7 +602,6 @@ public class JsonParserDstu2Test {
|
||||||
assertEquals("ext_url_value", ((StringDt)obs.getUndeclaredExtensions().get(0).getValue()).getValue());
|
assertEquals("ext_url_value", ((StringDt)obs.getUndeclaredExtensions().get(0).getValue()).getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeExtensionUndeclaredNonModifierWithChildExtension() {
|
public void testEncodeExtensionUndeclaredNonModifierWithChildExtension() {
|
||||||
Observation obs = new Observation();
|
Observation obs = new Observation();
|
||||||
|
@ -670,6 +669,7 @@ public class JsonParserDstu2Test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEncodeForceResourceId() {
|
public void testEncodeForceResourceId() {
|
||||||
Patient p = new Patient();
|
Patient p = new Patient();
|
||||||
|
@ -1703,6 +1703,46 @@ public class JsonParserDstu2Test {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See #449
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testReferenceEncodingOnCustomType() {
|
||||||
|
Organization org = new Organization();
|
||||||
|
org.setId("000111");
|
||||||
|
org.setName("Owner institution");
|
||||||
|
|
||||||
|
ExtendedDevice dev = new ExtendedDevice();
|
||||||
|
dev.setId("000222");
|
||||||
|
CodingDt devType = new CodingDt();
|
||||||
|
|
||||||
|
devType.setSystem("http://devTypeSystem");
|
||||||
|
devType.setCode("0");
|
||||||
|
dev.getType().addCoding(devType);
|
||||||
|
|
||||||
|
ExtensionDt someExt = new ExtensionDt();
|
||||||
|
someExt.setUrl("http://extensionsBaseUrl/Device#someExt");
|
||||||
|
ResourceReferenceDt orgRef = new ResourceReferenceDt();
|
||||||
|
orgRef.setResource(org);
|
||||||
|
someExt.setValue(orgRef); //this works
|
||||||
|
dev.addUndeclaredExtension(someExt);
|
||||||
|
|
||||||
|
dev.getSomeOrg().setResource(org); //this doesn't work
|
||||||
|
dev.setSomeOtherOrg(new ResourceReferenceDt(org)); //this almost works, the Organization/ prefix is missing
|
||||||
|
|
||||||
|
dev.getOwner().setResource(org); //this works
|
||||||
|
|
||||||
|
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = new ca.uhn.fhir.model.dstu2.resource.Bundle();
|
||||||
|
bundle.setId(new IdDt("000333"));
|
||||||
|
bundle.addEntry().setResource(dev);
|
||||||
|
bundle.addEntry().setResource(org);
|
||||||
|
|
||||||
|
String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle);
|
||||||
|
ourLog.info(encoded);
|
||||||
|
|
||||||
|
assertThat(encoded, containsString("reference\": \"Organization/000111\""));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See #144 and #146
|
* See #144 and #146
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue