View raw Markdown
type: resourceresource: CompartmentDefinition

CompartmentDefinition

Introduction

Scope and Usage

Each resource may belong to one or more logical compartments. A compartment is a logical grouping of resources which share a common property. Compartments have two principal roles:

Each compartment definition is associated with exactly one FHIR resource type, identified by CompartmentDefinition.code. The compartment also identifies all resources that are members of the compartment and what search parameters are used to determine membership. A compartment instance (the set of all resources tied to the 'compartment resource' - a resource instance of the compartment's type) contains all resources found by searching using the associated search parameters with a value of the compartment resource. For example, the compartment for Patient/123 would include Account?subject=Patient/123, AllergyIntolerance?patient=Patient/123, AllergyIntolerance?asserter=Patient/123, etc. Each CompartmentDefinition instance will list all resources available for that FHIR release (Additional resources are handled separately). Listed resources that have one or more .param elements are considered part of the compartment. Listed resources that do not have a .param element are considered to be outside the compartment.

Notes:

Boundaries and Relationships

Compartment definitions describe how particular compartment instances are named and identified, and how systems know which resources are in the compartment. The following compartments are defined by this specification:

<%compartmentlist%>

The full definitions of these compartments are published as CompartmentDefinition resources. Servers typically do not support the full definition of a compartment, and are not required to. Systems may publish CompartmentDefinition resources so that other systems may make use of compartments properly.

Notes

Base Resource

A compartment implicitly always includes the resource that is a 'root' of the compartment e.g. the resource Patient/123 is the root resource of the Patient Compartment for Patient/123. Thus an operation that retrieves everything within the compartment will include the base resource; a scope that grants access to everything within the compartment will grant access to the resource; etc.

Using Compartments

As an example of compartment usage, to retrieve a list of a patient's conditions, use the URL:

GET [base]/Patient/[id]/Condition

Additional search parameters can be defined, such as this hypothetical search for acute conditions:

GET [base]/Patient/[id]/Condition?code:in=http://hspc.org/ValueSet/acute-concerns

Note that as searches, these are syntactic variations on these two search URLs respectively:

GET [base]/Condition?patient=[id] GET [base]/Condition?patient=[id]&code:in=http://hspc.org/ValueSet/acute-concerns

The outcome of a compartment search is the same as the equivalent system or type search and will have full URLs that are not compartment-specific. For example, both these searches return the same outcome if there is no patient 333:

GET [base]/Patient/333/Condition GET [base]/Condition?patient=333

Whether the patient doesn't exist, or the user has no access to the patient, both these searches return an empty bundle with no matches. Some systems will include an operation outcome warning that there is no matching patient.

However, there is a key difference in functionality between compartment based searches and direct searches with parameters. Consider this search:

GET [base]/Patient/[id]/Communication

Because the definition of the patient compartment for Communication says that a Communication resource is in the patient compartment if the subject, sender, or recipient is the patient, the compartment search is actually the same as the union of these 3 searches:

GET [base]/Communication?subject=[id] GET [base]/Communication?sender=[id] GET [base]/Communication?recipient=[id]

There is no way to do this as a single search, except by using the _filter:

GET [base]/Communication?_filter=subject re [id] or sender re [id] or recipient re [id]

Further details of searching by compartment are described under the search operation. As a search related operation, the assignment of resources to compartments is only based on the current version of any of the resources involved. Note that contained patient resources cannot create a patient compartment of their own.

Supported Interactions: The only RESTful interaction defined on a compartment endpoint is search. Reads, writes (create, update, patch, delete), history, operations (e.g. $validate, $lastn) and batch/transaction POSTs are not defined when invoked through a compartment-qualified URL such as [base]/Patient/[id]/Condition/[rid] or [base]/Patient/[id]/Condition/$lastn. Clients SHOULD NOT expect servers to support these interactions via compartment-qualified paths, however servers MAY choose to implement them. To interact with a specific instance or invoke an operation that targets a resource type or instance, use the native URL for the resource (e.g. [base]/Condition/[id]). See the HTTP Search variants and Search Contexts for further details.

Note that while this specification describes how to use the compartment syntax to find resources that are logically associated with the compartment, the compartment is not part of the identity of the resource. E.g. the response to the following is not defined by this specification:

GET [base]/Patient/[patient-id]/Condition/[resource-id]

The response for write operations (PUT/DELETE/PATCH) are also not defined by this specification. Nor is the response to a POST defined:

POST [base]/Patient/[patient-id]/Condition

There is no expectation for servers to support either read or write to such URLs.

Logical Meaning of Compartments

Compartments may be used explicitly, like this, but can also be used implicitly. For instance, if a FHIR server is providing a patient view of a record, the authorized user associated with use of the FHIR RESTful API may be limited to accessing records from the compartment instance(s) logically associated with their identity. Irrespective of whether compartments are being used explicitly or implicitly, servers will need to make arrangements to make some resources with no direct link to a patient available to the client (medications, substances, binaries, etc.).

Note that resources may cross between compartments, or interlink them. Examples of this would be where a Diagnostic Report identifies a subject, but an Observation it references identifies a different subject, or where a List resource references items that identify different subjects. Such cross-linking may arise for many valid reasons, including:

Given the wide variety of use cases and contexts in which FHIR is used, compartments do not define how cross-linking is handled. Systems may reject resources, remove them from both compartments, or place them in both, or act in some other fashion.

The graph definition resource provides a method by which rules about cross-linking may be made and enforced.

It is at the discretion of the server whether to include resources in a compartment when the reference to the resource that establishes the compartment is in an extension.

Some resources are not in any compartment, e.g. Medication, Substance, Location. These resources are not linked directly to a patient or authored record, and are sometimes called 'master files'. Servers will need to make arrangements to make these resources available to the clients that are limited to particular compartments. For example, a Medication resource describes a medication itself and does not link to a patient; however, a resource such as MedicationAdministration connects the Medication (details of what was administered) to the patient (for whom was it administered), and so is required to interpret the administration.

Defining New Compartments

Compartments are defined and added to the list above when implementer communities identify them as common access points for data. As described below, compartments have both syntactical and logical consequences, and both these aspects of their functionality are evaluated when deciding whether to define compartments.

StructureDefinition

Elements (Simplified)

Mappings

Resource Packs

list-CompartmentDefinition-packs.xml

<?xml version="1.0" encoding="UTF-8"?>

<List xmlns="http://hl7.org/fhir">
  <id value="CompartmentDefinition-packs"/>
  <status value="current"/>
  <mode value="working"/>
</List>

Search Parameters

Full Search Parameters

Examples

Full Examples

Mapping Exceptions

compartmentdefinition-fivews-mapping-exceptions.xml

Unmapped Elements