ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator Java Examples

The following examples show how to use ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExampleRestfulServlet.java    From fhirstarters with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * This method is called automatically when the
 * servlet is initializing.
 */
@Override
public void initialize() {
	/*
	 * Two resource providers are defined. Each one handles a specific
	 * type of resource.
	 */
	List<IResourceProvider> providers = new ArrayList<IResourceProvider>();
	providers.add(new PatientResourceProvider());
	providers.add(new OrganizationResourceProvider());
	setResourceProviders(providers);
	
	/*
	 * Use a narrative generator. This is a completely optional step, 
	 * but can be useful as it causes HAPI to generate narratives for
	 * resources which don't otherwise have one.
	 */
	INarrativeGenerator narrativeGen = new DefaultThymeleafNarrativeGenerator();
	getFhirContext().setNarrativeGenerator(narrativeGen);

	/*
	 * Use nice coloured HTML when a browser is used to request the content
	 */
	registerInterceptor(new ResponseHighlighterInterceptor());
	
}
 
Example #2
Source File: Example99_NarrativeGenerator.java    From fhirstarters with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args) {
	
	// Create an encounter with an invalid status and no class
	Patient pat = new Patient();
	pat.addName().setFamily("Simpson").addGiven("Homer").addGiven("Jay");
	pat.addAddress().addLine("342 Evergreen Terrace").addLine("Springfield");
	pat.addIdentifier().setSystem("http://acme.org/mrns").setValue("12345");
	
	// Create a new context and enable the narrative generator
	FhirContext ctx = FhirContext.forDstu2();
	ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator());
	
	String res = ctx.newJsonParser().setPrettyPrint(true).encodeResourceToString(pat);
	System.out.println(res);
}