Skip to content

Resource's Narrative (including Narrative Generation)

Sean McIlvenna edited this page Mar 17, 2019 · 4 revisions

Because there are no FHIR operations that can be invoked to generate narrative on existing FHIR servers, custom narrative generation logic is created in ToF to produce narrative for various resources.

Mustache.js templates are used to create XHTML. Each resource type (should) have its own narrative template.

Narrative for a resource (Resource.text) is handled by the NarrativeComponent: <app-fhir-narrative [resource]="XXXX">

This renders an XHTML WYSIWYG editor for the user to create narrative content for the resource. A button is displayed to the user to generate narrative, where this narrative generation logic gets executed.

The narrative generation engine is unaware (at this time) of difference between the FHIR versions of resource. In other words: there is only one narrative template for all FHIR versions of a resource type.

Templates

All templates are stored in /src/app/assets/narrative-templates.

The NarrativeComponent attempts to download a mustache template from /assets/narrative-templates/RESOURCE_TYPE.mustache. If one is found, then a view model is prepared for the resource and the Mustache.js engine transforms the template using the view model.

View model

Regardless of the resource type, every view model has a "resource" property that represents the resource narrative is being generated for.

The view model is created in the NarrativeComponent.getNarrativeView(resource: any) method. This method may customize the view model depending on the resource type via other methods.

Some resource types have custom view model properties depending on their needs.

ImplementationGuide

  • hasPages: boolean - whether or not the implementation guide has any pages
  • pages: page[] - an array of all pages (where the page hierarchy is flattened)
  • hasResources: boolean - whether or not the implementation guide has any resources
  • resources: object[] - an array of all resources that are in the implementation guide ** reference: string - the resource reference of the resource in the implementation guide ** display: string - the name of the resource ** package: string - the package that the resource is contained in within the implementation guide (if any)