Skip to main content

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.

Overview

The Polysomnography module tracks comprehensive sleep study data for patients with sleep apnea. It consists of two distinct study types:

Basal Study

Initial diagnostic polysomnography to assess baseline sleep apnea severity

Titration Study

Pressure titration study to determine optimal CPAP/BiPAP settings
Both study types are linked to the patient’s active admission (ingreso) to ensure proper data organization across treatment cycles.

Basal Polysomnography

Model: PolisomnografiaBasal

The basal study establishes the patient’s baseline sleep apnea metrics before treatment begins. Location: apps/exams/models.py:184-224

Data Fields

fecha_basal
DateField
required
Date when the basal sleep study was conductedForm Label: “Fecha de Estudio Basal”
iah
DecimalField
required
Apnea-Hypopnea Index (AHI) - The number of apnea and hypopnea events per hour of sleep
  • Format: Decimal (5 digits, 2 decimal places)
  • Form Label: “Índice de Apneas (IAH)”
  • Clinical Significance: Primary diagnostic metric for sleep apnea severity
severidad_apnea
CharField
required
Clinical severity classification based on AHI scoreAvailable Choices:
  • NORMAL - Normal (no sleep apnea)
  • LEVE - Mild (AHI 5-15)
  • MODERADA - Moderate (AHI 15-30)
  • GRAVE - Severe (AHI > 30)
Form Label: “Severidad de Apneas”
ido
DecimalField
required
Oxygen Desaturation Index (ODI) - Average number of oxygen desaturation events per hour
  • Format: Decimal (5 digits, 2 decimal places)
  • Form Label: “IDO”
  • Clinical Significance: Measures oxygen deprivation during sleep
eficiencia
DecimalField
required
Sleep Efficiency - Percentage of time in bed actually spent sleeping
  • Format: Decimal (5 digits, 2 decimal places)
  • Form Label: “Eficiencia(%)”
  • Range: 0-100%

Relationships

ingreso
ForeignKey
Links to the patient’s active admission recordRelated Name: polisomnografias_basales
registrado_por
ForeignKey
User who registered this basal studyRelated Name: polisomnografias_basales_registradas

Registration Workflow

View: register_basal (apps/exams/views.py:217-242)
def register_basal(request, patient_id):
    patient = get_object_or_404(Patient, id=patient_id)
    ingreso_actual = patient.ingresos.filter(estado='ACTIVO').first()
    
    if request.method == 'POST':
        form = BasalForm(request.POST)
        if form.is_valid():
            basal = form.save(commit=False)
            basal.ingreso = ingreso_actual  # Link to active admission
            basal.registrado_por = request.user
            basal.save()
            return redirect('patient_clinical', patient_id=patient.id)
The basal IAH value is automatically used as a reference in the Monitoring module to calculate treatment correction percentage.

Titration Polysomnography

Model: PolisomnografiaTitulacion

The titration study determines the optimal pressure settings and mask configuration for PAP therapy. Location: apps/exams/models.py:228-289

Data Fields

fecha_titulacion
DateField
required
Date when the titration study was conductedForm Label: “Fecha de Estudio de Titulación”
tipo_titulacion
CharField
Type of positive airway pressure therapy titratedAvailable Choices:
  • CPAP - Continuous Positive Airway Pressure
  • BPAP - Bilevel Positive Airway Pressure
  • BPAP ST - BiPAP with Spontaneous/Timed backup rate
Form Label: “Tipo de Titulación”
presion_ipap
DecimalField
required
Inspiratory Positive Airway Pressure - Pressure delivered during inhalation
  • Format: Decimal (5 digits, 2 decimal places)
  • Unit: cmH₂O
  • Form Label: “Presión IPAP en Titulación”
  • Clinical Note: For CPAP mode, IPAP = EPAP (single pressure)
presion_epap
DecimalField
Expiratory Positive Airway Pressure - Pressure maintained during exhalation
  • Format: Decimal (5 digits, 2 decimal places)
  • Unit: cmH₂O
  • Form Label: “Presión EPAP en Titulación”
  • Optional: Only applicable for BiPAP modes
frecuencia_respiratoria
IntegerField
Respiratory Rate - Breaths per minute for BiPAP ST mode
  • Unit: Respirations per minute (rpm)
  • Form Label: “Frecuencia Respiratoria”
  • Optional: Only applicable for BiPAP ST mode
  • Help Text: “Respiraciones por minuto (rpm)“

Mask Configuration

tipo_mascara
CharField
required
Type of interface mask used during titrationAvailable Choices:
  • PILLOW NASAL - Nasal pillow (minimalist, inserted into nostrils)
  • NASAL - Nasal mask (covers nose only)
  • ORONASAL - Full face mask (covers nose and mouth)
Form Label: “Tipo Mascara” Default: “No especificado”
talla_mascara
CharField
required
Size of the mask fitted to the patientAvailable Choices:
  • SMALL - Small
  • MEDIUM - Medium
  • LARGE - Large
Form Label: “Talla Mascara” Default: “No especificado”

Relationships

ingreso
ForeignKey
Links to the patient’s active admission recordRelated Name: polisomnografias_titulaciones
registrado_por
ForeignKey
User who registered this titration studyRelated Name: polisomnografias_titulaciones_registradas

Registration Workflow

View: register_titulacion (apps/exams/views.py:247-272)
def register_titulacion(request, patient_id):
    patient = get_object_or_404(Patient, id=patient_id)
    ingreso_actual = patient.ingresos.filter(estado='ACTIVO').first()
    
    if request.method == 'POST':
        form = TitulacionForm(request.POST)
        if form.is_valid():
            titulacion = form.save(commit=False)
            titulacion.ingreso = ingreso_actual
            titulacion.registrado_por = request.user
            titulacion.save()
            return redirect('patient_clinical', patient_id=patient.id)

Clinical Workflow

Purpose: Establish baseline sleep apnea severity
  1. Conduct overnight polysomnography without treatment
  2. Record AHI, ODI, and sleep efficiency
  3. Classify severity (Normal/Mild/Moderate/Severe)
  4. Determine if PAP therapy is indicated
Key Metric: AHI determines treatment eligibility and severity classification
Purpose: Determine optimal PAP settings and mask fit
  1. Trial different pressure levels during sleep
  2. Test various mask types and sizes for comfort
  3. Record optimal IPAP/EPAP pressures
  4. Document respiratory rate for BiPAP ST if needed
Output: Prescription for home PAP therapy with specific settings
After titration, the determined settings are used to:
  • Configure the patient’s home PAP device (see Medical Equipment)
  • Provide the appropriately sized mask
  • Begin ongoing monitoring (see Monitoring)

Data Retrieval

Accessing Polysomnography Data

View: patient_clinical (apps/exams/views.py:12-58)
# Get all basal studies for active admission
basales = PolisomnografiaBasal.objects.filter(
    ingreso=ingreso_actual
).order_by('-id')

# Get all titration studies for active admission
titulaciones = PolisomnografiaTitulacion.objects.filter(
    ingreso=ingreso_actual
).order_by('-id')

# Get most recent basal IAH for monitoring reference
psg = PolisomnografiaBasal.objects.filter(
    ingreso=ingreso_actual
).last()
valor_basal = psg.iah if psg else 0
All polysomnography data is filtered by the patient’s active admission (estado='ACTIVO') to ensure data isolation between treatment cycles.

Clinical Significance

Apnea-Hypopnea Index (AHI)

The AHI is the gold standard for diagnosing and classifying sleep apnea:
SeverityAHI RangeClinical Significance
Normal< 5No sleep apnea
Mild5-15Minimal symptoms, lifestyle modifications may suffice
Moderate15-30Significant symptoms, PAP therapy recommended
Severe> 30High cardiovascular risk, immediate PAP therapy required

Oxygen Desaturation Index (ODI)

Measures how often blood oxygen drops ≥3% or ≥4% per hour:
  • Correlates with cardiovascular complications
  • Higher ODI indicates more severe oxygen deprivation
  • Used to assess treatment urgency

Sleep Efficiency

Percentage of time in bed actually spent sleeping:
  • Normal: 85-95%
  • Poor: < 85% (indicates sleep fragmentation)
  • Low efficiency suggests frequent awakenings from apnea events
The basal IAH value is automatically propagated to the Monitoring module at /exams/views.py:78-79, where it’s used to calculate treatment correction percentage.

Monitoring

Track treatment effectiveness using basal IAH as reference

Medical Equipment

Assign PAP devices using titration pressure settings

Pulmonology

Specialist consultations for complex cases

Build docs developers (and LLMs) love