Overview
The Work Schedule Management feature allows administrators to define when professionals are available to see patients. Each professional can have different schedules for different days of the week, enabling flexible workforce management.Data Model
Work schedules are structured as follows:Day of Week Values
- 0 - Sunday (Domingo)
- 1 - Monday (Lunes)
- 2 - Tuesday (Martes)
- 3 - Wednesday (Miércoles)
- 4 - Thursday (Jueves)
- 5 - Friday (Viernes)
- 6 - Saturday (Sábado)
Key Features
Create Work Schedule
Administrators can define work hours for professionals:Validate Schedule
System ensures:
- Time format is valid
- End time is after start time
- Professional doesn’t already have a schedule for this day
Validation Rules
Strict validation ensures schedule integrity frombackend/routes/workSchedule.ts:29-45:
Database Constraints
The model enforces important business rules:Each professional can only have ONE schedule per day of the week. This prevents conflicting schedules for the same day.
View Work Schedules
Work schedules can be retrieved:- All schedules: Complete list of all professional schedules
- By ID: Specific schedule details
- With Professional: Schedules are automatically included when retrieving professional information
Update Work Schedule
Schedules can be modified as needed:Updating a work schedule does not affect existing appointments. It only applies to future appointment bookings.
Appointment Integration
Work schedules are critical for appointment validation. When creating an appointment, the system:- Checks if the professional has a work schedule for the appointment day
- Validates the appointment time falls within the professional’s working hours
- Rejects appointments outside working hours
checkProfessionalSchedule in the appointment creation process.
API Endpoints
GET /api/workSchedule
Retrieve all work schedules.
Response:
GET /api/workSchedule/:id
Retrieve a specific work schedule by ID.
POST /api/workSchedule
Create a new work schedule (Admin only).
Required Fields:
- professionalID, dayOfWeek, startTime, endTime
PATCH /api/workSchedule/:id
Update a work schedule (Admin only).
Required Fields:
- dayOfWeek, startTime, endTime
Time Format Requirements
All times must be in HH:MM:SS format:- Valid: “09:00:00”, “14:30:00”, “18:45:00”
- Invalid: “9:00”, “14:30”, “6pm”
isValidTimeFormat custom validator.
Use Cases
Regular Weekly Schedule
For a professional working Monday to Friday, 9 AM to 5 PM:Part-Time Schedule
For a professional working only mornings on Monday and Wednesday:Split Shift Schedule
For a professional with morning and afternoon shifts, you would need to represent this differently since only one schedule per day is allowed. Consider using the full time range and managing breaks at the application level.Security
All work schedule operations require JWT authentication. Create and update operations are restricted to administrators only.
Database Relationships
Work schedules connect to:- Professionals (Many-to-One): Each schedule belongs to one professional
- Appointments (Indirectly): Used for validation during appointment creation
Workflow Example
Appointment Booking
When patients book appointments, the system automatically checks work schedules.
Best Practices
- Set up schedules immediately after registering a new professional
- Use consistent time formats (HH:MM:SS) to avoid validation errors
- Ensure end time is after start time to prevent invalid schedules
- One schedule per day - the system enforces this with unique constraints
- Update schedules in advance when professional availability changes
- Consider time zones if your clinic operates across multiple time zones
- Document schedule changes for professional and administrative records
- Validate existing appointments before changing schedules significantly
