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

FHIR Liquid Profile

From HL7Wiki
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:

 Template: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)

Comments

 Anything you put between {% comment %} and {% endcomment %} tags
 is turned into a comment.

Allows you to leave un-rendered code inside a Liquid template. Any text within the opening and closing comment blocks will not be output, and any Liquid code within will not be executed.

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 variable 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