device-compartment
device_compartment Validator Documentation
FHIR Compartment-Based Access Control for Device-Linked Resources
Intent
The device_compartment validator restricts access to resources explicitly linked to the authenticated device’s FHIR compartment. It ensures automated or headless devices (e.g., lab instruments, IoT sensors) can only interact with data they generate or manage.
Key Use Cases:
- Lab equipment submitting
DiagnosticReportresults. - Wearable devices recording
Observationdata (e.g., heart rate). - Imaging machines updating
MediaorImagingStudyresources.
Key Features
- Role Enforcement:
- Validates that the client has the
Devicerole. Requests from non-device roles (e.g.,Practitioner) are denied.
- Validates that the client has the
- Compartment Membership Check:
- Confirms the requested resource type belongs to the FHIR Device compartment (e.g.,
DeviceMetric,Observation).
- Confirms the requested resource type belongs to the FHIR Device compartment (e.g.,
- Reference Validation:
- For
create/updateoperations, ensures the resource references the device’s ID (e.g.,Observation.performer = Device/<id>).
- For
Validation Logic
| Step | Action | Error If Failed |
|---|---|---|
| 1 | Check client_role is Device. | 403 Forbidden (Invalid role) |
| 2 | Verify resource type is in the Device compartment. | 403 Forbidden (Invalid compartment) |
| 3 | For write operations, validate device ID in relevant fields (e.g., performer, device). | 403 Forbidden (Reference mismatch) |
Example Configurations
1. Read Access to Observation
{
"client_role": "Device",
"entity_name": "Observation",
"operation": "read",
"validator": "device_compartment"
}
Explanation: A device can read Observation resources
2. Submit a Device Metric
{
"client_role": "Device",
"entity_name": "DeviceMetric",
"operation": "create",
"validator": "device_compartment"
}
FHIR References
- Device Compartment Definition:
FHIR R4 Device Compartment (Official HL7 documentation). - Resource Examples:
Authentication Notes
- Headless Devices: Supports OAuth 2.0 Device Code Flow for authentication.
- Cloud Services: Not yet supported (future roadmap item).
Use Case: Lab Equipment Integration
A hematology analyzer uses this validator to:
- Submit lab results: Creates
Observationresources withperformerset to its Device ID. - Monitor calibration metrics: Updates
DeviceMetricresources linked to its compartment.
Error Handling:
- A device attempting to access another device’s
Observationdata receives a403 Forbiddenresponse.