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 Patients API provides endpoints for creating, viewing, updating, and searching patient records. All endpoints require authentication. Base Path: /patients/

Endpoints

List Patients

GET /patients/
Retrieve a paginated list of patients with active program entries. Supports search and filtering. View Function: patients_list in apps/patients/views.py:13

Query Parameters

Search term to filter by patient name (nombre), last name (apellido), or document number (documento). Case-insensitive partial matching.
mes_filtro
integer
Filter by current month in program (mes_capita). Valid values: 1-18.
page
integer
default:"1"
Page number for pagination. Returns 10 patients per page.

Response

Returns HTML template with:
page_obj
Paginator object
Django paginator containing patient records
object_list
array
List of Patient objects for current page
has_next
boolean
Whether there are more pages
has_previous
boolean
Whether there are previous pages
rango_meses
range
Range object (1-19) for month filter options
query
string
Current search query value
mes_filtro
string
Current month filter value

Example Request

curl -X GET "https://your-domain.com/patients/?query_search=Juan&mes_filtro=3&page=1" \
  -H "Cookie: sessionid=your-session-id"

Implementation Notes

  • Only returns patients with ingresos__estado='ACTIVO'
  • Uses distinct() to avoid duplicate results from JOIN
  • Month filter (mes_capita) requires iteration as it’s a model property
  • Optimized for Render deployment with 10 items per page

Create Patient

GET  /patients/create/
POST /patients/create/
Display patient creation form (GET) or create a new patient (POST). Automatically creates an active Ingreso entry. View Function: create_patient in apps/patients/views.py:63

POST Parameters

All parameters are form-encoded. Required fields marked with *:
nombre
string
required
Patient’s first name. Max 100 characters.
apellido
string
required
Patient’s last name. Max 100 characters.
tipo_documento
string
required
Document type. Options: RC, TI, CC, CE, PA, PE
documento
string
required
Unique document number. Max 20 characters.
fecha_nacimiento
date
required
Birth date in YYYY-MM-DD format.
genero
string
required
Gender. Options: M (Masculino), F (Femenino), O (Otro)
departamento
string
default:"SANTANDER"
Colombian department. See full list in models.py:17-50.
ciudad
string
required
City name. See available options in models.py:52-95.
zona
string
required
Residential zone. Options: URBANA, RURAL
telefono
string
required
Phone number. Max 20 characters.
celular
string
required
Mobile number. Max 20 characters.
estado_civil
string
required
Marital status. Options: SOLTERO, CASADO, UNIÓN LIBRE, VIUDO, DIVORCIADO
entidad_salud
string
required
Health entity. Options: ECOPETROL, SANITAS
estrato
integer
required
Socioeconomic stratum. Options: 1-6.
peso
decimal
Weight in kilograms. Max 5 digits, 2 decimal places.
altura
decimal
Height in meters. Max 4 digits, 2 decimal places.
perimetro_abdominal
decimal
Abdominal perimeter in cm. Max 5 digits, 2 decimal places.
cuello
decimal
Neck circumference in cm. Max 5 digits, 2 decimal places.
medico_remitente
string
required
Referring physician name. Max 100 characters.
especialidad
string
required
Physician specialty. Max 100 characters.
diagnostico_clinico
string
required
Clinical diagnosis. Currently only supports: G47.3 (Apnea del Sueño)
programa
string
required
Program type. Options: PROGRAMA AOS, PROGRAMA INSOMNIO
valor_capita
decimal
default:"259783"
Capita value. Max 10 digits, 2 decimal places.
fecha_inicio_programa
date
Program start date (for Ingreso). Defaults to current date if not provided.

Response

Success (302): Redirects to /patients/ with success message Validation Error (200): Re-displays form with error messages

Automatic Ingreso Creation

From apps/patients/views.py:80-84:
Ingreso.objects.create(
    paciente=patient,
    fecha_inicio=fecha_ingreso,
    estado='ACTIVO'
)
Every new patient automatically gets an active Ingreso entry with:
  • estado='ACTIVO'
  • fecha_inicio from form or current date
  • mes_capita calculated as 1

Get Patient Details

GET  /patients/<int:patient_id>/
POST /patients/<int:patient_id>/
View patient details and edit form (GET) or update patient data (POST). View Function: patient_detail in apps/patients/views.py:97

URL Parameters

patient_id
integer
required
Patient’s unique identifier

POST Parameters

Accepts same parameters as Create Patient endpoint. Updates existing patient record.

Response

Returns HTML template with:
patient
Patient object
Complete patient record
form
PatientForm
Pre-filled form for editing
ingreso_actual
Ingreso object
Current active Ingreso entry (estado=‘ACTIVO’)

Ingreso Date Update

From apps/patients/views.py:112-115:
nueva_fecha = form.cleaned_data.get('fecha_inicio_programa')
if ingreso_actual:
    ingreso_actual.fecha_inicio = nueva_fecha
    ingreso_actual.save()
Updating fecha_inicio_programa also updates the active Ingreso’s start date.

List Followups (Ingresos Manager)

GET /patients/follow
View all patients with their program entries (ingresos) for followup management. View Function: followups_manager in apps/patients/views.py:136

Query Parameters

query_search
string
Search by document, nombre, or apellido. Case-insensitive.
page
integer
default:"1"
Page number. Returns 10 patients per page.

Response

page_obj
Paginator object
Paginated patient list with prefetched ingresos
query
string
Current search query
total_count
integer
Total number of matching patients

Optimization

Uses prefetch_related('ingresos') to avoid N+1 queries when displaying multiple ingresos per patient.

Patient Model Structure

From apps/patients/models.py:6:

Core Fields

  • id - Auto-incrementing primary key
  • nombre - First name (CharField, max 100)
  • apellido - Last name (CharField, max 100)
  • tipo_documento - Document type (choices)
  • documento - Document number (CharField, unique, max 20)
  • fecha_nacimiento - Birth date (DateField)
  • genero - Gender (choices)

Contact & Location

  • departamento - Colombian department (choices)
  • ciudad - City (choices)
  • zona - Urban/Rural (choices)
  • telefono - Phone (CharField, max 20)
  • celular - Mobile (CharField, max 20)
  • estado_civil - Marital status (choices)

Medical Data

  • peso - Weight in kg (DecimalField, 5,2)
  • altura - Height in meters (DecimalField, 4,2)
  • perimetro_abdominal - Abdominal perimeter in cm (DecimalField, 5,2)
  • cuello - Neck circumference in cm (DecimalField, 5,2)
  • diagnostico_clinico - Clinical diagnosis (choices)
  • medico_remitente - Referring physician (CharField, max 100)
  • especialidad - Specialty (CharField, max 100)

Program Information

  • entidad_salud - Health entity (choices)
  • estrato - Socioeconomic stratum (IntegerField, 1-6)
  • programa - Program type (choices)
  • valor_capita - Capita value (DecimalField, 10,2, default 259783)

Computed Properties

From apps/patients/models.py:128-146:
@property
def ingreso_activo(self):
    """Returns the active Ingreso or None"""
    return self.ingresos.filter(estado='ACTIVO').first()

@property
def esta_activo(self):
    """Returns True if patient has an active Ingreso"""
    return self.ingresos.filter(estado='ACTIVO').exists()

@property
def edad(self):
    """Calculates current age from fecha_nacimiento"""
    # Age calculation logic

Ingresos API

Manage patient program entries and status changes

Exams API

View clinical data for patients

Build docs developers (and LLMs) love