mirror of
https://github.com/temetro/temetro.git
synced 2026-07-27 04:08:56 +00:00
a4f692d59d
Mirror the backend role changes (drop viewer, add pharmacy + lab and the lab statement). Replace the binary requiresClinical gating with access areas (clinical / pharmacy / lab) probed from Better Auth permissions — prescription:delete marks full clinicians, prescription:write the pharmacy area, lab:write the lab area — so pharmacy doesn't inherit the AI chat or notes. Pharmacy and lab land on their new dashboards and get their own nav items; reception behavior is unchanged. Includes the i18n keys for the new pages and the messages polish that lands in the following commits. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
103 lines
3.1 KiB
TypeScript
103 lines
3.1 KiB
TypeScript
import { createAccessControl } from "better-auth/plugins/access";
|
|
import {
|
|
adminAc,
|
|
memberAc,
|
|
ownerAc,
|
|
defaultStatements,
|
|
} from "better-auth/plugins/organization/access";
|
|
|
|
// Mirrors backend/src/lib/access.ts so the client's permission checks
|
|
// (organization.hasPermission / checkRolePermission) match the server.
|
|
export const statements = {
|
|
...defaultStatements,
|
|
patient: ["read", "write", "delete"],
|
|
appointment: ["read", "write", "delete"],
|
|
prescription: ["read", "write", "delete"],
|
|
task: ["read", "write", "delete"],
|
|
lab: ["read", "write"],
|
|
} as const;
|
|
|
|
export const ac = createAccessControl(statements);
|
|
|
|
// NOTE: `prescription: ["delete"]` doubles as the "full clinician" marker the
|
|
// route gating in lib/roles.ts probes (owner/admin/doctor/member only) — don't
|
|
// grant it to department roles like pharmacy.
|
|
export const owner = ac.newRole({
|
|
...ownerAc.statements,
|
|
patient: ["read", "write", "delete"],
|
|
appointment: ["read", "write", "delete"],
|
|
prescription: ["read", "write", "delete"],
|
|
task: ["read", "write", "delete"],
|
|
lab: ["read", "write"],
|
|
});
|
|
|
|
export const admin = ac.newRole({
|
|
...adminAc.statements,
|
|
patient: ["read", "write", "delete"],
|
|
appointment: ["read", "write", "delete"],
|
|
prescription: ["read", "write", "delete"],
|
|
task: ["read", "write", "delete"],
|
|
lab: ["read", "write"],
|
|
});
|
|
|
|
export const member = ac.newRole({
|
|
...memberAc.statements,
|
|
patient: ["read", "write"],
|
|
appointment: ["read", "write", "delete"],
|
|
prescription: ["read", "write", "delete"],
|
|
task: ["read", "write", "delete"],
|
|
lab: ["read", "write"],
|
|
});
|
|
|
|
// doctor (clinician): mirrors backend/src/lib/access.ts — same clinical access
|
|
// as `member`.
|
|
export const doctor = ac.newRole({
|
|
...memberAc.statements,
|
|
patient: ["read", "write"],
|
|
appointment: ["read", "write", "delete"],
|
|
prescription: ["read", "write", "delete"],
|
|
task: ["read", "write", "delete"],
|
|
lab: ["read", "write"],
|
|
});
|
|
|
|
// reception (front desk): scheduling + registration only, no clinical records.
|
|
export const reception = ac.newRole({
|
|
...memberAc.statements,
|
|
patient: ["read", "write"],
|
|
appointment: ["read", "write", "delete"],
|
|
task: ["read", "write"],
|
|
});
|
|
|
|
// pharmacy (dispensing): read patients/appointments, read/write prescriptions
|
|
// (status updates, NOT delete), and work the task queue.
|
|
export const pharmacy = ac.newRole({
|
|
...memberAc.statements,
|
|
patient: ["read"],
|
|
appointment: ["read"],
|
|
prescription: ["read", "write"],
|
|
task: ["read", "write"],
|
|
});
|
|
|
|
// lab (analyses): submits lab results via the dedicated `lab` statement (no
|
|
// patient:write) and works the lab task queue. No prescription statement.
|
|
export const lab = ac.newRole({
|
|
...memberAc.statements,
|
|
patient: ["read"],
|
|
appointment: ["read"],
|
|
task: ["read", "write"],
|
|
lab: ["read", "write"],
|
|
});
|
|
|
|
export const roles = { owner, admin, doctor, reception, pharmacy, lab, member };
|
|
|
|
// Human-readable labels for the role keys used in the UI.
|
|
export const ROLE_LABELS: Record<keyof typeof roles, string> = {
|
|
owner: "Owner",
|
|
admin: "Admin",
|
|
doctor: "Doctor",
|
|
reception: "Reception",
|
|
pharmacy: "Pharmacy",
|
|
lab: "Lab",
|
|
member: "Clinician",
|
|
};
|