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 Ingresos (Program Entries) API manages patient enrollment cycles in the sleep apnea program. Each Ingreso represents a 18-month program cycle with status tracking and lifecycle management.Ingreso endpoints are part of the Patients API module but warrant separate documentation due to their critical role in organizing clinical data.
Concepts
Ingreso Model
Fromapps/patients/models.py:153:
An Ingreso represents a program enrollment cycle with:
- Duration: 18 months maximum
- Status: ACTIVO, SUSPENDIDO, or TERMINADO
- Scope: Organizes all clinical exam data
- Calculation: Automatic mes_capita (month in program)
Mes Capita (Program Month)
Fromapps/patients/models.py:167-178:
Patient-Ingreso Relationship
- One patient can have multiple Ingresos (sequential program cycles)
- Only one Ingreso can be ACTIVO at a time per patient
- All clinical exams link to a specific Ingreso
- When starting a new cycle, previous exam data is archived
Endpoints
Change Ingreso Status
change_status_entry in apps/patients/views.py:169
URL Parameters
Ingreso’s unique identifier
New status value. Options:
ACTIVO, SUSPENDIDO, TERMINADOPOST Parameters (for TERMINADO status)
Program end date in YYYY-MM-DD format. Required when new_status is TERMINADO.
Reason for termination. Required when new_status is TERMINADO.
Implementation
Fromapps/patients/views.py:179-186:
Response
Success (302): Redirects to/patients/follow with success message
Status Transition Rules
Active program entry. Patient can have exams registered. Only one per patient.
Suspended entry. Temporary pause in program. Can be reactivated.
Terminated entry. Requires fecha_fin and motivo. Cannot be reactivated. Exam data is archived.
Create New Entry (Ingreso)
create_new_entry in apps/patients/views.py:193
URL Parameters
Patient’s unique identifier
POST Parameters
Program start date in YYYY-MM-DD format.
Validation Logic
Fromapps/patients/views.py:208-214:
You cannot create a new Ingreso if the patient has any ACTIVO or SUSPENDIDO entries. All previous entries must be TERMINADO first.
Response
Success (302): Redirects to/patients/follow with success message
Validation Error (302): Redirects to /patients/follow with error message
Automatic Ingreso Creation
Note that when creating a new patient via/patients/create/, an Ingreso is automatically created:
From apps/patients/views.py:80-84:
Ingreso Model Structure
Fromapps/patients/models.py:153:
Fields
Auto-incrementing primary key
Links to Patient model. Related name:
ingresosProgram start date
Program end date. Null until status changes to TERMINADO.
Current status. Choices: ACTIVO, SUSPENDIDO, TERMINADO
Reason for status change (especially for TERMINADO). Optional.
Computed Property
Calculated month in program (1-18). Read-only property based on fecha_inicio and current date.
Related Names
Access from Patient object:Ingreso Lifecycle
Lifecycle Rules
-
Initial Creation
- New patients get automatic ACTIVO Ingreso
- fecha_inicio defaults to current date or specified date
- mes_capita starts at 1
-
Active State (ACTIVO)
- Only one ACTIVO Ingreso per patient
- All new exam data links to this Ingreso
- mes_capita increments monthly (1-18)
- Can transition to SUSPENDIDO or TERMINADO
-
Suspended State (SUSPENDIDO)
- Temporary program pause
- Blocks new Ingreso creation
- Can reactivate to ACTIVO
- Can terminate to TERMINADO
-
Terminated State (TERMINADO)
- Requires fecha_fin and motivo
- Cannot be changed back
- Exam data is archived (not shown in clinical view)
- Allows new Ingreso creation
Impact on Clinical Data
Exam Filtering
All exam views filter by active Ingreso: Fromapps/exams/views.py:23-36:
Data Isolation
When a patient starts a new program cycle (new Ingreso), all previous exam data is automatically hidden. The clinical history view only displays exams linked to the current ACTIVO Ingreso.
- Clean slate for new program cycles
- Historical data preservation
- No confusion between old and new treatment data
Historical Access
To access archived exam data from previous cycles:Integration Examples
Check if Patient Can Start New Cycle
Get Current Program Month
Terminate Program Entry
Common Patterns
Active Ingreso Check
Always check for active Ingreso before registering exams:Patient Properties
Use Patient model properties for quick checks:Best Practices
-
Status Transitions
- Always provide fecha_fin and motivo when terminating
- Validate no ACTIVO/SUSPENDIDO entries before creating new
- Use clear, descriptive motivo text for audit trail
-
Data Integrity
- Check ingreso_actual exists before exam registration
- Link all exams to appropriate Ingreso
- Preserve registrado_por for audit trail
-
User Experience
- Show mes_capita in patient lists and forms
- Indicate when patient approaching month 18
- Warn before terminating with active exams
-
Clinical Workflows
- Complete all pending exams before terminating
- Document termination reasons thoroughly
- Allow time between termination and new cycle creation
Related Endpoints
Patients API
Manage patient records that own Ingresos
Exams API
Clinical data filtered by Ingreso