Overview
OdontologyApp supports multi-location clinic management through the branches system. Each branch represents a physical clinic location where patients are seen, appointments are scheduled, and staff are assigned. Interface Location:/branchesAPI Endpoint:
/api/branchesSource Code:
src/routes/branches/+page.svelte
Only users with the
MANAGE_BRANCHES permission (admins) can create, edit, or delete branches. All authenticated users can view the branch list.Database Schema
Branches Table
Field Descriptions
Unique branch identifier (auto-generated)
Branch name (e.g., “Sucursal Central”, “Sede Norte”)
Physical address of the clinic location
Emoji or icon representing the branch (defaults to 🏢)
Branch operational status:
active or inactiveTimestamp when the branch was created
Branch Relationships
Branches are connected to multiple system entities:User Assignments
Users (admins, doctors, secretaries) can be assigned to a primary branch:When a branch is deleted, the
ON DELETE SET NULL constraint sets the user’s branch_id to NULL, preventing orphaned references.Doctor-Branch Association
Doctors can work at multiple locations via thedoctor_branches table:
- Rotating doctor schedules
- Multi-location coverage
- Flexible appointment scheduling
Patient Assignments
Patients are registered at a specific branch:Appointment Tracking
Each appointment is linked to a branch location:Creating a Branch
API Request
Stored Procedure
Branches are created using thesp_create_branch stored procedure:
Response
Updating a Branch
API Request
Stored Procedure
Editable Fields
Name
Branch display name
Address
Physical location address
Icon
Visual identifier (emoji)
Status
Active or inactive
Branch Status
Active Branches
Status:active
- Appears in branch selection dropdowns
- Accepts new appointments
- Users can be assigned
- Fully operational
Inactive Branches
Status:inactive
- Hidden from most system views
- No new appointments can be scheduled
- Existing data is preserved
- Can be reactivated later
Deleting a Branch
API Request
Cascade Effects
Deleting a branch triggers several database operations:Stored Procedure
Branch Selection
Branches are displayed in various system interfaces:User Session
The logged-in user’s branch is stored in the session:Dropdowns and Forms
Branches appear in selection dropdowns throughout the system:- Patient registration
- Doctor assignment
- Appointment scheduling
- User account creation
Branch Icons
Branches support emoji icons for visual identification:Common Icons
| Icon | Meaning |
|---|---|
| 📍 | Default location marker |
| 🏢 | Office building |
| 🏥 | Hospital/clinic |
| 🏪 | Store/retail location |
| 🌟 | Flagship/premium location |
| 🏛️ | Historic/established location |
API Stored Procedures
List Branches
include_inactive(boolean): Include inactive branches in results
Create Branch
id of the newly created branch
Update Branch
Delete Branch
All stored procedures enforce transactional integrity and handle foreign key constraints automatically.
Permission Requirements
View Branches
Permission: None (all authenticated users)Roles: Admin, Doctor, Secretary All users can view the branch list to see available locations.
Manage Branches
Permission:MANAGE_BRANCHESRoles: Admin only Only administrators can create, edit, or delete branches.
Default Test Data
The system includes three test branches:| ID | Name | Address | Icon | Status |
|---|---|---|---|---|
| 1 | Sucursal Central | Av. Providencia 1234, Santiago | 📍 | active |
| 2 | Sucursal Norte | Av. Recoleta 456, Santiago | 🏢 | active |
| 3 | Sucursal Sur | Av. Gran Av 789, Santiago | 🏪 | active |
Multi-Branch Workflows
Scenario: Doctor Works at Multiple Locations
Dr. Carlos Soto works at both Central and Norte branches:Scenario: Patient Transfer Between Branches
If a patient moves to a new area, update their branch assignment:Scenario: Temporary Branch Closure
For renovations or temporary closures, set the branch to inactive:Branch Analytics
While not built into the current system, branches enable future analytics:- Appointments per location
- Revenue by branch
- Patient distribution across locations
- Doctor utilization by branch
- Inventory tracking per location
Best Practices
Descriptive Names
Descriptive Names
Use clear, descriptive branch names that staff and patients can easily identify (e.g., “Sucursal Norte” instead of “Branch 2”).
Complete Addresses
Complete Addresses
Always include full addresses with street number, city, and postal code for patient communications and navigation.
Inactive Over Delete
Inactive Over Delete
Prefer setting branches to
inactive rather than deleting them to preserve historical data and reporting accuracy.Unique Icons
Unique Icons
Assign unique icons to each branch for quick visual identification in the UI.
Regular Audits
Regular Audits
Periodically review branch assignments for users, doctors, and patients to ensure they remain accurate.
Related Resources
Doctor Management
Assigning doctors to branches
User Management
Managing user branch assignments
Appointments
Scheduling appointments at specific branches
