The default roles (receptionist, provider, manager, accountant, owner) cover most clinics. Real life is messier: a senior nurse who can prescribe, a part-time consultant who sees their own patients only, an external auditor who reads everything but writes nothing. The roles and permissions module lets you fit the system to the org chart instead of forcing the org chart to fit the system. This article walks how to build those custom roles without breaking the safety net.

Important correction. Prior docs said "most restrictive wins" for multi-role users. Reality: the system grants the UNION of all role permissions and scopes. Plan role assignments accordingly.

Where it lives#

  • Settings → Roles and permissions: the role designer (clone-then-edit only; no empty-template path).
  • Settings → Roles and permissions → Field visibility: per-role field masking presets.
  • HR → Employees → [employee]: assign one or more roles and the user's branches.

Teams can group members across branches, but team membership does not replace role grants or the user's accessible branches. Verify the endpoint's row scope rather than assuming that joining a team grants clinic-wide access.

The model#

Role#

A named collection of permissions. "Receptionist", "Senior nurse", "External auditor". Each role grants a set of actions on a set of resources.

Permission#

A (resource, action) pair. Example: (Invoice, edit). Granted on a role.

Scope#

Scope is a named row-level filter applied per feature per role. The shipping scope names today:

  • own_seller, rows where the logged-in user is the seller.
  • own_consultant, rows where the user is the assigned consultant.
  • branch, rows whose branch is in the user's User.branches set.
  • absent, no row filter (tenant-wide for that feature).

A role can carry a different scope per feature: Receptionist might have branch on bookings and own_seller on invoices in the same role.

Field masking#

Within an allowed resource, certain fields can be hidden by a per-role rule. Example: a reception role can read a patient record but sensitive PII is masked according to the three-state patient pattern (view, view_with_hidden, request, or absent).

Assignment, multi-role behaviour#

An employee can hold multiple roles at once. The effective grant is the union: if any role allows the feature, action, lookup, or report, the user gets it. Scope rules from each role apply per feature, so adding a second role with a broader scope widens access (the opposite of what an inheritance model would do).

This is why "add a second role for a week, remove it after" is the practical pattern for temporary elevated access, documented below.

Three different filters, not one#

Operators commonly confuse three independent mechanisms. They stack, they do not substitute:

  • Branch membership (the user's User.branches M2M to BusinessBranch). Determines which branch context the user can switch to in the top bar.
  • Scope (RoleFeatureAccess.scope). A named row-level filter applied to a queryset for one role and one feature: own_seller, own_consultant, branch, or absent.
  • Field masking (RoleFeatureAccess.field_masks). For each row the user is allowed to read, mask specific fields if the row matches a rule. Used today for cost, commission, profit on sales rows the user did not sell.

A staff member denied access to a row may be hitting any of these three. The debugging order below works through them.

Default roles, what they do#

  • Receptionist: book / cancel / reschedule, check-in, take payment, register patient, send messages. No clinical edit, no large refund.
  • Sales rep: receptionist + lead board, package selling, conversion. Not booking-restricted but defaults to their assigned reps.
  • Nurse / tech: vitals capture, document upload, MAR administration. Read clinical, no prescribe.
  • Provider: full clinical, prescribe, service report, photos. Plus scheduling own column.
  • Pharmacist: dispense queue, inventory of dispensary, MAR review.
  • Accountant: full financials, no clinical edit. Can void / refund within threshold.
  • HR head: employees, payroll, leave, no patient access by default.
  • Branch manager: branch-scoped manager view. Approves overrides, reviews reports.
  • Owner: elevated role access within the clinic's subscribed features; plan and subscription gates still apply.

Designing a custom role#

The four-question discipline#

  1. What does this role need to do daily? List the actions.
  2. On what data? Which patients, which branches, which categories?
  3. What must they not see? Sensitive fields, other branches.
  4. Who reviews their work? Approver path for overrides.

Steps#

  1. Settings → Roles and permissions → + New role.
  2. Name and description.
  3. Start from a template (e.g. Receptionist) and adjust.
  4. Tick / un-tick permissions per resource.
  5. Set scope: tenant / branch / own.
  6. Set field visibility: hide sensitive fields.
  7. Set thresholds (refund cap, discount floor, etc.).
  8. Save.
  9. Assign to test employee, validate behaviour.
  10. Roll out to real employees.

Example custom roles#

Senior nurse with prescribing#

  • Base: Nurse.
  • Plus: Prescribe (limited to a formulary of pre-approved drugs).
  • Plus: Allergy edit.
  • Field: see prescriptions, see active medications.
  • Scope: branch.
  • Review: any prescription audited against the formulary, off-formulary attempt creates a manager task.

External auditor (read-only)#

  • Base: empty.
  • Plus: Read on everything.
  • Plus: Export.
  • Field: hide patient personally-identifying info (mask name to MRN-only).
  • Scope: tenant.
  • Time-limited (auto-revoke after the audit window).
  • Every read logged for the regulator.

Part-time consultant#

  • Base: Provider.
  • Scope: own patients only.
  • Plus: see their own past patients across all sessions.
  • No access to other consultants' patients or financial reports.
  • Commission earned per session delivered, settled via vendor payment not payroll.

Reception lead with refund authority#

  • Base: Receptionist.
  • Plus: Approve refund up to AED 500.
  • Plus: Override conflict on booking (with audit).
  • Plus: Reassign tasks.
  • Scope: branch.

Marketing manager (no patient PII)#

  • Base: empty.
  • Plus: Lead board, campaigns, automations, messaging.
  • Plus: Reports (marketing scope).
  • Field: mask patient personal info on lead and patient records (campaign segmentation by tag and source, not by name).
  • Scope: tenant.

Field-level masking#

Common masks#

  • Allergies and prescriptions hidden from reception.
  • Mental health and family planning hidden from non-treating clinicians.
  • Patient name + phone hidden from marketing roles.
  • Cost / margin fields hidden from non-finance roles.
  • Salary fields hidden from non-HR roles.

Mask behaviour#

  • Masked field shows as ——— or a placeholder label.
  • For patient PII the three-state pattern controls reveal: view shows everything, view_with_hidden masks the critical bits, request opens read for same-day bookings only, and absent locks the field entirely.
  • API responses are masked too. Write-side serializers do not accept the masked snapshot fields, so a posted masked value cannot clobber the true value.
Coming soon. The behaviour described below is on the roadmap. Today: no general elevation-request flow ships. There is no approver inbox, no temporary-access grant model, no auto-revoke timer. The three-state patient PII pattern is the only granular elevation mechanism, and it opens access automatically for same-day bookings rather than via manager approval.

Numeric thresholds#

Coming soon. The behaviour described below is on the roadmap. Today: the role data model has no per-role numeric thresholds. Refund and override authority are gated by named action codes (for example sales.refund) and invoice-state checks, not by a configurable amount cap per role.

If you need amount-based authority today, model it through role assignment: receptionists do not hold the sales.refund action, finance officers do. Audit captures who pressed the button, not how much they were permitted to authorise.

Approval chains#

Coming soon. The behaviour described below is on the roadmap. Today: no approval-chain engine ships. Some actions emit override events for audit (floor-price override, conflict override) but there is no "request, approver inbox, approve or decline" workflow.

Branch scope#

  • Branch membership is the user's User.branches M2M, separate from any role.
  • The branch scope on a role's feature grant filters rows to those branches.
  • Tenant-wide visibility is the absence of a scope on a role's feature grant.
Coming soon. The behaviour described below is on the roadmap. Today: teams exist for operational grouping across branches. They do not independently grant feature access or replace the user's assigned branch access.

Debugging "why can't user X see Y?"#

Three steps, in this order:

  1. Confirm the role grants the feature. Open Settings → Permissions → [role] → Preview. If the feature is not there, the role does not grant it. Add it or assign a role that does.
  2. Confirm the role grants the action. Some buttons are action-gated (for example sales.view_invoice_cost). Preview shows actions separately from CRUD.
  3. Confirm scope and branch. If the feature is granted but the row is missing, check the role's scope on that feature, and whether the user's User.branches covers the row's branch.

Platform operators have a CLI shortcut: make show-role-access ROLE="Receptionist" SCHEMA=tenant_x prints the JSON config and the actual DB rows side by side, so DB drift surfaces immediately.

Temporary elevated access today#

There is no built-in time-bound elevation flow. The supported pattern is:

  1. Owner or HR Manager opens the employee.
  2. Add the elevated role as a second role (for example add "Finance Manager" alongside the existing "Receptionist").
  3. User signs out and back in; the access cache refreshes.
  4. When the elevated work is done, remove the second role.

The role grant and revoke are captured in the User history (simple_history). There is no automatic timer. Set a calendar reminder so the elevation does not become permanent by accident.

When someone joins#

  1. HR → + New employee.
  2. Assign primary branch.
  3. Assign role(s).
  4. Assign additional branches if multi-branch.
  5. Assign teams.
  6. Configure credentials (which services they can deliver, for clinicians).
  7. Save. Account activates. Welcome email with sign-in link.

When someone leaves#

  1. HR → [employee] → mark Inactive (User.is_active=False). Login is blocked from the next attempt.
  2. If the data must also disappear from default lists, soft-delete the user via the HR action. The user record stays in history rows.
  3. Existing bookings, leads, follow-ups, invoices that point at this user as seller, provider, or assignee continue to point at them. There is no auto-reassignment engine today. Reassign manually from each list using the bulk actions where they exist.
  4. For high-risk roles: force-logout active sessions through the session API (the matching JWT JTI is revoked), and pull the user history for the last 30 days of actions through module record History tabs.

Audit and access log#

  • Every grant / revoke / role-edit is logged.
  • Every override (refund above cap, discount below floor, masked-field elevation, conflict override) is logged.
  • Every read of a sensitive record is logged.
  • Access log queryable by user, by patient, by date range.
  • Required for regulator inspection in healthcare jurisdictions.

Common mistakes#

  • Owner-only everything: bottleneck day one. Delegate via thresholds.
  • Custom roles with overlapping permissions: hard to reason about who can do what. Keep roles distinct.
  • Granting tenant scope when branch would do: data leak across locations. Default to narrowest scope.
  • Skipping field masking on marketing role: PII in marketing reports, regulator complaint waiting.
  • No approval chain on big-impact actions: reception authorises a large refund alone, no manager review, money gone.
  • Leaving inactive employees with active accounts: security risk, audit nightmare. Always deactivate on exit.
  • Field masking for everyone except the user testing: convenience trap, ship as intended for production.

How roles connect to the rest of the system#

  • Every module: read / write / delete gated by role.
  • HR / employees: assignment.
  • Branches / teams: scope.
  • Audit log: every action stamped.
  • Reports: per-role data quality, override rate.
  • Approvals: tasks for managers from threshold breaches.
  • Patient portal: a distinct role (patient) with its own permission set.