This wiki has undergone a migration to Confluence found Here
<meta name="googlebot" content="noindex">

FHIR Liquid Profile

From HL7Wiki
Revision as of 15:37, 14 November 2018 by GrahameGrieve (talk | contribs) (Created page with "This page documents how FHIR uses the Liquid language for templating. The liquid templating engine is used for the following purposes: * Building narratives for resources * ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This page documents how FHIR uses the Liquid language for templating.

The liquid templating engine is used for the following purposes:

  • Building narratives for resources
  • Building resources from external data sources (V2, CDA, etc)

Broadly, FHIR applications that use Liquid templating:

  • Use a small subset of the liquid language (the syntax, and none of the functions)
  • Replace liquid expressions with FHIRPath expressions

Evaluation Context

Whenever a Liquid template is executed, there's a single object that is the focus that the template is occurring in.

  • When generating a resource, the resource itself is the focus.
  • In other contexts, the focus object must be explicitly specified.

In addition to the focus object, other variables may be provided as specified (where?)

Using Liquid Statements

The following liquid statements are used, with the functionality as documented

Statement

A statement consists of 2 pairs of braces with a FHIRPath statement:

 {{ expression ]}
  • Whitespace may be present before or after the expression statement, and is not significant.
  • The expression is executed in the context of the focus object (but may reference other variables)

If

The if control tag is

 {% if expression %}
 {% else %}
 {% endif %}
  • The expression is executed in the context of the focus object (but may reference other variables)
  • Whitespace may be present in the tags, and is not significant.
  • the else tag is optional
  • {% elseif expression %} is also allowed

Loop

The loop control tag is

 {% loop var in expression %}
   Template:Var.expression
 {% endloop %}
  • The loop will run once for each object returned by the expression
  • The loop vaiable is available to expressions using the named parameter
  • Whitespace may be present in the tags, and is not significant.

Include

The include control tag works like this:

 {%include filename parameters %}
  • the filename resolution is outside this spec
  • Whitespace may be present in the tags, and is not significant.
  • the parameters is a list of name=expression pairs, separated by whitespace
  • the parameters are available in the included file using the variable "include"

e.g. the following include:

 {%loop name in Patient.name%}{%include humanname.html name=name%}{%endloop%}

would lead to a statement like this in the included file:

 Template:Include.name.family

todo

  • What other liquid control things should be supported?
  • date syntax wrangling