SQL on FHIR
2.0.0-pre - ci-build International flag

SQL on FHIR, published by HL7. This guide is not an authorized publication; it is the continuous build for version 2.0.0-pre built by the FHIR (HL7® FHIR® Standard) CI Build. This version is based on the current content of https://github.com/FHIR/sql-on-fhir-v2/ and changes regularly. See the Directory of published versions

Logical Model: ViewDefinition - Detailed Descriptions

Draft as of 2024-10-03

Definitions for the ViewDefinition logical model.

Guidance on how to interpret the contents of this table can be found here

0. ViewDefinition
Definition

A ViewDefinition represents a tabular projection of a FHIR resource, where the columns and inclusion criteria are defined by FHIRPath expressions.

ShortView Definition
Logical ModelInstances of this logical model are not marked to be the target of a Reference
2. ViewDefinition.url
Definition

Canonical identifier for this view definition, represented as a URI (globally unique)

ShortCanonical identifier for this view definition, represented as a URI (globally unique)
Control0..1
Typeuri
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
4. ViewDefinition.identifier
Definition

Additional identifier for the view definition

ShortAdditional identifier for the view definition
NoteThis is a business identifier, not a resource identifier (see discussion)
Control0..1
TypeIdentifier
6. ViewDefinition.name
Definition

Name of the view definition, must be in a database-friendly format.

ShortName of view definition (computer and database friendly)
Control0..1
Typestring
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
Invariantssql-name: Name is limited to letters, numbers, or underscores and cannot start with an underscore -- i.e. with a regular expression of: ^[A-Za-z][A-Za-z0-9_]*$ This makes it usable as table names in a wide variety of databases. (empty() or matches('^[A-Za-z][A-Za-z0-9_]*$'))
8. ViewDefinition.title
Definition

A optional human-readable description of the view.

ShortName for this view definition (human friendly)
Control0..1
Typestring
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
10. ViewDefinition.meta
Definition

Metadata about the view definition

ShortMetadata about the view definition
Control0..1
TypeMeta
12. ViewDefinition.status
Definition

draft | active | retired | unknown

Shortdraft | active | retired | unknown
Control1..1
BindingThe codes SHALL be taken from PublicationStatus
(required to http://hl7.org/fhir/ValueSet/publication-status)
Typecode
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
14. ViewDefinition.experimental
Definition

For testing purposes, not real usage

ShortFor testing purposes, not real usage
Control0..1
Typeboolean
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
16. ViewDefinition.publisher
Definition

Name of the publisher/steward (organization or individual)

ShortName of the publisher/steward (organization or individual)
Control0..1
Typestring
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
18. ViewDefinition.contact
Definition

Contact details for the publisher

ShortContact details for the publisher
Control0..*
TypeContactDetail
20. ViewDefinition.description
Definition

Natural language description of the view definition

ShortNatural language description of the view definition
Control0..1
Typemarkdown
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
22. ViewDefinition.useContext
Definition

The context that the content is intended to support

ShortThe context that the content is intended to support
Control0..*
TypeUsageContext
24. ViewDefinition.copyright
Definition

Use and/or publishing restrictions

ShortUse and/or publishing restrictions
Control0..1
Typemarkdown
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
26. ViewDefinition.resource
Definition

The FHIR resource that the view is based upon, e.g. 'Patient' or 'Observation'.

ShortFHIR resource for the ViewDefinition
Control1..1
BindingThe codes SHALL be taken from ResourceType
(required to http://hl7.org/fhir/ValueSet/resource-types)
Typecode
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
28. ViewDefinition.fhirVersion
Definition

The FHIR version(s) for the FHIR resource. The value of this element is the formal version of the specification, without the revision number, e.g. [publication].[major].[minor].

ShortFHIR version(s) of the resource for the ViewDefinition
Control0..*
BindingThe codes SHALL be taken from FHIRVersion
(required to http://hl7.org/fhir/ValueSet/FHIR-version)
Typecode
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
30. ViewDefinition.constant
Definition

A constant is a value that is injected into a FHIRPath expression through the use of a FHIRPath external constant with the same name.

ShortConstant that can be used in FHIRPath expressions
Control0..*
TypeBackboneElement
32. ViewDefinition.constant.name
Definition

Name of constant (referred to in FHIRPath as %[name])

ShortName of constant (referred to in FHIRPath as %[name])
Control1..1
Typestring
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
Invariantssql-name: Name is limited to letters, numbers, or underscores and cannot start with an underscore -- i.e. with a regular expression of: ^[A-Za-z][A-Za-z0-9_]*$ This makes it usable as table names in a wide variety of databases. (empty() or matches('^[A-Za-z][A-Za-z0-9_]*$'))
34. ViewDefinition.constant.value[x]
Definition

The value that will be substituted in place of the constant reference. This is done by including %your_constant_name in a FHIRPath expression, which effectively converts the FHIR literal defined here to a FHIRPath literal used in the path expression.

Support for additional types may be added in the future.

ShortValue of constant
Control1..1
TypeChoice of: base64Binary, boolean, canonical, code, date, dateTime, decimal, id, instant, integer, integer64, oid, string, positiveInt, time, unsignedInt, uri, url, uuid
[x] NoteSeeChoice of Data Typesfor further information about how to use [x]
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
36. ViewDefinition.select
Definition

The select structure defines the columns to be used in the resulting view. These are expressed in the column structure below, or in nested selects for nested resources.

ShortA collection of columns and nested selects to include in the view.
Control1..*
TypeBackboneElement
Invariantssql-expressions: Can only have at most one of `forEach` or `forEachOrNull`. ((forEach | forEachOrNull).count() <= 1)
38. ViewDefinition.select.column
Definition

A column to be produced in the resulting table. The column is relative to the select structure that contains it.

ShortA column to be produced in the resulting table.
Control0..*
TypeBackboneElement
40. ViewDefinition.select.column.path
Definition

A FHIRPath expression that evaluates to the value that will be output in the column for each resource. The input context is the collection of resources of the type specified in the resource element. Constants defined in Reference({constant}) can be referenced as %[name].

ShortFHIRPath expression that creates a column and defines its content
Control1..1
Typestring
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
42. ViewDefinition.select.column.name
Definition

Name of the column produced in the output, must be in a database-friendly format. The column names in the output must not have any duplicates.

ShortColumn name produced in the output
Control1..1
Typestring
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
Invariantssql-name: Name is limited to letters, numbers, or underscores and cannot start with an underscore -- i.e. with a regular expression of: ^[A-Za-z][A-Za-z0-9_]*$ This makes it usable as table names in a wide variety of databases. (empty() or matches('^[A-Za-z][A-Za-z0-9_]*$'))
44. ViewDefinition.select.column.description
Definition

A human-readable description of the column.

ShortDescription of the column
Control0..1
Typemarkdown
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
46. ViewDefinition.select.column.collection
Definition

Indicates whether the column may have multiple values. Defaults to false if unset.

ViewDefinitions must have this set to true if multiple values may be returned. Implementations SHALL report an error if multiple values are produced when that is not the case.

ShortIndicates whether the column may have multiple values.
Control0..1
Typeboolean
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
48. ViewDefinition.select.column.type
Definition

A FHIR StructureDefinition URI for the column's type. Relative URIs are implicitly given the 'http://hl7.org/fhir/StructureDefinition/' prefix. The URI may also use FHIR element ID notation to indicate a backbone element within a structure. For instance, Observation.referenceRange may be specified to indicate the returned type is that backbone element.

This field must be provided if a ViewDefinition returns a non-primitive type. Implementations should report an error if the returned type does not match the type set here, or if a non-primitive type is returned but this field is unset.

ShortA FHIR StructureDefinition URI for the column's type.
Control0..1
Typeuri
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
50. ViewDefinition.select.column.tag
Definition

Tags can be used to attach additional metadata to columns, such as implementation-specific directives or database-specific type hints.

ShortAdditional metadata describing the column
Control0..*
TypeBackboneElement
52. ViewDefinition.select.column.tag.name
Definition

A name that identifies the meaning of the tag. A namespace should be used to scope the tag to a particular context. For example, 'ansi/type' could be used to indicate the type that should be used to represent the value within an ANSI SQL database.

ShortName of tag
Control1..1
Typestring
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
54. ViewDefinition.select.column.tag.value
Definition

Value of tag

ShortValue of tag
Control1..1
Typestring
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
56. ViewDefinition.select.select
Definition

Nested select relative to a parent expression. If the parent select has a forEach or forEachOrNull, this child select will apply for each item in that expression.

ShortNested select relative to a parent expression.
Control0..*
TypeSeettp://hl7.org/fhir/uv/sql-on-fhir/StructureDefinition/ViewDefinition#ViewDefinition.select
58. ViewDefinition.select.forEach
Definition

A FHIRPath expression to retrieve the parent element(s) used in the containing select, relative to the root resource or parent select, if applicable. forEach will produce a row for each element selected in the expression. For example, using forEach on address in Patient will generate a new row for each address, with columns defined in the corresponding column structure.

ShortA FHIRPath expression to retrieve the parent element(s) used in the containing select. The default is effectively `$this`.
Control0..1
Typestring
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
60. ViewDefinition.select.forEachOrNull
Definition

Same as forEach, but produces a single row with null values in the nested expression if the collection is empty. For example, with a Patient resource, a forEachOrNull on address will produce a row for each patient even if there are no addresses; it will simply set the address columns to null.

ShortSame as forEach, but will produce a row with null values if the collection is empty.
Control0..1
Typestring
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
62. ViewDefinition.select.unionAll
Definition

A unionAll combines the results of multiple selection structures. Each structure under the unionAll must produce the same column names and types. The results from each nested selection will then have their own row.

ShortCreates a union of all rows in the given selection structures.
Control0..*
TypeSeettp://hl7.org/fhir/uv/sql-on-fhir/StructureDefinition/ViewDefinition#ViewDefinition.select
64. ViewDefinition.where
Definition

A series of zero or more FHIRPath constraints to filter resources for the view. Every constraint must evaluate to true for the resource to be included in the view.

ShortA series of zero or more FHIRPath constraints to filter resources for the view.
Control0..*
TypeBackboneElement
66. ViewDefinition.where.path
Definition

A FHIRPath expression that defines a filter that must evaluate to true for a resource to be included in the output. The input context is the collection of resources of the type specified in the resource element. Constants defined in Reference({constant}) can be referenced as %[name].

ShortA FHIRPath expression defining a filter condition
Control1..1
Typestring
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension
68. ViewDefinition.where.description
Definition

A human-readable description of the above where constraint.

ShortA human-readable description of the above where constraint.
Control0..1
Typestring
Primitive ValueThis primitive element may be present, or absent, or replaced by an extension