Compartments API

Overview

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

  • Function as an access mechanism for finding a set of related resources quickly (described here)

  • Provide a definitional basis for applying access control to resources quickly

Read more about compartments in the FHIR documentation. All examples in this tutorial are executable in Aidbox REST console.

Aidbox supports 5 default FHIR compartments in FHIR versions 1.4.0, 1.8.0, 3.0.1, 3.2.0, 3.3.0, 4.0.0, 4.0.1

Defining Compartments (FHIR R4)

In order to use compartments, you will need to create CompartmentDefinition resources on your server. Visit FHIR documentation for official CompartmentDefinition examples or use the following REST console snippets to create the resources.

Which CompartmentDefinitionis used is determined by its code or id:

  1. The compartment withid = target resourceTypeis used

  2. Else if not found compartment withcode = target resourceTypeis used

If multiple compartments with the code = traget resourceType are found then it is not determined which one will be used since FHIR spec doesn't specify this case

PUT /fhir/CompartmentDefinition/Patient

resourceType: CompartmentDefinition
id: Patient
url: http://hl7.org/fhir/CompartmentDefinition/patient
experimental: true
name: Base FHIR compartment definition for Patient
status: draft
publisher: FHIR Project Team
version: 4.0.1
date: '2019-11-01T09:29:23+11:00'
search: true
code: Patient
contact:
- telecom:
  - {system: url, value: 'http://hl7.org/fhir'}
description: ...
# array that enumerates resources included in the compartment
resource: ...