Overview
Nutritionist components provide interfaces for nutritionists to manage their profiles, view and manage patients, and collect patient data. These components are restricted to users with thenutricionista role.
NutricionistaProfile
Location:app/Livewire/Nutricionista/NutricionistaProfile.php:14
View: resources/views/livewire/nutricionista/nutricionista-profile.blade.php
Purpose
Manages nutritionist profile information including personal details, profile photo, consultation pricing, and password changes.Traits
WithFileUploads- Enables file upload functionality for profile photos
Properties
| Property | Type | Default | Description |
|---|---|---|---|
name | string | - | Nutritionist’s name |
email | string | - | Email address (read-only) |
phone | string | '' | Contact phone number |
profile_photo | mixed | null | Uploaded profile photo file |
profile_photo_path | string | '' | Current photo path |
consultation_price | float | 30.00 | Price per consultation |
current_password | string | '' | Current password for verification |
password | string | '' | New password |
password_confirmation | string | '' | Password confirmation |
hasPersonalData | bool | false | Whether personal data exists |
hasPassword | bool | false | Whether custom password is set |
Validation Rules
Location:app/Livewire/Nutricionista/NutricionistaProfile.php:32
Methods
mount(): void
Location: app/Livewire/Nutricionista/NutricionistaProfile.php:66
Initializes the component with the authenticated nutritionist’s data.
Process:
- Verifies user has
nutricionistarole (aborts with 403 if not) - Loads user name and email
- Checks if user has custom password (not default)
- Loads personal data if exists
- Loads consultation price from settings
saveProfile(): void
Location: app/Livewire/Nutricionista/NutricionistaProfile.php:93
Saves profile information including name, phone, photo, and consultation price.
Process:
- Validates profile fields
- Updates user name
- Handles profile photo upload:
- Deletes old photo if exists
- Stores new photo in
profile-photosdirectory
- Updates or creates
PersonalDatarecord - Updates or creates
NutricionistaSettingswith consultation price - Redirects with success message
success: “Tu perfil ha sido actualizado correctamente.”error: “Error al actualizar el perfil: “
updatePassword(): void
Location: app/Livewire/Nutricionista/NutricionistaProfile.php:148
Updates the nutritionist’s password with proper verification.
Process:
- Validates current password (if user has custom password)
- Validates new password (min 8 chars, confirmed)
- Verifies current password matches
- Hashes and saves new password
- Sends
PasswordChangedNotificationto user - Resets password fields
- Redirects with success message
password_success: “Tu contraseña ha sido actualizada correctamente.”password_error: “La contraseña actual es incorrecta.” or “Error al actualizar la contraseña: “
Usage Example
PatientDataForm
Location:app/Livewire/Nutricionista/PatientDataForm.php:11
View: resources/views/livewire/nutricionista/patient-data-form.blade.php
Purpose
Allows nutritionists to create personal data records for patients who don’t have them yet. Used during the first appointment workflow.Properties
| Property | Type | Default | Description |
|---|---|---|---|
patient | User | - | Patient user model |
appointmentId | ?int | null | Associated appointment ID |
cedula | string | '' | National ID number |
phone | string | '' | Phone number |
address | string | '' | Physical address |
birth_date | string | '' | Date of birth |
gender | string | '' | Gender (male/female/other) |
hasPersonalData | bool | false | Whether patient has data |
isReadOnly | bool | false | Form is read-only |
Validation Rules
Location:app/Livewire/Nutricionista/PatientDataForm.php:24
Methods
mount(User $patient, ?int $appointmentId = null): void
Location: app/Livewire/Nutricionista/PatientDataForm.php:50
Initializes the form for a specific patient.
Process:
- Verifies authenticated user is a nutritionist (aborts with 403 if not)
- Verifies patient has
pacienterole (aborts with 404 if not) - Checks if patient already has personal data
- If data exists, loads it and sets form to read-only
- Stores optional appointment ID for post-save redirect
save(): void
Location: app/Livewire/Nutricionista/PatientDataForm.php:80
Creates personal data record for the patient.
Process:
- Prevents save if patient already has data
- Validates all input fields
- Creates
PersonalDatarecord - Sends
PersonalDataCreatedNotificationto patient - Redirects based on appointment ID:
- If appointment ID exists: redirects to create attention record
- Otherwise: redirects to patient list
error: “Este paciente ya tiene datos personales asignados.” or “Error al guardar los datos: “
Usage Example
PatientsTable
Location:app/Livewire/Nutricionista/PatientsTable.php:10
View: resources/views/livewire/nutricionista/patients-table.blade.php
Purpose
Provides a filterable, sortable table of all patients associated with the authenticated nutritionist.Traits
WithPagination- Enables pagination support
Properties
| Property | Type | Default | Description |
|---|---|---|---|
search | string | '' | Search term for name/email |
estado | string | '' | Filter by user state |
proximas_citas | string | '' | Filter patients with upcoming appointments |
sort | string | 'name' | Sort order (name/recent) |
Query String Parameters
Location:app/Livewire/Nutricionista/PatientsTable.php:19
Methods
updatingSearch(): void
Location: app/Livewire/Nutricionista/PatientsTable.php:27
Resets pagination when search changes.
updatedEstado(): void
Location: app/Livewire/Nutricionista/PatientsTable.php:32
Resets pagination when state filter changes.
updatedProximasCitas(): void
Location: app/Livewire/Nutricionista/PatientsTable.php:37
Resets pagination when appointment filter changes.
clearFilters(): void
Location: app/Livewire/Nutricionista/PatientsTable.php:47
Resets all filters and sorting to defaults.
render()
Location: app/Livewire/Nutricionista/PatientsTable.php:56
Builds and executes the query to fetch filtered patients.
Query Features:
- Filters to users with
pacienterole - Eager loads relationships:
userStatepersonalDataappointmentsAsPaciente(only next pending appointment)
- Counts total appointments per patient
- Filters by search term (case-insensitive ILIKE)
- Filters by user state
- Filters by upcoming appointments if requested
- Sorts by name or most recent appointment
- Paginates with 12 patients per page
name: Alphabetical by patient namerecent: By most recent appointment date
patients- Paginated patient collectionuserStates- All available user states for filtering
Advanced Query Example
Location:app/Livewire/Nutricionista/PatientsTable.php:95
Filtering patients with upcoming appointments:
Usage Example
Security Considerations
- All components verify the authenticated user has the
nutricionistarole PatientDataFormadditionally verifies the target user has thepacienterole- Patient data cannot be edited once created (read-only after initial save)
- File uploads are restricted to images with 2MB max size
- Cedula (national ID) uniqueness is enforced
- Password changes require current password verification
- All inputs are validated server-side
Related Models
App\Models\User- User accountsApp\Models\PersonalData- Personal informationApp\Models\NutricionistaSettings- Nutritionist-specific settingsApp\Models\UserState- User account statesApp\Models\Appointment- Appointments
Notifications
PasswordChangedNotification- Sent when password is updatedPersonalDataCreatedNotification- Sent to patient when their data is created