Download app/integrations/monitoreo.py from Modulo-6/api: direct link, hf CLI and curl.
- Browser
- Download file 2.42 kB
-
https://huggingface.co/spaces/Modulo-6/api/resolve/main/app/integrations/monitoreo.py
- Command line
-
hf download hf://spaces/Modulo-6/api/app/integrations/monitoreo.py
-
curl -L -o monitoreo.py https://huggingface.co/spaces/Modulo-6/api/resolve/main/app/integrations/monitoreo.py
2.42 kB
| """ | |
| M9 Monitoreo — altas y bajas de pacientes en monitoreo. | |
| """ | |
| from datetime import datetime, timezone | |
| from app.config import settings | |
| from app.integrations import core_events | |
| from app.integrations._base import _post | |
| def notify_alta(paciente_id: int, cama_id: int | None = None) -> bool: | |
| """ | |
| Además del webhook REST directo (sin cambios), publica el mismo evento al bus del | |
| Core (ALTA_MONITOREO, event_type_id=26) vía `core_events.publish_event`. | |
| `cama_id`: la cama a la que se asocia el ingreso a monitoreo — la cama destino en un | |
| ingreso o traslado (ver call sites en `solicitud_service.py`/`cama_service.py`). | |
| """ | |
| if settings.mock_external_services: | |
| return True | |
| payload = { | |
| "evento": "ALTA_MONITOREO", | |
| "paciente_id": paciente_id, | |
| "cama_id": cama_id, | |
| "timestamp": datetime.now(timezone.utc).isoformat(), | |
| } | |
| # Canal primario: evento via M10 Core. Backup HTTP si falla o no está configurado. | |
| event_type_id = settings.monitoreo_alta_event_type_id | |
| if event_type_id is not None: | |
| ok_event = core_events.publish_event(event_type_id, payload) | |
| if ok_event: | |
| return True | |
| return _post( | |
| f"{settings.m9_monitoreo_url}/api/v1/webhooks/internacion/alta-monitoreo", payload | |
| ) is not None | |
| def notify_baja(paciente_id: int, cama_id: int | None = None) -> bool: | |
| """ | |
| Mismo esquema que `notify_alta`, para BAJA_MONITOREO (event_type_id=27). | |
| `cama_id`: la cama que el paciente deja — la cama origen en un traslado, o la cama que | |
| se libera en un alta médica (ver call sites en `solicitud_service.py`/`cama_service.py`). | |
| """ | |
| if settings.mock_external_services: | |
| print(f"[SIMULACION] Request a M9 Monitoreo → baja de paciente {paciente_id}") | |
| return True | |
| payload = { | |
| "evento": "BAJA_MONITOREO", | |
| "paciente_id": paciente_id, | |
| "cama_id": cama_id, | |
| "timestamp": datetime.now(timezone.utc).isoformat(), | |
| } | |
| # Canal primario: evento via M10 Core. Backup HTTP si falla o no está configurado. | |
| event_type_id = settings.monitoreo_baja_event_type_id | |
| if event_type_id is not None: | |
| ok_event = core_events.publish_event(event_type_id, payload) | |
| if ok_event: | |
| return True | |
| return _post( | |
| f"{settings.m9_monitoreo_url}/api/v1/webhooks/internacion/baja-monitoreo", payload | |
| ) is not None | |