Overview
TheAttentionController handles the creation and management of clinical attention records. It processes anthropometric measurements, calculates nutritional metrics, and stores comprehensive patient evaluation data. This is the core controller for documenting nutritionist-patient consultations.
Namespace: App\Http\Controllers
Middleware: auth, verified, role:nutricionista
Route Prefix: /nutricionista
Creating Attention Records
create(Appointment $appointment)
Displays the form to create a new clinical attention record.GET /nutricionista/citas/{appointment}/atender
Route Name: nutricionista.attentions.create
Parameters:
appointment(Appointment): Route model binding
- Appointment must belong to authenticated nutritionist (403 if not)
- Appointment must be in “pendiente” state
- Patient must have personal data (redirects to data form if missing)
- If appointment not “pendiente”: redirect to appointment show with error
- If patient lacks personal data: redirect to patient data form with warning
store(Request appointment)
Stores a new clinical attention record with anthropometric data.POST /nutricionista/citas/{appointment}/atender
Route Name: nutricionista.attentions.store
Parameters:
appointment(Appointment): Route model binding- Request body with extensive validation (see below)
- Creates
Attentionrecord - Creates
AttentionDatarecord - Updates appointment state to “completada”
- Sends
AttentionCompletedNotificationto patient
Request Parameters (Create/Update)
Basic Measurements (Required)
Body Circumferences (Required)
Activity & Goal (Required)
sedentary- Little to no exerciselight- Light exercise 1-3 days/weekmoderate- Moderate exercise 3-5 days/weekactive- Heavy exercise 6-7 days/weekvery_active- Very heavy exercise, physical job, or training twice/day
deficit- Weight loss (caloric deficit)maintenance- Weight maintenancesurplus- Weight gain (caloric surplus)
Calculated Body Composition (Optional)
Macronutrient Plan (Optional)
Food Equivalents (Optional)
Clinical Notes (Required)
Example Request Body
Updating Attention Records
edit(Appointment $appointment)
Displays the form to edit an existing attention record.GET /nutricionista/citas/{appointment}/editar-atencion
Route Name: nutricionista.attentions.edit
Parameters:
appointment(Appointment): Route model binding
- Appointment must belong to authenticated nutritionist (403 if not)
- Appointment must have an attention record
- If no attention exists: redirect to appointment show with error
update(Request appointment)
Updates an existing clinical attention record.PUT /nutricionista/citas/{appointment}/editar-atencion
Route Name: nutricionista.attentions.update
Parameters:
appointment(Appointment): Route model binding- Request body with same validation as
store()method
- Updates
Attentionrecord (diagnosis, recommendations) - Updates
AttentionDatarecord (all measurements) - Does NOT change appointment state
- Does NOT send notifications
- Appointment must belong to authenticated nutritionist (403 if not)
- Appointment must have an existing attention record
- Same validation rules as create
Validation Error Messages
The controller provides comprehensive Spanish error messages:Database Structure
Attention Table
Stores the main attention record:AttentionData Table
Stores all anthropometric and nutritional data:Business Logic
Appointment State Transition
When an attention is created:- Appointment state changes from “pendiente” to “completada”
- This is permanent (cannot revert to “pendiente”)
- Updating an attention does NOT change the appointment state
Patient Data Prerequisite
Before creating an attention:- Patient must have
PersonalDatarecord (gender, birth_date) - If missing, nutritionist is redirected to complete patient data first
- This ensures age and gender are available for calculations
Notification Flow
Only on create (not update):- Transaction commits successfully
- Attention and AttentionData are created
- Appointment state updated to “completada”
AttentionCompletedNotificationsent to patient- Patient can view completed attention in their history
Error Handling
Database Transaction
Bothstore() and update() use transactions:
Common Error Scenarios
- Appointment not pending: “Esta cita no puede ser atendida. Estado actual: ”
- Missing patient data: Redirects to patient data form with warning
- Unauthorized access: 403 Forbidden
- Validation failure: Returns with validation errors
- Database error: Transaction rollback with error message
Dependencies
The AttentionController uses: Models:App\Models\AppointmentApp\Models\AttentionApp\Models\AttentionDataApp\Models\AppointmentState
App\Notifications\AttentionCompletedNotification
Illuminate\Support\Facades\DBfor transactionsIlluminate\Http\Requestfor validation