diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/parser/JsonParserR4Test.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/parser/JsonParserR4Test.java index f3d4897a10a..cf9a68e5f4a 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/parser/JsonParserR4Test.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/parser/JsonParserR4Test.java @@ -447,6 +447,34 @@ public class JsonParserR4Test { assertEquals("535", ((StringType) houseNumberExt.getValue()).getValue()); } + + private Composition createComposition(String sectionText) { + Composition c = new Composition(); + Narrative compositionText = new Narrative().setStatus(Narrative.NarrativeStatus.GENERATED); + compositionText.setDivAsString("Composition"); + Narrative compositionSectionText = new Narrative().setStatus(Narrative.NarrativeStatus.GENERATED); + compositionSectionText.setDivAsString(sectionText); + c.setText(compositionText); + c.addSection().setText(compositionSectionText); + return c; + } + + /** + * See #402 (however JSON is fine) + */ + @Test + public void testEncodingTextSection() { + + String sectionText = "sectionText"; + Composition composition = createComposition(sectionText); + + String encoded = ourCtx.newJsonParser().encodeResourceToString(composition); + ourLog.info(encoded); + + int idx = encoded.indexOf(sectionText); + assertNotEquals(-1, idx); + } + /** * 2019-09-19 - Pre #1489 diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/parser/XmlParserR4Test.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/parser/XmlParserR4Test.java new file mode 100644 index 00000000000..cf97110174f --- /dev/null +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/parser/XmlParserR4Test.java @@ -0,0 +1,45 @@ +package ca.uhn.fhir.parser; + +import static org.junit.Assert.assertNotEquals; + +import org.hl7.fhir.r4.model.Composition; +import org.hl7.fhir.r4.model.Narrative; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import ca.uhn.fhir.context.FhirContext; + +public class XmlParserR4Test { + private static final Logger ourLog = LoggerFactory.getLogger(XmlParserR4Test.class); + private static FhirContext ourCtx = FhirContext.forR4(); + + + private Composition createComposition(String sectionText) { + Composition c = new Composition(); + Narrative compositionText = new Narrative().setStatus(Narrative.NarrativeStatus.GENERATED); + compositionText.setDivAsString("Composition"); + Narrative compositionSectionText = new Narrative().setStatus(Narrative.NarrativeStatus.GENERATED); + compositionSectionText.setDivAsString(sectionText); + c.setText(compositionText); + c.addSection().setText(compositionSectionText); + return c; + } + + /** + * See #402 section.text is overwritten by composition.text + */ + @Test + public void testEncodingTextSection() { + + String sectionText = "sectionText"; + Composition composition = createComposition(sectionText); + + String encoded = ourCtx.newXmlParser().encodeResourceToString(composition); + ourLog.info(encoded); + + int idx = encoded.indexOf(sectionText); + assertNotEquals(-1, idx); + } + +}