diff --git a/example-projects/hapi-fhir-jpaserver-dynamic/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java b/example-projects/hapi-fhir-jpaserver-dynamic/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java index bbd4d228ed8..b6c86dc655b 100644 --- a/example-projects/hapi-fhir-jpaserver-dynamic/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java +++ b/example-projects/hapi-fhir-jpaserver-dynamic/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java @@ -108,7 +108,7 @@ public class JpaServerDemo extends RestfulServer { * This server tries to dynamically generate narratives */ FhirContext ctx = getFhirContext(); - ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator(getFhirContext())); + ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); /* * Default to JSON and pretty printing diff --git a/example-projects/hapi-fhir-jpaserver-dynamic/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemoDstu2.java b/example-projects/hapi-fhir-jpaserver-dynamic/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemoDstu2.java index 0d4121947d9..3c802e6cb10 100644 --- a/example-projects/hapi-fhir-jpaserver-dynamic/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemoDstu2.java +++ b/example-projects/hapi-fhir-jpaserver-dynamic/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemoDstu2.java @@ -108,7 +108,7 @@ public class JpaServerDemoDstu2 extends RestfulServer { * This server tries to dynamically generate narratives */ FhirContext ctx = getFhirContext(); - ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator(getFhirContext())); + ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); /* * Default to JSON and pretty printing diff --git a/example-projects/hapi-fhir-jpaserver-example-postgres/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java b/example-projects/hapi-fhir-jpaserver-example-postgres/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java index 06cfed3e03a..93ae03951b4 100644 --- a/example-projects/hapi-fhir-jpaserver-example-postgres/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java +++ b/example-projects/hapi-fhir-jpaserver-example-postgres/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java @@ -75,7 +75,7 @@ public class JpaServerDemo extends RestfulServer { * This server tries to dynamically generate narratives */ FhirContext ctx = getFhirContext(); - ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator(getFhirContext())); + ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); /* * Default to JSON and pretty printing diff --git a/examples/src/main/java/example/Narrative.java b/examples/src/main/java/example/Narrative.java index 4e5acefb25c..d8c5c9aa4ce 100644 --- a/examples/src/main/java/example/Narrative.java +++ b/examples/src/main/java/example/Narrative.java @@ -1,16 +1,15 @@ package example; -import java.io.IOException; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.dstu2.valueset.NarrativeStatusEnum; import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator; import ca.uhn.fhir.parser.DataFormatException; +@SuppressWarnings("unused") public class Narrative { -public static void main(String[] args) throws DataFormatException, IOException { +public static void main(String[] args) throws DataFormatException { //START SNIPPET: example1 Patient patient = new Patient(); @@ -21,7 +20,7 @@ patient.addAddress().addLine("742 Evergreen Terrace").setCity("Springfield").set FhirContext ctx = FhirContext.forDstu2(); // Use the narrative generator -ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator(ctx)); +ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); // Encode the output, including the narrative String output = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(patient); diff --git a/examples/src/main/java/example/NarrativeGenerator.java b/examples/src/main/java/example/NarrativeGenerator.java index c0ad5d3ab28..daeab7ae4ae 100644 --- a/examples/src/main/java/example/NarrativeGenerator.java +++ b/examples/src/main/java/example/NarrativeGenerator.java @@ -1,18 +1,17 @@ package example; -import java.io.IOException; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.narrative.CustomThymeleafNarrativeGenerator; +@SuppressWarnings("unused") public class NarrativeGenerator { - public void testGenerator() throws IOException { + public void testGenerator() { //START SNIPPET: gen FhirContext ctx = FhirContext.forDstu2(); String propFile = "classpath:/com/foo/customnarrative.properties"; -CustomThymeleafNarrativeGenerator gen = new CustomThymeleafNarrativeGenerator(ctx, propFile); +CustomThymeleafNarrativeGenerator gen = new CustomThymeleafNarrativeGenerator(propFile); ctx.setNarrativeGenerator(gen); //END SNIPPET: gen 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 7c0925a0298..dd0c486ae2a 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 @@ -36,7 +36,7 @@ public abstract class BaseThymeleafNarrativeGenerator extends ThymeleafNarrative /** * Constructor */ - public BaseThymeleafNarrativeGenerator() { + protected BaseThymeleafNarrativeGenerator() { super(); } @@ -58,7 +58,7 @@ public abstract class BaseThymeleafNarrativeGenerator extends ThymeleafNarrative List propFileName = getPropertyFile(); try { - NarrativeTemplateManifest manifest = NarrativeTemplateManifest.forManifestFileLocation(propFileName); + NarrativeTemplateManifest manifest = NarrativeTemplateManifest.forManifestFileContents(propFileName); setManifest(manifest); } catch (IOException e) { throw new InternalErrorException(e); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGenerator.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGenerator.java index 9512e15dc03..f466a96ba2c 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGenerator.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGenerator.java @@ -23,7 +23,6 @@ package ca.uhn.fhir.narrative; import java.util.Arrays; import java.util.List; -import ca.uhn.fhir.context.FhirContext; import org.apache.commons.lang3.Validate; public class CustomThymeleafNarrativeGenerator extends BaseThymeleafNarrativeGenerator { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative2/NarrativeTemplateManifest.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative2/NarrativeTemplateManifest.java index b3ddc8e61c8..84496ac7c13 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative2/NarrativeTemplateManifest.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative2/NarrativeTemplateManifest.java @@ -92,22 +92,6 @@ public class NarrativeTemplateManifest implements INarrativeTemplateManifest { } } - public static NarrativeTemplateManifest forManifestFileLocation(FhirContext theFhirContext, String... thePropertyFilePaths) throws IOException { - return forManifestFileLocation(Arrays.asList(thePropertyFilePaths)); - } - - public static NarrativeTemplateManifest forManifestFileLocation(Collection thePropertyFilePaths) throws IOException { - ourLog.debug("Loading narrative properties file(s): {}", thePropertyFilePaths); - - List manifestFileContents = new ArrayList<>(thePropertyFilePaths.size()); - for (String next : thePropertyFilePaths) { - String resource = loadResource(next); - manifestFileContents.add(resource); - } - - return forManifestFileContents(manifestFileContents); - } - public static NarrativeTemplateManifest forManifestFileContents(String... theResources) throws IOException { return forManifestFileContents(Arrays.asList(theResources)); } diff --git a/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java b/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java index ada28037c90..c2bff0b1cfd 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java +++ b/hapi-fhir-cli/hapi-fhir-cli-jpaserver/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java @@ -125,7 +125,7 @@ public class JpaServerDemo extends RestfulServer { * This server tries to dynamically generate narratives */ FhirContext ctx = getFhirContext(); - ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator(getFhirContext())); + ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); /* * Default to XML and pretty printing diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/BaseResourceProviderDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/BaseResourceProviderDstu2Test.java index 5d2c2e612a0..28d6be346d9 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/BaseResourceProviderDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/BaseResourceProviderDstu2Test.java @@ -74,9 +74,9 @@ public abstract class BaseResourceProviderDstu2Test extends BaseJpaDstu2Test { ourRestServer.setResourceProviders((List)myResourceProviders); - ourRestServer.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator(myFhirCtx)); + ourRestServer.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); - ourRestServer.setPlainProviders(mySystemProvider); + ourRestServer.registerProvider(mySystemProvider); JpaConformanceProviderDstu2 confProvider = new JpaConformanceProviderDstu2(ourRestServer, mySystemDao, myDaoConfig); confProvider.setImplementationDescription("THIS IS THE DESC"); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/BaseResourceProviderDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/BaseResourceProviderDstu3Test.java index 751c0cab18c..42bec3d1cd1 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/BaseResourceProviderDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/BaseResourceProviderDstu3Test.java @@ -92,10 +92,10 @@ public abstract class BaseResourceProviderDstu3Test extends BaseJpaDstu3Test { ourRestServer.setResourceProviders((List) myResourceProviders); - ourRestServer.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator(myFhirCtx)); + ourRestServer.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); myTerminologyUploaderProvider = myAppCtx.getBean(TerminologyUploaderProviderDstu3.class); - ourRestServer.setPlainProviders(mySystemProvider, myTerminologyUploaderProvider); + ourRestServer.registerProviders(mySystemProvider, myTerminologyUploaderProvider); SubscriptionTriggeringProvider subscriptionTriggeringProvider = myAppCtx.getBean(SubscriptionTriggeringProvider.class); ourRestServer.registerProvider(subscriptionTriggeringProvider); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BaseResourceProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BaseResourceProviderR4Test.java index 9d6f92504f9..49e99f77006 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BaseResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BaseResourceProviderR4Test.java @@ -99,12 +99,12 @@ public abstract class BaseResourceProviderR4Test extends BaseJpaR4Test { ourRestServer.setResourceProviders((List) myResourceProviders); - ourRestServer.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator(myFhirCtx)); + ourRestServer.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); myTerminologyUploaderProvider = myAppCtx.getBean(TerminologyUploaderProviderR4.class); ourGraphQLProvider = myAppCtx.getBean("myGraphQLProvider"); - ourRestServer.setPlainProviders(mySystemProvider, myTerminologyUploaderProvider, ourGraphQLProvider); + ourRestServer.registerProviders(mySystemProvider, myTerminologyUploaderProvider, ourGraphQLProvider); JpaConformanceProviderR4 confProvider = new JpaConformanceProviderR4(ourRestServer, mySystemDao, myDaoConfig); confProvider.setImplementationDescription("THIS IS THE DESC"); diff --git a/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java b/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java index 3c4643f0bb7..38506ddd976 100644 --- a/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java +++ b/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemo.java @@ -109,7 +109,7 @@ public class JpaServerDemo extends RestfulServer { * This server tries to dynamically generate narratives */ FhirContext ctx = getFhirContext(); - ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator(getFhirContext())); + ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); /* * Default to JSON and pretty printing diff --git a/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemoDstu2.java b/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemoDstu2.java index 0d4121947d9..3c802e6cb10 100644 --- a/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemoDstu2.java +++ b/hapi-fhir-jpaserver-example/src/main/java/ca/uhn/fhir/jpa/demo/JpaServerDemoDstu2.java @@ -108,7 +108,7 @@ public class JpaServerDemoDstu2 extends RestfulServer { * This server tries to dynamically generate narratives */ FhirContext ctx = getFhirContext(); - ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator(getFhirContext())); + ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); /* * Default to JSON and pretty printing diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java index 8a1f91ccc09..0b8c67b5eac 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java @@ -159,7 +159,7 @@ public class TestRestfulServer extends RestfulServer { * This server tries to dynamically generate narratives */ FhirContext ctx = getFhirContext(); - ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator(getFhirContext())); + ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); /* * The resource and system providers (which actually implement the various FHIR @@ -171,7 +171,7 @@ public class TestRestfulServer extends RestfulServer { } setResourceProviders(beans); - setPlainProviders(plainProviders); + registerProviders(plainProviders); /* * Enable CORS diff --git a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2_1Test.java b/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2_1Test.java index 5d0eb4d5a5b..e31cf6be5bb 100644 --- a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2_1Test.java +++ b/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2_1Test.java @@ -1020,7 +1020,7 @@ public class JsonParserDstu2_1Test { Patient p = new Patient(); p.addName().addFamily("Smith").addGiven("John"); - ourCtx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator(ourCtx)); + ourCtx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); String output = ourCtx.newJsonParser().encodeResourceToString(p); ourLog.info(output); diff --git a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2_1Test.java b/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2_1Test.java index 056eb96fa7f..423d63a141f 100644 --- a/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2_1Test.java +++ b/hapi-fhir-structures-dstu2.1/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2_1Test.java @@ -1695,7 +1695,7 @@ public class XmlParserDstu2_1Test { Patient p = new Patient(); p.addName().addFamily("Smith").addGiven("John"); - ourCtx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator(ourCtx)); + ourCtx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); String output = ourCtx.newXmlParser().encodeResourceToString(p); ourLog.info(output); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorDstu2Test.java index 5824972527f..aee9f9abfdc 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorDstu2Test.java @@ -26,7 +26,7 @@ public class CustomThymeleafNarrativeGeneratorDstu2Test { public void testGenerator() { // CustomThymeleafNarrativeGenerator gen = new CustomThymeleafNarrativeGenerator("file:src/test/resources/narrative/customnarrative.properties"); - CustomThymeleafNarrativeGenerator gen = new CustomThymeleafNarrativeGenerator(ourCtx,"classpath:narrative/customnarrative_dstu2.properties"); + CustomThymeleafNarrativeGenerator gen = new CustomThymeleafNarrativeGenerator("classpath:narrative/customnarrative_dstu2.properties"); ourCtx.setNarrativeGenerator(gen); Practitioner p = new Practitioner(); @@ -35,7 +35,7 @@ public class CustomThymeleafNarrativeGeneratorDstu2Test { p.addAddress().addLine("line1").addLine("line2"); p.getName().addFamily("fam1").addGiven("given"); - gen.populateResourceNarrative(p); + gen.populateResourceNarrative(ourCtx, p); String actual = p.getText().getDiv().getValueAsString(); ourLog.info(actual); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorDstu2Test.java index 88509c6417e..c9b160ba8bf 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorDstu2Test.java @@ -1,32 +1,12 @@ package ca.uhn.fhir.narrative; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import java.util.Date; - -import org.hamcrest.core.StringContains; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.TemporalPrecisionEnum; import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt; import ca.uhn.fhir.model.dstu2.composite.QuantityDt; import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt; import ca.uhn.fhir.model.dstu2.composite.SimpleQuantityDt; -import ca.uhn.fhir.model.dstu2.resource.DiagnosticReport; -import ca.uhn.fhir.model.dstu2.resource.Medication; -import ca.uhn.fhir.model.dstu2.resource.MedicationOrder; -import ca.uhn.fhir.model.dstu2.resource.Observation; -import ca.uhn.fhir.model.dstu2.resource.OperationOutcome; -import ca.uhn.fhir.model.dstu2.resource.Parameters; -import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.dstu2.resource.*; import ca.uhn.fhir.model.dstu2.valueset.DiagnosticReportStatusEnum; import ca.uhn.fhir.model.dstu2.valueset.MedicationOrderStatusEnum; import ca.uhn.fhir.model.dstu2.valueset.ObservationStatusEnum; @@ -34,6 +14,18 @@ import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.util.TestUtil; +import org.hamcrest.core.StringContains; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import java.util.Date; + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.not; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; public class DefaultThymeleafNarrativeGeneratorDstu2Test { private static FhirContext ourCtx = FhirContext.forDstu2(); @@ -48,7 +40,7 @@ public class DefaultThymeleafNarrativeGeneratorDstu2Test { @Before public void before() { - myGen = new DefaultThymeleafNarrativeGenerator(ourCtx); + myGen = new DefaultThymeleafNarrativeGenerator(); myGen.setUseHapiServerConformanceNarrative(true); ourCtx.setNarrativeGenerator(myGen); @@ -65,7 +57,7 @@ public class DefaultThymeleafNarrativeGeneratorDstu2Test { value.setBirthDate(new Date(), TemporalPrecisionEnum.DAY); - myGen.populateResourceNarrative(value); + myGen.populateResourceNarrative(ourCtx, value); String output = value.getText().getDiv().getValueAsString(); ourLog.info(output); assertThat(output, StringContains.containsString("
joe john BLOW
")); @@ -77,7 +69,7 @@ public class DefaultThymeleafNarrativeGeneratorDstu2Test { Parameters value = new Parameters(); value.setId("123"); - myGen.populateResourceNarrative(value); + myGen.populateResourceNarrative(ourCtx, value); String output = value.getText().getDiv().getValueAsString(); ourLog.info(output); assertThat(output, not(containsString("narrative"))); @@ -99,7 +91,7 @@ public class DefaultThymeleafNarrativeGeneratorDstu2Test { OperationOutcome oo = ourCtx.newXmlParser().parseResource(OperationOutcome.class, parse); - myGen.populateResourceNarrative(oo); + myGen.populateResourceNarrative(ourCtx, oo); String output = oo.getText().getDiv().getValueAsString(); ourLog.info(output); @@ -137,7 +129,7 @@ public class DefaultThymeleafNarrativeGeneratorDstu2Test { value.addResult().setResource(obs); } - myGen.populateResourceNarrative(value); + myGen.populateResourceNarrative(ourCtx, value); String output = value.getText().getDiv().getValueAsString(); ourLog.info(output); @@ -162,11 +154,11 @@ public class DefaultThymeleafNarrativeGeneratorDstu2Test { mp.setStatus(MedicationOrderStatusEnum.ACTIVE); mp.setDateWritten(new DateTimeDt("2014-09-01")); - myGen.populateResourceNarrative(mp); + myGen.populateResourceNarrative(ourCtx, mp); String output = mp.getText().getDiv().getValueAsString(); - assertTrue("Expected medication name of ciprofloaxin within narrative: " + output, output.indexOf("ciprofloaxin") > -1); - assertTrue("Expected string status of ACTIVE within narrative: " + output, output.indexOf("ACTIVE") > -1); + assertTrue("Expected medication name of ciprofloaxin within narrative: " + output, output.contains("ciprofloaxin")); + assertTrue("Expected string status of ACTIVE within narrative: " + output, output.contains("ACTIVE")); } @@ -175,7 +167,7 @@ public class DefaultThymeleafNarrativeGeneratorDstu2Test { Medication med = new Medication(); med.getCode().setText("ciproflaxin"); - myGen.populateResourceNarrative(med); + myGen.populateResourceNarrative(ourCtx, med); String output = med.getText().getDiv().getValueAsString(); assertThat(output, containsString("ciproflaxin")); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BundleTypeInResponseTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BundleTypeInResponseTest.java index 139a6209183..f5e8c9ed6dc 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BundleTypeInResponseTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BundleTypeInResponseTest.java @@ -71,7 +71,7 @@ public class BundleTypeInResponseTest { ServletHandler proxyHandler = new ServletHandler(); RestfulServer servlet = new RestfulServer(ourCtx); - servlet.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator(ourCtx)); + servlet.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/narrative2/ThymeleafNarrativeGeneratorTest.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/narrative2/ThymeleafNarrativeGeneratorTest.java index 56d54527bf1..1135b62fffa 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/narrative2/ThymeleafNarrativeGeneratorTest.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/narrative2/ThymeleafNarrativeGeneratorTest.java @@ -58,13 +58,13 @@ public class ThymeleafNarrativeGeneratorTest { ref.setReference("DiagnosticReport/1").setResource(dr1); sect.getEntry().add(ref); - NarrativeTemplateManifest manifest = NarrativeTemplateManifest.forManifestFileLocation(myCtx, "classpath:narrative2/narratives.properties"); - ThymeleafNarrativeGenerator gen = new ThymeleafNarrativeGenerator(myCtx); + NarrativeTemplateManifest manifest = NarrativeTemplateManifest.forManifestFileContents("classpath:narrative2/narratives.properties"); + ThymeleafNarrativeGenerator gen = new ThymeleafNarrativeGenerator(); gen.setManifest(manifest); - gen.populateResourceNarrative(composition); + gen.populateResourceNarrative(myCtx, composition); - // Firt narrative should be empty + // First narrative should be empty String narrative = composition.getSection().get(0).getText().getDiv().getValueAsString(); assertThat(narrative, Matchers.emptyOrNullString()); @@ -78,7 +78,7 @@ public class ThymeleafNarrativeGeneratorTest { @Test public void testTemplateCount() throws IOException { - NarrativeTemplateManifest manifest = NarrativeTemplateManifest.forManifestFileLocation(myCtx, "classpath:narrative2/narratives.properties"); + NarrativeTemplateManifest manifest = NarrativeTemplateManifest.forManifestFileContents("classpath:narrative2/narratives.properties"); assertEquals(4, manifest.getNamedTemplateCount()); } diff --git a/restful-server-example/src/main/java/ca/uhn/example/servlet/ExampleRestfulServlet.java b/restful-server-example/src/main/java/ca/uhn/example/servlet/ExampleRestfulServlet.java index 97f8c81a375..99f8cb960de 100644 --- a/restful-server-example/src/main/java/ca/uhn/example/servlet/ExampleRestfulServlet.java +++ b/restful-server-example/src/main/java/ca/uhn/example/servlet/ExampleRestfulServlet.java @@ -48,7 +48,7 @@ public class ExampleRestfulServlet extends RestfulServer { * but can be useful as it causes HAPI to generate narratives for * resources which don't otherwise have one. */ - INarrativeGenerator narrativeGen = new DefaultThymeleafNarrativeGenerator(getFhirContext()); + INarrativeGenerator narrativeGen = new DefaultThymeleafNarrativeGenerator(); getFhirContext().setNarrativeGenerator(narrativeGen); /*