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:
{% raw %}{% fragment ResourceType/id syntax %}{% endraw %}
where:

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

{% fragment Patient/example XML %}

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, {% raw %}{% fragment Patient/example JSON BASE:name.where(use='usual') %}{% endraw %} will result in the following:

{% fragment Patient/example JSON BASE:name.where(use='official').first() %}

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 ellide (replace with '...'); or you can define the elements you don't want to ellide.

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

{% fragment Patient/example XML BASE:name.where(use='official').first() ELLIDE:use|given[1]|period %}

'EXCEPT:' works slightly differently. With Except you identify the elements to retain (be unellided) 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 ellide everything except the family name: {% raw %}{% fragment Patient/example XML EXCEPT:id|name EXCEPT:family BASE:name %}{% endraw %}

{% fragment Patient/example XML EXCEPT:id|name EXCEPT:family BASE:name %}

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