This page is part of the FHIR Specification v6.0.0-ballot1: Release 6 Ballot (1st Draft) (see Ballot Notes). The current version is 5.0.0. For a full list of available versions, see the Directory of published versions
Modeling and Methodology Work Group | Maturity Level: Normative | Standards Status: Partially Normative |
Types Framework Cross Reference: Base Types | Datatypes | Resources | Patterns
The FHIR specification defines a set of datatypes that are used for the resource elements. There are five categories of datatypes:
This page describes the general-purpose datatypes (categories 1 and 2).
Datatypes Summary.
Legend: see Standards Status Colors
A limited set of these datatypes may appear in extensions. All datatypes (including primitives) may have extensions, but only the following datatypes may include Modifier Extensions:
The following table describes the primitive types that are used in this specification. Primitive types are those that specialize PrimitiveType, with a value, and no additional elements as children (though, like
all types, they have id
and extensions). See also the Examples.
Primitive Types | |||
FHIR Name | Value Domain | XML Representation | JSON representation |
---|---|---|---|
base64Binary | A stream of bytes, base64 encoded (RFC 4648 ). base64Binary content does not include any whitespace or line feeds, but reading applications should ignore whitespace characters (per RFC 4648 ) | xs:base64Binary | A JSON string - base64 content |
Regex: (?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)? |
XML Definition | JSON Definition | |
There is no specified upper limit to the size of a binary, but systems will have to impose some implementation based limit to the size they support. This should be clearly documented, though there is no computable way for this at this time | |||
boolean | true | false | xs:boolean, except that 0 and 1 are not valid values | JSON boolean (true or false) |
Regex: true|false |
XML Definition | JSON Definition | |
canonical | A URI that refers to a resource by its canonical URL
(resources with a url property).
The canonical type differs from a uri in that it has special meaning in this specification,
and in that it may have a version appended, separated by a vertical bar (|).
Note that the type canonical is not used for the actual canonical URLs that are the target
of these references, but for the URIs that refer to them, and may have the version suffix in them.
Like other URIs, elements of type canonical may also have #fragment references. Unlike
other URIs, canonical URLs are never relative - they are either absolute URIs, or fragment identifiers |
xs:anyURI | A JSON string - a canonical URL |
Regex: \S* |
XML Definition | JSON Definition | |
code | Indicates that the value is taken from a set of controlled strings defined elsewhere (see Using codes for further discussion). Technically, a code is restricted to a string which has at least one character and no leading or trailing whitespace, and where there is no whitespace other than single spaces in the contents | xs:token | JSON string |
Regex: [^\s]+( [^\s]+)* This datatype can be bound to a ValueSet |
XML Definition | JSON Definition | |
date | A date, or partial date (e.g. just year or year + month) as used in human communication. The format is a subset of [ISO8601] : YYYY, YYYY-MM, or YYYY-MM-DD, e.g. 2018, 1973-06, or 1905-08-23. There SHALL be no timezone offset. Dates SHALL be valid dates. | union of xs:date, xs:gYearMonth, xs:gYear | A JSON string - a union of xs:date, xs:gYearMonth, xs:gYear |
Regex: ([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2][0-9]|3[0-1]) |
XML Definition | JSON Definition | |
dateTime | A date, date-time or partial date (e.g. just year or year + month) as used in human communication. The format is a subset of [ISO8601] : YYYY, YYYY-MM, YYYY-MM-DD or YYYY-MM-DDThh:mm:ss+zz:zz, e.g. 2018, 1973-06, 1905-08-23, 2015-02-07T13:28:17-05:00 or 2017-01-01T00:00:00.000Z. If hours and minutes are specified, a timezone offset SHALL be populated. Actual timezone codes can be sent using the Timezone Code extension, if desired. Seconds must be provided due to schema type constraints but may be zero-filled and may be ignored at receiver discretion. Milliseconds are optionally allowed. Dates SHALL be valid dates. The time "24:00" is not allowed. Leap Seconds are allowed - see below | union of xs:dateTime, xs:date, xs:gYearMonth, xs:gYear | A JSON string - a union of xs:dateTime, xs:date, xs:gYearMonth, xs:gYear |
Regex: ([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2][0-9]|3[0-1]) |
XML Definition | JSON Definition | |
decimal | Rational numbers that have a decimal representation. Decimals in FHIR cannot have more than 18 digits and a decimal point. See below about the precision of the number | union of xs:decimal and xs:double (see below for limitations) | A JSON number (see below for limitations) |
Regex: -?(0|[1-9][0-9]{0,17})(\.[0-9]{1,17})?([eE][+-]?[0-9]{1,9}})? |
XML Definition | JSON Definition | |
id | Any combination of upper- or lower-case ASCII letters ('A'..'Z', and 'a'..'z', numerals ('0'..'9'), '-' and '.', with a length limit of 64 characters. (This might be an integer, an un-prefixed OID, UUID or any other identifier pattern that meets these constraints.) | xs:string | JSON string |
Regex: [A-Za-z0-9\-\.]{1,64} |
XML Definition | JSON Definition | |
instant | An instant in time in a format that is a subset of [ISO8601] : YYYY-MM-DDThh:mm:ss.sss+zz:zz (e.g. 2015-02-07T13:28:17.239+02:00 or 2017-01-01T00:00:00Z). The time SHALL specified at least to the second and SHALL include a timezone offset.
Actual timezone codes can be sent using the [[[http://hl7.org/fhir/StructureDefinition/timezone extension]]], if desired.
Note: This is intended for when precisely observed times are required (typically system logs etc.), and not human-reported times - for those, use date or dateTime (which can be as precise as instant , but is not required to be). instant is a more constrained dateTime |
xs:dateTime | A JSON string - an xs:dateTime |
Note: This type is for system times, not human times (see date and dateTime below). | |||
Regex: ([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])T( |
XML Definition | JSON Definition | |
integer | A signed integer in the range −2,147,483,648..2,147,483,647 (32-bit; for larger values, use decimal) | xs:int, except that leading 0 digits are not allowed | JSON number (with no decimal point) |
Regex: [0]|[-+]?[1-9][0-9]* |
XML Definition | JSON Definition | |
integer64 | A signed integer in the range -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 (64-bit). This type is defined to allow for record/time counters that can get very large |
xs:long, except that leading 0 digits are not allowed | JSON String (due to issues with precision in floating point libraries) |
Regex: [0]|[-+]?[1-9][0-9]* |
XML Definition | JSON Definition | |
markdown | A FHIR string (see below) that may contain markdown syntax for optional processing by a markdown presentation engine, in the GFM extension of CommonMark format (see below) |
xs:string | JSON string |
Regex: ^[\s\S]+$ (can't put size limit in the regex - too large) |
XML Definition | JSON Definition | |
oid | An OID represented as a URI (RFC 3001 ); e.g. urn:oid:1.2.3.4.5 | xs:anyURI | JSON string - uri |
Regex: urn:oid:[0-2](\.(0|[1-9][0-9]*))+ |
XML Definition | JSON Definition | |
string | A sequence of Unicode characters | xs:string | JSON String |
Note that strings SHALL NOT exceed 1,048,576 (1024*1024) characters in size. Because UTF-8 characters can be expressed with more than one byte, the string size may be more than 1MB. Strings SHOULD not contain Unicode character points below 32, except for u0009 (horizontal tab), u000D (carriage return) and u000A (line feed). Leading and Trailing whitespace is allowed, but SHOULD be removed when using the XML format. Note: This means that a string that consists only of whitespace could be trimmed to nothing, which would be treated as an invalid element value. Therefore strings SHOULD always contain non-whitespace content | |||
This datatype can be bound to a ValueSet | |||
Regex: ^[\s\S]+$ (see notes below) |
XML Definition | JSON Definition | |
positiveInt | Any positive integer in the range 1..2,147,483,647 |
xs:positiveInteger | JSON number |
Regex: [1-9][0-9]* |
XML Definition | JSON Definition | |
time | A time during the day, in the format hh:mm:ss (a subset of [ISO8601] ). There is no date specified. Seconds must be provided due to schema type constraints but may be zero-filled and may be ignored at receiver discretion. The time "24:00" SHALL NOT be used. A timezone offset SHALL NOT be present. Times can be converted to a Duration since midnight. | xs:time | A JSON string - an xs:time |
Regex: ([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60)(\.[0-9]{1,9})? |
XML Definition | JSON Definition | |
unsignedInt | Any non-negative integer in the range 0..2,147,483,647 |
xs:nonNegativeInteger | JSON number |
Regex: [0]|([1-9][0-9]*) |
XML Definition | JSON Definition | |
uri | A Uniform Resource Identifier Reference (RFC 3986 ). Note: URIs are case sensitive. For UUID (urn:uuid:53fefa32-fcbb-4ff8-8a92-55ee120877b7) use all lowercase | xs:anyURI | A JSON string - a URI |
Regex: \S* (This regex is very permissive, but URIs must be valid. Implementers are welcome to use more specific regex statements for a URI in specific contexts) |
XML Definition | JSON Definition | |
URIs can be absolute or relative, and may have an optional fragment identifier This datatype can be bound to a ValueSet |
|||
url | A Uniform Resource Locator (RFC 1738 ). Note URLs are accessed directly using the specified protocol. Common URL protocols are http{s}: , ftp: , mailto: and mllp: , though many others are defined |
xs:anyURI | A JSON string - a URL |
Regex: \S* |
XML Definition | JSON Definition | |
uuid | A UUID (aka GUID) represented as a URI (RFC 4122 ); e.g. urn:uuid:c757873d-ec9a-4326-a141-556f43239520 | xs:anyURI | JSON string - uri |
Regex: urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} |
XML Definition | JSON Definition |
Notes:
INF
, -INF
and NaN
are not allowed, and JSON is restricted to the precision limits documented in XML schema for xs:double and xs:decimal [\r\n\t\x{0020}-\x{FFFF}]*
or [\r\n\t\u0020-\uFFFF]*
are better expressions of the constraints on string, but poorly supported (see Regex Tutorial for details).
The string
regex also applies to markdown
as well. The regex does not enforce the length limitcode
.http://example.com/fhir/Patient/1234
, the last part "1234" (highlighted in red) is the part that is an id datatype.uri
, not an id
. UUIDs in URIs SHALL also be represented in lowercase (urn:uuid:59bf0ef4-e89c-4628-9b51-12ae3fdbe22b).uri
, url
and canonical
datatypes:
url
and canonical
are specializations of uri
, they are never substituted for each other.">"
characters preceding character content (">"
becomes "\>"
) before processing the content or by using a markdown
processor-specific flag that accomplishes the same effect. This means that HTML content cannot be embedded in markdown to influence rendering.string
to markdown
in a later version of this FHIR specification
is considered a non-breaking change for elements with a single type. It is a breaking change for multi-type/choice elements because the type name
is reflected in the element name. (Adding markdown
as an additional choice to a multi-type element is not a breaking change). The impact
of a lack of escaping on existing string data on safe rendering should be considered in evaluating changes from string to markdown - see next bullet.Implementation Note: A simple way to convert plain text to be safe as markdown is to prefix any of the characters *, &, #, [, <, >, and ` with a backslash (\). When presenting markdown as plain text, implementers may wish to reverse this transform.
All elements using these primitive types may have one or more of a value as described above, an internal identity (e.g. xml:id), and extensions. For an example, take an element of name "count" and type "integer".
XML
The value is represented in XML as an attribute named "value":
<count value="2"/>
The full representation, with id, extensions and value:
<count id="a1" value="2"> <extension url="..."> <valueXX.../> </extension> </count>
JSON
In JSON, for convenience, the value is represented as the property itself:
"count" : 2
The full representation, with id, extensions and value, showing the id and extensions in the sibling property:
"count" : 2 "_count" : { "id" : "a1", "extension" : [{ "url" : "...", "valueXXX" : "...." }] }
RDF
The value is represented in RDF as a relationship with the URI "http://hl7.org/fhir/value". Using the normal prefix, this becomes:
fhir:Type.count [ fhir:value "2"^^xsd:integer ]
For the types date and DateTime, the type must be specified explicitly. For all other types, it is optional. The full representation, with id, extensions and value:
fhir:Type.count [ Element.id "a1"; fhir:value "2"^^xsd:integer; Element.extension [ fhir:Extension.url ".."; fhir:Extension.valueXX... ] ]
For additional details, see the XML, JSON and Turtle format definitions. When the value is missing, and there are no extensions, the element is not represented at all. This means that in xml, attributes are never present with a length of 0 (value=""), and properties are never a 0 length string or null in JSON ("name" : "" is not valid). (note: there is one specific use of the null in the JSON representation).
According to XML schema, leading and trailing whitespace in the value attribute is ignored for the types boolean, integer, decimal, base64Binary, instant, uri, date, dateTime, oid, and uri. Note that this means that the schema aware XML libraries give different attribute values to non-schema aware libraries when reading the XML instances. For this reason, the value attribute for these types SHOULD not have leading and trailing spaces. String values should only have leading and trailing spaces if they are part of the content of the value. In JSON and Turtle whitespace in string values is always significant. Primitive types other than string SHALL NOT have leading or trailing whitespace.
In XML, these types are represented as XML Elements with child elements with the name of the defined elements of the type. The name of the element is defined where the type is used. In JSON, the datatype is represented by an object with properties named the same as the XML elements. Since the JSON representation is almost exactly the same, only the first example has an additional explicit JSON representation.
Complex datatypes may be "profiled". A Structure Definition or type "constraint" makes a set of rules about which elements SHALL have values and what the possible values are.
UML Diagrams of the Datatypes
FHIR Infrastructure Work Group | Maturity Level: 5 | Standards Status: Normative |
See also Examples, Detailed Descriptions, Mappings, Profiles, Extensions and R4 Conversions
This type is for containing or referencing attachments - additional data content defined in other formats. The most common use of this type is to include images or reports in some report format such as PDF. However, it can be used for any data that has a MIME type.
Structure
Name | Flags | Card. | Type | Description & Constraints | ||||
---|---|---|---|---|---|---|---|---|
Attachment | N | Element | Content in a format defined elsewhere + Rule: If the Attachment has data, it SHALL have a contentType Elements defined in Ancestors: id, extension | |||||
contentType | ΣC | 0..1 | code | Mime type of the content, with charset etc. Binding: Mime Types (Required) | ||||
language | Σ | 0..1 | code | Human language of the content (BCP-47) Binding: All Languages (Required)
| ||||
data | C | 0..1 | base64Binary | Data inline, base64ed | ||||