Skip to main content

practitioner_compartment Validator Documentation

practitioner_compartment Validator Documentation
FHIR Compartment-Based Access Control for Practitioner Resources


Intent​

The practitioner_compartment validator restricts access to resources explicitly linked to the authenticated practitioner’s FHIR compartment. This ensures practitioners can only interact with data they are directly associated with (e.g., orders they created, patients they treat).

Key Use Cases:

  • Practitioners viewing lab results they ordered (DiagnosticReport).
  • Practitioners updating medication requests they authored (MedicationRequest).
  • Practitioners accessing encounter records where they are the primary provider (Encounter).

Key Features​

  1. Role Enforcement:
    • Validates that the client has the Practitioner role. Requests from non-practitioner roles (e.g., Patient) are denied.
  2. Compartment Membership Check:
    • Confirms the requested resource type belongs to the system-defined Practitioner compartment (e.g., MedicationRequest, Encounter, ServiceRequest).
  3. Reference Validation:
    • For create/update operations, ensures the resource references the practitioner’s ID (e.g., MedicationRequest.requester = Practitioner/<id>).

Validation Logic​

StepActionError If Failed
1Check the caller's role is Practitioner.403 Forbidden (Invalid role)
2Verify the resource type is in the Practitioner compartment and not excluded from it.403 Forbidden (Invalid compartment)
3On read and search, verify the returned row references the caller in one of that type's compartment fields.403 Forbidden (Not in compartment)
4On create and update, verify the submitted payload references the caller as Practitioner/<id> in one of practitioner, performer, requester.403 Forbidden (Reference mismatch)
5On delete, fetch the stored resource and verify it references the caller.403 Forbidden

Steps 3 and 4 ask different questions of different data, and the read side is the broader one. Step 3 uses the compartment definition's inclusion criteria for the resource type, which for many types name fields well beyond the three above. Step 4 uses only those three.

The write check reads three fields, and only three

practitioner, performer, requester. A reference to the caller anywhere else in the payload does not satisfy it, however natural it looks in FHIR terms.

Encounter.participant.individual is the case that catches people out: it is the conventional way to say "this practitioner took part in this encounter", and it is not one of the three, so an Encounter create carrying only that reference is denied. If your callers need to create resources that link to a practitioner through some other element, choose a validator whose contract matches — organization_compartment or legitimate_interest — rather than expecting this one to look further.


Example Configurations​

1. Read Access to Lab Reports​

{
"client_role": "Practitioner",
"entity_name": "DiagnosticReport",
"operation": "read",
"validator": "practitioner_compartment"
}

Explanation: A practitioner can read a DiagnosticReport only if it references them through one of the fields the Practitioner compartment defines for that type, such as performer.

2. Create a Service Request​

{
"client_role": "Practitioner",
"entity_name": "ServiceRequest",
"operation": "create",
"validator": "practitioner_compartment"
}

Requirements: The ServiceRequest body must reference the practitioner in practitioner, performer or requester. One is enough:

"requester": {
"reference": "Practitioner/<practitioner_id>"
}

Otherwise, the request is denied.


FHIR References​

  1. General Compartment Guidance:
    FHIR Compartments (Official HL7 documentation).
  2. Resource Examples:

Use Case: Clinic Workflow Integration​

A hospital EHR system uses this validator to:

  1. Restrict lab order access: Practitioners see only Observations resources they have access rights.
  2. Audit surgical procedures: Ensures Procedure resources reference the surgeon’s ID in performer.

Error Handling:

  • A practitioner attempting to update another provider’s MedicationStatement receives a 403 Forbidden response.