Spaces:
Runtime error
Runtime error
Download app/integrations/monitoreo.py from MateFerreyra/Modulo-6: direct link, hf CLI and curl.
- Browser
- Download file 2.06 kB
-
https://huggingface.co/spaces/MateFerreyra/Modulo-6/resolve/main/app/integrations/monitoreo.py
- Command line
-
hf download hf://spaces/MateFerreyra/Modulo-6/app/integrations/monitoreo.py
-
curl -L -o monitoreo.py https://huggingface.co/spaces/MateFerreyra/Modulo-6/resolve/main/app/integrations/monitoreo.py
2.06 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) -> bool: | |
| """ | |
| Además del webhook REST directo (sin cambios), publica el mismo evento al bus del | |
| Core (ALTA_MONITOREO) vía `core_events.publish_event`. Es un no-op mientras | |
| `monitoreo_alta_event_type_id` no esté configurado — M9 todavía no compartió su | |
| `event_type_id` real (ver `M6_DISEÑO.md` §7). | |
| """ | |
| if settings.mock_external_services: | |
| return True | |
| payload = { | |
| "evento": "ALTA_MONITOREO", | |
| "paciente_id": paciente_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) -> bool: | |
| """Mismo esquema que `notify_alta`, para BAJA_MONITOREO.""" | |
| 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, | |
| "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 | |