Overview
Patient components provide interfaces for patients to view their appointment history, filter appointments, and track their interactions with nutritionists. These components are restricted to users with thepaciente role.
AppointmentList
Location:app/Livewire/Paciente/AppointmentList.php:10
View: resources/views/livewire/paciente/appointment-list.blade.php
Purpose
Provides a paginated, filterable list of all appointments for the authenticated patient, with options to filter by state, nutritionist, and date range.Traits
WithPagination- Enables pagination support
Properties
| Property | Type | Default | Description |
|---|---|---|---|
estado | string | '' | Filter by appointment state |
nutricionista | string | '' | Filter by nutritionist ID |
fecha_desde | string | '' | Start date for date range filter |
fecha_hasta | string | '' | End date for date range filter |
Query String Parameters
Location:app/Livewire/Paciente/AppointmentList.php:19
The component persists filter state in the URL:
- Bookmarkable filtered appointment views
- Browser back/forward navigation with filters preserved
- Shareable links with specific filters applied
Methods
updatingEstado(): void
Location: app/Livewire/Paciente/AppointmentList.php:26
Resets pagination when the appointment state filter changes.
updatingNutricionista(): void
Location: app/Livewire/Paciente/AppointmentList.php:31
Resets pagination when the nutritionist filter changes.
updatingFechaDesde(): void
Location: app/Livewire/Paciente/AppointmentList.php:36
Resets pagination when the start date filter changes.
updatingFechaHasta(): void
Location: app/Livewire/Paciente/AppointmentList.php:41
Resets pagination when the end date filter changes.
limpiarFiltros(): void
Location: app/Livewire/Paciente/AppointmentList.php:46
Resets all filters to their default empty state and returns to page 1.
render()
Location: app/Livewire/Paciente/AppointmentList.php:52
Builds and executes the query to fetch the patient’s filtered appointments.
Base Query:
nutricionista- The nutritionist associated with the appointmentappointmentState- The current state of the appointment (pending, completed, cancelled)
-
By Appointment State (
app/Livewire/Paciente/AppointmentList.php:59) -
By Nutritionist (
app/Livewire/Paciente/AppointmentList.php:66) -
By Date Range (
app/Livewire/Paciente/AppointmentList.php:71)
nutricionistas- List of all nutritionists for the filter dropdown, ordered alphabetically by name
appointments- Paginated collection of appointmentsnutricionistas- Collection of nutritionist users for filtering
Usage Example
View Integration
The component is typically used in a patient dashboard with filter controls:Filter Behavior
Live Updates
All filters usewire:model.live to automatically update the appointment list as soon as a filter value changes, without requiring a button click.
Combined Filters
Filters can be combined. For example:- Show only pending appointments with a specific nutritionist
- Show completed appointments within a date range
- Show all appointments with a specific nutritionist from a specific date onwards
Date Range Validation
The component doesn’t enforce thatfecha_desde must be before fecha_hasta. If you set an end date before a start date, the query will return no results (which is expected database behavior).
Security Considerations
- Component automatically filters appointments to only show those belonging to the authenticated patient
- Uses
auth()->id()to ensure patients can only view their own appointments - All inputs are sanitized through Livewire’s automatic escaping
- Date inputs are validated through HTML5 date input type
- Nutritionist filter validates against actual user IDs
Performance Optimizations
Eager Loading
Location:app/Livewire/Paciente/AppointmentList.php:55
The component eager loads related models to prevent N+1 query problems:
Pagination
Usingpaginate(10) instead of get() ensures only 10 records are fetched from the database at a time, reducing memory usage and query time for patients with many appointments.
Indexed Queries
The filters use indexed columns:paciente_id- Foreign key indexnutricionista_id- Foreign key indexstart_time- Likely indexed for sorting performance
Related Models
App\Models\Appointment- Appointment recordsApp\Models\User- User accounts (for nutritionists)App\Models\AppointmentState- Appointment states (pending, completed, cancelled)
Related Components
Patients may also interact with:- Settings components for managing their profile
- Notification components for appointment reminders
Appointment States
Typical appointment states in NutriFit:- pendiente - Appointment is scheduled and upcoming
- completada - Appointment was completed successfully
- cancelada - Appointment was cancelled
Future Enhancements
Potential improvements for this component:- Add export functionality to download appointment history
- Add calendar view alongside list view
- Add appointment rescheduling capability
- Add filtering by appointment type or service
- Add statistics summary (total appointments, completed, cancelled)