The Admin API is the control plane of the MELIKA platform. It exposes a unified set of endpoints that let administrators monitor live statistics, manage user accounts, oversee appointments, build doctor schedules (individually or in bulk), and maintain the specialty and medication catalogs. Every endpoint in this group is protected by JWT verification and an admin-role guard — no operation can be performed by a patient or a doctor token.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Imjuanisss/proyecto-melika/llms.txt
Use this file to discover all available pages before exploring further.
All
/admin routes require an Authorization: Bearer <token> header where the JWT payload contains rol = 'admin'. Requests without a valid token return 401 Unauthorized; requests with a non-admin token return 403 Forbidden.Statistics
Get Platform Statistics
Retrieve a real-time snapshot of the entire platform: aggregate counts of active records, appointment-state breakdown, the five most recent appointments, and the five most-requested doctors.GET /admin/stats
No query parameters or request body required.
200 OK
Aggregate counts across the platform.
Appointment counts grouped by status across all appointments.
The five most recently created appointments across all doctors and patients.
The five doctors with the highest number of non-cancelled appointments.
User Management
Administrators can list all users with flexible filtering and toggle any non-admin account between active and inactive states.List Users
GET /admin/usuarios
Filter by user role. Accepted values:
paciente, medico, admin.Case-insensitive substring search (
ILIKE) applied to nombre, primer_apellido, and email.Filter by account status. Accepted values:
true, false.created_at descending (newest accounts first).
200 OK — array of user objects.
Toggle User Status
PATCH /admin/usuarios/:id/estado
Toggles the activo field of the specified user. If the user is currently active they will be deactivated, and vice versa.
ID of the user to toggle.
200 OK
Human-readable confirmation:
"Usuario activado." or "Usuario desactivado.".| Status | Condition |
|---|---|
400 | Attempted to deactivate an admin account. |
404 | No user found with the given ID. |
Appointment Management
Administrators have a global view of every appointment and can update any appointment’s status, including releasing the associated time slot when a cancellation occurs.List Appointments
GET /admin/citas
Filter by appointment status. Accepted values:
pendiente, completada, cancelada, no_asistio.Lower date bound (inclusive), format
YYYY-MM-DD.Upper date bound (inclusive), format
YYYY-MM-DD.Case-insensitive substring search (
ILIKE) on patient and doctor names.fecha DESC, hora_inicio DESC.
200 OK — array of full appointment objects including patient name, doctor name, specialty, and time-slot end time (hora_fin).
Update Appointment Status
PATCH /admin/citas/:id/estado
ID of the appointment to update.
New status. Accepted values:
pendiente, completada, cancelada, no_asistio.Optional cancellation reason. Recommended when
estado is cancelada.200 OK
Human-readable confirmation of the status change.
| Status | Condition |
|---|---|
400 | Invalid estado value supplied. |
404 | No appointment found with the given ID. |
Schedule Management
Administrators can create, update, and delete individual time slots (franjas_horarias) for any doctor, or generate an entire day’s schedule in a single bulk request. All slots are exactly 40 minutes long (DURACION_FRANJA_MIN = 40).
Get Schedules (FullCalendar format)
GET /admin/horarios
Returns schedule events formatted for FullCalendar. Each event represents one franja_horaria and is color-coded by availability/appointment status.
Start date of the range to fetch, format
YYYY-MM-DD.End date of the range to fetch, format
YYYY-MM-DD.Filter events to a specific doctor.
200 OK — array of FullCalendar event objects.
Create a Single Slot
POST /admin/horarios
Creates one time slot for a doctor. The slot duration is not validated server-side on this route — use POST /admin/horarios/masivo to guarantee 40-minute alignment.
ID of the doctor this slot belongs to.
Date of the slot, format
YYYY-MM-DD.Start time of the slot, format
HH:MM.End time of the slot, format
HH:MM. Should be exactly 40 minutes after hora_inicio.201 Created
"Franja creada."The newly created slot.
| Status | Condition |
|---|---|
404 | Doctor not found or inactive. |
409 | A slot with the same doctor, date, and time already exists (unique constraint). |
Bulk Generate Slots
POST /admin/horarios/masivo
Automatically generates all 40-minute slots that fit within a workday window, optionally skipping a break period. This is the recommended way to populate a full day’s schedule.
Slot duration is fixed at 40 minutes (
DURACION_FRANJA_MIN = 40). The generator advances the cursor by 40 minutes at a time from hora_inicio until there is no room for another full slot before hora_fin. Any window that overlaps with inicio_descanso–fin_descanso is skipped entirely.ID of the doctor for whom slots are generated.
Date for the generated slots, format
YYYY-MM-DD.Workday start time, format
HH:MM.Workday end time, format
HH:MM. The range must accommodate at least one 40-minute slot.Break start time, format
HH:MM. Optional. Must fall strictly within the workday window.Break end time, format
HH:MM. Optional. Must fall strictly within the workday window and be after inicio_descanso.201 Created
Human-readable summary (e.g.
"Se crearon 12 franjas (0 ya existían).").Number of new slots successfully inserted into the database.
Number of slots skipped because they already existed (unique constraint).
Total slots attempted (
insertadas + duplicadas).| Status | Condition |
|---|---|
400 | Missing required fields (id_medico, fecha, hora_inicio, hora_fin). |
400 | Time range is too short to fit a single 40-minute slot. |
400 | Break window falls outside the workday boundaries or inicio_descanso >= fin_descanso. |
404 | Doctor not found or inactive. |
Update a Slot
PUT /admin/horarios/:id
Updates the date and/or times of an existing free slot. The updated slot must be exactly 40 minutes long and must not overlap with any other slot for the same doctor on the same date.
ID of the slot to update.
New date for the slot, format
YYYY-MM-DD.New start time, format
HH:MM.New end time, format
HH:MM. Must be exactly 40 minutes after hora_inicio.200 OK
"Franja actualizada correctamente."The updated slot object with the same shape as the
franja returned by POST /admin/horarios.| Status | Condition |
|---|---|
400 | Slot has an active appointment (disponible = FALSE) and cannot be modified. |
400 | Duration is not exactly 40 minutes. |
400 | hora_inicio >= hora_fin. |
404 | Slot not found. |
409 | The new time window overlaps with an existing slot for the same doctor on the same date. |
Delete a Slot
DELETE /admin/horarios/:id
Permanently removes a time slot from the database.
ID of the slot to delete.
200 OK
"Franja eliminada."| Status | Condition |
|---|---|
400 | Slot has an active appointment and cannot be deleted. |
404 | Slot not found. |
Specialty Management
Administrators control the specialty catalog that doctors are associated with and patients browse when booking appointments.Create a Specialty
POST /admin/especialidades
Unique name of the specialty (e.g.
"Cardiología"). Duplicate names return 409.Short description shown to patients.
Base consultation price for this specialty.
URL or path of the specialty’s image. Stored as
imagen_url in the database.201 Created
Confirmation message.
The newly created specialty record.
| Status | Condition |
|---|---|
409 | A specialty with the same nombre already exists. |
Update a Specialty
PUT /admin/especialidades/:id
ID of the specialty to update.
New name for the specialty.
Updated description.
Updated base price.
Updated image URL. Stored as
imagen_url in the database.Active status of the specialty. Defaults to
true if omitted.200 OK
Confirmation message.
The updated specialty record.
Toggle Specialty Status
PATCH /admin/especialidades/:id/estado
Toggles the activa boolean of the specialty. Deactivating a specialty hides it from patient-facing catalog views without deleting it.
ID of the specialty to toggle.
200 OK
"Especialidad activada." or "Especialidad desactivada.".Medication Management
Administrators maintain the medication catalog used by doctors when creating prescriptions and clinical records. The admin medication routes usenombre_comercial, principio_activo, and presentaciones field names directly (unlike the public POST /medicamentos route which uses short aliases).
Create a Medication
POST /admin/medicamentos
Commercial name of the medication. Stored directly as
nombre_comercial.Active ingredient(s). Stored directly as
principio_activo.Medication class. Accepted values:
OTC (over-the-counter), Rx (prescription-only). Defaults to OTC.Name of the pharmaceutical laboratory.
Legacy text category label (optional).
Free-text description of the medication.
Clinical indications.
Contraindications.
Physical form / presentations (e.g.
"Tabletas 500 mg"). Stored directly as presentaciones.INVIMA registration number. Must be unique when provided.
URL of the medication’s product image.
201 Created
"Medicamento creado."The newly created medication record as stored in the database.
| Status | Condition |
|---|---|
400 | nombre_comercial or principio_activo missing. |
409 | The registro_invima value already exists in the database. |
Update a Medication
PUT /admin/medicamentos/:id
Accepts the same body fields as POST /admin/medicamentos and replaces the existing record.
ID of the medication to update.
Updated commercial name.
Updated active ingredient.
Updated medication class:
OTC or Rx.Updated laboratory name.
Updated description.
Updated clinical indications.
Updated contraindications.
Updated presentations.
Updated INVIMA number.
Updated product image URL.
Active status of the medication. Defaults to
true if omitted.200 OK
Confirmation message.
The updated medication record.
| Status | Condition |
|---|---|
404 | No medication found with the given ID. |
Toggle Medication Status
PATCH /admin/medicamentos/:id/estado
Toggles the activo boolean of a medication. Deactivated medications remain in the database for historical prescription records but are hidden from active catalog views.
ID of the medication to toggle.
200 OK
"Medicamento activado." or "Medicamento desactivado.".| Status | Condition |
|---|---|
404 | No medication found with the given ID. |