Guidance for FHIR IG Creation
0.1.0 - CI Build International flag

Guidance for FHIR IG Creation, published by HL7 International - FHIR Management Group. This guide is not an authorized publication; it is the continuous build for version 0.1.0 built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/FHIR/ig-guidance/ and changes regularly. See the Directory of published versions

Using Instance Fragments

This page describes how to embed 'fragments' of a resource within a page, possibly elliding out portions of the instance to only show the portions that are relevant to what the surrounding text needs to talk about.

To embed content from an instance, use the following structure:
{% fragment ResourceType/id syntax %}
where:

  • ResourceType is 'Patient', 'Observation', etc. For a logical model instance, this will be 'Binary'.
  • id is the unique resource id of the resource within the IG.
  • syntax is either 'XML' or 'JSON'. (TTL is not yet supported.)

For example, {% fragment Patient/example XML %} in this IG evaluates to


  <!--  

test comment for display

 -->
<Patient xmlns="http://hl7.org/fhir">
  <id value="example"/>
  <meta>
    <profile
             value="http://example.org/fhir/uv/myig/StructureDefinition/mypatient"/>
  </meta>
  <text>
    <status value="generated"/>
    <div xmlns="http://www.w3.org/1999/xhtml"><p class="res-header-id"><b>Generated Narrative: Patient example</b></p><a name="example"> </a><a name="hcexample"> </a><a name="example-en-US"> </a><p style="border: 1px #661aff solid; background-color: #e6e6ff; padding: 10px;">Jack Smith  (no stated gender), DoB: 2018-09-07</p><hr/><table class="grid"><tr><td style="background-color: #f3f5da" title="Known Marital status of Patient">Marital Status:</td><td colspan="3"><span title="Codes:">Married</span></td></tr></table></div>
  </text>
  <name>
    <use value="usual"/>
    <family value="Smith"/>
    <given value="Jack"/>
  </name>
  <name>
    <use value="official"/>
    <family value="Smith"/>
    <given value="John"/>
    <given value="Jacob"/>
    <given value="Jingleheimer"/>
    <period>
      <end value="2001-01-01"/>
    </period>
  </name>
  <name>
    <use value="official"/>
    <family value="Smith"/>
    <given value="John"/>
    <given value="Jacob"/>
    <given value="Jingleheimer"/>
    <period>
      <start value="2001-01-01"/>
    </period>
  </name>
  <birthDate value="2018-09-07"/>
  <maritalStatus>
    <text value="Married"/>
  </maritalStatus>
</Patient>

Filtering

However, often examples can be somewhat sizeable and you don't necessarily want to include the entire example in the flow of your narrative - you only need a portion. To filter to a limited portion of the specified resource, you need to declare a 'base' element within that resource that will be included as your fragment. The 'base' is expressed as a FHIRPath expression evaluated against the root of the resource.

For example, {% fragment Patient/example JSON BASE:name.where(use='usual') %} will result in the following:

{
  "resourceType" : "HumanName",
  "use" : "official",
  "family" : "Smith",
  "given" : [
    "John",
    "Jacob",
    "Jingleheimer"
  ],
  "period" : {
    "end" : "2001-01-01"
  }
}

Ellipsing

Sometimes you want to perform more filtering than only selecting an element within your instance. You want to only show a portion of that element, hiding (ellipsing) the content you don't care about. There are two ways to do this: you can either define the specific elements you want to elide (replace with '...'); or you can define the elements you don't want to elide.

The 'ELIDE:' filter can only be specified once, but with FHIRPath '|', you can express as many elements as you like. For example, {% fragment Patient/example XML BASE:name.where(use='official').first() ELIDE:use|given[1]|period %} will look like this:


<HumanName xmlns="http://hl7.org/fhir">
  ...
  <family value="Smith"/>
  <given value="John"/>
  ...
  <given value="Jingleheimer"/>
  ...
</HumanName>

'EXCEPT:' works slightly differently. With Except you identify the elements to retain (be unelided) but you can also specify a descendant 'BASE:' element those expressions are evaluated within. For example, the following expression will return the patient showing only id an names, and within name, will elide everything except the family name: {% fragment Patient/example XML EXCEPT:id|name EXCEPT:family BASE:name %}


  <!--  

test comment for display

 -->
<Patient xmlns="http://hl7.org/fhir">
  <id value="example"/>
  ...
  <name>
    ...
    <family value="Smith"/>
    ...
  </name>
  <name>
    ...
    <family value="Smith"/>
    ...
  </name>
  <name>
    ...
    <family value="Smith"/>
    ...
  </name>
  ...
</Patient>

The overall syntax for fragments is as follows: {% fragment [resource]/[id] [XML|JSON] (BASE:[base FHIRPath])? (ELIDE:[elide elements path])? (EXCEPT:[except elements FHIRPath] (BASE:[except base FHIRPath])?)* %}