diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java index 44550187d2b..ca32e26447c 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java @@ -287,7 +287,7 @@ public class FhirTerser { retVal = new ArrayList<>(); for (T nextElement : values) { BaseRuntimeElementCompositeDefinition nextChildDef = (BaseRuntimeElementCompositeDefinition) myContext.getElementDefinition((Class) nextElement.getClass()); - List foundValues = getValues(nextChildDef, nextElement, theSubList.subList(1, theSubList.size()), theWantedClass); + List foundValues = getValues(nextChildDef, nextElement, theSubList.subList(1, theSubList.size()), theWantedClass, theCreate); retVal.addAll(foundValues); } } @@ -332,7 +332,7 @@ public class FhirTerser { retVal = new ArrayList<>(); for (T nextElement : values) { BaseRuntimeElementCompositeDefinition nextChildDef = (BaseRuntimeElementCompositeDefinition) myContext.getElementDefinition((Class) nextElement.getClass()); - List foundValues = getValues(nextChildDef, nextElement, theSubList.subList(1, theSubList.size()), theWantedClass); + List foundValues = getValues(nextChildDef, nextElement, theSubList.subList(1, theSubList.size()), theWantedClass, theCreate); retVal.addAll(foundValues); } } @@ -381,7 +381,7 @@ public class FhirTerser { } else { for (IBase nextElement : values) { BaseRuntimeElementCompositeDefinition nextChildDef = (BaseRuntimeElementCompositeDefinition) myContext.getElementDefinition(nextElement.getClass()); - List foundValues = getValues(nextChildDef, nextElement, theSubList.subList(1, theSubList.size()), theWantedClass); + List foundValues = getValues(nextChildDef, nextElement, theSubList.subList(1, theSubList.size()), theWantedClass, theCreate); retVal.addAll(foundValues); } } diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/util/FhirTerserDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/util/FhirTerserDstu2Test.java index 0139b2d6b13..e66eabdc9cd 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/util/FhirTerserDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/util/FhirTerserDstu2Test.java @@ -185,6 +185,7 @@ public class FhirTerserDstu2Test { p.setActive(true); p.addUndeclaredExtension(false, "http://acme.org/extension", new StringDt("value")); p.addUndeclaredExtension(false, "http://acme.org/otherExtension", new StringDt("otherValue")); + p.addUndeclaredExtension(false, "http://acme.org/parentExtension").addUndeclaredExtension(false, "http://acme.org/childExtension", new StringDt("nestedValue")); System.out.println(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p)); @@ -200,6 +201,13 @@ public class FhirTerserDstu2Test { assertTrue(values.get(0) instanceof ExtensionDt); assertEquals("http://acme.org/extension", ((ExtensionDt) values.get(0)).getUrl()); assertEquals("value", ((StringDt) ((ExtensionDt) values.get(0)).getValue()).getValueAsString()); + + values = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')"); + assertEquals(1, values.size()); + assertTrue(values.get(0) instanceof IBaseExtension); + assertTrue(values.get(0) instanceof ExtensionDt); + assertEquals("http://acme.org/childExtension", ((ExtensionDt) values.get(0)).getUrl()); + assertEquals("nestedValue", ((StringDt) ((ExtensionDt) values.get(0)).getValue()).getValueAsString()); } @Test @@ -208,6 +216,7 @@ public class FhirTerserDstu2Test { p.setActive(true); p.addUndeclaredExtension(false, "http://acme.org/extension", new StringDt("value")); p.addUndeclaredExtension(false, "http://acme.org/otherExtension", new StringDt("otherValue")); + p.addUndeclaredExtension(false, "http://acme.org/parentExtension").addUndeclaredExtension(false, "http://acme.org/childExtension", new StringDt("nestedValue")); System.out.println(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p)); @@ -244,6 +253,24 @@ public class FhirTerserDstu2Test { assertTrue(values.get(0) instanceof ExtensionDt); assertEquals("http://acme.org/extension", ((ExtensionDt) values.get(0)).getUrl()); assertEquals("modifiedValue", ((StringDt) ((ExtensionDt) values.get(0)).getValue()).getValueAsString()); + + values = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')"); + assertEquals(1, values.size()); + assertTrue(values.get(0) instanceof IBaseExtension); + assertTrue(values.get(0) instanceof ExtensionDt); + assertEquals("http://acme.org/childExtension", ((ExtensionDt) values.get(0)).getUrl()); + assertEquals("nestedValue", ((StringDt) ((ExtensionDt) values.get(0)).getValue()).getValueAsString()); + + ((ExtensionDt) values.get(0)).setValue(new StringDt("modifiedNestedValue")); + + System.out.println(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p)); + + values = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')"); + assertEquals(1, values.size()); + assertTrue(values.get(0) instanceof IBaseExtension); + assertTrue(values.get(0) instanceof ExtensionDt); + assertEquals("http://acme.org/childExtension", ((ExtensionDt) values.get(0)).getUrl()); + assertEquals("modifiedNestedValue", ((StringDt) ((ExtensionDt) values.get(0)).getValue()).getValueAsString()); } @Test @@ -252,6 +279,8 @@ public class FhirTerserDstu2Test { p.addUndeclaredExtension(false, "http://acme.org/extension", new StringDt("value1")); p.addUndeclaredExtension(false, "http://acme.org/extension", new StringDt("value2")); p.addUndeclaredExtension(false, "http://acme.org/otherExtension", new StringDt("otherValue")); + p.addUndeclaredExtension(false, "http://acme.org/parentExtension").addUndeclaredExtension(false, "http://acme.org/childExtension", new StringDt("nestedValue1")); + p.addUndeclaredExtension(false, "http://acme.org/parentExtension").addUndeclaredExtension(false, "http://acme.org/childExtension", new StringDt("nestedValue2")); System.out.println(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p)); @@ -265,6 +294,17 @@ public class FhirTerserDstu2Test { assertTrue(values.get(1) instanceof ExtensionDt); assertEquals("http://acme.org/extension", ((ExtensionDt) values.get(1)).getUrl()); assertEquals("value2", ((StringDt) ((ExtensionDt) values.get(1)).getValue()).getValueAsString()); + + values = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')"); + assertEquals(2, values.size()); + assertTrue(values.get(0) instanceof IBaseExtension); + assertTrue(values.get(0) instanceof ExtensionDt); + assertEquals("http://acme.org/childExtension", ((ExtensionDt) values.get(0)).getUrl()); + assertEquals("nestedValue1", ((StringDt) ((ExtensionDt) values.get(0)).getValue()).getValueAsString()); + assertTrue(values.get(1) instanceof IBaseExtension); + assertTrue(values.get(1) instanceof ExtensionDt); + assertEquals("http://acme.org/childExtension", ((ExtensionDt) values.get(1)).getUrl()); + assertEquals("nestedValue2", ((StringDt) ((ExtensionDt) values.get(1)).getValue()).getValueAsString()); } @Test @@ -273,6 +313,7 @@ public class FhirTerserDstu2Test { p.setActive(true); p.addUndeclaredExtension(false, "http://acme.org/extension", new StringDt("value")); p.addUndeclaredExtension(false, "http://acme.org/otherExtension", new StringDt("otherValue")); + p.addUndeclaredExtension(false, "http://acme.org/parentExtension").addUndeclaredExtension(false, "http://acme.org/childExtension", new StringDt("nestedValue")); System.out.println(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p)); @@ -285,7 +326,13 @@ public class FhirTerserDstu2Test { assertEquals(1, extValues.size()); assertTrue(extValues.get(0).getValue() instanceof StringDt); assertEquals("http://acme.org/extension", extValues.get(0).getUrl()); - assertEquals("value", ((StringDt) (extValues.get(0).getValue())).getValueAsString()); + assertEquals("value", ((StringDt) extValues.get(0).getValue()).getValueAsString()); + + extValues = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')", ExtensionDt.class); + assertEquals(1, extValues.size()); + assertTrue(extValues.get(0).getValue() instanceof StringDt); + assertEquals("http://acme.org/childExtension", extValues.get(0).getUrl()); + assertEquals("nestedValue", ((StringDt) extValues.get(0).getValue()).getValueAsString()); } @Test @@ -294,6 +341,7 @@ public class FhirTerserDstu2Test { p.setActive(true); p.addUndeclaredExtension(false, "http://acme.org/extension", new StringDt("value")); p.addUndeclaredExtension(false, "http://acme.org/otherExtension", new StringDt("otherValue")); + p.addUndeclaredExtension(false, "http://acme.org/parentExtension").addUndeclaredExtension(false, "http://acme.org/childExtension", new StringDt("nestedValue")); System.out.println(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p)); @@ -326,6 +374,22 @@ public class FhirTerserDstu2Test { assertTrue(extValues.get(0).getValue() instanceof StringDt); assertEquals("http://acme.org/extension", extValues.get(0).getUrl()); assertEquals("modifiedValue", ((StringDt) (extValues.get(0).getValue())).getValueAsString()); + + extValues = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')", ExtensionDt.class); + assertEquals(1, extValues.size()); + assertTrue(extValues.get(0).getValue() instanceof StringDt); + assertEquals("http://acme.org/childExtension", extValues.get(0).getUrl()); + assertEquals("nestedValue", ((StringDt) extValues.get(0).getValue()).getValueAsString()); + + extValues.get(0).setValue(new StringDt("modifiedNestedValue")); + + System.out.println(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p)); + + extValues = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')", ExtensionDt.class); + assertEquals(1, extValues.size()); + assertTrue(extValues.get(0).getValue() instanceof StringDt); + assertEquals("http://acme.org/childExtension", extValues.get(0).getUrl()); + assertEquals("modifiedNestedValue", ((StringDt) extValues.get(0).getValue()).getValueAsString()); } @Test @@ -343,6 +407,11 @@ public class FhirTerserDstu2Test { assertEquals(1, extValues.size()); assertEquals("http://acme.org/extension", extValues.get(0).getUrl()); assertNull(extValues.get(0).getValue()); + + extValues = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')", ExtensionDt.class, true); + assertEquals(1, extValues.size()); + assertEquals("http://acme.org/childExtension", extValues.get(0).getUrl()); + assertNull(extValues.get(0).getValue()); } @Test @@ -363,6 +432,13 @@ public class FhirTerserDstu2Test { assertTrue(values.get(0) instanceof ExtensionDt); assertEquals("http://acme.org/extension", ((ExtensionDt) values.get(0)).getUrl()); assertNull(((ExtensionDt) values.get(0)).getValue()); + + values = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')", true); + assertEquals(1, values.size()); + assertTrue(values.get(0) instanceof IBaseExtension); + assertTrue(values.get(0) instanceof ExtensionDt); + assertEquals("http://acme.org/childExtension", ((ExtensionDt) values.get(0)).getUrl()); + assertNull(((ExtensionDt) values.get(0)).getValue()); } @Test @@ -371,6 +447,7 @@ public class FhirTerserDstu2Test { p.setActive(true); p.addUndeclaredExtension(false, "http://acme.org/extension", new StringDt("value")); p.addUndeclaredExtension(false, "http://acme.org/otherExtension", new StringDt("otherValue")); + p.addUndeclaredExtension(false, "http://acme.org/parentExtension").addUndeclaredExtension(false, "http://acme.org/childExtension", new StringDt("nestedValue")); System.out.println(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p)); @@ -380,12 +457,19 @@ public class FhirTerserDstu2Test { assertTrue(values.get(0) instanceof BooleanDt); assertTrue(((BooleanDt) values.get(0)).getValue()); - values = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/extension')"); + values = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/extension')", true); assertEquals(1, values.size()); assertTrue(values.get(0) instanceof IBaseExtension); assertTrue(values.get(0) instanceof ExtensionDt); assertEquals("http://acme.org/extension", ((ExtensionDt) values.get(0)).getUrl()); assertEquals("value", ((StringDt) ((ExtensionDt) values.get(0)).getValue()).getValueAsString()); + + values = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')", true); + assertEquals(1, values.size()); + assertTrue(values.get(0) instanceof IBaseExtension); + assertTrue(values.get(0) instanceof ExtensionDt); + assertEquals("http://acme.org/childExtension", ((ExtensionDt) values.get(0)).getUrl()); + assertEquals("nestedValue", ((StringDt) ((ExtensionDt) values.get(0)).getValue()).getValueAsString()); } @Test diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/util/FhirTerserDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/util/FhirTerserDstu3Test.java index bf0ffde4ee0..923762241f8 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/util/FhirTerserDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/util/FhirTerserDstu3Test.java @@ -182,6 +182,11 @@ public class FhirTerserDstu3Test { p.addModifierExtension() .setUrl("http://acme.org/modifierExtension") .setValue(new StringType("modifierValue")); + p.addExtension() + .setUrl("http://acme.org/parentExtension") + .addExtension() + .setUrl("http://acme.org/childExtension") + .setValue(new StringType("nestedValue")); System.out.println(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p)); @@ -204,6 +209,13 @@ public class FhirTerserDstu3Test { assertTrue(values.get(0) instanceof Extension); assertEquals("http://acme.org/modifierExtension", ((Extension) values.get(0)).getUrl()); assertEquals("modifierValue", ((StringType) ((Extension) values.get(0)).getValue()).getValueAsString()); + + values = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')"); + assertEquals(1, values.size()); + assertTrue(values.get(0) instanceof IBaseExtension); + assertTrue(values.get(0) instanceof Extension); + assertEquals("http://acme.org/childExtension", ((Extension) values.get(0)).getUrl()); + assertEquals("nestedValue", ((StringType) ((Extension) values.get(0)).getValue()).getValueAsString()); } @Test @@ -219,6 +231,11 @@ public class FhirTerserDstu3Test { p.addModifierExtension() .setUrl("http://acme.org/modifierExtension") .setValue(new StringType("modifierValue")); + p.addExtension() + .setUrl("http://acme.org/parentExtension") + .addExtension() + .setUrl("http://acme.org/childExtension") + .setValue(new StringType("nestedValue")); System.out.println(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p)); @@ -273,6 +290,24 @@ public class FhirTerserDstu3Test { assertTrue(values.get(0) instanceof Extension); assertEquals("http://acme.org/modifierExtension", ((Extension) values.get(0)).getUrl()); assertEquals("modifiedModifierValue", ((StringType) ((Extension) values.get(0)).getValue()).getValueAsString()); + + values = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')"); + assertEquals(1, values.size()); + assertTrue(values.get(0) instanceof IBaseExtension); + assertTrue(values.get(0) instanceof Extension); + assertEquals("http://acme.org/childExtension", ((Extension) values.get(0)).getUrl()); + assertEquals("nestedValue", ((StringType) ((Extension) values.get(0)).getValue()).getValueAsString()); + + ((Extension) values.get(0)).setValue(new StringType("modifiedNestedValue")); + + System.out.println(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p)); + + values = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')"); + assertEquals(1, values.size()); + assertTrue(values.get(0) instanceof IBaseExtension); + assertTrue(values.get(0) instanceof Extension); + assertEquals("http://acme.org/childExtension", ((Extension) values.get(0)).getUrl()); + assertEquals("modifiedNestedValue", ((StringType) ((Extension) values.get(0)).getValue()).getValueAsString()); } @Test @@ -293,6 +328,16 @@ public class FhirTerserDstu3Test { p.addModifierExtension() .setUrl("http://acme.org/modifierExtension") .setValue(new StringType("modifierValue2")); + p.addExtension() + .setUrl("http://acme.org/parentExtension") + .addExtension() + .setUrl("http://acme.org/childExtension") + .setValue(new StringType("nestedValue1")); + p.addExtension() + .setUrl("http://acme.org/parentExtension") + .addExtension() + .setUrl("http://acme.org/childExtension") + .setValue(new StringType("nestedValue2")); System.out.println(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p)); @@ -317,6 +362,17 @@ public class FhirTerserDstu3Test { assertTrue(values.get(1) instanceof Extension); assertEquals("http://acme.org/modifierExtension", ((Extension) values.get(1)).getUrl()); assertEquals("modifierValue2", ((StringType) ((Extension) values.get(1)).getValue()).getValueAsString()); + + values = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')"); + assertEquals(2, values.size()); + assertTrue(values.get(0) instanceof IBaseExtension); + assertTrue(values.get(0) instanceof Extension); + assertEquals("http://acme.org/childExtension", ((Extension) values.get(0)).getUrl()); + assertEquals("nestedValue1", ((StringType) ((Extension) values.get(0)).getValue()).getValueAsString()); + assertTrue(values.get(1) instanceof IBaseExtension); + assertTrue(values.get(1) instanceof Extension); + assertEquals("http://acme.org/childExtension", ((Extension) values.get(1)).getUrl()); + assertEquals("nestedValue2", ((StringType) ((Extension) values.get(1)).getValue()).getValueAsString()); } @Test @@ -332,6 +388,11 @@ public class FhirTerserDstu3Test { p.addModifierExtension() .setUrl("http://acme.org/modifierExtension") .setValue(new StringType("modifierValue")); + p.addExtension() + .setUrl("http://acme.org/parentExtension") + .addExtension() + .setUrl("http://acme.org/childExtension") + .setValue(new StringType("nestedValue")); System.out.println(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p)); @@ -351,6 +412,12 @@ public class FhirTerserDstu3Test { assertTrue(extValues.get(0).getValue() instanceof StringType); assertEquals("http://acme.org/modifierExtension", extValues.get(0).getUrl()); assertEquals("modifierValue", ((StringType) (extValues.get(0).getValue())).getValueAsString()); + + extValues = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')", Extension.class); + assertEquals(1, extValues.size()); + assertTrue(extValues.get(0).getValue() instanceof StringType); + assertEquals("http://acme.org/childExtension", extValues.get(0).getUrl()); + assertEquals("nestedValue", ((StringType) extValues.get(0).getValue()).getValueAsString()); } @Test @@ -366,6 +433,11 @@ public class FhirTerserDstu3Test { p.addModifierExtension() .setUrl("http://acme.org/modifierExtension") .setValue(new StringType("modifierValue")); + p.addExtension() + .setUrl("http://acme.org/parentExtension") + .addExtension() + .setUrl("http://acme.org/childExtension") + .setValue(new StringType("nestedValue")); System.out.println(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p)); @@ -414,6 +486,22 @@ public class FhirTerserDstu3Test { assertTrue(extValues.get(0).getValue() instanceof StringType); assertEquals("http://acme.org/modifierExtension", extValues.get(0).getUrl()); assertEquals("modifiedModifierValue", ((StringType) (extValues.get(0).getValue())).getValueAsString()); + + extValues = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')", Extension.class); + assertEquals(1, extValues.size()); + assertTrue(extValues.get(0).getValue() instanceof StringType); + assertEquals("http://acme.org/childExtension", extValues.get(0).getUrl()); + assertEquals("nestedValue", ((StringType) extValues.get(0).getValue()).getValueAsString()); + + extValues.get(0).setValue(new StringType("modifiedNestedValue")); + + System.out.println(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p)); + + extValues = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')", Extension.class); + assertEquals(1, extValues.size()); + assertTrue(extValues.get(0).getValue() instanceof StringType); + assertEquals("http://acme.org/childExtension", extValues.get(0).getUrl()); + assertEquals("modifiedNestedValue", ((StringType) extValues.get(0).getValue()).getValueAsString()); } @Test @@ -436,6 +524,11 @@ public class FhirTerserDstu3Test { assertEquals(1, extValues.size()); assertEquals("http://acme.org/modifierExtension", extValues.get(0).getUrl()); assertNull(extValues.get(0).getValue()); + + extValues = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')", Extension.class, true); + assertEquals(1, extValues.size()); + assertEquals("http://acme.org/childExtension", extValues.get(0).getUrl()); + assertNull(extValues.get(0).getValue()); } @Test @@ -463,6 +556,18 @@ public class FhirTerserDstu3Test { assertTrue(values.get(0) instanceof Extension); assertEquals("http://acme.org/modifierExtension", ((Extension) values.get(0)).getUrl()); assertNull(((Extension) values.get(0)).getValue()); + + System.out.println(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p)); + + values = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')", true); + + System.out.println(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p)); + + assertEquals(1, values.size()); + assertTrue(values.get(0) instanceof IBaseExtension); + assertTrue(values.get(0) instanceof Extension); + assertEquals("http://acme.org/childExtension", ((Extension) values.get(0)).getUrl()); + assertNull(((Extension) values.get(0)).getValue()); } @Test @@ -478,6 +583,11 @@ public class FhirTerserDstu3Test { p.addModifierExtension() .setUrl("http://acme.org/modifierExtension") .setValue(new StringType("modifierValue")); + p.addExtension() + .setUrl("http://acme.org/parentExtension") + .addExtension() + .setUrl("http://acme.org/childExtension") + .setValue(new StringType("nestedValue")); System.out.println(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p)); @@ -487,19 +597,26 @@ public class FhirTerserDstu3Test { assertTrue(values.get(0) instanceof BooleanType); assertTrue(((BooleanType) values.get(0)).booleanValue()); - values = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/extension')"); + values = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/extension')", true); assertEquals(1, values.size()); assertTrue(values.get(0) instanceof IBaseExtension); assertTrue(values.get(0) instanceof Extension); assertEquals("http://acme.org/extension", ((Extension) values.get(0)).getUrl()); assertEquals("value", ((StringType) ((Extension) values.get(0)).getValue()).getValueAsString()); - values = ourCtx.newTerser().getValues(p, "Patient.modifierExtension('http://acme.org/modifierExtension')"); + values = ourCtx.newTerser().getValues(p, "Patient.modifierExtension('http://acme.org/modifierExtension')", true); assertEquals(1, values.size()); assertTrue(values.get(0) instanceof IBaseExtension); assertTrue(values.get(0) instanceof Extension); assertEquals("http://acme.org/modifierExtension", ((Extension) values.get(0)).getUrl()); assertEquals("modifierValue", ((StringType) ((Extension) values.get(0)).getValue()).getValueAsString()); + + values = ourCtx.newTerser().getValues(p, "Patient.extension('http://acme.org/parentExtension').extension('http://acme.org/childExtension')", true); + assertEquals(1, values.size()); + assertTrue(values.get(0) instanceof IBaseExtension); + assertTrue(values.get(0) instanceof Extension); + assertEquals("http://acme.org/childExtension", ((Extension) values.get(0)).getUrl()); + assertEquals("nestedValue", ((StringType) ((Extension) values.get(0)).getValue()).getValueAsString()); } @Test