Release 4

This page is part of the FHIR Specification (v4.0.1: R4 - Mixed Normative and STU) in it's permanent home (it will always be available at this URL). The current version which supercedes this version is 5.0.0. For a full list of available versions, see the Directory of published versions . Page versions: R4B R4 R3 R2

2.28.0 Element

FHIR Infrastructure Work GroupMaturity Level: NormativeStandards Status: Normative
This page has been approved as part of an ANSI standard. See the Infrastructure Package for further details.

The base definition for all elements contained inside a resource. All elements, whether defined as a Data Type (including primitives) or as part of a resource structure, have this base content:

There are 3 kinds of descendant types that specialize Element:

Note that resources themselves all specialize the base type Resource.

Structure

NameFlagsCard.TypeDescription & Constraintsdoco
.. ElementIn/aBase for all elements
All FHIR elements must have a @value or children
... id0..1stringUnique id for inter-element referencing
... extension0..*ExtensionAdditional content defined by implementations

doco Documentation for this format

XML Template

<[name] xmlns="http://hl7.org/fhir" id="Internal id (e.g. like xml:id) (string)"> doco
 <extension><!-- 0..* Extension Additional content defined by implementations --></extension>
</[name]>

JSON Template

// complex types:

{doco
  "id" : "<string>", // Internal Id
  "extension" : [{//  Additional content defined by implementations
    // from Element: extension (recursive)
    "url" : "<uri>", // R!  identifies the meaning of the extension
    "value[x]" : <*> // identifies the meaning of the extension
  }]
}
// primitive types:

{doco
  "{name}" : "value",  // The primitive value
  "{name}_" : { // Special syntax for the id and extensions
    "id" : "<string>", // Internal Id
    "extension" : [{//  Additional content defined by implementations
      // from Element: extension (recursive)
      "url" : "<uri>", // R!  identifies the meaning of the extension
      "value[x]" : <*> // identifies the meaning of the extension
    }]
  }
}

Structure

NameFlagsCard.TypeDescription & Constraintsdoco
.. ElementIElementBase for all elements
All FHIR elements must have a @value or children
... id0..1stringUnique id for inter-element referencing
... extension0..*ExtensionAdditional content defined by implementations

doco Documentation for this format

XML Template

<[name] xmlns="http://hl7.org/fhir" id="Internal id (e.g. like xml:id) (string)"> doco
 <extension><!-- 0..* Extension Additional content defined by implementations --></extension>
</[name]>

JSON Template

// complex types:

{doco
  "id" : "<string>", // Internal Id
  "extension" : [{//  Additional content defined by implementations
    // from Element: extension (recursive)
    "url" : "<uri>", // R!  identifies the meaning of the extension
    "value[x]" : <*> // identifies the meaning of the extension
  }]
}
// primitive types:

{doco
  "{name}" : "value",  // The primitive value
  "{name}_" : { // Special syntax for the id and extensions
    "id" : "<string>", // Internal Id
    "extension" : [{//  Additional content defined by implementations
      // from Element: extension (recursive)
      "url" : "<uri>", // R!  identifies the meaning of the extension
      "value[x]" : <*> // identifies the meaning of the extension
    }]
  }
}

 

Constraints

idLevelLocationDescriptionExpression
ele-1Rule (base)All FHIR elements must have a @value or childrenhasValue() or (children().count() > id.count())

This constraint exists to reduce syntactical variation in resource contents. If an element has no children, then it is always omitted from the resource, as opposed to optionally present without any content.

As the base type for all elements included in a resource, Element is an important structural element of FHIR. Even the primitive types inherit the base features and representation rules that apply to the Element type.

Elements are represented by an XML element. The name of the element comes from the context in which it is used, not from the type. The internal id is represented as an attribute (similar to xml:id, but see below about scope). Extensions are represented as XML elements. Here is the representation for an element 'use' of type Coding:

  <use id="[internal id]">
    <extension url="..."/>
      ... if there are any extensions
    <extension>
    .. elements of Coding type...
  </use>

Primitive types have the same representation; the actual primitive value appears as an XML attribute named value on the XML element. For example, a code property named "status" will be represented like this:

  <status id="[internal id]" value="[value of code]"">
    <extension url="..."/>
      ... if there are any extensions
    <extension>
  </status>

Elements (except for primitive types, see below) are represented by a JSON object property. The name of the property comes from the context in which it is used, not from the type. The internal id is represented as a JSON string property named "id". Extensions are represented in a JSON array of objects named "extension". Here is the representation for a property 'use' of type Coding:

  {
    "use" : {
      "id" : "[internal id]",
      "extension" : [
        ..extensions, if present...
      ],
      .. properties of Coding type...
    }
  }

Primitive types are represented differently; the actual primitive value appears as a JSON string or number property. If an internal id or extensions are present, they appear in a JSON object with the name of the primitive value property with "_" prepended. For example, a code property named "status" will be represented like this:

  {
    "status" : "[value of code]",
    "_status" : {
      "id" : "[internal id]",
      "extension" : [
        ..extensions, if present...
      ]
    }
  }

The exact use of this pattern is described here.

The id property of the element is defined to allow implementers to build implementation functionality that makes use of internal references inside the resource. This specification does not define any general use for the internal id, though some resources (e.g. StructureDefinition) and extensions (e.g. originalText, narrativeLink) make use of it.

The internal id is unique within the scope of the resource that contains it. Specifically, this means:

  • The id SHALL be unique within a given resource
  • The uniqueness boundary extends into contained resources. i.e. a contained resource cannot have the same id as any element in the resource that contains it or any other contained resource
  • The uniqueness boundary is broken at Bundle.entry.resource and Parameters.parameter.resource, since these are elements that aggregate different resources
  • The id element does not have extensions itself

These rules ensure that there is no need to change internal identifiers while exchanging resources.