Overview
OdontologyApp implements a comprehensive Role-Based Access Control (RBAC) system with three primary roles: Admin, Doctor, and Secretary. Each role has a specific set of permissions that control access to features and data. Permissions Location:src/lib/permissions.js
User Roles
Admin
Full system access including user management, configuration, and administrative tools.
Doctor
Clinical operations including patient records, medical histories, and treatment planning.
Secretary
Patient registration, appointment scheduling, and administrative support.
Permission System
Permission Categories
Permissions are organized into logical modules:- Patient Management - Creating, viewing, editing, and deleting patient records
- Appointment Management - Scheduling and managing appointments
- Clinical Operations - Medical records, odontograms, anamnesis, indications
- Operational Tools - Reminders, inventory, reports
- Administration - Users, doctors, branches, security, system logs
Checking Permissions
The system provides a helper function to verify if a role has a specific permission:Complete Permission Matrix
Patient Management
| Permission | Admin | Doctor | Secretary | Description |
|---|---|---|---|---|
VIEW_PATIENTS | ✅ | ✅ | ✅ | Access patient list and records |
CREATE_PATIENTS | ✅ | ❌ | ✅ | Register new patients |
EDIT_PATIENTS | ✅ | ✅ | ✅ | Modify patient information |
DELETE_PATIENTS | ✅ | ❌ | ❌ | Remove patients from system |
PRINT_PATIENTS | ✅ | ✅ | ✅ | Print or export patient files |
Appointment Management
| Permission | Admin | Doctor | Secretary | Description |
|---|---|---|---|---|
VIEW_APPOINTMENTS | ✅ | ✅ | ✅ | View appointment calendar |
CREATE_APPOINTMENTS | ✅ | ❌ | ✅ | Schedule new appointments |
EDIT_APPOINTMENTS | ✅ | ❌ | ✅ | Modify existing appointments |
CANCEL_APPOINTMENTS | ✅ | ❌ | ✅ | Cancel or delete appointments |
Doctors can view appointments but cannot create or modify them. This workflow ensures secretaries manage scheduling while doctors focus on clinical work.
Clinical Operations
| Permission | Admin | Doctor | Secretary | Description |
|---|---|---|---|---|
VIEW_MEDICAL_RECORDS | ✅ | ✅ | ✅ | View patient medical history |
CREATE_MEDICAL_RECORDS | ✅ | ✅ | ❌ | Create new medical records |
EDIT_MEDICAL_RECORDS | ✅ | ✅ | ❌ | Modify medical records |
VIEW_ODONTOGRAM | ✅ | ✅ | ✅ | View dental chart |
EDIT_ODONTOGRAM | ✅ | ✅ | ❌ | Update dental chart |
VIEW_ANAMNESIS | ✅ | ✅ | ✅ | View patient health history |
EDIT_ANAMNESIS | ✅ | ✅ | ❌ | Modify anamnesis records |
VIEW_INDICATIONS | ✅ | ✅ | ✅ | View medical indications |
CREATE_INDICATIONS | ✅ | ✅ | ❌ | Create new indications |
VIEW_ATTACHMENTS | ✅ | ✅ | ✅ | View patient files/images |
UPLOAD_ATTACHMENTS | ✅ | ✅ | ❌ | Upload files to patient records |
Operational Features
| Permission | Admin | Doctor | Secretary | Description |
|---|---|---|---|---|
VIEW_REMINDERS | ✅ | ❌ | ✅ | View reminder dashboard |
SEND_REMINDERS | ✅ | ❌ | ✅ | Send WhatsApp/Email reminders |
VIEW_INVENTORY | ✅ | ✅ | ❌ | View inventory levels |
MANAGE_INVENTORY | ✅ | ❌ | ❌ | Manage stock and supplies |
VIEW_REPORTS | ✅ | ❌ | ❌ | Access financial reports |
Administration
| Permission | Admin | Doctor | Secretary | Description |
|---|---|---|---|---|
VIEW_DOCTORS | ✅ | ✅ | ✅ | View doctor list |
MANAGE_DOCTORS | ✅ | ❌ | ❌ | Create/edit/delete doctors |
MANAGE_BRANCHES | ✅ | ❌ | ❌ | Manage clinic locations |
MANAGE_USERS | ✅ | ❌ | ❌ | Create and manage user accounts |
VIEW_LOGS | ✅ | ❌ | ❌ | View system audit logs |
ACCESS_ROADMAP | ✅ | ❌ | ❌ | View development roadmap |
MANAGE_SECURITY | ✅ | ❌ | ❌ | Manage user permissions |
VIEW_TREATMENTS | ✅ | ❌ | ❌ | View treatment catalog |
MANAGE_TREATMENTS | ✅ | ❌ | ❌ | Modify treatment definitions |
VIEW_DOCS | ✅ | ✅ | ✅ | Access system documentation |
All administrative functions are restricted to the Admin role to maintain system integrity and security.
Permission Enforcement
Server-Side Protection
All API endpoints verify permissions using thecheckPermission middleware:
Route-Level Protection
The server hook (src/hooks.server.js) enforces role-based route access:
Database-Level Permissions
Permissions Table
Thepermissions table stores all available permissions:
User Permissions Table
Theuser_permissions table enables granular permission assignment:
Role Definitions in Code
Admin Role
Admins have all permissions in the system:Doctor Role
Doctors have clinical-focused permissions:Secretary Role
Secretaries manage administrative and front-office tasks:Best Practices
Principle of Least Privilege
Principle of Least Privilege
Each role should only have the minimum permissions necessary to perform their job functions. Doctors don’t need user management access, and secretaries don’t need to modify clinical records.
Separation of Duties
Separation of Duties
Clinical and administrative tasks are separated between doctors and secretaries to ensure proper workflows and accountability.
Centralized Permission Logic
Centralized Permission Logic
All permission definitions are centralized in
permissions.js, making it easy to audit and modify access control policies.Always Verify on the Server
Always Verify on the Server
Never rely solely on client-side permission checks. All API endpoints must verify permissions independently.
Related Resources
Authentication
Learn how users log in and sessions are managed
Doctor Management
Managing doctor accounts and assignments
Branch Management
Multi-location clinic configuration
