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

FHIR Typing System

From HL7Wiki
Revision as of 03:22, 1 May 2016 by GrahameGrieve (talk | contribs) (Created page with "How typing works in FHIR = Elements = A FHIR resource or other data structure (an "instance") contains a tree of elements, where each element has a name, a definition, and ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

How typing works in FHIR

Elements

A FHIR resource or other data structure (an "instance") contains a tree of elements, where each element has a name, a definition, and either a value or child elements or both.

Each element has a definition, which which defines the meaning and content of the element. Specifically, the ElementDefinition defines - the name of the element - it's cardinality (how many times it can appear) - additional definitional material (documentation, mappings, etc) - value set bindings (for some types) - conformance flags that provide additional details about the correct use of an element. - the type of the element (see below)

Types

Element Definitions are organised into trees of their own that specify what elements can (or must) exist in an instance of data. These are known as "types" - the type is given a name, that identifies the tree of elements for re-use in across the FHIR specification and eco-system.

The root element of a type is actually an unnamed element. FOr convenience, a type definition uses the type name as the name of the root element, but this is removed. Any instance of data has an unnamed root element.

Note: the XML representation uses the type as the element name too, but this is to hook up the xml representation to the xml schema. The JSON representation does not use any name, and the RDF representation uses the absolute URL of a resource, if it is known.

Type Binding

When an element has a an assigned 'type' (other than anonymous types, see below), this is a reference to a tree of elements that provide the content for the element. In order to actually use an element with an assigned type, the details of the type must be looked up, and the bound to the element that has that type. When a type is bound like this, this list summarises what happens with the various parts of the ElementDefinition:

  • path : from the element
  • representation: from the element (not defined on a type)
  • name: from the element (not defined on a type)
  • label: from the element (not defined on a type)
  • code: from the element
  • slicing: from the element (not defined on a type)
  • short: from the element
  • definition: from the element
  • comments: from the element
  • requirements: from the element
  • alias: from the element
  • min: from the element
  • max: from the element
  • base: from the element
  • contentReference: use the type details from the target of the content reference
  • type: from the type
  • defaultValue[x]: from the element (not defined on a type)
  • meaningWhenMissing: from the element (not defined on a type)
  • fixed[x]: from the element (not defined on a type)
  • pattern[x]: from the element (not defined on a type)
  • example[x]: from the element, else from the type
  • minValue[x]: from the element (not defined on a type)
  • maxValue[x]: from the element (not defined on a type)
  • maxLength: from the element (not defined on a type)
  • condition: from the element and the type (all apply)
  • mustSupport: from the element (not defined on a type)
  • isModifier: from the element (not defined on a type)
  • isSummary: from the element
  • binding: from the element else from the type
  • mapping: from the element and the type (all apply)

Choice Types

An element may have nmore than one possible types defined. todo: document the [x]

Base Types

There are two types from which all other types are derived in the FHIR typing system derive:

Element Resource

Other than these elements have no type from which they derive, they are no different to other types.

These types are abstract types - some other type must be derived from them to create types that can be instantiated.

All other types derive from one of these 2 base types. There are 2 forms of derivation:

  • specialization
  • constraint

On the FHIR Restful interface, all instances of data that are encountered have a Resource as the base type for the root element. However instances of logical models will have a root element derived from Element, not Resource.

Derivation by Specialization

When a type is derived from another by specialization, it extends the semantics of the type. Specializing types may:

  • add additional elements
  • add additional constraints
  • provide additional definitions and mappings

A type that specializes another type creates a new type that can (unless it is marked as abstract) be created in an instance, or be referenced in another structure as a named type

Derivation by Constraint

When a type is defined as a constraint on another type, it cannot introduce any new elements. It can only - narrow the cardinality of elements - add additional constraints - provide additional definitions and mappings

Types created as constraints on other types are not concrete types; they can never be created directly, or referenced as types on other elements definitions. Instead, they are treated as additional sets of rules that can apply to the concrete type from which they are defined. In an element definition, they are referenced as a profile on a type.

An instance of the concrete type may conform to multiple constrained types at once, though this may or may not be stated explicitly.

Some use of constraining types is discussed further below.

Primitive Types

The FHIR Specification defines a series of special types that are known as primitive types. These are the only types that define elements that have a value.

All primitive types have the same basic structure:

 Element 
   - extension : 0..* elements as defined by the Extension type
   - value
 

Each primitive type assigns a different value domain to it's value - typically a boolean, integer, decimal, string, or some kind of constraint on these.

Only the base specification can define a primitive type, or derive a specialised type from a primitive type.

All primitive types have a name that starts with a lowercase character. All other types start with an uppercase character.

Complex Types

All other types that are defined through out the FHIR eco-system are called 'complex types'. A complex type defines a tree of elements where the root element derives from Element or BackboneElement, and the element has 1 or more typed child elements. Complex Types will be one of the following:

  • a resource
  • a data type used in resources or other data types
  • a logical model
  • an anonymous type

Resources

Resources are a particular type which are the defined focus of the various exchange mechanism defined in the FHIR specification. As a type, the only thing that distinguishes them is that they define properties that are used in the exchange specifications.

Data Types

A primitive type, or a complex type. The type is used in resources, other data types, and logical models. Data types do not have an identity.

Most, but not all, of the data types defined in the specification are defined on the data types page. There's no technical difference between the ones that are defined on the data types page and the ones that aren't, it's just that the ones defined on the data types page are defined for general use, while the ones defined elsewhere are specifically defined for a particular use.

Logical Types

Types defined that are logical models, and/or may be used as the type in another logical model. A logical model is FHIR speak for 'a tree of data that has no particular use in the FHIR exchange paradigms'. In FHIR, they are typically used to represent ad-hoc combinations of FHIR data for packaging convenience, and/or content models as defined by other specifications (e.g. CDA, CIMI, openEHR).

Logical Models may use normal FHIR data types - or even resources - and have the full suite of the FHIR definitional framework to call on (e.g. terminology definitions/service, mapping language, etc).

Anonymous Types

Anonymous types are used widely in FHIR models. They are used where ever a type has more than one level of children. For instance, take the Timing Data type:

 Timing
  - event
  - repeat
    - period
    - etc
  

The 'repeat' element here is an anonymous type. It is an element assigned the type of 'Element' or 'BackboneElement' that defines child elements of it's own. The element is a Complex Data type, but one that is not assigned a name, it is just defined implicitly as part of the type in which it is defined, and where the type binding defined above is regarded as having already happened.