overwritten section text in composition #402

This commit is contained in:
Oliver Egger 2019-05-29 21:56:39 +02:00
parent 43a8499bf6
commit 24c9c27abb
3 changed files with 74 additions and 2 deletions

View File

@ -369,8 +369,7 @@ public class XmlParser extends BaseParser /* implements IParser */ {
} else {
narr = null;
}
// FIXME potential null access on narr see line 623
if (gen != null && narr.isEmpty()) {
if (gen != null && (narr==null || narr.isEmpty())) {
gen.populateResourceNarrative(myContext, theResource);
}
if (narr != null && narr.isEmpty() == false) {

View File

@ -374,6 +374,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);
}
@AfterClass
public static void afterClassClearContext() {

View File

@ -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);
}
}