From ec2326b1f294b1a849bf8aa6108bee8241e8a6bc Mon Sep 17 00:00:00 2001 From: James Date: Fri, 4 Jul 2014 16:17:53 -0400 Subject: [PATCH] Narrative fixes --- .../fhir/model/dstu/resource/Encounter.java | 17 +++++++ .../ca/uhn/fhir/model/primitive/StringDt.java | 3 +- .../BaseThymeleafNarrativeGenerator.java | 37 ++++++++++++-- .../java/ca/uhn/fhir/parser/JsonParser.java | 3 -- .../uhn/fhir/rest/server/RestfulServer.java | 3 ++ .../ca/uhn/fhir/narrative/HumanNameDt.html | 6 --- .../ca/uhn/fhir/narrative/Patient.html | 2 +- .../narrative/{ => datatype}/AddressDt.html | 0 .../uhn/fhir/narrative/datatype/CodeDt.html | 3 ++ .../narrative/datatype/CodeableConceptDt.html | 13 +++++ .../narrative/{ => datatype}/DateTimeDt.html | 0 .../fhir/narrative/datatype/HumanNameDt.html | 6 +++ .../fhir/narrative/datatype/IdentifierDt.html | 4 ++ .../uhn/fhir/narrative/datatype/PeriodDt.html | 5 ++ .../narrative/{ => datatype}/QuantityDt.html | 0 .../narrative/{ => datatype}/StringDt.html | 0 .../uhn/fhir/narrative/narratives.properties | 37 ++++++++++---- .../uhn/fhir/narrative/title/Encounter.html | 15 ++++++ .../ca/uhn/fhir/narrative/title/Patient.html | 7 +-- ...efaultThymeleafNarrativeGeneratorTest.java | 50 ++++++++++++++++--- .../src/main/resources/logback.xml | 20 +++++++- .../WEB-INF/templates/tmpl-navbar-left.html | 7 ++- .../src/main/resources/vm/templates.vm | 16 ++++++ 23 files changed, 213 insertions(+), 41 deletions(-) delete mode 100644 hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/HumanNameDt.html rename hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/{ => datatype}/AddressDt.html (100%) create mode 100644 hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/CodeDt.html create mode 100644 hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/CodeableConceptDt.html rename hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/{ => datatype}/DateTimeDt.html (100%) create mode 100644 hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/HumanNameDt.html create mode 100644 hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/IdentifierDt.html create mode 100644 hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/PeriodDt.html rename hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/{ => datatype}/QuantityDt.html (100%) rename hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/{ => datatype}/StringDt.html (100%) create mode 100644 hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/title/Encounter.html diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/resource/Encounter.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/resource/Encounter.java index 62bcfbfea42..a9480a9986d 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/resource/Encounter.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/dstu/resource/Encounter.java @@ -583,6 +583,23 @@ public class Encounter extends BaseResource implements IResource { return myType; } + /** + * Gets the value(s) for type (Specific type of encounter). + * creating it if it does + * not exist. Will not return null. + * + *

+ * Definition: + * Specific type of encounter (e.g. e-mail consultation, surgical day-care, skilled nursing, rehabilitation) + *

+ */ + public BoundCodeableConceptDt getTypeFirstRep() { + if (getType().size()==0) { + addType(); + } + return getType().get(0); + } + /** * Sets the value(s) for type (Specific type of encounter) * diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/StringDt.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/StringDt.java index 6ddf09e3809..86e00f0a4e1 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/StringDt.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/model/primitive/StringDt.java @@ -126,7 +126,8 @@ public class StringDt extends BasePrimitive implements IQueryParameterTy */ @Override public boolean isEmpty() { - return super.isBaseEmpty() && StringUtils.isBlank(getValue()); + boolean retVal = super.isBaseEmpty() && StringUtils.isBlank(getValue()); + return retVal; } @Override 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 d2622224797..6a46748e5ec 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 @@ -53,8 +53,10 @@ import org.thymeleaf.standard.expression.IStandardExpressionParser; import org.thymeleaf.standard.expression.StandardExpressions; import org.thymeleaf.templateresolver.TemplateResolver; import org.thymeleaf.util.DOMUtils; +import org.w3c.dom.Text; import ca.uhn.fhir.context.ConfigurationException; +import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu.composite.NarrativeDt; import ca.uhn.fhir.model.dstu.valueset.NarrativeStatusEnum; @@ -94,6 +96,8 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener initialize(); } + ourLog.trace("Generating resource title {}", theResource); + String name = null; if (StringUtils.isNotBlank(theProfile)) { name = myProfileToName.get(theProfile); @@ -102,6 +106,8 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener name = myClassToName.get(theResource.getClass()); } + ourLog.trace("Template name is {}", name); + if (name == null) { if (myIgnoreMissingTemplates) { ourLog.debug("No title template available for profile: {}", theProfile); @@ -116,6 +122,9 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener context.setVariable("resource", theResource); String result = myTitleTemplateEngine.process(name, context); + + ourLog.trace("Produced {}", result); + StringBuilder b = new StringBuilder(); boolean inTag = false; for (int i = 0; i < result.length(); i++) { @@ -152,6 +161,8 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener result = result.substring(0, result.lastIndexOf('<')); } + result = result.replace(">", ">").replace("<", "<").replace("&", "&"); + return result; } catch (Exception e) { if (myIgnoreFailures) { @@ -214,6 +225,9 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener if (myInitialized) { return; } + + ourLog.info("Initializing narrative generator"); + myProfileToName = new HashMap(); myClassToName = new HashMap, String>(); myNameToNarrativeTemplate = new HashMap(); @@ -250,6 +264,9 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener resolver.setResourceResolver(new TitleResourceResolver()); myTitleTemplateEngine.setTemplateResolver(resolver); StandardDialect dialect = new StandardDialect(); + HashSet additionalProcessors = new HashSet(); + additionalProcessors.add(new NarrativeAttributeProcessor()); + dialect.setAdditionalProcessors(additionalProcessors); myTitleTemplateEngine.setDialect(dialect); myTitleTemplateEngine.initialize(); } @@ -486,7 +503,13 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener Context context = new Context(); context.setVariable("resource", value); - String name = myClassToName.get(value.getClass()); + String name = null; + Class nextClass = value.getClass(); + do { + name = myClassToName.get(nextClass); + nextClass=nextClass.getSuperclass(); + } while (name == null && nextClass.equals(Object.class)==false); + if (name == null) { if (myIgnoreMissingTemplates) { ourLog.debug("No narrative template available for type: {}", value.getClass()); @@ -497,10 +520,18 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener } String result = myProfileTemplateEngine.process(name, context); - Document dom = DOMUtils.getXhtmlDOMFor(new StringReader(result)); + String trim = result.trim(); + Document dom = DOMUtils.getXhtmlDOMFor(new StringReader(trim)); Element firstChild = (Element) dom.getFirstChild(); - for (Node next : firstChild.getChildren()) { + for (int i = 0; i < firstChild.getChildren().size(); i++) { + Node next = firstChild.getChildren().get(i); + if (i == 0 && firstChild.getChildren().size() == 1) { + if (next instanceof org.thymeleaf.dom.Text) { + org.thymeleaf.dom.Text nextText = (org.thymeleaf.dom.Text) next; + nextText.setContent(nextText.getContent().trim()); + } + } theElement.addChild(next); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java index 54c9a7b1b1d..79f506da829 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java @@ -223,7 +223,6 @@ public class JsonParser extends BaseParser implements IParser { eventWriter.writeEnd(); eventWriter.flush(); - eventWriter.close(); } private void encodeChildElementToStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, JsonGenerator theWriter, IElement theValue, BaseRuntimeElementDefinition theChildDef, String theChildName) throws IOException { @@ -507,7 +506,6 @@ public class JsonParser extends BaseParser implements IParser { RuntimeResourceDefinition resDef = myContext.getResourceDefinition(theResource); encodeResourceToJsonStreamWriter(resDef, theResource, eventWriter, null,false); eventWriter.flush(); - eventWriter.close(); } @Override @@ -538,7 +536,6 @@ public class JsonParser extends BaseParser implements IParser { eventWriter.writeEnd(); eventWriter.flush(); - eventWriter.close(); } /** diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java index beeb31cda7f..f29ad4cc76f 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java @@ -783,9 +783,12 @@ public class RestfulServer extends HttpServlet { if (theContext.getNarrativeGenerator() != null) { String title = theContext.getNarrativeGenerator().generateTitle(next); + ourLog.info("Narrative generator created title: {}", title); if (StringUtils.isNotBlank(title)) { ResourceMetadataKeyEnum.TITLE.put(next, title); } + } else { + ourLog.info("No narrative generator specified"); } bundle.addResource(next, theContext, theServerBase); diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/HumanNameDt.html b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/HumanNameDt.html deleted file mode 100644 index dc31fbb41e1..00000000000 --- a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/HumanNameDt.html +++ /dev/null @@ -1,6 +0,0 @@ -
- Dr - John - SMITH - Jr -
diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/Patient.html b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/Patient.html index 32459aa260c..c8ad016b4ba 100644 --- a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/Patient.html +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/Patient.html @@ -16,7 +16,7 @@ a browser. Identifier - 8708660 + 8708660 Address diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/AddressDt.html b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/AddressDt.html similarity index 100% rename from hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/AddressDt.html rename to hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/AddressDt.html diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/CodeDt.html b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/CodeDt.html new file mode 100644 index 00000000000..9035b165488 --- /dev/null +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/CodeDt.html @@ -0,0 +1,3 @@ +
+ +
diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/CodeableConceptDt.html b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/CodeableConceptDt.html new file mode 100644 index 00000000000..8d04c0f83b5 --- /dev/null +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/CodeableConceptDt.html @@ -0,0 +1,13 @@ +
+ + + + + + + + + + + +
diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/DateTimeDt.html b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/DateTimeDt.html similarity index 100% rename from hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/DateTimeDt.html rename to hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/DateTimeDt.html diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/HumanNameDt.html b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/HumanNameDt.html new file mode 100644 index 00000000000..60c0b98f2ce --- /dev/null +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/HumanNameDt.html @@ -0,0 +1,6 @@ +
+ Dr + John + SMITH + Jr +
diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/IdentifierDt.html b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/IdentifierDt.html new file mode 100644 index 00000000000..a5d6437f0bc --- /dev/null +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/IdentifierDt.html @@ -0,0 +1,4 @@ +
+ + +
diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/PeriodDt.html b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/PeriodDt.html new file mode 100644 index 00000000000..11b2757a253 --- /dev/null +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/PeriodDt.html @@ -0,0 +1,5 @@ +
+ + + +
diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/QuantityDt.html b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/QuantityDt.html similarity index 100% rename from hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/QuantityDt.html rename to hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/QuantityDt.html diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/StringDt.html b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/StringDt.html similarity index 100% rename from hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/StringDt.html rename to hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/datatype/StringDt.html diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/narratives.properties b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/narratives.properties index 0062367beb8..f9afc4ad70b 100644 --- a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/narratives.properties +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/narratives.properties @@ -3,38 +3,53 @@ # Primitive Datatypes ################################################ -string.class=ca.uhn.fhir.model.primitive.StringDt -string.narrative=classpath:ca/uhn/fhir/narrative/StringDt.html +code.class=ca.uhn.fhir.model.primitive.CodeDt +code.narrative=classpath:ca/uhn/fhir/narrative/datatype/CodeDt.html datetime.class=ca.uhn.fhir.model.primitive.DateTimeDt -datetime.narrative=classpath:ca/uhn/fhir/narrative/DateTimeDt.html +datetime.narrative=classpath:ca/uhn/fhir/narrative/datatype/DateTimeDt.html # Instant uses DateTime narrative instant.class=ca.uhn.fhir.model.primitive.InstantDt -instant.narrative=classpath:ca/uhn/fhir/narrative/DateTimeDt.html +instant.narrative=classpath:ca/uhn/fhir/narrative/datatype/DateTimeDt.html + +string.class=ca.uhn.fhir.model.primitive.StringDt +string.narrative=classpath:ca/uhn/fhir/narrative/datatype/StringDt.html ################################################ # Composite Datatypes ################################################ address.class=ca.uhn.fhir.model.dstu.composite.AddressDt -address.narrative=classpath:ca/uhn/fhir/narrative/AddressDt.html +address.narrative=classpath:ca/uhn/fhir/narrative/datatype/AddressDt.html + +codeableconcept.class=ca.uhn.fhir.model.dstu.composite.CodeableConceptDt +codeableconcept.narrative=classpath:ca/uhn/fhir/narrative/datatype/CodeableConceptDt.html humanname.class=ca.uhn.fhir.model.dstu.composite.HumanNameDt -humanname.narrative=classpath:ca/uhn/fhir/narrative/HumanNameDt.html +humanname.narrative=classpath:ca/uhn/fhir/narrative/datatype/HumanNameDt.html + +identifier.class=ca.uhn.fhir.model.dstu.composite.IdentifierDt +identifier.narrative=classpath:ca/uhn/fhir/narrative/datatype/IdentifierDt.html + +period.class=ca.uhn.fhir.model.dstu.composite.PeriodDt +period.narrative=classpath:ca/uhn/fhir/narrative/datatype/PeriodDt.html quantity.class=ca.uhn.fhir.model.dstu.composite.QuantityDt -quantity.narrative=classpath:ca/uhn/fhir/narrative/QuantityDt.html +quantity.narrative=classpath:ca/uhn/fhir/narrative/datatype/QuantityDt.html ################################################ # Resources ################################################ +diagnosticreport.class=ca.uhn.fhir.model.dstu.resource.DiagnosticReport +diagnosticreport.narrative=classpath:ca/uhn/fhir/narrative/DiagnosticReport.html +diagnosticreport.title=classpath:ca/uhn/fhir/narrative/title/DiagnosticReport.html + +encounter.class=ca.uhn.fhir.model.dstu.resource.Encounter +encounter.title=classpath:ca/uhn/fhir/narrative/title/Encounter.html + patient.class=ca.uhn.fhir.model.dstu.resource.Patient patient.narrative=classpath:ca/uhn/fhir/narrative/Patient.html patient.title=classpath:ca/uhn/fhir/narrative/title/Patient.html - -diagnosticreport.class=ca.uhn.fhir.model.dstu.resource.DiagnosticReport -diagnosticreport.narrative=classpath:ca/uhn/fhir/narrative/DiagnosticReport.html -diagnosticreport.title=classpath:ca/uhn/fhir/narrative/title/DiagnosticReport.html diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/title/Encounter.html b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/title/Encounter.html new file mode 100644 index 00000000000..40abd264e2c --- /dev/null +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/title/Encounter.html @@ -0,0 +1,15 @@ +
+ + + / + + + / + + + / + + + / + +
diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/title/Patient.html b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/title/Patient.html index 6b94c7e9760..d2ff5902a74 100644 --- a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/title/Patient.html +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/narrative/title/Patient.html @@ -1,9 +1,6 @@
- Dr - John - SMITH - Jr + - (8708660) + (8708660)
diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTest.java index e2e0ef0bb6a..8194dfc03da 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTest.java @@ -10,20 +10,27 @@ import org.junit.Before; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.TemporalPrecisionEnum; import ca.uhn.fhir.model.dstu.composite.NarrativeDt; +import ca.uhn.fhir.model.dstu.composite.PeriodDt; import ca.uhn.fhir.model.dstu.composite.QuantityDt; import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt; import ca.uhn.fhir.model.dstu.resource.Conformance; import ca.uhn.fhir.model.dstu.resource.DiagnosticReport; +import ca.uhn.fhir.model.dstu.resource.Encounter; import ca.uhn.fhir.model.dstu.resource.Observation; import ca.uhn.fhir.model.dstu.resource.Patient; import ca.uhn.fhir.model.dstu.valueset.DiagnosticReportStatusEnum; +import ca.uhn.fhir.model.dstu.valueset.EncounterClassEnum; +import ca.uhn.fhir.model.dstu.valueset.EncounterTypeEnum; import ca.uhn.fhir.model.dstu.valueset.ObservationStatusEnum; +import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.parser.DataFormatException; public class DefaultThymeleafNarrativeGeneratorTest { + private FhirContext myCtx; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DefaultThymeleafNarrativeGeneratorTest.class); private DefaultThymeleafNarrativeGenerator gen; @@ -33,14 +40,20 @@ public class DefaultThymeleafNarrativeGeneratorTest { gen.setUseHapiServerConformanceNarrative(true); gen.setIgnoreFailures(false); gen.setIgnoreMissingTemplates(false); + + myCtx=new FhirContext(); + myCtx.setNarrativeGenerator(gen); } + + + @Test public void testGeneratePatient() throws DataFormatException { Patient value = new Patient(); value.addIdentifier().setSystem("urn:names").setValue("123456"); - value.addName().addFamily("blow").addGiven("joe").addGiven("john"); + value.addName().addFamily("blow").addGiven("joe").addGiven(null).addGiven("john"); value.getAddressFirstRep().addLine("123 Fake Street").addLine("Unit 1"); value.getAddressFirstRep().setCity("Toronto").setState("ON").setCountry("Canada"); @@ -52,11 +65,33 @@ public class DefaultThymeleafNarrativeGeneratorTest { String title = gen.generateTitle(value); assertEquals("joe john BLOW (123456)", title); ourLog.info(title); + + value.getIdentifierFirstRep().setLabel("FOO MRN 123"); + title = gen.generateTitle(value); + assertEquals("joe john BLOW (FOO MRN 123)", title); + ourLog.info(title); + + } + + + @Test + public void testGenerateEncounter() throws DataFormatException { + Encounter enc = new Encounter(); + + enc.addIdentifier("urn:visits", "1234567"); + enc.setClassElement(EncounterClassEnum.AMBULATORY); + enc.setPeriod(new PeriodDt().setStart(new DateTimeDt("2001-01-02T11:11:00"))); + enc.setType(EncounterTypeEnum.ANNUAL_DIABETES_MELLITUS_SCREENING); + + String title = gen.generateTitle(enc); + assertEquals("1234567 / ADMS / ambulatory / Tue Jan 02 11:11:00 EST 2001 - ?", title); + ourLog.info(title); + } @Test public void testGenerateServerConformance() throws DataFormatException { - Conformance value = new FhirContext().newXmlParser().parseResource(Conformance.class, new InputStreamReader(getClass().getResourceAsStream("/server-conformance-statement.xml"))); + Conformance value = myCtx.newXmlParser().parseResource(Conformance.class, new InputStreamReader(getClass().getResourceAsStream("/server-conformance-statement.xml"))); String output = gen.generateNarrative(value).getDiv().getValueAsString(); @@ -76,6 +111,7 @@ public class DefaultThymeleafNarrativeGeneratorTest { String output = gen.generateNarrative("http://hl7.org/fhir/profiles/DiagnosticReport", value).getDiv().getValueAsString(); ourLog.info(output); + assertThat(output,StringContains.containsString(value.getName().getText().getValue())); } @Test @@ -85,7 +121,7 @@ public class DefaultThymeleafNarrativeGeneratorTest { value.getIssued().setValueAsString("2011-02-22T11:13:00"); value.setStatus(DiagnosticReportStatusEnum.FINAL); - value.getName().setText("Some Diagnostic Report"); + value.getName().setText("Some & Diagnostic Report"); { Observation obs = new Observation(); obs.getName().addCoding().setCode("1938HB").setDisplay("Hemoglobin"); @@ -106,7 +142,7 @@ public class DefaultThymeleafNarrativeGeneratorTest { String output = generateNarrative.getDiv().getValueAsString(); ourLog.info(output); - assertThat(output, StringContains.containsString("
Some Diagnostic Report
")); + assertThat(output, StringContains.containsString("
Some & Diagnostic Report
")); String title = gen.generateTitle(value); ourLog.info(title); @@ -115,11 +151,9 @@ public class DefaultThymeleafNarrativeGeneratorTest { // Now try it with the parser - FhirContext context = new FhirContext(); - context.setNarrativeGenerator(gen); - output = context.newXmlParser().setPrettyPrint(true).encodeResourceToString(value); + output = myCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(value); ourLog.info(output); - assertThat(output, StringContains.containsString("
Some Diagnostic Report
")); + assertThat(output, StringContains.containsString("
Some & Diagnostic Report
")); } diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/resources/logback.xml b/hapi-fhir-jpaserver-uhnfhirtest/src/main/resources/logback.xml index 8da72a0e285..bcd2eb75fef 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/resources/logback.xml +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/resources/logback.xml @@ -9,8 +9,24 @@ - - + + + INFO + + ${fhir.logdir}/logFile.log + + ${fhir.logdir}/logFile.%d{yyyy-MM-dd}.log.gz + 30 + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} %msg%n + + + + + \ No newline at end of file diff --git a/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/tmpl-navbar-left.html b/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/tmpl-navbar-left.html index 0fa4a33ab69..b8583eace63 100644 --- a/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/tmpl-navbar-left.html +++ b/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/tmpl-navbar-left.html @@ -16,7 +16,7 @@
-
+