The services module lets clinic administrators define reusable clinical service workflows — structured sequences of stages that staff must complete in order, with optional evidence requirements and deadline tracking for each stage. Once defined, a service can be contracted for an individual patient; the system snapshots the current stage definitions at the moment of contracting, so future edits to the template never disrupt in-progress patient journeys.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Arthurr23/XHealtXperience/llms.txt
Use this file to discover all available pages before exploring further.
Three-Layer Service Hierarchy
Services are organized in three nested layers:LineaServicio is the top-level grouping category. For example, a clinic might have lines like “Cardiología”, “Cirugía Estética”, or “Medicina General”. Each line has a nombre, optional descripcion, and an activo flag.
Servicio is the clinical service itself — the thing a patient actually contracts. It belongs to a LineaServicio and holds scheduling and billing metadata.
ServicioEtapa represents one step within the service workflow, ordered by orden. Steps run sequentially; a stage cannot be completed if any preceding stage is still pending.
Servicio Field Reference
Human-readable service name, e.g., “Consulta Inicial de Cardiología”.
Foreign key to the parent
LineaServicio.Agreed price for this service. Used as the default
precio_acordado when contracting for a patient.Expected total service duration in minutes. Passed to the appointment scheduler when booking a consultation for this service.
When
true, the appointment form allows this service to be booked as a recurring series.Controls visibility. Inactive services are hidden from reception and patient-facing views via
scopeActivos.Long-form description shown to staff when browsing the catalog.
Pre-appointment requirements or patient instructions (nullable free text).
scopeActivos — Catalog Filtering
Servicio::scopeActivos() adds WHERE activo = true to any query. Non-admin roles always see the filtered catalog; the Administrador Clinica role sees all services (active and inactive) so deactivated services can be reactivated when needed:
ServicioEtapa — Stage Definition
Each stage on a service template carries:
Stage name (e.g., “Toma de muestras”, “Revisión médica”).
Execution order (1-based). Stages are always processed in ascending order.
When
true, the staff member must attach a file to mark the stage complete.Description of what evidence is expected (e.g., “Foto”, “PDF de laboratorio”).
Hours allowed to complete this stage from the moment the previous one was finished. Triggers deadline tracking on
PacienteServicioEtapa.vence_at.JSON array of Spatie role names that receive an email alert when this stage fails or expires. Defaults to
["Doctor","Recepcion"].ServicioStaffPerfil — Authorized Roles
Each Servicio can have one or more ServicioStaffPerfil records, each holding a single Spatie role_name. These define which roles are authorized to complete or fail stages on that service:
PacienteServicioController::autorizarEjecucion(): the request user must either be an Administrador Clinica or hold one of the roles listed in servicio_staff_perfiles.
Setting Up a New Service
Create a Service Line
Navigate to the Admin Dashboard → Services tab. Click Nueva Línea de Servicio and provide a
nombre and optional descripcion. The line must be active to appear in the service creation form.Create the Service
Within the service line, click Nuevo Servicio. Supply the
nombre, precio, duracion_minutos, whether it permite_recurrencia, and select at least one authorized role in roles[].Define the Stage Workflow
Include the The entire service, its staff profiles, and its stages are created in a single database transaction.
etapas[] array in the same request (or via the edit form). Each stage object needs at minimum a nombre; add requiere_evidencia, plazo_horas, and notificar_roles as needed.Assign the Service to a Patient
From the patient’s detail page, a receptionist or admin selects the service and clicks Contratar. The system snapshots all currently-active stages from The
servicio_etapas into new paciente_servicio_etapas rows:PacienteServicio record is created with estado = en_progreso and precio_acordado set to the service’s current precio.Stage Execution Lifecycle
Once a service is contracted, all stage tracking lives inpaciente_servicio_etapas. Stages have these possible states: pendiente, completado, fallido.
Completing a Stage
PATCH /paciente-servicio-etapas/{etapa}/completar
- The request must include
evidencia(file) whenrequiere_evidencia = true. - The controller blocks completion if any earlier-ordered stage is not yet in
completadostate. - On success, the deadline (
vence_at) for the next stage is recalculated fromnow(). - When all stages of a
PacienteServicioreachcompletado, the parent record’sestadois automatically updated tocompletado.
Failing a Stage
PATCH /paciente-servicio-etapas/{etapa}/fallar
A notas field with the failure reason is required. Marking a stage as fallido also sets the parent PacienteServicio.estado to bloqueado and triggers email notifications to all roles listed in notificar_roles for that stage.
Reactivating a Failed Stage
PATCH /paciente-servicio-etapas/{etapa}/reactivar
Only the Administrador Clinica role can reactivate a failed stage. This resets the stage to pendiente and restores the PacienteServicio.estado to en_progreso.
Progress Calculation
ThePacienteServicio::progreso() method returns an integer from 0 to 100, calculated as the percentage of stages in completado state out of the total stages in the snapshot:
Service Workflow Diagram
Route Reference
| Method | Path | Description | Required Role |
|---|---|---|---|
GET | /servicios | List service catalog (active only for non-admins) | Any authenticated |
POST | /servicios | Create service with stages and staff roles | Administrador Clinica |
PATCH | /servicios/{servicio} | Edit service metadata, stages, and roles | Administrador Clinica |
PATCH | /servicios/{servicio}/toggle | Activate or deactivate a service | Administrador Clinica |
DELETE | /servicios/{servicio} | Delete a service (blocked if patients are linked) | Administrador Clinica |
GET | /lineas-servicio | List service lines | Administrador Clinica |
POST | /lineas-servicio | Create a new service line | Administrador Clinica |
PATCH | /lineas-servicio/{lineaServicio} | Edit a service line | Administrador Clinica |
PATCH | /lineas-servicio/{lineaServicio}/toggle | Activate or deactivate a service line | Administrador Clinica |
DELETE | /lineas-servicio/{lineaServicio} | Delete a service line | Administrador Clinica |
GET | /pacientes/{paciente}/servicios | List services contracted by a patient | Any authenticated |
POST | /pacientes/{paciente}/servicios | Contract a service for a patient | Administrador Clinica, Recepcion |
PATCH | /paciente-servicio-etapas/{etapa}/completar | Mark a stage as completed | Authorized roles per servicio_staff_perfiles |
PATCH | /paciente-servicio-etapas/{etapa}/fallar | Mark a stage as failed | Authorized roles per servicio_staff_perfiles |
PATCH | /paciente-servicio-etapas/{etapa}/reactivar | Reactivate a failed stage | Administrador Clinica |