mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-08 14:05:02 +00:00
Narrative enhancements
This commit is contained in:
parent
ece3fab5f8
commit
4953c5629c
@ -0,0 +1,9 @@
|
|||||||
|
package ca.uhn.fhir.narrative;
|
||||||
|
|
||||||
|
public class BaseThymeleafNarrativeGenerator {
|
||||||
|
|
||||||
|
public String getPropertyFile() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -38,8 +38,9 @@ import ca.uhn.fhir.model.dstu.valueset.NarrativeStatusEnum;
|
|||||||
import ca.uhn.fhir.model.primitive.XhtmlDt;
|
import ca.uhn.fhir.model.primitive.XhtmlDt;
|
||||||
import ca.uhn.fhir.parser.DataFormatException;
|
import ca.uhn.fhir.parser.DataFormatException;
|
||||||
|
|
||||||
public class ThymeleafNarrativeGenerator implements INarrativeGenerator {
|
public class DefaultThymeleafNarrativeGenerator extends BaseThymeleafNarrativeGenerator implements INarrativeGenerator {
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ThymeleafNarrativeGenerator.class);
|
|
||||||
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DefaultThymeleafNarrativeGenerator.class);
|
||||||
|
|
||||||
private HashMap<String, String> myDatatypeClassNameToNarrativeTemplate;
|
private HashMap<String, String> myDatatypeClassNameToNarrativeTemplate;
|
||||||
private TemplateEngine myDatatypeTemplateEngine;
|
private TemplateEngine myDatatypeTemplateEngine;
|
||||||
@ -51,11 +52,11 @@ public class ThymeleafNarrativeGenerator implements INarrativeGenerator {
|
|||||||
private TemplateEngine myProfileTemplateEngine;
|
private TemplateEngine myProfileTemplateEngine;
|
||||||
private HashMap<String, String> myProfileToNarrativeTemplate;
|
private HashMap<String, String> myProfileToNarrativeTemplate;
|
||||||
|
|
||||||
public ThymeleafNarrativeGenerator() throws IOException {
|
public DefaultThymeleafNarrativeGenerator() throws IOException {
|
||||||
myProfileToNarrativeTemplate = new HashMap<String, String>();
|
myProfileToNarrativeTemplate = new HashMap<String, String>();
|
||||||
myDatatypeClassNameToNarrativeTemplate = new HashMap<String, String>();
|
myDatatypeClassNameToNarrativeTemplate = new HashMap<String, String>();
|
||||||
|
|
||||||
String propFileName = "classpath:ca/uhn/fhir/narrative/narratives.properties";
|
String propFileName = getPropertyFile();
|
||||||
loadProperties(propFileName);
|
loadProperties(propFileName);
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -81,6 +82,11 @@ public class ThymeleafNarrativeGenerator implements INarrativeGenerator {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPropertyFile() {
|
||||||
|
return "classpath:ca/uhn/fhir/narrative/narratives.properties";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NarrativeDt generateNarrative(String theProfile, IResource theResource) {
|
public NarrativeDt generateNarrative(String theProfile, IResource theResource) {
|
||||||
if (myIgnoreMissingTemplates && !myProfileToNarrativeTemplate.containsKey(theProfile)) {
|
if (myIgnoreMissingTemplates && !myProfileToNarrativeTemplate.containsKey(theProfile)) {
|
||||||
@ -174,9 +180,9 @@ public class ThymeleafNarrativeGenerator implements INarrativeGenerator {
|
|||||||
private InputStream loadResource(String name) {
|
private InputStream loadResource(String name) {
|
||||||
if (name.startsWith("classpath:")) {
|
if (name.startsWith("classpath:")) {
|
||||||
String cpName = name.substring("classpath:".length());
|
String cpName = name.substring("classpath:".length());
|
||||||
InputStream resource = ThymeleafNarrativeGenerator.class.getResourceAsStream(cpName);
|
InputStream resource = DefaultThymeleafNarrativeGenerator.class.getResourceAsStream(cpName);
|
||||||
if (resource == null) {
|
if (resource == null) {
|
||||||
resource = ThymeleafNarrativeGenerator.class.getResourceAsStream("/" + cpName);
|
resource = DefaultThymeleafNarrativeGenerator.class.getResourceAsStream("/" + cpName);
|
||||||
if (resource == null) {
|
if (resource == null) {
|
||||||
throw new ConfigurationException("Can not find '" + cpName + "' on classpath");
|
throw new ConfigurationException("Can not find '" + cpName + "' on classpath");
|
||||||
}
|
}
|
@ -8,9 +8,14 @@
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div class="hapiHeaderText">
|
<div class="hapiHeaderText">
|
||||||
|
<!--/*
|
||||||
|
Show the DiagnosticReport's name.text value, or if that isn't populated, show the
|
||||||
|
display value on the first coding, and if that's missing too show a default "Untitled"
|
||||||
|
value
|
||||||
|
*/-->
|
||||||
<th:block th:if="${not resource.name.text.empty}" th:text="${resource.name.text.value}"/>
|
<th:block th:if="${not resource.name.text.empty}" th:text="${resource.name.text.value}"/>
|
||||||
<th:block th:if="${resource.name.text.empty} and ${not #lists.isEmpty(resource.name.coding)} and ${not resource.name.coding[0].empty} and ${not resource.name.coding[0].display.empty}" th:text="${resource.name.coding[0].display}"/>
|
<th:block th:if=" ${resource.name.text.empty} and ${not resource.name.codingFirstRep.display.empty}" th:text="${resource.name.codingFirstRep.display}"/>
|
||||||
<th:block th:if="${resource.name.text.empty} and ${not #lists.isEmpty(resource.name.coding)} and ${not resource.name.coding[0].empty} and ${resource.name.coding[0].display.empty}" th:text="Untitled Diagnostic Report"/>
|
<th:block th:if= "${resource.name.text.empty} and ${resource.name.codingFirstRep.display.empty}" th:text="Untitled Diagnostic Report"/>
|
||||||
<!--/*--> Complete Blood Count <!--*/-->
|
<!--/*--> Complete Blood Count <!--*/-->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -22,11 +22,11 @@ import ca.uhn.fhir.parser.DataFormatException;
|
|||||||
|
|
||||||
public class ThymeleafNarrativeGeneratorTest {
|
public class ThymeleafNarrativeGeneratorTest {
|
||||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ThymeleafNarrativeGeneratorTest.class);
|
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ThymeleafNarrativeGeneratorTest.class);
|
||||||
private ThymeleafNarrativeGenerator gen;
|
private DefaultThymeleafNarrativeGenerator gen;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() throws IOException {
|
public void before() throws IOException {
|
||||||
gen = new ThymeleafNarrativeGenerator();
|
gen = new DefaultThymeleafNarrativeGenerator();
|
||||||
gen.setIgnoreFailures(false);
|
gen.setIgnoreFailures(false);
|
||||||
gen.setIgnoreMissingTemplates(true);
|
gen.setIgnoreMissingTemplates(true);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user