Overview
TheNutricionistaController handles all nutritionist-specific operations in NutriFit. It manages appointment scheduling, patient management, clinical history tracking, and availability configuration.
Namespace: App\Http\Controllers
Middleware: auth, verified, role:nutricionista
Route Prefix: /nutricionista
Dashboard
index()
Displays the nutritionist dashboard with statistics and upcoming appointments.GET /nutricionista/dashboard
Route Name: nutricionista.dashboard
Returns: View with:
- Appointments today (pending only)
- Appointments this week (pending only)
- Next appointment
- Today’s appointment schedule
- Upcoming appointments grouped by week and date (next 4 weeks)
- Schedule configuration status
Appointment Management
appointments(Request $request)
Lists all appointments with filtering options.GET /nutricionista/citas
Route Name: nutricionista.appointments.index
Query Parameters:
estado(string, optional): Filter by state (todos,pendiente,completada,cancelada,vencida)search(string, optional): Search by patient name or emailfecha_desde(date, optional): Start date filterfecha_hasta(date, optional): End date filter
showAppointment(Appointment $appointment)
Displays detailed information about a specific appointment.GET /nutricionista/appointments/{appointment}
Route Name: nutricionista.appointments.show
Parameters:
appointment(Appointment): Route model binding
cancelAppointment(Appointment $appointment)
Cancels a pending appointment.POST /nutricionista/appointments/{appointment}/cancel
Route Name: nutricionista.appointments.cancel
Parameters:
appointment(Appointment): Route model binding
- Updates appointment state to “cancelada”
- Sends immediate notification to nutritionist
- Sends delayed notification to patient (20 seconds)
- Appointment must belong to authenticated nutritionist
- Appointment must be in “pendiente” state
rescheduleForm(Appointment $appointment)
Displays the rescheduling form with available time slots.GET /nutricionista/appointments/{appointment}/reschedule
Route Name: nutricionista.appointments.reschedule
Parameters:
appointment(Appointment): Route model binding
- 4 weeks of available time slots
- Current appointment details
- Patient information
- Appointment must belong to authenticated nutritionist
- Appointment must be in “pendiente” state
rescheduleAppointment(Request appointment)
Processes the appointment rescheduling.POST /nutricionista/appointments/{appointment}/reschedule
Route Name: nutricionista.appointments.reschedule.store
Parameters:
appointment(Appointment): Route model bindingdate(date, required): New appointment date (must be today or future)time(string, required): New appointment time (HH:MM format)reschedule_reason(string, optional): Reason for rescheduling (max 500 chars)
- Updates appointment start_time and end_time
- Sends notification to patient with old/new times and reason
- Checks for scheduling conflicts
- Verifies time slot availability
- Appointment must be in “pendiente” state
Schedule Management
schedules()
Displays the nutritionist’s schedule configuration.GET /nutricionista/horarios
Route Name: nutricionista.schedules.index
Returns: View with:
- Current schedules grouped by day of week
- Days of week mapping
- Consultation duration (45 minutes)
saveSchedules(Request $request)
Saves or updates the nutritionist’s availability schedule.POST /nutricionista/horarios
Route Name: nutricionista.schedules.save
Parameters:
time_slots(array, optional): Array of time slot strings in format “day_time” (e.g., “1_08:00”)
- Deletes all existing schedules for the nutritionist
- Creates new schedule entries grouped by consecutive time ranges
- Each schedule has consultation_duration = 45 minutes
Patient Management
patients()
Displays the list of patients.GET /nutricionista/pacientes
Route Name: nutricionista.patients.index
Returns: Patient listing view
showPatient(User $patient)
Displays detailed patient information and appointment history.GET /nutricionista/pacientes/{patient}
Route Name: nutricionista.patients.show
Parameters:
patient(User): Route model binding
- Patient personal data
- Appointment statistics (total, completed, cancelled, pending)
- All appointments with this nutritionist
- Next appointment
- Last attention data
patientData(User appointment = null)
Displays the patient personal data form.GET /nutricionista/pacientes/{patient}/datos/{appointment?}
Route Name: nutricionista.patients.data
Parameters:
patient(User): Route model bindingappointment(optional): Appointment ID
patientHistory(User $patient)
Displays patient clinical history with progress charts.GET /nutricionista/pacientes/{patient}/historial
Route Name: nutricionista.patients.history
Parameters:
patient(User): Route model binding
- All attention records for this patient with this nutritionist
- Chart data for visualization (weight, BMI, body fat, measurements, etc.)
- Progress statistics comparing first and last attention
- Weight, BMI, body fat percentage
- Circumferences (waist, hip, neck, wrist, arms, thighs, calves)
- Metabolic data (TMB, TDEE, target calories)
- Ratios (WHR, WHT)
Creating Appointments for Patients
createAppointment()
Displays the form to assign an appointment to a patient.GET /nutricionista/citas/asignar
Route Name: nutricionista.appointments.create
Returns: View with:
- List of all patients (with role validation)
- Consultation price from nutritionist settings
getAvailableSchedules(User $paciente)
Returns available time slots for a specific patient (JSON API).GET /nutricionista/citas/asignar/{paciente}/horarios
Route Name: nutricionista.appointments.schedules
Parameters:
paciente(User): Route model binding
- Patient information (id, name, email, initials, profile_photo)
- 4 weeks of available time slots
- Whether patient has previous appointments with this nutritionist
- Error messages if patient is ineligible
- Patient must have role “paciente”
- Patient must be clinically enabled
- Patient cannot have pending appointments with ANY nutritionist
storeAppointment(Request $request)
Stores a new appointment assigned by the nutritionist.POST /nutricionista/citas/asignar
Route Name: nutricionista.appointments.store
Parameters:
paciente_id(integer, required): Patient user IDappointment_date(date, required): Date (must be today or future)appointment_time(string, required): Time in HH:MM formatappointment_type(string, required): Type (primera_vez,seguimiento,control)reason(string, optional): Appointment reason (max 500 chars)notes(string, optional): Internal notes (max 1000 chars)price(numeric, required): Consultation price (min 0)
- Creates appointment with “pendiente” state
- Sends confirmation notification to patient (delayed 20 seconds)
- Sends reminder notification to nutritionist (immediate)
- Patient must be clinically enabled
- Patient cannot have pending appointments
- Time slot must be available
- Schedule must exist for selected day
Profile Management
updatePassword(Request $request)
Updates the nutritionist’s password.POST /nutricionista/perfil/contrasena
Route Name: nutricionista.profile.update-password
Parameters:
current_password(string, required if not default): Current passwordpassword(string, required): New password (min 8 chars)password_confirmation(string, required): Password confirmation
- Current password must match (if user has non-default password)
- New password must be at least 8 characters
- Password confirmation must match
Private Helper Methods
prepareChartData($attentions)
Prepares attention data for Chart.js visualization.$attentions(Collection): Collection of Attention models
calculateProgressStats($attentions)
Calculates progress statistics comparing first and last attention.$attentions(Collection): Collection of Attention models
Dependencies
The NutricionistaController uses: Models:App\Models\UserApp\Models\AppointmentApp\Models\NutricionistaScheduleApp\Models\AttentionApp\Models\AppointmentState
App\Notifications\AppointmentCancelledByNutricionistaApp\Notifications\AppointmentRescheduledNotificationApp\Notifications\AppointmentCreatedNotificationApp\Notifications\AppointmentCreatedForPatientNotificationApp\Notifications\PasswordChangedNotification