From c7558c77802e2d694d9779564a0a92db54e270f8 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 24 Mar 2015 17:18:34 -0400 Subject: [PATCH] Fix #131 - Narrative generator incorrectly sets the Resource.text.status to 'generated' even if the given resource type does not have a template (and therefore no narrative is actually generated). --- ...Enum.java => RestSearchParameterType.java} | 0 .../BaseThymeleafNarrativeGenerator.java | 4 + .../ca/uhn/fhir/parser/XmlParserTest.java | 18 ++++ .../src/test/resources/condition.xml | 85 +++++++++++++++++++ src/changes/changes.xml | 5 ++ 5 files changed, 112 insertions(+) rename hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/valueset/{SearchParamTypeEnum.java => RestSearchParameterType.java} (100%) create mode 100644 hapi-fhir-structures-dstu/src/test/resources/condition.xml diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/valueset/SearchParamTypeEnum.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/valueset/RestSearchParameterType.java similarity index 100% rename from hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/valueset/SearchParamTypeEnum.java rename to hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/valueset/RestSearchParameterType.java diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGenerator.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGenerator.java index a9de45737e55..69a24b3a6ebf 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGenerator.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGenerator.java @@ -147,6 +147,10 @@ public void generateNarrative(String theProfile, IBaseResource theResource, Base result = cleanWhitespace(result); ourLog.trace("Post-whitespace cleaning: ", result); } + + if (isBlank(result)) { + return; + } theNarrative.getDiv().setValueAsString(result); theNarrative.getStatus().setValueAsString("generated"); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java index 8591b53b8e22..0d189ac743f2 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java @@ -50,6 +50,7 @@ import ca.uhn.fhir.model.dstu.resource.AllergyIntolerance; import ca.uhn.fhir.model.dstu.resource.Binary; import ca.uhn.fhir.model.dstu.resource.Composition; +import ca.uhn.fhir.model.dstu.resource.Condition; import ca.uhn.fhir.model.dstu.resource.Conformance; import ca.uhn.fhir.model.dstu.resource.Conformance.RestResource; import ca.uhn.fhir.model.dstu.resource.DiagnosticReport; @@ -73,6 +74,7 @@ import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.model.primitive.StringDt; +import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator; import ca.uhn.fhir.narrative.INarrativeGenerator; import ca.uhn.fhir.parser.JsonParserTest.MyPatientWithOneDeclaredAddressExtension; import ca.uhn.fhir.parser.JsonParserTest.MyPatientWithOneDeclaredExtension; @@ -97,6 +99,22 @@ public void testComposition() { } + /** + * See #131 + */ + @Test + public void testParseAndReencodeCondition() { + FhirContext ctx = FhirContext.forDstu1(); + ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); + InputStreamReader reader = new InputStreamReader(XmlParserTest.class.getResourceAsStream("/condition.xml")); + Condition cond = ctx.newXmlParser().parseResource(Condition.class, reader); + + String enc = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(cond); + ourLog.info(enc); + + assertThat(enc, not(containsString("generated"))); + } + @Test public void testEncodeOmitsVersionAndBase() { Patient p = new Patient(); diff --git a/hapi-fhir-structures-dstu/src/test/resources/condition.xml b/hapi-fhir-structures-dstu/src/test/resources/condition.xml new file mode 100644 index 000000000000..8908600b00db --- /dev/null +++ b/hapi-fhir-structures-dstu/src/test/resources/condition.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/changes/changes.xml b/src/changes/changes.xml index f78065d0eda4..391e6f519c0f 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -64,6 +64,11 @@ reference if the base matches the base for the server giving the response. + + Narrative generator incorrectly sets the Resource.text.status to 'generated' even if the + given resource type does not have a template (and therefore no narrative is actually generated). + Thanks to Bill de Beaubien for reporting! +