Skip to main content

relatedperson_compartment Validator Documentation

relatedperson_compartment Validator Documentation
FHIR Compartment-Based Access Control for Caregivers & Relatives


Intent​

The relatedperson_compartment validator restricts access to resources linked to a patient associated with the authenticated RelatedPerson user. This enables caregivers, family members, or legally authorized representatives to access specific patient data with tighter controls than full patient accounts.

Key Use Cases:

  • A parent reviewing measurements they recorded for a child (Observation, matched on performer).
  • A legal guardian sending or reading messages about the patient's care (Communication, matched on sender / recipient for both). Anchoring a Communication create with sender or recipient naming the caller satisfies the write check and leaves the resource readable afterward, since both are also this compartment's read criteria for Communication.
  • A spouse retrieving documents they authored (DocumentReference, matched on author).

Key Features​

  1. Role Enforcement:
    • Requires the client to have the RelatedPerson role. Requests from other roles (e.g., Patient or Practitioner) are denied.
  2. Compartment Membership Check:
    • Validates that the resource type belongs to the FHIR RelatedPerson compartment (e.g., Observation, Communication, CommunicationRequest, DocumentReference). Immunization and DiagnosticReport are excluded from it, so pairing either with this validator denies every request.
  3. Reference Validation:
    • For write operations, ensures the submitted resource references the RelatedPerson themselves — not the patient — in one of subject, actor, requester, or the resource type's own compartment criterion.

Validation Logic​

StepActionError If Failed
1Check the caller's role is RelatedPerson.403 Forbidden (Invalid role)
2Verify the resource type is in the RelatedPerson 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 RelatedPerson/<id> in one of subject, actor, requester, or the resource type's own compartment criterion.403 Forbidden (Reference mismatch)
5On delete, fetch the stored resource and verify it references the caller.403 Forbidden
The write check names the RelatedPerson, and one field is enough

Two things about step 4 are commonly got wrong.

It is an OR, not an AND. A payload satisfying any single one of subject, actor, requester, or the resource type's own compartment criterion, passes. There is no requirement to populate more than one.

The reference it looks for is RelatedPerson/<id>, not the linked patient. A payload naming only Patient/<id> — even the correct patient — does not satisfy this validator on a write. The caller's own identity has to appear.

The linkage to the patient is expressed in the data through RelatedPerson.patient, and it governs what the caller can read: a row belongs to the compartment when it references the RelatedPerson via the fields the FHIR RelatedPerson compartment defines for that resource type.


Example Configurations​

1. Read Access to Observations They Recorded​

{
"client_role": "RelatedPerson",
"entity_name": "Observation",
"operation": "read",
"validator": "relatedperson_compartment"
}

Explanation: The RelatedPerson can read an Observation only if the returned resource references them through the field the RelatedPerson compartment defines for that type — here, performer. A resource that references only the patient, with no link to this RelatedPerson, is not in their compartment.

Note the choice of type: DiagnosticReport and Immunization are on the RelatedPerson compartment's exclusion list, so a rule naming either denies every request regardless of what the data references.

2. Create a CommunicationRequest​

{
"client_role": "RelatedPerson",
"entity_name": "CommunicationRequest",
"operation": "create",
"validator": "relatedperson_compartment"
}

Requirements: The body must reference the caller in subject, actor, requester, or the resource type's own compartment criterion. One is enough:

"requester": { "reference": "RelatedPerson/<related_person_id>" }

Otherwise, the request is denied.

requester rather than subject on purpose. requester is both a write field and one of the read criteria the compartment defines for CommunicationRequest, so a resource anchored that way is readable afterwards. subject would satisfy the write and then match nothing on any subsequent read — the resource would be created and immediately invisible. Whenever a type offers both, anchor the write with a field that is also a read criterion.


FHIR References​

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

Use Case: Pediatric Care Management​

A parenting app uses this validator to allow guardians to:

  1. Review measurements they recorded: reads Observation resources whose performer names them, which is what puts the row inside their RelatedPerson compartment.
  2. Ask the clinic to make contact: creates CommunicationRequest resources naming themselves in requester.

Appointment resolves like any other member of this compartment. R4 nests the reference at Appointment.participant.actor, and the validator maps that nesting the same way for every compartment that lists actor as an inclusion criterion — RelatedPerson included — so a guardian can both read an Appointment that names them as participant.actor and create one naming themselves the same way.

Error Handling:

  • A guardian attempting to read a resource that does not reference them receives 403 Forbidden.
  • A guardian submitting a write that names only the child's Patient reference, with no RelatedPerson reference, receives 403 Forbidden — see the warning above.