Skip to content

Example Complex Extension

chrisgrenz edited this page Apr 26, 2016 · 3 revisions

Complex Extension

Adding an extension that contains sub-elements rather than a single value.

Standard disclaimer: These extensions are contrived for the purpose of illustrating syntax. DO NOT assume that the content exists or is useful in any particular context!

Here we'll create an extension to patient for research authorization with type, flag, and date.

In the instance

<Patient xmlns="http://hl7.org/fhir">
...snip...
	<extension url="http://example.com/fhir/StructureDefinition/patient-research-authorization">
		<!-- Relative URLs are used for sub-elements -->
		<!-- DISCUSS: What would an absolute URL be for this sub-element?
		http://example.com/fhir/StructureDefinition/patient-research-authorization#type - Not an id/anchor?
		http://example.com/fhir/StructureDefinition/patient-research-authorization/type - Normal URL conversion
		-->
		<extension url="type">
			<valueCode value="Minnesota"/>
		</extension>
		<extension url="flag">
			<valueBoolean value="true"/>
		</extension>
		<extension url="date">
			<valueDate value="2013-01-31"/>
		</extension>
	</extension>
...snip...

The extension profile

An extension profile

  • Extends the HL7 Extension type
  • Fixes all url elements (Element.url and any sub-element element.url paths)
  • Slice Extension.extension as needed for sub-elements
  • Constrains as appropriate the value[x] element(s)

The differential (what's different from Extension):

<differential>
	<!-- URI for the whole extension profile -->
	<element>
		<path value="Element.url" />
		<fixedUri value="http://example.com/fhir/StructureDefinition/patient-research-authorization" />
	</element>
	<!-- Extension is always sliced by @url, so no need to re-define here. -->
	<element>
		<path value="Element.extension" />
		<!-- Name the sub-element type. This is by convention the same as the url for the sub-element. -->
		<name value="type" />
		<!-- A single "type" sub-element is required. -->
		<min value="1" />
		<max value="1" />
	</element>
	<element>
		<path value="Element.extension.url" />
		<name value="type.url" />
		<!-- This fixes the url attribute in the instance. By convention matches the sub-element name -->
		<fixedUri value="type" />
	</element>
	<element>
		<path value="Element.extension.value[x]" />
		<name value="type.value[x]" />
		<min value="1" />
		<!-- "type" sub-element has value with datatype code. -->
		<type>
			<code value="code" />
		</type>
	</element>
	<!-- The next sub-element ("flag") -->
	<element>
		<path value="Element.extension" />
		<name value="flag" />
		<max value="1" />
	</element>
	<element>
		<path value="Element.extension.url" />
		<name value="flag.url" />
		<fixedUri value="flag" />
	</element>
	<element>
		<path value="Element.extension.value[x]" />
		<name value="flag.value[x]" />
		<min value="1" />
		<type>
			<code value="boolean" />
		</type>
	</element>
	<element>
		<path value="Element.extension" />
		<name value="date" />
		<max value="1" />
	</element>
	<element>
		<path value="Element.extension.url" />
		<name value="date.url" />
		<fixedUri value="date" />
	</element>
	<element>
		<path value="Element.extension.value[x]" />
		<name value="date.value[x]" />
		<min value="1" />
		<type>
			<code value="code" />
		</type>
	</element>
</differential>

The Resource Profile

The extension can then be added to a profile as a known/expected extension. This is as simple as adding a slice of extension to the profile.

When adding an extension to the profile:

  • Assign a name to the extension (as a named slice of extension).
  • Constrain the type of the profile to the extension profile (using the extension profile's URI)

There is no need to add an additional information to the resource profile - the value[x] and/or any sub-extension will be pulled in from the extension profile.

<differential>
	<element>
		<path value="Patient.extension" />
		<name value="researchAuth" />
		<type>
			<code value="Extension" />
			<profile value="http://example.com/fhir/StructureDefinition/patient-research-authorization" />
		</type>
	</element>
</differential>

Clone this wiki locally