Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encode narratives of contained resources #3402

Merged
merged 2 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
encode narratives of contained resources
fixes #1466
  • Loading branch information
patrick-werner committed Feb 17, 2022
commit 9f2af9747fbd600c78acd0955554515cdf0394b9
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ protected Iterable<CompositeChildElement> compositeChildIterator(IBase theCompos
} else if (myNext.getDef() instanceof RuntimeChildNarrativeDefinition) {
if (isSuppressNarratives() || isSummaryMode()) {
continue;
} else if (theContainedResource) {
continue;
}
} else if (myNext.getDef() instanceof RuntimeChildContainedResources) {
if (theContainedResource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,6 @@ private void encodeCompositeElementChildrenToStreamWriter(RuntimeResourceDefinit
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,6 @@ private void encodeCompositeElementToStreamWriter(IBaseResource theResource, IBa
}
}
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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
type: fix
issue: 1466
title: "The XML and JSON Parser are now encoding narratives of contained resourcess"
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ public void testEncodeContainedResourcesManualContainUsingNonLocalId() {
}

@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
Expand All @@ -990,9 +990,9 @@ public void testEncodeContainedWithNarrativeIsSuppresed() throws Exception {
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")));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ public void testEncodeContainedResourcesManualContainUsingNonLocalId() {
}

@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
Expand All @@ -1389,9 +1389,9 @@ public void testEncodeContainedWithNarrativeIsSuppresed() throws Exception {
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")));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ public void testEncodeContainedResourcesManualContainUsingNonLocalId() {
}

@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
Expand All @@ -1433,9 +1433,9 @@ public void testEncodeContainedWithNarrativeIsSuppresed() throws Exception {
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")));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ public void testEncodeContainedResourcesMore() throws Exception {
}

@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
Expand All @@ -532,7 +532,7 @@ public void testEncodeContainedWithNarrativeIsSuppresed() throws Exception {

String encoded = parser.encodeResourceToString(patient);
ourLog.info(encoded);
assertThat(encoded, not(containsString("FOOBAR")));
assertThat(encoded, (containsString("FOOBAR")));
assertThat(encoded, (containsString("BARFOO")));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,39 @@
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;
Expand Down Expand Up @@ -343,7 +369,7 @@ public void testEncodeAndParseExtensions() throws Exception {
/**
* See #216 - Profiled datatypes should use their unprofiled parent type as
* the choice[x] name
*
* <p>
* Disabled after conversation with Grahame
*/
@Test
Expand Down Expand Up @@ -763,7 +789,7 @@ public void testEncodeContainedResources() throws Exception {
}

@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
Expand All @@ -782,11 +808,11 @@ public void testEncodeContainedWithNarrativeIsSuppresed() throws Exception {
ourLog.info(encoded);

assertThat(encoded, stringContainsInOrder("<Patient", "<text>",
"<div xmlns=\"http://www.w3.org/1999/xhtml\">BARFOO</div>", "<contained>", "<Organization", "</Organization"));
"<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")));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ public void testEncodeContainedResourcesManualContainUsingNonLocalId() {
}

@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
Expand All @@ -1032,9 +1032,9 @@ public void testEncodeContainedWithNarrativeIsSuppresed() throws Exception {
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")));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ public void testEncodeContainedResourcesMore() throws Exception {
}

@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
Expand All @@ -549,7 +549,7 @@ public void testEncodeContainedWithNarrativeIsSuppresed() throws Exception {

String encoded = parser.encodeResourceToString(patient);
ourLog.info(encoded);
assertThat(encoded, not(containsString("FOOBAR")));
assertThat(encoded, (containsString("FOOBAR")));
assertThat(encoded, (containsString("BARFOO")));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ public void testEncodeContainedResources() throws Exception {
}

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ public void testEncodeContainedResourcesManualContainUsingNonLocalId() {
}

@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
Expand All @@ -1252,9 +1252,9 @@ public void testEncodeContainedWithNarrativeIsSuppresed() throws Exception {
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")));

}
Expand Down