Skip to main content

encounter-compartment

encounter_compartment Validator Documentation

FHIR Compartment-Based Access Control for Encounter-Associated Resources


Intent

The encounter_compartment validator restricts access to resources explicitly tied to a specific FHIR Encounter. This ensures users (e.g., clinicians, temporary roles) can only interact with data relevant to a time-bound clinical context, such as an emergency visit, surgery, or inpatient stay.

Key Use Cases:

  • Emergency department staff accessing resources tied to an active patient encounter.
  • Surgical teams updating records during an operation.
  • Temporary access to lab results or imaging studies generated during a specific encounter.

Key Features

  1. Role Enforcement:
    • Validates that the client has the Encounter role (or a role mapped to an encounter context, e.g., Surgeon with encounter-scoped permissions).
  2. Compartment Membership Check:
    • Confirms the requested resource type belongs to the FHIR Encounter compartment (e.g., Procedure, Observation, Encounter itself).
  3. Reference Validation:
    • For create/update operations, ensures the resource references the encounter’s ID (e.g., Procedure.context.reference = Encounter/<id>).

Validation Logic

StepActionError If Failed
1Check client_role is mapped to an encounter (e.g., Encounter role or a role with encounter context).403 Forbidden (Invalid role/context)
2Verify resource type is in the Encounter compartment.403 Forbidden (Invalid compartment)
3For write operations, validate encounter ID in relevant fields (e.g., context, encounter).403 Forbidden (Reference mismatch)

Example Configurations

1. Read Access to Procedures Linked to an Encounter

{
"client_role": "Encounter",
"entity_name": "Procedure",
"operation": "read",
"validator": "encounter_compartment"
}

Explanation: A user with encounter-scoped access can read Procedure resources only if Procedure.context.reference matches Encounter/<encounter_id>.

2. Create an Observation During an Inpatient Stay

{
"client_role": "Encounter",
"entity_name": "Observation",
"operation": "create",
"validator": "encounter_compartment"
}

Requirements: The Observation body must include:

"context": {
"reference": "Encounter/<encounter_id>"
}

Otherwise, the request is denied.


FHIR References

  1. Encounter Compartment Definition:
    FHIR R4 Encounter Compartment (Official HL7 documentation).
  2. Resource Examples:

Use Case: Emergency Department Workflow

  1. Temporary Access: A triage nurse with the Encounter role can:
    • View Observation resources (e.g., vital signs) tied to the active encounter.
    • Update Encounter.status to reflect patient progress.
  2. Audit Compliance: All actions are automatically scoped to the encounter, simplifying audit trails.

Error Handling:

  • A clinician attempting to access a DiagnosticReport outside the encounter’s time window receives 403 Forbidden.

Assumptions & Notes

  • If your system does not use a dedicated Encounter role, replace client_role with roles that inherit encounter context (e.g., EmergencyClinician with metadata linking to an encounter).
  • The compartment is ephemeral: Access expires when the encounter is marked as finished.