general_practitioner Validator Documentation
general_practitioner Validator Documentation Access Control Based on the Patient–GP Relationship
Intent
The general_practitioner validator grants access on the strength of one specific clinical relationship: the practitioner named in a patient's Patient.generalPractitioner element. It answers two symmetrical questions.
- For a practitioner caller — am I this patient's GP? If so, the practitioner reaches that patient's data.
- For a patient caller — is this my GP? If so, the patient may look up their own GP's
Practitioner,PractitionerRoleorOrganizationrecord.
Unlike the compartment validators it does not ask whether a resource references the caller. It resolves which patient the request concerns, then checks the GP relationship on that patient — which means the relationship is read live from the FHIR server on every request, and revoking it takes effect immediately.
Key Use Cases:
- Primary-care coordination, where a GP needs the record of every patient who has named them.
- A patient portal offering "my doctor" — contact details, affiliation, opening hours.
- Referral workflows that must confirm a treating relationship before releasing data.
Validation Logic
| Step | Action | If it fails |
|---|---|---|
| 1 | Refuse outright if the operation is create. | 403 Forbidden |
| 2 | Determine which patient (or patients) the request concerns — see below. | 403 Forbidden — no patient could be resolved |
| 3 | Fetch each of those patients and read their generalPractitioner. | 403 Forbidden — the patient does not exist or cannot be read |
| 4 | For a practitioner caller: the caller must be listed in generalPractitioner. For a patient caller: the resource being requested must itself be listed there. | 403 Forbidden |
Every patient the request touches must clear, not merely one. Where a request resolves to more than one patient, all of them are checked.
create is never permittedThe validator refuses create before resolving anything. There is no configuration that changes this. A rule pairing general_practitioner with create will publish successfully and then deny every request, so pick a different validator for resources your callers need to create.
Which patient the request concerns
This is the part worth understanding, because it is what makes the validator safe on writes.
| Caller | Operation | Patient resolved from |
|---|---|---|
Patient | any (except create) | The caller's own identity, from their token |
Practitioner, target type is Patient | any (except create) | The requested resource id itself |
Practitioner, any other type | read, search | The patient or subject reference on the row returned by the FHIR server |
Practitioner, any other type | update | The patient/subject of the stored resource, and the patient/subject of the submitted payload. Both must clear |
Practitioner, any other type | delete | The patient/subject of the stored resource |
Two details in that table carry real weight:
On writes, the payload is not evidence about the stored resource. An update or delete resolves the patient from the resource as it exists on the server, not from what the caller submitted. Otherwise the GP of one patient could modify any resource at all simply by naming their own patient in the request body.
An update is checked against both ends. The stored resource proves you may touch it; the payload proves you are not re-pointing it at a patient whose GP you are not. A caller who is GP to only one of the two is denied, in both directions.
The target resource id is taken from the request's own resource argument, not from any id inside the submitted body.
What a patient caller may request
A caller with the Patient role may use this validator only against Practitioner, PractitionerRole and Organization. Any other resource type is denied. The resource requested must itself appear in the patient's generalPractitioner list — so a patient reaches their own GP's record, and no one else's.
Example Configurations
1. A GP reading their patients' observations
{
"client_role": "Practitioner",
"entity_name": "Observation",
"operation": "read",
"validator": "general_practitioner"
}
Explanation: the practitioner may read an Observation when the patient it references names them in Patient.generalPractitioner. Adding a matching search rule is optional — a search with no search rule falls back to the read rules for the same triple.
2. A patient looking up their own GP
{
"client_role": "Patient",
"entity_name": "Practitioner",
"operation": "read",
"validator": "general_practitioner"
}
Explanation: the patient may read Practitioner/<id> only when that exact reference appears in their own generalPractitioner. Pair it with the same rule for Organization if your portal shows the practice as well as the doctor.
3. A GP correcting a record
{
"client_role": "Practitioner",
"entity_name": "Condition",
"operation": "update",
"validator": "general_practitioner"
}
Requirements: the caller must be GP to the patient the stored Condition references and to the patient the submitted payload references. In the ordinary case where the update does not move the resource between patients, those are the same patient and one relationship suffices.
Setting up the relationship
The validator reads Patient.generalPractitioner, a standard R4 element that may reference a Practitioner, a PractitionerRole or an Organization, and may hold more than one entry.
{
"resourceType": "Patient",
"id": "patient-example",
"generalPractitioner": [
{ "reference": "Practitioner/dr-example" },
{ "reference": "Organization/practice-example" }
]
}
References are compared as resources, not as strings, so versioned and absolute forms of the same reference are all recognised. A patient with no generalPractitioner at all grants nothing under this validator.
Nothing in this validator writes the element. Populate it through your own registration or assignment workflow — and remember that whatever rule governs Patient updates decides who is allowed to change who a patient's GP is.
Error Handling
Every denial returns the same message, Access denied under GeneralPractitioner validation, whatever the underlying reason. That is deliberate: distinguishing "no such patient" from "you are not their GP" would let a practitioner enumerate which patient ids exist in the project, which is itself a disclosure. The specific reason is recorded server-side.
If a rule using this validator denies everything and you cannot see why, check in this order:
- The operation is not
create. - The patient record actually carries a
generalPractitionerentry. - That entry references the caller in the form you expect — a
PractitionerRolereference does not match aPractitionercaller. - For a patient caller, the resource type is one of
Practitioner,PractitionerRole,Organization.