handlebars-helpers-fhir

1.0.0 • Public • Published

Handlebars

handlebars-helpers-fhir

Helper functions for the Handlebars templating engine using fhirpath to reference HL7 FHIR resources from within templates.

Prerequisites

Handlebars!

$ npm install handlebars --save

Installation

Install package

$ npm install handlebars-helpers-fhir --save

Register helpers with handlebars

const Handlebars = require('handlebars');
require('handlebars-helpers-fhir').registerWith(Handlebars);

Use

#if-fhir

The if-fhir block helper will conditionally render a block based on a fhirpath expression. If the fhirpath expression returns an empty array, Handlebars will not render the block.

{{#if-fhir . expression='Patient.address.where(use=\'temp\')'}}
  <p>Patient has a temporary address.</p>
{{/if-fhir}}

The helper can render an {{else}} section.

{{#if-fhir . expression='Patient.address.where(use=\'temp\')'}}
  <p>Patient has a temporary address.</p>
{{else}}
  <p>Patient does not have a temporary address.</p>
{{/if-fhir}}

#unless-fhir

The unless-fhir block helper will conditionally render a block based on a fhirpath expression. If the fhirpath expression returns an empty array, Handlebars will render the block.

{{#unless-fhir . expression='Patient.address.where(use=\'temp\')'}}
  <p class="button">Add temporary address</p>
{{/unless-fhir}}

#each-fhir

The each-fhir block helper will render a block for each item found using a fhirpath expression.

{{#each-fhir . expression='Patient.address'}}
  <p>{{use}}: {{text}}</p>
{{/each-fhir}}

You can optionally supply an {{else}} section which will render only if evaluating the fhirpath expression returns no matches.

{{#each-fhir . expression='Patient.address'}}
  <p>{{use}}: {{text}}</p>
{{else}}
  <p>No address found</p>
{{/each-fhir}}

The each-fhir block helper supports the @index, @key, @first and @last loop variables.

The each-fhir block helper does not support block parameters.

#with-fhir

The with-fhir block helper will render a block after switching context to the first item found using a fhirpath expression.

{{#with-fhir . expression='Patient.address.first()'}}
  <p>{{text}}</p>
{{/with-fhir}}

You can optionally supply an {{else}} section which will render only if evaluating the fhirpath expression returns no matches.

{{#with-fhir . expression='Patient.address.first()'}}
  <p>{{text}}</p>
{{else}}
  No address
{{/with-fhir}}

#resolve-fhir

The resolve-fhir block helper will render a block after switching context to the first FHIR resource from the first reference found by evaluating the fhirpath expression.

{{#resolve-fhir . expression='Patient.managingOrganization.reference'}}
  <p>Healthcare provider is {{name}}</p>
{{/resolve-fhir}}

You can optionally supply an {{else}} section which will render when with the fhirpath expression returns no matches OR the referenced FHIR resource cannot be found.

{{#resolve-fhir . expression='Patient.managingOrganization.reference'}}
  <p>Healthcare provider is {{name}}</p>
{{else}}
  <p>Healthcare provider unknown</p>
{{/resolve-fhir}}

The resolve-fhir block helper suppports only internal references (i.e. within @root.entry and @root.contained).

License

handlebars-helpers-fhir is free software: you can redistribute it and/or modify it under the terms of the MIT license.

Acknowledgements

Supported by Black Pear Software

Package Sidebar

Install

npm i handlebars-helpers-fhir

Weekly Downloads

126

Version

1.0.0

License

MIT

Unpacked Size

62.7 kB

Total Files

6

Last publish

Collaborators

  • dunmail