encode narratives of contained resources (#3402)

* encode narratives of contained resources
fixes #1466

* encode narratives of contained resources
fixes #1466
This commit is contained in:
Patrick Werner 2022-02-17 19:54:03 +01:00 committed by GitHub
parent 631391819b
commit 0c5d868f44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 57 additions and 32 deletions

View File

@ -199,8 +199,6 @@ public abstract class BaseParser implements IParser {
} else if (myNext.getDef() instanceof RuntimeChildNarrativeDefinition) {
if (isSuppressNarratives() || isSummaryMode()) {
continue;
} else if (theContainedResource) {
continue;
}
} else if (myNext.getDef() instanceof RuntimeChildContainedResources) {
if (theContainedResource) {

View File

@ -534,8 +534,6 @@ public class JsonParser extends BaseParser implements IJsonLikeParser {
beginArray(theEventWriter, nextChildSpecificName);
inArray = true;
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childDef, null, theContainedResource, nextChildElem, force, theEncodeContext);
} else if (nextChild instanceof RuntimeChildNarrativeDefinition && theContainedResource) {
// suppress narratives from contained resources
} else {
encodeChildElementToStreamWriter(theResDef, theResource, theEventWriter, nextValue, childDef, nextChildSpecificName, theContainedResource, nextChildElem, false, theEncodeContext);
}

View File

@ -446,8 +446,6 @@ public class XmlParser extends BaseParser {
}
}
encodeChildElementToStreamWriter(theResource, theEventWriter, nextChild, nextValue, childName, childDef, getExtensionUrl(extension.getUrl()), theContainedResource, nextChildElem, theEncodeContext);
} else if (nextChild instanceof RuntimeChildNarrativeDefinition && theContainedResource) {
// suppress narratives from contained resources
} else {
encodeChildElementToStreamWriter(theResource, theEventWriter, nextChild, nextValue, childName, childDef, extensionUrl, theContainedResource, nextChildElem, theEncodeContext);
}

View File

@ -0,0 +1,5 @@
---
type: fix
issue: 1466
title: "The XML and JSON Parsers are now encoding narratives of contained resources.
Narratives were skipped before for contained resources. This was a rule which was only valid in STU1 (https://www.hl7.org/fhir/DSTU1/narrative.html), and was removed in DSTU2+ "

View File

@ -971,7 +971,7 @@ public class XmlParserDstu2_1Test {
}
@Test
public void testEncodeContainedWithNarrativeIsSuppresed() throws Exception {
public void testEncodeContainedWithNarrative() throws Exception {
IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
// Create an organization, note that the organization does not have an ID
@ -990,9 +990,9 @@ public class XmlParserDstu2_1Test {
ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder("<Patient", "<text>", "<div xmlns=\"http://www.w3.org/1999/xhtml\">BARFOO</div>", "<contained>", "<Organization", "</Organization"));
assertThat(encoded, not(stringContainsInOrder("<Patient", "<text>", "<contained>", "<Organization", "<text", "</Organization")));
assertThat(encoded, stringContainsInOrder("<Patient", "<text>", "<contained>", "<Organization", "<text", "</Organization"));
assertThat(encoded, not(containsString("FOOBAR")));
assertThat(encoded, (containsString("FOOBAR")));
assertThat(encoded, (containsString("BARFOO")));
}

View File

@ -1370,7 +1370,7 @@ public class XmlParserDstu2Test {
}
@Test
public void testEncodeContainedWithNarrativeIsSuppresed() throws Exception {
public void testEncodeContainedWithNarrative() throws Exception {
IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
// Create an organization, note that the organization does not have an ID
@ -1389,9 +1389,9 @@ public class XmlParserDstu2Test {
ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder("<Patient", "<text>", "<div xmlns=\"http://www.w3.org/1999/xhtml\">BARFOO</div>", "<contained>", "<Organization", "</Organization"));
assertThat(encoded, not(stringContainsInOrder("<Patient", "<text>", "<contained>", "<Organization", "<text", "</Organization")));
assertThat(encoded, stringContainsInOrder("<Patient", "<text>", "<contained>", "<Organization", "<text", "</Organization"));
assertThat(encoded, not(containsString("FOOBAR")));
assertThat(encoded, (containsString("FOOBAR")));
assertThat(encoded, (containsString("BARFOO")));
}

View File

@ -1414,7 +1414,7 @@ public class XmlParserDstu3Test {
}
@Test
public void testEncodeContainedWithNarrativeIsSuppresed() throws Exception {
public void testEncodeContainedWithNarrative() throws Exception {
IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
// Create an organization, note that the organization does not have an ID
@ -1433,9 +1433,9 @@ public class XmlParserDstu3Test {
ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder("<Patient", "<text>", "<div xmlns=\"http://www.w3.org/1999/xhtml\">BARFOO</div>", "<contained>", "<Organization", "</Organization"));
assertThat(encoded, not(stringContainsInOrder("<Patient", "<text>", "<contained>", "<Organization", "<text", "</Organization")));
assertThat(encoded, stringContainsInOrder("<Patient", "<text>", "<contained>", "<Organization", "<text", "</Organization"));
assertThat(encoded, not(containsString("FOOBAR")));
assertThat(encoded, containsString("FOOBAR"));
assertThat(encoded, (containsString("BARFOO")));
}

View File

@ -515,7 +515,7 @@ public class JsonParserHl7OrgDstu2Test {
}
@Test
public void testEncodeContainedWithNarrativeIsSuppresed() throws Exception {
public void testEncodeContainedWithNarrative() throws Exception {
IParser parser = ourCtx.newJsonParser().setPrettyPrint(true);
// Create an organization, note that the organization does not have an ID
@ -532,7 +532,7 @@ public class JsonParserHl7OrgDstu2Test {
String encoded = parser.encodeResourceToString(patient);
ourLog.info(encoded);
assertThat(encoded, not(containsString("FOOBAR")));
assertThat(encoded, (containsString("FOOBAR")));
assertThat(encoded, (containsString("BARFOO")));
}

View File

@ -14,13 +14,39 @@ import org.apache.commons.io.IOUtils;
import org.hamcrest.core.IsNot;
import org.hamcrest.core.StringContains;
import org.hamcrest.text.StringContainsInOrder;
import org.hl7.fhir.dstu2.model.*;
import org.hl7.fhir.dstu2.model.Address;
import org.hl7.fhir.dstu2.model.Address.AddressUse;
import org.hl7.fhir.dstu2.model.Address.AddressUseEnumFactory;
import org.hl7.fhir.dstu2.model.Binary;
import org.hl7.fhir.dstu2.model.Bundle;
import org.hl7.fhir.dstu2.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.dstu2.model.CodeableConcept;
import org.hl7.fhir.dstu2.model.Composition;
import org.hl7.fhir.dstu2.model.Condition;
import org.hl7.fhir.dstu2.model.DateTimeType;
import org.hl7.fhir.dstu2.model.DateType;
import org.hl7.fhir.dstu2.model.DecimalType;
import org.hl7.fhir.dstu2.model.DiagnosticReport;
import org.hl7.fhir.dstu2.model.DocumentManifest;
import org.hl7.fhir.dstu2.model.EnumFactory;
import org.hl7.fhir.dstu2.model.Enumeration;
import org.hl7.fhir.dstu2.model.Enumerations.AdministrativeGender;
import org.hl7.fhir.dstu2.model.Extension;
import org.hl7.fhir.dstu2.model.HumanName;
import org.hl7.fhir.dstu2.model.Identifier;
import org.hl7.fhir.dstu2.model.Identifier.IdentifierUse;
import org.hl7.fhir.dstu2.model.InstantType;
import org.hl7.fhir.dstu2.model.MedicationStatement;
import org.hl7.fhir.dstu2.model.Narrative.NarrativeStatus;
import org.hl7.fhir.dstu2.model.Observation;
import org.hl7.fhir.dstu2.model.Organization;
import org.hl7.fhir.dstu2.model.Patient;
import org.hl7.fhir.dstu2.model.PrimitiveType;
import org.hl7.fhir.dstu2.model.Reference;
import org.hl7.fhir.dstu2.model.Resource;
import org.hl7.fhir.dstu2.model.SimpleQuantity;
import org.hl7.fhir.dstu2.model.Specimen;
import org.hl7.fhir.dstu2.model.StringType;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
@ -343,7 +369,7 @@ public class XmlParserHl7OrgDstu2Test {
/**
* See #216 - Profiled datatypes should use their unprofiled parent type as
* the choice[x] name
*
* <p>
* Disabled after conversation with Grahame
*/
@Test
@ -763,7 +789,7 @@ public class XmlParserHl7OrgDstu2Test {
}
@Test
public void testEncodeContainedWithNarrativeIsSuppresed() throws Exception {
public void testEncodeContainedWithNarrative() throws Exception {
IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
// Create an organization, note that the organization does not have an ID
@ -784,9 +810,9 @@ public class XmlParserHl7OrgDstu2Test {
assertThat(encoded, stringContainsInOrder("<Patient", "<text>",
"<div xmlns=\"http://www.w3.org/1999/xhtml\">BARFOO</div>", "<contained>", "<Organization", "</Organization"));
assertThat(encoded,
not(stringContainsInOrder("<Patient", "<text>", "<contained>", "<Organization", "<text", "</Organization")));
stringContainsInOrder("<Patient", "<text>", "<contained>", "<Organization", "<text", "</Organization"));
assertThat(encoded, not(containsString("FOOBAR")));
assertThat(encoded, (containsString("FOOBAR")));
assertThat(encoded, (containsString("BARFOO")));
}

View File

@ -1013,7 +1013,7 @@ public class XmlParserDstu2_1Test {
}
@Test
public void testEncodeContainedWithNarrativeIsSuppresed() throws Exception {
public void testEncodeContainedWithNarrative() throws Exception {
IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
// Create an organization, note that the organization does not have an ID
@ -1032,9 +1032,9 @@ public class XmlParserDstu2_1Test {
ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder("<Patient", "<text>", "<div xmlns=\"http://www.w3.org/1999/xhtml\">BARFOO</div>", "<contained>", "<Organization", "</Organization"));
assertThat(encoded, not(stringContainsInOrder("<Patient", "<text>", "<contained>", "<Organization", "<text", "</Organization")));
assertThat(encoded, stringContainsInOrder("<Patient", "<text>", "<contained>", "<Organization", "<text", "</Organization"));
assertThat(encoded, not(containsString("FOOBAR")));
assertThat(encoded, (containsString("FOOBAR")));
assertThat(encoded, (containsString("BARFOO")));
}

View File

@ -532,7 +532,7 @@ public class JsonParserHl7OrgDstu2Test {
}
@Test
public void testEncodeContainedWithNarrativeIsSuppresed() throws Exception {
public void testEncodeContainedWithNarrative() throws Exception {
IParser parser = ourCtx.newJsonParser().setPrettyPrint(true);
// Create an organization, note that the organization does not have an ID
@ -549,7 +549,7 @@ public class JsonParserHl7OrgDstu2Test {
String encoded = parser.encodeResourceToString(patient);
ourLog.info(encoded);
assertThat(encoded, not(containsString("FOOBAR")));
assertThat(encoded, (containsString("FOOBAR")));
assertThat(encoded, (containsString("BARFOO")));
}

View File

@ -510,7 +510,7 @@ public class XmlParserHl7OrgDstu2Test {
}
@Test
public void testEncodeContainedWithNarrativeIsSuppresed() throws Exception {
public void testEncodeContainedWithNarrative() throws Exception {
IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
// Create an organization, note that the organization does not have an ID

View File

@ -1233,7 +1233,7 @@ public class Dstu3XmlParserTest {
}
@Test
public void testEncodeContainedWithNarrativeIsSuppresed() throws Exception {
public void testEncodeContainedWithNarrative() throws Exception {
IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
// Create an organization, note that the organization does not have an ID
@ -1252,9 +1252,9 @@ public class Dstu3XmlParserTest {
ourLog.info(encoded);
assertThat(encoded, stringContainsInOrder("<Patient", "<text>", "<div xmlns=\"http://www.w3.org/1999/xhtml\">BARFOO</div>", "<contained>", "<Organization", "</Organization"));
assertThat(encoded, not(stringContainsInOrder("<Patient", "<text>", "<contained>", "<Organization", "<text", "</Organization")));
assertThat(encoded, stringContainsInOrder("<Patient", "<text>", "<contained>", "<Organization", "<text", "</Organization"));
assertThat(encoded, not(containsString("FOOBAR")));
assertThat(encoded, (containsString("FOOBAR")));
assertThat(encoded, (containsString("BARFOO")));
}