Clinical records (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.
historias_clinicas) are the structured medical histories MELIKA generates per appointment. Each record is tightly coupled to a single appointment (id_cita is UNIQUE), ensuring a one-to-one relationship between a consultation and its clinical narrative. Only authenticated physicians (isMedico) may create or add notes; patients may read their own histories and manage the visibility of their own uploaded documents. All endpoints require a valid JWT (verifyToken).
Data Model
Thehistorias_clinicas table captures the complete clinical encounter — from chief complaint and anamnesis through vital signs, ICD-10 diagnosis, and the prescribing physician’s legal signature block. The table supports three record types via tipo_registro: a primary history (historia_principal) and two note types (nota_aclaracion, nota_evolucion). Notes link back to their originating record through id_historia_original.
| Field | Type | Notes |
|---|---|---|
id | integer | Primary key |
id_paciente | integer | FK → patients |
id_medico | integer | FK → doctors |
id_cita | integer | FK → appointments — UNIQUE per historia_principal |
tipo_registro | VARCHAR | historia_principal, nota_aclaracion, or nota_evolucion |
estado | VARCHAR | activo or anulado_por_aclaracion |
id_historia_original | integer | FK → parent history (set on notes only) |
tipo_consulta | VARCHAR | presencial or teleconsulta. Default presencial |
eps_aseguradora | VARCHAR | Health insurer name |
contacto_responsable_nombre | VARCHAR | Name of responsible contact |
contacto_responsable_telefono | VARCHAR | Phone of responsible contact |
motivo_consulta | TEXT | Required. Chief complaint |
anamnesis | TEXT | Medical history narrative |
antecedentes_patologicos | TEXT | Pathological history |
antecedentes_quirurgicos | TEXT | Surgical history |
antecedentes_alergicos | TEXT | Allergy history |
antecedentes_familiares | TEXT | Family medical history |
antecedentes_ginecoobstetricos | TEXT | Gyneco-obstetric history |
habitos | TEXT | Lifestyle habits (smoking, alcohol, etc.) |
tension_arterial_sistolica | FLOAT | Systolic blood pressure (mmHg) |
tension_arterial_diastolica | FLOAT | Diastolic blood pressure (mmHg) |
frecuencia_cardiaca | integer | Heart rate (bpm) |
frecuencia_respiratoria | integer | Respiratory rate (breaths/min) |
temperatura_corporal | FLOAT | Body temperature (°C) |
peso_kg | FLOAT | Weight in kilograms |
talla_cm | FLOAT | Height in centimetres |
imc | FLOAT | BMI — auto-calculated from peso_kg / (talla_cm/100)² |
exploracion_por_sistemas | TEXT | Systems review findings |
examen_fisico | TEXT | Physical examination findings |
diagnostico_cie10 | VARCHAR(10) | ICD-10 diagnosis code (uppercased on save) |
descripcion_diagnostico | TEXT | Human-readable diagnosis description |
plan_tratamiento | TEXT | Treatment plan |
medicamentos_recetados | JSONB | Free-text prescription stored as { "texto": "..." } |
ordenes_medicas | TEXT | Medical orders |
recomendaciones | TEXT | Patient recommendations |
incapacidad_dias | integer | Days of medical leave granted |
observaciones | TEXT | Additional observations |
medico_nombre_firma | VARCHAR | Required. Signing physician’s full name |
medico_cedula_firma | VARCHAR | Signing physician’s ID number |
medico_rethus_firma | VARCHAR | Required. Physician’s RETHUS registry number |
created_at | timestamp | Auto-generated |
updated_at | timestamp | Auto-updated |
medicamentos_recetados Format
Prescribed medications entered in the free-text clinical notes field are normalised and stored as a JSONB object with a single texto key. The API returns the value already unwrapped to the plain string.
recetas_medicas table via the recetas array in the request body (see below).
Endpoints
GET /historias/paciente/:id_paciente
Retrieves a summary list of all primary clinical records (tipo_registro = historia_principal) belonging to a specific patient. Each record is enriched with the physician’s full name, specialty, appointment date, and a count of attached notes. Patients may only request their own records; physicians may access records for patients with whom they share at least one appointment.
Authentication: verifyToken
The unique identifier of the patient whose clinical records are being requested.
Clinical record identifier.
Chief complaint recorded during the consultation.
ICD-10 code assigned by the physician.
Human-readable diagnosis description.
Always
historia_principal for records returned by this endpoint.Record state:
activo or anulado_por_aclaracion.Count of attached clarification/evolution notes.
First name of the physician who created the record.
First surname of the physician.
Medical specialty of the attending physician.
Appointment date (
YYYY-MM-DD).Appointment start time.
GET /historias/cita/:id_cita
Returns the primary clinical record associated with a specific appointment, together with its attached clarification/evolution notes, prescription lines (recetas), and exam orders (examenes). If no record exists for the appointment yet, all arrays are returned empty.
Authentication: verifyToken
The appointment ID for which to retrieve the clinical record.
The primary clinical record object (all
historias_clinicas columns) enriched with patient and physician demographics, specialty name, and appointment metadata (fecha_cita, hora_inicio, tipo_cita). Returns null if no record exists yet.Ordered list of
nota_aclaracion and nota_evolucion records linked to this history.Prescription line items from
recetas_medicas for this history.Exam orders from
ordenes_examenes for this history.GET /historias/:id/completa
Retrieves a single primary clinical record by its own ID with full detail — including all columns expanded, any attached clarification/evolution notes, prescription lines, and exam orders. Authentication:verifyToken
The clinical record’s own primary key.
The complete primary clinical record with patient and physician demographics appended.
Clarification and evolution notes attached to this history, ordered by creation date.
Prescription line items linked to this history.
Exam orders linked to this history.
POST /historias
Creates a new primary clinical record for an appointment. The record is permanently linked viaid_cita. The controller runs full professional validation (vital-sign ranges, required clinical fields, patient-age coherence) before persisting. If recetas or examenes arrays are provided they are inserted transactionally in the same request. On success, the linked appointment’s estado is automatically updated to completada.
Authentication: verifyToken + isMedico
The appointment this record belongs to. Must not already have an associated primary record.
Chief complaint — the patient’s primary reason for the consultation.
Medical history narrative gathered during the consultation.
Allergy history.
Findings from the physical examination.
ICD-10 diagnosis code (max 10 characters). Stored uppercased.
Plain-language description of the diagnosis.
Recommended treatment plan.
Full name of the signing physician as it should appear on the record.
Signing physician’s RETHUS registry number.
Pathological history.
Surgical history.
Family medical history.
Gyneco-obstetric history.
Lifestyle habits.
presencial (default) or teleconsulta.Health insurer name.
Responsible contact’s name.
Responsible contact’s phone.
Systolic blood pressure (mmHg).
Diastolic blood pressure (mmHg).
Heart rate (bpm).
Respiratory rate (breaths/min).
Body temperature (°C).
Weight in kilograms. Used to auto-calculate
imc.Height in centimetres. Used to auto-calculate
imc.Systems review narrative.
Free-text prescription summary. Stored as
{ "texto": "..." } in the database.Medical orders text.
Patient recommendations.
Days of medical leave granted.
Additional observations.
Signing physician’s national ID number.
Array of prescription line items to insert into
recetas_medicas. Each item: medicamento (required), dosis (required), frecuencia (required), duracion (required), via_administracion (optional), indicaciones (optional).Array of exam orders to insert into
ordenes_examenes. Each item: tipo_examen (required), nombre_examen (required), justificacion_clinica (optional)."Historia, recetas y exámenes guardados exitosamente."The newly created clinical record.
medicamentos_recetados is returned as the unwrapped plain text string.POST /historias/:id/aclaracion
Appends a clarification or evolution note (nota_aclaracion / nota_evolucion) to an existing primary clinical record. Both this route and PUT /historias/:id map to the same actualizarHistoria controller and accept the same request body. Only the original authoring physician may add notes.
Authentication: verifyToken + isMedico
The primary clinical record to annotate (
tipo_registro = historia_principal).Note type:
nota_aclaracion or nota_evolucion.Reason for this note (e.g. summary of the clarification).
Signing physician’s full name.
Signing physician’s RETHUS number.
Updated or supplementary anamnesis.
Updated physical examination findings.
Updated ICD-10 code.
Updated diagnosis description.
Updated treatment plan.
Updated free-text prescription summary.
Updated weight (kg).
Updated height (cm).
imc is recalculated automatically.Additional observations.
Signing physician’s national ID.
New prescription line items to attach to this note.
New exam orders to attach to this note.
"Nota de aclaración/evolución registrada exitosamente."The newly created note record with
medicamentos_recetados unwrapped to plain text.PUT /historias/:id
Alternative route for adding an evolution or clarification note. Accepts the identical request body asPOST /historias/:id/aclaracion and routes to the same actualizarHistoria controller. Use whichever HTTP method is more natural for your client.
Authentication: verifyToken + isMedico
The primary clinical record to annotate.
POST /historias/:id/aclaracion — see that section for the full field list.
"Nota de aclaración/evolución registrada exitosamente."The newly created note record.
PATCH /historias/gestionar-cita/:id
Allows a physician to update the status of one of their appointments tocompletada or no_asistio, optionally recording medical notes.
Authentication: verifyToken + isMedico
The appointment ID to manage.
New appointment status. Accepted values:
completada, no_asistio.Optional clinical notes to record alongside the status update.
"✅ Cita completada." or "📋 Paciente ausente."Document Endpoints
Clinical documents (lab results, imaging reports, referrals, external records) are stored separately from structured histories in thedocumentos_clinicos table and linked to patients by id_paciente. Patients may only upload documento_externo type; physicians may upload formula_medica, orden_examen, and historia_clinica types. Medical documents (origen = 'medico') are immutable — they can never be hidden or deleted.
GET /historias/documentos/paciente/:id_paciente
Lists all clinical documents on file for a patient. When the requesting user is a patient, documents whereoculto_paciente = TRUE are automatically excluded from the response.
Authentication: verifyToken
The patient whose documents to retrieve.
Document identifier.
Linked clinical history ID (nullable).
Owning patient’s identifier.
Uploading physician’s ID (nullable for patient-uploaded documents).
Document type:
historia_clinica, formula_medica, orden_examen, or documento_externo.Who uploaded the document:
medico or paciente.Original filename (nullable).
URL to the stored document file.
Human-readable document description.
Whether the patient has hidden this document from their view.
First name of the uploading physician (joined from
usuarios).First name of the owning patient (joined from
usuarios).GET /historias/documentos/:id
Retrieves a single clinical document by its ID, with joined physician and patient name fields. Authentication:verifyToken
The document’s unique identifier.
Document identifier.
Owning patient’s identifier.
Document type.
medico or paciente.URL to the file.
Document description.
Visibility flag.
POST /historias/documentos
Registers a new clinical document. Required fields depend on the caller’s role: patients may only registerdocumento_externo for themselves; physicians may register formula_medica, orden_examen, or historia_clinica for patients under their care.
Authentication: verifyToken
The patient this document belongs to.
Document type. Patient-allowed:
documento_externo. Physician-allowed: formula_medica, orden_examen, historia_clinica.Full URL pointing to the stored document file (e.g. a cloud storage URL).
ID of the linked clinical history (optional).
Original filename of the document.
A brief human-readable description of the document contents.
"Documento registrado."The newly created document object including its auto-generated
id and all persisted fields.PATCH /historias/documentos/:id/ocultar
Allows a patient to hide one of their own externally uploaded documents (origen = 'paciente'). Once hidden, the document remains in the database but is excluded from patient-facing document lists. Physician-uploaded documents (origen = 'medico') cannot be hidden.
Authentication: verifyToken + isPaciente
The ID of the document to hide. Must belong to the authenticated patient and have
origen = 'paciente'."Ocultado."Hiding is a one-way patient action — it sets
oculto_paciente = TRUE. There is no unhide route. Physicians and administrators may still access hidden documents through privileged views.