Merge pull request #13 from MateFerreyra/jps/integracion-M10
Browse files- .authtest.md.swp +0 -0
- app/main.py +28 -2
- documentation/end_to_end_tests/flujo_internacion_completo.md +213 -0
- documentation/openapi_m1.json +0 -0
.authtest.md.swp
ADDED
|
Binary file (1.02 kB). View file
|
|
|
app/main.py
CHANGED
|
@@ -7,12 +7,12 @@ import asyncio
|
|
| 7 |
import contextlib
|
| 8 |
import logging
|
| 9 |
from contextlib import asynccontextmanager
|
| 10 |
-
from fastapi import FastAPI, Request, status
|
| 11 |
from fastapi.middleware.cors import CORSMiddleware
|
| 12 |
from fastapi.responses import JSONResponse
|
| 13 |
|
| 14 |
from app.config import settings
|
| 15 |
-
from app.dependencies import create_access_token
|
| 16 |
from app.integrations import rabbit_consumer
|
| 17 |
|
| 18 |
from app.routers import auth, camas, internal, quirofanos, solicitudes, webhooks, auditoria
|
|
@@ -126,6 +126,32 @@ def health():
|
|
| 126 |
return {"status": "ok", "module": "M6 - Internación "}
|
| 127 |
|
| 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
# ─── Manejadores de errores globales ───────────────────────────────────────
|
| 130 |
|
| 131 |
|
|
|
|
| 7 |
import contextlib
|
| 8 |
import logging
|
| 9 |
from contextlib import asynccontextmanager
|
| 10 |
+
from fastapi import Depends, FastAPI, Request, status
|
| 11 |
from fastapi.middleware.cors import CORSMiddleware
|
| 12 |
from fastapi.responses import JSONResponse
|
| 13 |
|
| 14 |
from app.config import settings
|
| 15 |
+
from app.dependencies import create_access_token, require_roles
|
| 16 |
from app.integrations import rabbit_consumer
|
| 17 |
|
| 18 |
from app.routers import auth, camas, internal, quirofanos, solicitudes, webhooks, auditoria
|
|
|
|
| 126 |
return {"status": "ok", "module": "M6 - Internación "}
|
| 127 |
|
| 128 |
|
| 129 |
+
# ─── Debug: ver qué valores resolvió pydantic-settings en este proceso ─────
|
| 130 |
+
|
| 131 |
+
_SECRET_FIELD_MARKERS = ("secret", "password", "key", "database_url")
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
@app.get(
|
| 135 |
+
f"{PREFIX}/_debug/settings",
|
| 136 |
+
tags=["Debug"],
|
| 137 |
+
summary="[DEBUG] Ver los valores reales que resolvió la app en este proceso",
|
| 138 |
+
)
|
| 139 |
+
def debug_settings(user: dict = Depends(require_roles("ADMINISTRATIVO"))):
|
| 140 |
+
"""
|
| 141 |
+
Para confirmar que una variable/secret cargada en HF Spaces realmente
|
| 142 |
+
llegó al proceso en ejecución (y no quedó vacía o desactualizada tras un
|
| 143 |
+
restart). Los campos sensibles (contraseñas, secrets, keys) no se
|
| 144 |
+
exponen en texto plano — solo si están seteados y su longitud.
|
| 145 |
+
"""
|
| 146 |
+
result = {}
|
| 147 |
+
for name, value in settings.model_dump().items():
|
| 148 |
+
if any(marker in name for marker in _SECRET_FIELD_MARKERS):
|
| 149 |
+
result[name] = f"***set (len={len(value)})***" if value else "*** EMPTY/MISSING ***"
|
| 150 |
+
else:
|
| 151 |
+
result[name] = value
|
| 152 |
+
return result
|
| 153 |
+
|
| 154 |
+
|
| 155 |
# ─── Manejadores de errores globales ───────────────────────────────────────
|
| 156 |
|
| 157 |
|
documentation/end_to_end_tests/flujo_internacion_completo.md
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
| 1 |
+
# E2E — Internación completa: HCE (M1) → solicitud → aprobación → alta → limpieza/facturación
|
| 2 |
+
|
| 3 |
+
Mock manual de punta a punta: trae los datos de un paciente real desde M1, dispara la
|
| 4 |
+
solicitud de internación sobre M6, la aprueba, y da de alta al paciente (cama pasa a
|
| 5 |
+
`EN_LIMPIEZA` y se notifica — mockeado — a Facturación/M7 y Monitoreo/M9).
|
| 6 |
+
|
| 7 |
+
> **Nota sobre "la cola de M6".** Hoy M6 no tiene un consumer de RabbitMQ corriendo:
|
| 8 |
+
> M1 llama directamente a los webhooks REST de M6 (`POST /webhooks/hce/...`), que son
|
| 9 |
+
> los que encolan la solicitud en estado `PENDIENTE` (la "cola" a la que se refiere
|
| 10 |
+
> `M6_DISEÑO.md`: `GET /solicitudes?estado=PENDIENTE`). Los pasos 2 y 4 de abajo son,
|
| 11 |
+
> en la práctica, esas llamadas REST — no una publicación a un exchange de RabbitMQ.
|
| 12 |
+
|
| 13 |
+
Requiere `MOCK_EXTERNAL_SERVICES=true` en M6 (default) para que las notificaciones
|
| 14 |
+
salientes a Core/M7/M9 no fallen por no tener esos servicios arriba, y
|
| 15 |
+
`ENVIRONMENT=development` para poder usar `GET /auth/token`.
|
| 16 |
+
|
| 17 |
+
## 0. Variables
|
| 18 |
+
|
| 19 |
+
```bash
|
| 20 |
+
export M1_URL="http://localhost:8001" # ajustar al M1 real / desplegado
|
| 21 |
+
export M6_URL="http://localhost:8000/api/v1"
|
| 22 |
+
|
| 23 |
+
export PACIENTE_ID=7
|
| 24 |
+
export CAMA_ID=101
|
| 25 |
+
export HOSPITAL_ID="HOSP-001"
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
---
|
| 29 |
+
|
| 30 |
+
## 1. [M1] Obtener datos del paciente
|
| 31 |
+
|
| 32 |
+
### 1.1 — Token de desarrollo de M1
|
| 33 |
+
|
| 34 |
+
```bash
|
| 35 |
+
M1_TOKEN=$(curl -s -X POST "$M1_URL/api/v1/dev/login" \
|
| 36 |
+
-H "Content-Type: application/json" \
|
| 37 |
+
-d '{}' | python3 -c "import sys,json; print(json.load(sys.stdin)['access_token'])")
|
| 38 |
+
|
| 39 |
+
echo "M1_TOKEN=$M1_TOKEN"
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
### 1.2 — Asegurar que el paciente de prueba existe en la caché de HCE
|
| 43 |
+
|
| 44 |
+
```bash
|
| 45 |
+
curl -s -X POST "$M1_URL/api/v1/dev/paciente?id_paciente=$PACIENTE_ID" \
|
| 46 |
+
-H "Authorization: Bearer $M1_TOKEN"
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
### 1.3 — Datos básicos del paciente
|
| 50 |
+
|
| 51 |
+
```bash
|
| 52 |
+
curl -s "$M1_URL/api/v1/pacientes/$PACIENTE_ID" \
|
| 53 |
+
-H "Authorization: Bearer $M1_TOKEN"
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
### 1.4 — Ficha médica (grupo sanguíneo, peso, altura, observaciones)
|
| 57 |
+
|
| 58 |
+
```bash
|
| 59 |
+
curl -s "$M1_URL/api/v1/pacientes/$PACIENTE_ID/ficha-medica" \
|
| 60 |
+
-H "Authorization: Bearer $M1_TOKEN"
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
### 1.5 — Antecedentes clínicos
|
| 64 |
+
|
| 65 |
+
```bash
|
| 66 |
+
curl -s "$M1_URL/api/v1/pacientes/$PACIENTE_ID/antecedentes" \
|
| 67 |
+
-H "Authorization: Bearer $M1_TOKEN"
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
### 1.6 — Alertas clínicas (posibles contraindicaciones a chequear contra la cama)
|
| 71 |
+
|
| 72 |
+
```bash
|
| 73 |
+
curl -s "$M1_URL/api/v1/pacientes/$PACIENTE_ID/alertas" \
|
| 74 |
+
-H "Authorization: Bearer $M1_TOKEN"
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
> Si 1.3–1.6 devuelven `404`/vacío, repetir 1.2 (el paciente de prueba no llegó a
|
| 78 |
+
> crearse en la caché local de M1) o crear ficha médica con
|
| 79 |
+
> `POST /api/v1/pacientes/{id}/ficha-medica` antes de continuar.
|
| 80 |
+
|
| 81 |
+
---
|
| 82 |
+
|
| 83 |
+
## 2. [M6] Publicar el evento de solicitud de internación
|
| 84 |
+
|
| 85 |
+
### 2.1 — Token de M6 (rol ADMINISTRATIVO — hace falta para el paso 3)
|
| 86 |
+
|
| 87 |
+
```bash
|
| 88 |
+
M6_TOKEN=$(curl -s "$M6_URL/auth/token?usuario=ADMINISTRATIVO&password=x" \
|
| 89 |
+
| python3 -c "import sys,json; print(json.load(sys.stdin)['access_token'])")
|
| 90 |
+
|
| 91 |
+
echo "M6_TOKEN=$M6_TOKEN"
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
### 2.2 — (Prerrequisito) crear la cama de destino si todavía no existe
|
| 95 |
+
|
| 96 |
+
```bash
|
| 97 |
+
curl -s -X POST "$M6_URL/camas" \
|
| 98 |
+
-H "Authorization: Bearer $M6_TOKEN" \
|
| 99 |
+
-H "Content-Type: application/json" \
|
| 100 |
+
-d '{
|
| 101 |
+
"numero": '"$CAMA_ID"',
|
| 102 |
+
"piso": 1,
|
| 103 |
+
"sector": "SALA_COMUN",
|
| 104 |
+
"tipo": "ESTANDAR",
|
| 105 |
+
"hospital_id": "'"$HOSPITAL_ID"'"
|
| 106 |
+
}'
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
Tiene que quedar en `estado: "DISPONIBLE"` — es el estado con el que se crea por default.
|
| 110 |
+
|
| 111 |
+
### 2.3 — Publicar el evento de solicitud (webhook entrante de M1)
|
| 112 |
+
|
| 113 |
+
```bash
|
| 114 |
+
curl -s -X POST "$M6_URL/webhooks/hce/solicitud" \
|
| 115 |
+
-H "Authorization: Bearer $M6_TOKEN" \
|
| 116 |
+
-H "Content-Type: application/json" \
|
| 117 |
+
-d '{
|
| 118 |
+
"tipo": "INTERNACION",
|
| 119 |
+
"solicitud_hce_id": "HCE-SOL-001",
|
| 120 |
+
"paciente_id": '"$PACIENTE_ID"',
|
| 121 |
+
"medico_solicitante_id": 10,
|
| 122 |
+
"cama_solicitada_id": '"$CAMA_ID"',
|
| 123 |
+
"origen": "GUARDIA",
|
| 124 |
+
"diagnostico_ingreso": "Neumonía adquirida en la comunidad",
|
| 125 |
+
"obra_social_id": "OSDE-210",
|
| 126 |
+
"numero_afiliado": "A-99887766",
|
| 127 |
+
"prioridad": "ALTA",
|
| 128 |
+
"hospital_id": "'"$HOSPITAL_ID"'",
|
| 129 |
+
"observaciones": "Paciente requiere oxígeno suplementario",
|
| 130 |
+
"timestamp": "'"$(date -u +%Y-%m-%dT%H:%M:%SZ)"'"
|
| 131 |
+
}'
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
Respuesta esperada (`200`):
|
| 135 |
+
|
| 136 |
+
```json
|
| 137 |
+
{
|
| 138 |
+
"mensaje": "Solicitud recibida y pendiente de aprobación",
|
| 139 |
+
"solicitud_id": "SOL-00001",
|
| 140 |
+
"estado": "PENDIENTE"
|
| 141 |
+
}
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
Guardar el `solicitud_id` devuelto:
|
| 145 |
+
|
| 146 |
+
```bash
|
| 147 |
+
export SOLICITUD_ID="SOL-00001"
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
---
|
| 151 |
+
|
| 152 |
+
## 3. [M6] Aprobar la solicitud
|
| 153 |
+
|
| 154 |
+
```bash
|
| 155 |
+
curl -s -X PATCH "$M6_URL/solicitudes/$SOLICITUD_ID" \
|
| 156 |
+
-H "Authorization: Bearer $M6_TOKEN" \
|
| 157 |
+
-H "Content-Type: application/json" \
|
| 158 |
+
-d '{"accion": "APROBAR"}'
|
| 159 |
+
```
|
| 160 |
+
|
| 161 |
+
Respuesta esperada (`200`): `estado: "APROBADA"`, `cama_asignada_id: 101`. Internamente
|
| 162 |
+
esto valida al paciente contra Core (`core.validate_patient`, mockeado), chequea
|
| 163 |
+
contraindicaciones contra `cama.contraindicaciones_incompatibles`, ocupa la cama
|
| 164 |
+
(`estado → OCUPADA`, `paciente_id` seteado) y notifica — mockeado — a HCE y Monitoreo.
|
| 165 |
+
|
| 166 |
+
Verificar la cama ocupada:
|
| 167 |
+
|
| 168 |
+
```bash
|
| 169 |
+
curl -s "$M6_URL/camas/$CAMA_ID" -H "Authorization: Bearer $M6_TOKEN"
|
| 170 |
+
```
|
| 171 |
+
|
| 172 |
+
---
|
| 173 |
+
|
| 174 |
+
## 4. [M6] Publicar el evento de alta médica
|
| 175 |
+
|
| 176 |
+
```bash
|
| 177 |
+
curl -s -X POST "$M6_URL/webhooks/hce/alta-medica" \
|
| 178 |
+
-H "Authorization: Bearer $M6_TOKEN" \
|
| 179 |
+
-H "Content-Type: application/json" \
|
| 180 |
+
-d '{
|
| 181 |
+
"paciente_id": '"$PACIENTE_ID"',
|
| 182 |
+
"medico_firmante_id": 10,
|
| 183 |
+
"tipo_alta": "ALTA_MEDICA",
|
| 184 |
+
"timestamp": "'"$(date -u +%Y-%m-%dT%H:%M:%SZ)"'"
|
| 185 |
+
}'
|
| 186 |
+
```
|
| 187 |
+
|
| 188 |
+
Respuesta esperada (`200`):
|
| 189 |
+
|
| 190 |
+
```json
|
| 191 |
+
{
|
| 192 |
+
"mensaje": "Alta médica procesada. Cama en limpieza.",
|
| 193 |
+
"cama_id": 101,
|
| 194 |
+
"estado_cama": "EN_LIMPIEZA"
|
| 195 |
+
}
|
| 196 |
+
```
|
| 197 |
+
|
| 198 |
+
Antes de mover la cama a `EN_LIMPIEZA`, M6 exige confirmación (mockeada si
|
| 199 |
+
`MOCK_EXTERNAL_SERVICES=true`) de:
|
| 200 |
+
- **Facturación (M7)** — `facturacion.notify_cierre_cama` (cierre de la internación).
|
| 201 |
+
- **Monitoreo (M9)** — `monitoreo.notify_baja` (baja del paciente monitoreado).
|
| 202 |
+
|
| 203 |
+
Si cualquiera de las dos falla (`502`), la cama no cambia de estado.
|
| 204 |
+
|
| 205 |
+
### Verificación final
|
| 206 |
+
|
| 207 |
+
```bash
|
| 208 |
+
curl -s "$M6_URL/camas/$CAMA_ID" -H "Authorization: Bearer $M6_TOKEN"
|
| 209 |
+
curl -s "$M6_URL/auditoria?cama_id=$CAMA_ID" -H "Authorization: Bearer $M6_TOKEN"
|
| 210 |
+
```
|
| 211 |
+
|
| 212 |
+
`GET /auditoria` debe mostrar la traza completa: `SOLICITUD_RECIBIDA` →
|
| 213 |
+
`SOLICITUD_APROBADA` → `CAMA_ASIGNADA` → `CAMA_ALTA`.
|
documentation/openapi_m1.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|