


image::https://specifications.openehr.org/images/openEHR_logo_RGB.svg["openEHR logo",align="center"]

# Foundation Types





## Acknowledgements

### Contributors

This specification has benefited from formal and informal input from the openEHR and wider health informatics community.

### Trademarks

* 'openEHR' is a registered trademark of the openEHR Foundation




ifdef::package_qualifiers[]
endif::[]

# Preface

## Purpose

This document describes the openEHR Foundation Types, a collection of built-in and library types whose semantics are assumed by all other openEHR specifications.

The intended audience includes:

* Standards bodies producing health informatics standards;
* Research groups using openEHR, {iso_13606}[ISO 13606^], archetypes and related technologies;
* The open source healthcare community;
* Solution vendors.

## Related Documents

Prerequisite documents for reading this document include:

* The {openehr_overview}[openEHR Architecture Overview^].

## Status

This specification is in the STABLE state. The development version of this document can be found at {openehr_base_development_foundation_types}[{openehr_base_development_foundation_types}^].

Known omissions or questions are indicated in the text with a 'to be determined' paragraph, as follows:
*TBD*: (example To Be Determined paragraph)

## Feedback

Feedback may be provided on the {openehr_technical_list}[technical mailing list^].

Issues may be raised on the https://specifications.openehr.org/components/{component}/open_issues[specifications Problem Report tracker^].

To see changes made due to previously reported issues, see the https://specifications.openehr.org/components/{component}/history[{component} component Change Request tracker^].

## Previous Versions

This specification is based on the types originally defined in the {openehr_rm_103_support}[openEHR Support Information Model from Release 1.0.3 of the Reference Model^]. Some changes have been made as follows.

### Interval types

The additional types `Point_interval` and `Proper_interval` have been added, to support the common need for a point value and a proper interval to be specified as substitutable types. The types `Multiplicity_interval` and `Cardinality` have been added, from the {openehr_am_aom2}[AOM2 specification^].

### Functional meta-types

A collection of meta-types representing routines, procedures and functions has been added, to support specifications that need to use these concepts. 

# Overview

The openEHR Foundation Types (`org.openehr.base.foundation_types` package) consists of generic low level types assumed by and used throughout the openEHR components and specifications. The types described here are specified in order to establish the names and minimal semantics of typical standard classes, as used by all other openEHR specifications, and to provide a mapping point into implementation technologies. 

The set of types chosen here is based on a common set derived from various published sources, including:

* {iso_8601}[ISO 8601 (2019) date/time standard^];
* Major interoperability formalisms, including {omg_idl}[OMG IDL], {w3c_xml_schema}[W3C XML-schema^];
* Major typed programming languages, including Java, C#, C++, etc.

The package structure is illustrated below.

.`base.foundation_types` Package
image::UML/diagrams/BASE-foundation_types-packages.svg[id=foundation_types_packages, align="center"]

The `primitive_types`, `structures` and `time` packages describe types assumed by the openEHR specifications to exist in any implementation technology, such as a programming language, schema language or database environment.

The `functional` package includes types enabling functional programming primitives to be expressed in the openEHR modelling environment, i.e. functions-as-objects and 'lambda' expressions.

The types are described in this specification are typically of two kinds: _built-in types_, which are those built into a type system of the development language, and _library types_, which are assumed to be available in a (class) library defined in the formalism. Thus, the type `Boolean` is always assumed to exist in a formalism, while the type `Array<T>` is assumed to be available in a library. For practical purposes, these two categories do not matter greatly - whether `String` is really a library class (the usual case) or an inbuilt type doesn't make much difference to the programmer. They are shown separately here mainly as an explanatory convenience. The built-in types are indicated in the UML with the `«Value_type»` stereotype.

The assumptions that openEHR makes about existing types are documented below in terms of interface definitions. Each of these definitions contains _only the assumptions required for the given type to be used in the openEHR type system_ - *it is not by any means a complete interface definition*. The name and semantics of any function used here for an assumed type *might not be identical* to those found in some implementation technologies. Any mapping required should be stated in the relevant implementation technology specification (ITS). To give a concrete example, where the assumed `Set<T>` type defined below has an operation `has (item: T): Boolean` which is used throughout the openEHR specifications, Java has the method `contains()` on its `Set<T>` class. In a Java implementation, the `contains()` method should then be used throughout the openEHR classes as expressed in Java, in place of the `has ()` method.

## Operators

Some operations have symbolic or textual operator equivalents defined, in order to support parsing of textual form of expressions. Two categories of operator are supported via two stereotypes that add a list of Strings to an operation, enabling standard operators, and optionally, symbolic operators to be associated with a function. These are as follows.

* `«ops»`: default operator(s) for an operation, assumed to be expressible in normal text, for example `'='` for `_equal_()`;
* `«sym_ops»`: additional symbolic operators typically defined for mathematical and logical operations, e.g. `'∀'` for `Container._for_all_()`.

The main utility of such operators is to enable function signature-matching from parsed expressions. For example, the expression `a_date_time - P1Y` (subtract a time period of 1 year from a date/time) has the signature `<[Iso8601_duration], ?>`, equivalent to a function of the form `func (dur: Iso8601_duration): ?` defined on the type `Iso8601_date_time` (i.e. the return type is unknown until the function definition can be inferred). The correct function can be found on the latter type by searching for a function with the operator `'-'` and taking a single `Iso8601_duration` argument. In this specification, this turns out to be the `Iso8601_duration._subtract_()` operation.

The operators provided by these means are not intended to prevent other kinds of operators being associated with functions defined on types in the openEHR specifications, rather they provide a minimal set for common operations.

## The Any Class

Within all object-oriented and most other modern programming and modelling environments exists an ultimate ancestor type to which all others conform. In this specification, we assume the type `Any`, which defines a bare minimum of operations, and stands for the real `Any` or `Object` type found in real technologies.

The primary operations specified are those for equality, i.e.:

* `_equal_(other: Any): Boolean`: return `True` if this and `_other_` are equal in value for value types, and for reference types, if they refer to the same object;
* `_is_equal_(other: Any): Boolean`: return `True` if this and `_other_` are equal in value; typically redefined in descendants.

In these specifications, the `_equal_()` operation is normally rendered using its operator, i.e. the `'='` sign, while `_is_equal_()` is always specified as a function call.

## openEHR Leaf Types

The sections below provide formal definitions of all the foundation types used in openEHR. A subset of these can be understood as terminal or leaf types, typically used as terminal value types in other information models. The following diagram provides an _aide memoire_ for the leaf types.

.Leaf Types
image::UML/diagrams/BASE-foundation_types-leaf_types.svg[id=foundation_types_leaf_types, align="center"]

## Class Definitions


# Primitive Types

## Overview

This section describes primitive types assumed by all openEHR models. These are types supported directly by most programing languages, and usually visible via either a class interface and/or a built-in raw value type. The following table lists the primitive types assumed by openEHR.

|===
|Type name +
 in openEHR |Description                                                        

|`Octet`    |a type whose value is an 8-bit value.
|`Character`|a type whose value is a member of an 8-bit character-set
             (ISO: "repertoire").
|`Boolean`  |logical True/False values; usually physically represented as an 
             integer, but need not be.
|`Integer`  |32-bit integers.
|`Integer64`|64-bit integers.                                                   
|`Real`     |32-bit real numbers in any interoperable representation, including
             single-width IEEE floating point.
|`Double`   |64-bit real numbers, in any interoperable representation including
            double-precision IEEE floating point.
|`String`   |represents unicode-enabled strings.
|===

The figure below illustrates these types. Simple inheritance relationships are shown which facilitate the type descriptions below. Actual inheritance from or substitutability for an `Any` class is not assumed, and is shown only for convenience (e.g. to indicate that the '=' operator is available on any type). The type `Ordered_numeric` is on the other hand is used to indicate assumed substitutability of numeric types, and is intended to be mapped to an equivalent type in a real type system (e.g. in Java, `java.lang.Number`). Data-oriented implementation type systems such as XML-schema do not have such operations.

.`base.foundation_types.primitive_types` Package
image::UML/diagrams/BASE-foundation_types.primitive_types.svg[id=foundation_types_primitive_types, align="center"]

## Unicode

It is assumed in the openEHR specifications that Unicode is supported by the type `String`. Unicode is needed for all Asian, Arabic and other script languages, for both data values (particularly plain text and coded text) and for many predefined string attributes of the classes in the openEHR Reference Model. It encompasses all existing character sets. In openEHR, UTF-8 encoding is assumed.

## Class Definitions














# Structure Types

## Overview

The types described in this section are basic data structures assumed to be standard available in implementation technologies. The following types constitute the minimum set of structure types assumed by openEHR of an implementation environment.

|===
|Type name +
 in openEHR             |Description

|`Array<T>`             |physical container of items indexed by number
|`List<T>`              |container of items, implied order, non-unique membership
|`Set<T>`               |container of items, no order, unique membership
|`Hash<K:Ordered, V>`   |a table of values of any type V, keyed by values of any `Ordered` descendant K, typically `String` or `Integer`, but may be more complex types, e.g. a coded term type.
|===

The following UML diagram illustrates the `base.foundation_types.structures` package. As with the primitive types, inheritance and abstract classes are used for convenience of the definitions in openEHR models, but are not assumed to exist in exactly the same way within implementation technologies. Hence, in an implementation, various workarounds or equivalences may be needed to obtain the defined semantics.

.`base.foundation_types.structures` package
image::UML/diagrams/BASE-foundation_types.structures.svg[id=foundation_types_structure_types, align="center"]

## Class Definitions







# Interval

## Overview

Another kind of structure commonly needed in rich data is the interval. The definition of the `Interval<T>` class here is an intensional one, i.e. it states its members by implication from its limits, rather than enumerating them. To support the common need for defining times in models that could be either a fixed point in time or a time interval, the classes `Point_interval<T>` and `Proper_interval<T>` are provided. If `Interval<X>` is defined as the type of feature in a class in an openEHR model, where `X` is some descendant of `Ordered`, then at runtime, either a `Point_interval` or `Proper_interval` may be attached.

In addition to the generic interval types, the derived types `Multiplicity_interval` and `Cardinality` are provided, for use in models to represent multiplicity, optionality, and cardinality.

The following UML diagram illustrates the `interval` package.

.`base.foundation_types.interval` package
image::UML/diagrams/BASE-foundation_types.interval.svg[id=foundation_types_interval, align="center"]

## Class Definitions






# Time Types

## Overview

The primitive Date/Time types used in openEHR are represented by classes defined in the package `base.foundation_types.time`. These are concrete types based on the {iso_8601_official}[ISO 8601 (2019) date/time standard^] semantics, which supports partial dates, times, and complex durations, all of which are needed in the biomedical and clinical domains. These classes have a `String` physical representation.  and are assumed to exist in close to the form specified here, because they are specified in other openEHR specifications.

The `time` package is shown below.

.`base.foundation_types.time` package
image::UML/diagrams/BASE-foundation_types.time.svg[id=foundation_types_time_types, align="center"]

## Primitive Time Types

The set of ISO 8601 based types define dates and times with a `String` representation (as per ISO 8601), and the ISO 8601 'partial' and 'extended' semantics. They are defined as descendents of the native types described above, and add the necessary elements required for ISO 8601.

NOTE: class names of the form `Iso8601_xxx` have been used here to clearly identify these classes where used elsewhere in the openEHR specifications. In real implementations, other class names may be used as convenient, just as for the other primitive types.

NOTE: For reasons of readability in data, it is strongly recommended that the 'extended' form of date and time strings be used when writing and displaying data, rather than the compact form. An extended date has the form `yyyy-mm-dd` rather than `yyyymmdd`, and an extended time has the form `hh:mm:ss` rather than `hhmmss`. Nevertheless, both forms should be supported so that openEHR-based systems that use 'straight-through' processing on legacy data that may be in the compact form remain conformant to the specifications.

ISO 8601 semantics not included in these types include:

* 'expanded' dates, which have year numbers of greater than 4 digits, and may be negative; in openEHR, only 4-digit year numbers are assumed;
* the `YYYY-"W"WW-D` method of expressing dates (since this is imprecise and difficult to compute with due to variable week starting dates, and not required in health);
* partial date/times with fractional minutes or hours, e.g. `hh,hhh` or `mm,mm`; in openEHR, only fractional seconds are supported;
* the interval syntax. Intervals of date/times are supported in openEHR, but their syntax form is defined by ADL, and is standardised across all comparable types, not just dates and times.

Deviations from the published standard include the following.

* Durations are supposed to take the form of `PnnW` or `PnnYnnMnnDTnnHnnMnnS`, but in openEHR, the W (week) designator can be used in combination with the other designators, since it is very common to state durations of pregnancy as some combination of weeks and days.
* Durations in openEHR may take a negative sign, indicating a duration prior to an origin. This supports healthcare needs such as 'adjusted age' (e.g. '-P3M', an age of 'minus 3 months') for very premature newborns.
* Partial variants of `Iso8601_date_time` can include missing hours, days and months, whereas {iso_8601}[ISO 8601:2019^] (section 4.3.3 c) only allows missing seconds and minutes. The reasons for this deviation are:
** the same deviation is used in HL7v2 and HL7v3 TS (timestamp) type, i.e. there are data in existing clinical systems matching this specification;
** in a typed object model, this deviation is more sensible anyway; the ISO 8601 rule is most likely a limitation of the purely syntactic means of expression. In real systems where a timestamp/date-time is specified in a screen form, it makes sense to allow it to be as partial as possible, rather than artificially restricted to only missing seconds and minutes.
* The time `24:00:00` (or `240000`) is not allowed anywhere, whereas in ISO 8601:2019 it appears to be legal at least for pure times. This deviation also appears to be used in HL7v2 and HL7v3 (where midnight is defined as the time `00:00:00`), and is preferable to the documented standard, since a date/time with time of `24:00:00` is really the next day, i.e. the date part is then incorrect.

Negation for ISO 8601 durations is also supported by {w3c_xml_schema}[W3C XML-schema^] and various programming languages. See {iso_8601}[Wikipedia^] and the {iso_8601_official}[official ISO 8601 standard^] for details. Note that in the date, time and date/time formats shown below, 'Z' and 'T' are literals.  In the duration class shown below, 'P', 'Y', 'M', 'W', 'D', 'H', 'S' and 'T' are literals.

## Derived Interval / Time Types

A number of useful types may be generated from the Date/time classes and the Interval classes. These are shown in blue on the following diagram.

.Useful time interval types
image::UML/diagrams/BASE-foundation_types.time-intervals.svg[id=foundation_types_time_intervals, align="center"]

## Computational Functions

A number of computational functions are defined in the interfaces of the concrete data/time types, of two kinds:

* _definite_: computed according to the usual numeric rules for arithmetic, in which all values are treated as _definite_, i.e. exact and invariant;
* _nominal_: computed using commonly accepted rules of 'everyday' calendrical time, in which 'year' and 'month' are understood to be variable periods.

Most of the functions defined on the date/time types are of the definite kind. The exception is functions involving `Iso8601_duration` values, which take both definite and nominal forms. The definite forms are named using the standard names `_add_()`, `_subtract_()` etc, while the nominal versions have names of the form `_xxx_nominal_()`, e.g. `_add_nominal_()` etc.

An example of an operation having both forms is addition for the type `Iso8601_date`. The definite operation is called `_add_()` and treats the `Iso8601_duration` argument as an exact amount, based on constant values for length of year and month, defined by `Time_definitions._Average_days_in_month_` and `Time_definitions._Average_days_in_year_`.

The nominal form of the operation is `_add_nominal_()`, and is computed according to 'everyday' rules, i.e. in which the phrase 'a year from now' means the same date next year (with occasional slight adjustment), and 'in a month' means the same date next month (or possibly a day or earlier due to next month being shorter). In a similar way, the addition of a period of one day (`'P1D'`), although itself a regular quantity is computed differently to the definite form: in the definite form, addition of `P1D` results in the addition of exactly 24h of time to the date, which may result in a time that is different by one hour due to a change of summer time during the interval, while the nominal addition results in the same time on the next of previous day, even though occasionally this will represent 23 or 25 hours' difference.

The definite functions have standard operators such as `'\+'`, `'-'`, etc. associated with them, while the nominal functions have the operators `'++'`, `'--'`, etc.

## Class Definitions









# Terminology Package

## Overview

The `base.foundation_types.terminology` package provides leaf types used to represent a _terminology code_, i.e. a code within a _terminology_, and a _term_, which is the combination of a code and one rubric (natural language) string associated with it. Terminology codes are sometimes called _concept codes_ among terminology experts, and when used as references, _concept references_.

An instance of `Terminology_code` is a reference to any referenceable _entity_ within a terminology or ontology, which may be:

* a single _term_, for which a rubric(s) and potentially relationships (at least the `IS-A` relationship) are defined;
* a _value set_ i.e. a set of single terms, possibly in a tree or other structure corresponding to relationships between the member terms;
* any other terminological entity referencable with a code.

An instance of `Terminology_term` provides a way to record a terminology code and the rubric used in some operational context, allowing the receiver or reader of the data to avoid having to perform a terminology lookup to obtain the rubric, e.g. for display purposes.

.`base.foundation_types.terminology` package
image::UML/diagrams/BASE-foundation_types.terminology.svg[id=foundation_types_terminology_types, align="center"]

## Class Definitions



# Functional Meta-types

## Overview

A small number of meta-types are defined that correspond to functional programming primitives, otherwise known as 'closures', 'lambda expressions' and so on. These concepts are supported in most modern programming languages now, and the types defined here are intended to provide a minimal formal basis to enable other openEHR specification to defined function-related elements. Since UML does not contain native functional elements, the semantics here are approximated using normal class facilities.

The following illustrates the `functional` package.

.base.foundation_types.functional Package
image::UML/diagrams/BASE-foundation_types.functional.svg[id=foundation_types_functional, align="center"]

Two key abstractions are required, namely 'function as a type', and 'tuple', which enables arguments to be formalised. To provide a 'function' type, a 'routine' type is also required. For completeness, a 'procedure' type is also defined. The 'tuple' type is defined as a generic meta-type whose descendants may additionally define any number of generic parameter types, corresponding to a type list.

## Class Definitions







# Type Cross-Reference

The following table provides a cross-reference from openEHR foundation types to their equivalents in common implementation formalisms. Where there is no equivalent listed, a specific library may still exist, or an implementation may be required of the openEHR specification.

|===
| **openEHR Type** | **Description** | **Java** | **.NET** | **TypeScript** | **XML Schema** | **JSON Schema**

| `Octet`
| 8-bit binary data
| `byte` or `java.lang.Byte`
| `System.Byte`
| `number` (0–255)
| `xs:byte`
| `{type: "integer", minimum: 0, maximum: 255}`

| `Character`
| Single Unicode character
| `java.lang.Character`
| `System.Char`
| `string` (length=1)
| `xs:string` (length=1)
| `{type: "string", minLength: 1, maxLength: 1}`

| `Boolean`
| logical True/False values
| `java.lang.Boolean`
| `System.Boolean`
| `boolean`
| `xs:boolean`
| `{type: "boolean"}`

| `Integer`
| Integer number (32-bit)
| `java.lang.Integer`
| `System.Int32`
| `number`
| `xs:integer`
| `{type: "integer"}`

| `Integer64`
| Integer number (64-bit)
| `java.lang.Long`
| `System.Int64`
| `number`
| `xs:long`
| `{type: "integer"}`

| `Real`
| Floating-point number (32-bit)
| `java.lang.Float`
| `System.Single`
| `number`
| `xs:float` or `xs:decimal`
| `{type: "number"}`

| `Double`
| Floating-point number (64-bit)
| `java.lang.Double`
| `System.Double`
| `number`
| `xs:double`
| `{type: "number"}`

| `String`
| Unicode-enabled strings
| `java.lang.String`
| `System.String`
| `string`
| `xs:string`
| `{type: "string"}`

| `Date`
| ISO 8601 Date
| `java.time.LocalDate`
| `System.DateTime`
| `Date`
| `xs:date`
| `{type: "string", format: "date"}`

| `Time`
| ISO 8601 Time
| `java.time.LocalTime`
| `System.DateTime`
| `Date`
| `xs:time`
| `{type: "string", format: "time"}`

| `DateTime`
| ISO 8601 Date-Time
| `java.time.LocalDateTime`
| `System.DateTime`
| `Date`
| `xs:dateTime`
| `{type: "string", format: "date-time"}`

| `Duration`
| ISO 8601 Duration
| `java.time.Duration`
| `System.TimeSpan`
| `string` (ISO 8601 format)
| `xs:duration`
| `{type: "string", format: "duration"}`

| `Uri`
| Universal Resource Identifier
| `java.net.URI`
| `System.Uri`
| `string`
| `xs:anyURI`
| `{type: "string", format: "uri"}`

| `Hrid`
| Human-readable knowledge-artefact identifier (a `String` constrained to the HRID syntax)
| `java.lang.String`
| `System.String`
| `string`
| `xs:string` (pattern-restricted)
| `{type: "string", pattern: "..."}`

| `Array<T>`
| Contiguous Array
| `Array<T>`
| `Array<T>`
| `Array<T>`
| `xs:sequence`
| `{type: "array", items: {}}`

| `List<T>`
| Ordered List
| `java.util.List<T>`
| `System.Collections.Generic.List<T>`
| `Array<T>`
| `xs:sequence`
| `{type: "array", items: {}}`

| `Set<T>`
| Unordered, unique membership container
| `java.util.Set<T>`
| `System.Collections.Generic.HashSet<T>`
| `Set<T>`
| `xs:all`
| `{type: "array", uniqueItems: true}`

| `Hash<K:Ordered, V>`
| Unique-keyed map
| `java.util.Map<K, V>`
| `System.Collections.Generic.Dictionary<K, V>`
| `Record<K, V>`
| -
| `{type: "object", additionalProperties: {}}`

| `Interval<T>`
| Interval of ordered types
| Custom class needed
| Custom class needed
| `{start: T; end: T}`
| Custom type needed
| `{type: "object", properties: {"start": {}, "end": {}}}`

| `Iso8601_date`
| ISO 8601-encoded date type
| `java.text.SimpleDateFormat`
| use formatted string
| use formatted string
| `xs:date`
| `{type: "string", format: "date"}`

| `Iso8601_time`
| ISO 8601-encoded time type
| `java.text.SimpleDateFormat`
| use formatted string
| use formatted string
| `xs:time`
| `{type: "string", format: "time"}`

| `Iso8601_date_time`
| ISO 8601-encoded date/time type
| `java.text.SimpleDateFormat`
| use formatted string
| use formatted string
| `xs:dateTime`
| `{type: "string", format: "date-time"}`

| `Iso8601_duration`
| ISO 8601-encoded duration type
| `java.text.SimpleDateFormat`
| use formatted string
| use formatted string
| `xs:duration`
| `{type: "string", format: "duration"}`
|===



:sectnums!:

:sectnums!:
