Skip to main content

organization_compartment Validator Documentation

organization_compartment Validator Documentation Organization-Scoped Access Control for FHIR Resources


Intent​

The organization_compartment validator restricts access to resources belonging to an organization the caller is actively part of. It is the primary mechanism for multi-tenant isolation, where several organizations share one FHIR repository and must not see each other's data.

It applies to any resource type. There is no allowlist of eligible types and no special status for any particular resource.

Key Use Cases:

  • Scoping resources to the organization that created them, whatever their type.
  • Letting practitioners see only resources linked to their own organization.
  • Isolating sensitive records — research agreements, consent documents — along organizational boundaries.

Two ways a resource joins an organization compartment​

There are two, and they are complementary rather than alternatives:

  • Field resolution — the organization is derived from the resource's own FHIR fields. This is the default and it needs no special data.
  • The organization-compartment extension — an explicit tag naming the organization, for resources whose fields carry no organization link at all.

Which one applies depends on the operation.


On a read or search the resource comes from the FHIR server, so a tag on it is part of the stored data rather than something the caller just supplied.

StepActionIf it fails
1Resolve the caller's active organizations from PractitionerRole.organization where active = true, plus parent organizations if role inheritance is configured.403 Forbidden — the caller has no active organizations
2If the fetched resource carries the organization-compartment extension, compare the organization it names against those active organizations.403 Forbidden — the tag is authoritative when present, so a mismatch denies outright rather than falling through
3If it carries no tag, resolve the organization from the resource's own fields (see the map below).403 Forbidden — the organization does not match, or the type has no organization link to resolve

A tag whose valueReference does not name an Organization is treated as if it were absent, and step 3 decides instead.

The validator does not check client_role. Which roles may use this validator is decided by the client_role field of the rule that selects it, not by the validator itself. Practitioners are the usual caller because active organizations are resolved from PractitionerRole, but nothing in the validator requires it.

Resource → organization field map​

CategoryResource typesOrganization link
DirectPatientmanagingOrganization
Organizationthe resource's own id must be in the caller's active organizations
LocationmanagingOrganization
HealthcareServiceprovidedBy
Device, DeviceDefinitionowner
PractitionerRoleorganization
Patient-linkedObservation, DiagnosticReport, Condition, Procedure, MedicationRequest, MedicationAdministration, Encounter, CarePlan, AllergyIntolerance, Immunization, Specimen, ImagingStudy, ServiceRequest, DocumentReference, ClinicalImpression, Media, QuestionnaireResponse, FamilyMemberHistory, NutritionOrder, Consentresolved through subject or patient → that Patient's managingOrganization

A resource type in neither category has no organization to resolve, and access is denied. That is what the extension exists to solve.


Validation Logic — create, update and delete​

The payload's tag is never consulted on a write

On create, update and delete the organization is resolved from stored state and resource fields only. A tag in the submitted payload has no effect whatsoever.

This is deliberate, and it is a security property rather than an oversight. A create carrying an id overwrites whatever already lives at that id, so honouring a caller-supplied tag on a write would let any caller name their own organization in the payload and overwrite any resource in the project — a one-field bypass of the entire compartment.

OperationWhat must hold
create (no id in the payload)The organization resolved from the payload's fields is one of the caller's active organizations.
create (with an id that already exists)The organization of the stored resource must match as well — this is an overwrite, and it is checked like an update.
updateBoth the stored resource and the submitted payload must resolve to an organization the caller holds. Both, because an update satisfying only the payload could re-point a resource you do not own into your own compartment.
deleteThe stored resource must resolve to an organization the caller holds. A target that does not exist, or cannot be read, is denied.

Because a MedBackend write replaces the whole resource rather than patching it, an update that omits the organization anchor is refused. Omitting the field would erase it and walk the resource out of every compartment. Send the complete resource.

There is no second chance on a write. Reads are re-checked row by row as they come back from the server; writes are decided once, at the gate, so every ambiguity denies.

Denial messages are deliberately uniform​

Every organization-compartment write denial returns the same message regardless of the underlying reason. (Reads are more forthcoming: they distinguish a caller with no active organizations, a missing row, a patient-linked resource carrying no patient reference, and a resource type with no organization link at all. What they never disclose is which organization holds a resource the caller was refused.) "No such resource", "not yours" and "that type has no organization link" are indistinguishable to the caller on purpose — a message naming the owning organization would tell a denied caller who holds the resource, and one distinguishing "missing" from "forbidden" would let a caller enumerate which ids exist.


The organization-compartment extension​

The extension exists for resources that have no clear association to an organization — everything outside the field map above. Tagging is how you say "this resource belongs to that organization" for anything MedBackend cannot infer.

Tag a resource by adding the extension with a reference to the owning organization. Any resource type takes the same tag:

{
"resourceType": "Consent",
"id": "consent-example",
"extension": [
{
"url": "https://medbackend.com/fhir/Extensions/organization-compartment",
"valueReference": { "reference": "Organization/123" }
}
]
}

The URL is fixed platform-wide. It is not configurable per project, and a tag carrying any other URL is ignored.

Two operational limits to know before designing around it:

  1. The tag is not searchable. It is not backed by a FHIR search parameter, so an organization-scoped search over tagged resources cannot be narrowed at the FHIR server — the result set is fetched and then filtered. The only search-time narrowing that exists is on Patient.managingOrganization, which is field resolution. Anchor your data model on fields where you can, and reserve the tag for what fields cannot express.
  2. The tag must be written by a trusted server-side process, and cannot be set through the API. Per the rule above, a tag arriving in a write payload is ignored — which is exactly what stops it being a bypass. Write it in your own provisioning or ingestion workflow at resource-creation time.

Example Configurations​

{
"client_role": "Practitioner",
"entity_name": "Consent",
"operation": "read",
"validator": "organization_compartment"
}

Explanation: A practitioner can read a Consent resource if either

  • it carries the organization-compartment extension and that extension references one of their active organizations, or
  • it carries no such extension, and the organization resolved from its fields is one of those organizations. For Consent that is Consent.patient → that Patient's managingOrganization.

The tag is not a precondition. An untagged resource is not out of bounds; it is resolved from its fields instead.

2. Write access​

{
"client_role": "Practitioner",
"entity_name": "Observation",
"operation": "create",
"validator": "organization_compartment"
}

Requirements: the submitted Observation must reference a Patient in subject (or patient) whose managingOrganization is one of the caller's active organizations. Adding the extension to the payload will not help — it is not read.


Role Inheritance Configuration​

Control hierarchical access in the project's settings.json. Note that the key lives under the legitimate_interest validator even though it also governs organization inheritance:

{
"rbac": {
"validators": {
"legitimate_interest": {
"role_inheritance_levels": 2
}
}
}
}

Direction matters, and it is not the same for every caller.

  • For practitioners, inheritance runs upward. A practitioner in a child organization additionally gains that organization's ancestors, so someone in a department also reaches the parent hospital's resources.
  • For devices, it runs downward. A device owned by a parent organization reaches into that organization's children. Devices read their own depth from validators.device_compartment.inheritance_levels, capped at five levels.

Each level costs a round-trip to the FHIR server, so keep it shallow.


Use Case: Multi-Tenant Resource Isolation​

  1. Isolate resources of any type: Clinic A cannot read a resource belonging to Clinic B, whether it is a Consent, an Observation, a DocumentReference or anything else.
  2. Enable cross-organization audits: auditors at a root organization review child-organization resources through role inheritance.

Error Handling:

  • A practitioner with no active PractitionerRole is denied everything under this validator — there is no organization to compare against.
  • A practitioner requesting a resource type that is neither directly nor patient-linked to an organization, and carries no tag, is denied.

FHIR References​

  1. FHIR Compartments Guide
  2. Organization · Organization.partOf
  3. PractitionerRole
  4. Extensibility