Overview
The doctor management system handles medical staff accounts, their specialties, license information, and branch assignments. Doctors have their own user accounts with clinical permissions and can be assigned to specific clinic locations. Interface Location:/doctorsAPI Endpoint:
/api/doctorsSource Code:
src/routes/doctors/+page.svelte
Only users with the
MANAGE_DOCTORS permission (admins) can create, edit, or delete doctor accounts. All users with VIEW_DOCTORS permission can view the doctor list.Database Schema
Users Table
Doctors are stored in theusers table with role = 'doctor':
Doctors Table
Additional medical information is stored in thedoctors table:
Doctor-Branch Association
Doctors can be assigned to multiple branches:This many-to-many relationship allows doctors to work at multiple clinic locations, providing scheduling flexibility.
Supported Specialties
The system supports the following dental specialties:Odontología General
General dentistry and preventive care
Cirugía Oral y Maxilofacial
Surgical procedures and maxillofacial surgery
Ortodoncia
Braces and orthodontic treatment
Endodoncia
Root canal treatment
Periodoncia
Gum disease treatment
Prostodoncia
Dentures and prosthetic dentistry
Odontopediatría
Pediatric dentistry
Radiología Oral
Dental imaging and diagnostics
Patología Oral
Oral disease diagnosis
Implantología
Dental implants
Creating a Doctor Account
Required Information
Doctor’s full name (e.g., “Dr. Carlos Soto”)
Unique username for system login
Secure password (hashed with bcrypt)
Doctor’s email address (optional)
Medical specialty (defaults to “Odontología General”)
Professional license or exequátur number
Primary branch assignment
API Request
Automatic Initials Generation
The system automatically generates user initials from the full name:- “Dr. Carlos Soto” →
CS - “María González López” →
MGL
Password Security
Passwords are hashed using bcrypt before storage:users table, ensuring plaintext passwords are never saved.
Updating Doctor Information
Edit Endpoint
Password Changes
When editing a doctor, the password field is optional:- Leave blank to keep the existing password
- Provide a new password to update credentials
Doctor Status
Doctors can have two status values:| Status | Description | Effect |
|---|---|---|
active | Doctor is currently working | Can log in and access the system |
inactive | Doctor is temporarily or permanently unavailable | Cannot log in; appointments cannot be scheduled |
Inactivating a doctor does not delete their records or past clinical data. Use this for medical leave, vacation, or staff changes.
Deleting Doctors
Delete Endpoint
Cascade Behavior
Deleting a doctor triggers the following database actions:Doctor Record Deletion
The associated record in the
doctors table is automatically deleted (ON DELETE CASCADE)Viewing Doctors
Doctor List View
The doctor management interface displays:- Doctor Avatar with generated initials
- Full Name and username
- Specialty with icon
- License Number (exequátur)
- Assigned Branch
- Status (Active/Inactive)
- Action Buttons (Edit/Delete for admins)
Search and Filtering
Doctors can be searched by:- Name
- Specialty
- License number
API Stored Procedures
The doctor API uses several MySQL stored procedures:List Doctors
Create Doctor
Update Doctor
Delete Doctor
Permission Requirements
View Doctors
Permission:VIEW_DOCTORSRoles: Admin, Doctor, Secretary All authenticated users can view the list of doctors to see who is available for appointments.
Manage Doctors
Permission:MANAGE_DOCTORSRoles: Admin only Only administrators can create, edit, or delete doctor accounts.
Branch Assignments
Primary Branch
Each doctor has abranch_id field in the users table representing their primary location.
Multiple Branch Support
Thedoctor_branches table allows assigning doctors to multiple locations:
- Scheduling appointments at different locations
- Rotating doctors between branches
- Multi-location coverage
Default Test Data
The system includes a test doctor account:| Field | Value |
|---|---|
| Name | Dr. Carlos Soto |
| Username | doctor |
| Password | doctor123 |
| [email protected] | |
| Role | doctor |
| Specialty | Cirugía Oral |
| License | MAT-12345 |
| Branch | Sucursal Norte (ID: 2) |
| Assigned Branches | Central, Norte |
Best Practices
Unique Usernames
Unique Usernames
Ensure each doctor has a unique, memorable username. Consider using format like
dr.lastname or firstname.lastname.Professional Licenses
Professional Licenses
Always record license/exequátur numbers for regulatory compliance and verification.
Inactive vs Delete
Inactive vs Delete
Use the inactive status for temporary removals (vacation, leave). Only delete accounts when doctors permanently leave the practice.
Email Notifications
Email Notifications
Ensure doctors provide valid email addresses for system notifications and password recovery.
Strong Passwords
Strong Passwords
Enforce strong password policies when creating doctor accounts to protect patient data.
Related Resources
Authentication
How doctors log in and manage their sessions
Roles & Permissions
Doctor role capabilities and access levels
Branch Management
Managing clinic locations for doctor assignments
