Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/KevxxAlva/femesalud-zen-flow/llms.txt

Use this file to discover all available pages before exploring further.

The consultations table is the richest clinical object in FemeSalud. A consultation is always linked to a parent appointment and captures the full encounter record: chief complaint, complete vitals, systematic physical examination, colposcopy findings, obstetric control measurements, and the treatment plan including diagnosis, indications, and follow-up date. Because a consultation may also consume materials (gloves, swabs, reagents), consumable line items are stored in a child table (consultation_consumables) and are always written atomically with the consultation itself through dedicated Supabase RPC functions.
Consultations are never inserted or updated with direct table writes. All create and update operations must go through the create_consultation_rpc and update_consultation_rpc Supabase remote procedure calls. This ensures the consultation row and its consumables are always committed together in a single database transaction, preventing orphaned or mismatched records.

Visit Type Enum

export type VisitType =
  | "CONTROL"
  | "EMERGENCIA"
  | "CONSULTA_NUEVA"
  | "POST_TRATAMIENTO"
  | "OTRO";
ValueClinical meaning
CONSULTA_NUEVAFirst consultation for a new problem or episode.
CONTROLRoutine follow-up or monitoring visit.
EMERGENCIAUnscheduled urgent or emergency encounter.
POST_TRATAMIENTOPost-treatment review after a procedure or therapy.
OTROAny other visit type not covered above.

Core Identity Fields

id
uuid
required
Primary key. Auto-generated UUID returned by the RPC after a successful insert.
appointment_id
uuid
required
Foreign key to appointments.id. Each appointment can have at most one consultation. The has_consultation flag on AppointmentWithPatient reflects whether this link exists.
patient_id
uuid
required
Foreign key to patients.id. Denormalised from the appointment to allow direct patient-scoped queries without joining through appointments.
doctor_id
uuid
Foreign key to profiles.id. Nullable — may be null if the consultation was created by a user without a matching profile row.
visit_type
visit_type_enum
required
Classifies the clinical purpose of the visit. Defaults to CONSULTA_NUEVA on insert if not provided. See the VisitType enum above for accepted values.
is_first_visit
boolean
required
true when this is the patient’s first consultation at the clinic. Defaults to false. Used to auto-populate initial anamnesis sections in the UI.
subjective_exam
text
Subjective examination — the patient’s own description of their symptoms and concerns (anamnesis). Nullable.
contact_channel
text
Marketing or referral channel through which the patient first contacted the clinic (e.g. Instagram, Referido, Google). Nullable. Used in CRM and acquisition reports.

Vitals Fields

height_cm
number
Patient height in centimetres. Nullable.
weight_kg
number
Patient weight in kilograms. Nullable.
bmi
number
Body Mass Index. Nullable. May be auto-calculated in the UI from height_cm and weight_kg, but is stored as a separate column so it can be queried directly.
blood_pressure
text
Arterial blood pressure as a free-text string in systolic/diastolic format (e.g. "120/80"). Nullable.
heart_rate
number
Heart rate in beats per minute. Nullable.
respiratory_rate
number
Respiratory rate in breaths per minute. Nullable.
temperature
number
Body temperature in degrees Celsius. Nullable.

Physical Examination Fields

All physical exam fields are nullable free-text strings describing findings for each body system.
skin
text
Skin examination findings. Nullable.
head_neck
text
Head and neck examination findings. Nullable.
breasts
text
Breast examination findings. Nullable.
abdomen
text
Abdominal examination findings. Nullable.
gynecological
text
Gynecological examination findings (speculum, bimanual). Nullable.
extremities
text
Extremities examination findings. Nullable.
neurological
text
Neurological examination findings. Nullable.

Colposcopy Fields

Colposcopy fields are populated when the visit includes a colposcopic procedure. All fields are nullable.
acetic_acid_test
text
Result or description of the acetic acid (VIA) test finding. Nullable.
acetic_clock_position
text
Clock-face position of the acetic acid finding on the cervix (e.g. "3"). Nullable.
acetic_relative_position
text
Relative anatomical position of the acetic acid finding (e.g. "anterior lip"). Nullable.
lugol_test
text
Result or description of the Lugol’s iodine (VILI) test finding. Nullable.
lugol_clock_position
text
Clock-face position of the Lugol finding on the cervix. Nullable.
lugol_relative_position
text
Relative anatomical position of the Lugol finding. Nullable.

Obstetric Control Fields

These fields are used during prenatal or obstetric follow-up consultations. All fields are nullable.
gestational_age
text
Gestational age at the time of the visit (e.g. "28 weeks + 3 days"). Stored as text to accommodate mixed formats. Nullable.
fetal_weight
number
Estimated fetal weight in grams. Nullable.
obstetric_bp
text
Obstetric blood pressure reading in systolic/diastolic format. Separate from the general blood_pressure vital to allow independent tracking. Nullable.
uterine_height
number
Uterine fundal height in centimetres measured by tape measure. Nullable.
presentation
text
Fetal presentation (e.g. cefálica, podálica, transversa). Nullable.
fetal_heart_rate
number
Fetal heart rate in beats per minute. Nullable.
fetal_movements
text
Description of fetal movement activity as reported by the patient or observed. Nullable.
edema
text
Presence and severity of oedema (e.g. "No", "+/+++"). Nullable.
alarm_signs
text
Presence and description of obstetric alarm signs. Nullable.

Treatment & Plan Fields

diagnosis
text
Clinical diagnosis or differential diagnosis at the end of the encounter. Nullable.
indications
text
Prescription or treatment indications given to the patient. May be populated from a prescription_templates row. Nullable.
complementary_exams
text
Additional examinations or tests ordered during the consultation (labs, imaging, etc.). Nullable.
plan
text
Overall clinical management plan narrative. Nullable.
next_appointment_date
date string
ISO 8601 date (YYYY-MM-DD) suggested for the patient’s next visit. Nullable.

Audit Fields

created_at
timestamptz
required
Timestamp set automatically by the database when the consultation is first created.
updated_at
timestamptz
required
Timestamp updated automatically on each modification.

ConsultationConsumable Sub-table

Materials used during a consultation are stored in the consultation_consumables table. Rows in this table are always replaced wholesale when a consultation is updated — the RPC deletes existing consumables and inserts the new set in the same transaction.
id
uuid
required
Primary key. Auto-generated UUID.
consultation_id
uuid
required
Foreign key to consultations.id. Links the consumable to its parent consultation.
item_name
text
required
Name of the material or supply item used (e.g. "Guantes de látex", "Ácido acético 5%").
quantity
number
required
Quantity of the item consumed. Defaults to 1.
unit
text
Unit of measure (e.g. "par", "ml", "unidad"). Nullable.
created_at
timestamptz
required
Timestamp set automatically when the row is inserted.
The TypeScript interface mirroring this table is:
export interface ConsultationConsumable {
  id?: string;
  consultation_id?: string;
  item_name: string;
  quantity: number;
  unit: string | null;
}

Supabase RPCs

create_consultation_rpc

Creates a new consultation and its associated consumables in a single database transaction.
const { data, error } = await supabase.rpc("create_consultation_rpc", {
  p_consultation: consultationData, // ConsultationInput (without consumables)
  p_consumables: consumables,       // ConsultationConsumable[] (without id/consultation_id)
});
Returns the newly created Consultation object, including the generated id.

update_consultation_rpc

Updates an existing consultation’s fields and replaces all its consumables atomically.
const { data, error } = await supabase.rpc("update_consultation_rpc", {
  p_consultation_id: id,  // uuid of the consultation to update
  p_patch: patch,         // Partial<ConsultationInput> — only changed fields
  p_consumables: consumables, // Full new list of ConsultationConsumable[]
});
The existing consultation_consumables rows are deleted and re-inserted within the same transaction, so the consumables list is always consistent with the patch. Passing an empty array clears all consumables.
Because both RPCs are transactional, a failure in either the consultation write or the consumables write rolls back the entire operation. The client will receive a Supabase PostgrestError and no partial data will be committed to the database.

Build docs developers (and LLMs) love