Documentation Index
Fetch the complete documentation index at: https://mintlify.com/diegolozadev/DataMed/llms.txt
Use this file to discover all available pages before exploring further.
Database Schema
DataMed uses a relational database (PostgreSQL in production, SQLite in development) with a carefully designed schema to manage patient data, clinical exams, and program cycles.Core Models Overview
DataMed’s data model consists of three primary components:- Patient Management: Patient demographics and enrollment
- Program Cycles: Ingreso model for 18-month capita cycles
- Clinical Exams: Multiple exam types linked to cycles
Entity Relationship Diagram
Patient Model
The foundational model storing patient demographics and clinical baseline data.Fields
Patient’s first name
Patient’s last name
Document type: RC, TI, CC, CE, PA, PE
Unique document number (primary identifier)
Date of birth
Gender: M (Masculino), F (Femenino), O (Otro)
Colombian department (default: SANTANDER)
City from predefined list
URBANA or RURAL
Home phone number
Mobile phone number
Marital status: SOLTERO, CASADO, UNIÓN LIBRE, VIUDO, DIVORCIADO
Health insurance provider (EPS): ECOPETROL, SANITAS
Socioeconomic stratum (1-6)
Weight in kilograms
Height in meters
Abdominal circumference in centimeters
Neck circumference in centimeters
Referring physician name
Physician’s specialty
Clinical diagnosis (currently limited to G47.3 - Sleep Apnea)
Program: PROGRAMA AOS or PROGRAMA INSOMNIO
Capita value (default: 259783)
Computed Properties
apps/patients/models.py
Ingreso Model
Represents a patient’s enrollment in an 18-month program cycle. Critical for data organization.Fields
Related patient (CASCADE delete)
Program start date
Program end date (null until terminated)
Status: ACTIVO, SUSPENDIDO, TERMINADO (default: ACTIVO)
Reason for status change or termination
Computed Property: mes_capita
Automatically calculates current program month (1-18):apps/patients/models.py
Design Pattern: Data Isolation
All clinical exams are linked to anIngreso, not directly to Patient. This ensures:
- Historical data preservation when cycles close
- Clean separation between program cycles
- Accurate capita month tracking
Clinical Exam Models
Monitoreo (CPAP/BiPAP Monitoring)
Tracks device usage and treatment effectiveness. Key Fields:uso_diario: Daily usage percentagedias_uso_horas_4: Days with ≥4 hours usagehipopnea_basal: Baseline AHI (copied from PSG Basal)hipopnea_residual: Residual AHI with treatmentporcentaje_correccion: Auto-calculated((basal - residual) / basal) * 100modo_ventilatorio: CPAP, BPAP, BPAP STpresion_ipap,presion_epap: Pressure settingsmascara_cpap,tamano_mascara: Mask type and size
PolisomnografiaBasal (Diagnostic Sleep Study)
Baseline polysomnography before treatment. Key Fields:fecha_basal: Study dateiah: Apnea-Hypopnea Indexseveridad_apnea: LEVE, MODERADA, GRAVE, NORMALido: Oxygen Desaturation Indexeficiencia: Sleep efficiency percentage
PolisomnografiaTitulacion (Pressure Titration Study)
Sleep study to determine optimal device settings. Key Fields:tipo_titulacion: CPAP, BPAP, BPAP STfecha_titulacion: Study datepresion_ipap,presion_epap: Titrated pressuresfrecuencia_respiratoria: Respiratory rate (rpm)talla_mascara,tipo_mascara: Mask configuration
Psicologia (Psychology Assessment)
Mental health screening for sleep disorder patients. Key Fields:inventario_depre_beck: Beck Depression Inventory (0-63)inventario_ansiedad_beck: Beck Anxiety Inventory (0-63)escala_atenas: Athens Insomnia Scale (1-10)
Nutricion (Nutrition Consultation)
Dietary and nutritional assessment. Key Fields:estado_nutricional: DESNUTRICIÓN to OBESIDAD IIIcarbohidratos_pct: Carbohydrate percentagerumiacion: SI/NO for nocturnal ruminationcafeina: Caffeine consumption (mg/day)
Neumologia (Pulmonology Consultation)
Specialist respiratory consultation tracking. Key Fields:fecha_consulta: Consultation datemedico_tratante: Physician nameespecialidad: Medical specialty
EquipoMedico (Medical Equipment)
Device and mask assignment tracking. Key Fields:tipo_mascara_eq_medico: PILLOW NASAL, NASAL, ORONASALreferencia_mascara: Mask model referencetalla_mascara: S, M, Lmarca_equipo: BMC, RESMED, PHILIPS RESPIRONICS, etc.serial_equipo: Device serial numbermodo_ventilatorio: CPAP, BiPAP, BiPAP ST
Seguimiento (Follow-up Tracking)
General follow-up appointment records. Key Fields:fecha_atencion: Service datetipo_servicio: Type of service provided
SeguimientoAdaptacion (Adaptation Notes)
Detailed notes on patient adaptation to treatment. Key Fields:observaciones: Detailed text observationscreated_at: Timestamp (auto)
Common Patterns
User Tracking
All clinical exam models track who registered the data:- Audit trail for all clinical data
- User info preserved even if account deleted (
SET_NULL) - Query all exams registered by a user:
user.monitoreos_registrados.all()
Timestamps
All exam models have automatic timestamps:Related Name Conventions
- Patient → Ingresos:
patient.ingresos.all() - Ingreso → Monitoreos:
ingreso.monitoreos.all() - Ingreso → Psicologias:
ingreso.psicologias.all()
Indexes and Performance
Automatic Indexes
Django creates indexes for:- Primary keys (
id) - Foreign keys (all relationships)
- Unique fields (
documento)
Query Optimization
Database Migrations
DataMed uses Django migrations to evolve the schema. Key migrations:0001_initial.py: Initial Patient model0003_ingreso.py: Added Ingreso model for cycles0007_polisomnografiatitulacion_polisomnografiabasal_...: Sleep study models0016_remove_equipomedico_patient_...: Migrated to Ingreso-based relationships
Data Integrity
Constraints
- Unique constraint:
Patient.documento - Required fields: Most fields have
null=False, blank=False - Cascading deletes: Most relationships use
CASCADE - Soft deletes: Users use
SET_NULLto preserve audit trail
Validation
Django enforces:- Field length limits
- Choice constraints (e.g., estado must be ACTIVO/SUSPENDIDO/TERMINADO)
- Foreign key integrity
Next Steps
Migrations
Learn how to manage schema changes
Backup & Restore
Protect your data with backups
API Reference
Query and manipulate data via Django views
Patient Management
Understand patient lifecycle workflows