Various fixes
Browse files- .DS_Store +0 -0
- .claude/settings.local.json +7 -1
- app/crud/solicitud.py +0 -2
- app/integrations/hce.py +18 -0
- app/main.py +2 -0
- app/routers/webhooks.py +3 -2
- app/schemas/cama.py +1 -1
- app/schemas/enums.py +2 -0
- app/services/cama_service.py +7 -1
- app/services/solicitud_service.py +9 -2
.DS_Store
CHANGED
|
Binary files a/.DS_Store and b/.DS_Store differ
|
|
|
.claude/settings.local.json
CHANGED
|
@@ -3,7 +3,13 @@
|
|
| 3 |
"allow": [
|
| 4 |
"Bash(Get-ChildItem -Recurse \"C:\\\\Users\\\\mateo\\\\OneDrive\\\\Documentos\\\\modulo6\" -Name)",
|
| 5 |
"Bash(Get-ChildItem -Path \"c:\\\\Users\\\\mateo\\\\OneDrive\\\\Documentos\\\\Modulo-6-backend\" -Force)",
|
| 6 |
-
"Bash(Select-Object Name, Mode)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
]
|
| 8 |
}
|
| 9 |
}
|
|
|
|
| 3 |
"allow": [
|
| 4 |
"Bash(Get-ChildItem -Recurse \"C:\\\\Users\\\\mateo\\\\OneDrive\\\\Documentos\\\\modulo6\" -Name)",
|
| 5 |
"Bash(Get-ChildItem -Path \"c:\\\\Users\\\\mateo\\\\OneDrive\\\\Documentos\\\\Modulo-6-backend\" -Force)",
|
| 6 |
+
"Bash(Select-Object Name, Mode)",
|
| 7 |
+
"Bash(python -m py_compile app/schemas/enums.py app/schemas/cama.py app/crud/solicitud.py app/services/cama_service.py app/services/solicitud_service.py app/integrations/hce.py app/routers/webhooks.py app/main.py)",
|
| 8 |
+
"Bash(python3 -m py_compile app/schemas/enums.py app/schemas/cama.py app/crud/solicitud.py app/services/cama_service.py app/services/solicitud_service.py app/integrations/hce.py app/routers/webhooks.py app/main.py)",
|
| 9 |
+
"Bash(git fetch *)",
|
| 10 |
+
"Bash(git stash *)",
|
| 11 |
+
"Bash(git pull *)",
|
| 12 |
+
"Bash(python3 -m py_compile app/main.py app/crud/solicitud.py app/integrations/hce.py app/routers/webhooks.py app/schemas/cama.py app/schemas/enums.py app/services/cama_service.py app/services/solicitud_service.py)"
|
| 13 |
]
|
| 14 |
}
|
| 15 |
}
|
app/crud/solicitud.py
CHANGED
|
@@ -24,8 +24,6 @@ def get_all(
|
|
| 24 |
q = db.query(Solicitud)
|
| 25 |
if estado:
|
| 26 |
q = q.filter(Solicitud.estado == estado)
|
| 27 |
-
else:
|
| 28 |
-
q = q.filter(Solicitud.estado == "PENDIENTE")
|
| 29 |
if tipo:
|
| 30 |
q = q.filter(Solicitud.tipo == tipo)
|
| 31 |
if hospital_id:
|
|
|
|
| 24 |
q = db.query(Solicitud)
|
| 25 |
if estado:
|
| 26 |
q = q.filter(Solicitud.estado == estado)
|
|
|
|
|
|
|
| 27 |
if tipo:
|
| 28 |
q = q.filter(Solicitud.tipo == tipo)
|
| 29 |
if hospital_id:
|
app/integrations/hce.py
CHANGED
|
@@ -37,6 +37,24 @@ def notify_evento_episodio(
|
|
| 37 |
) is not None
|
| 38 |
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
def notify_movimiento(
|
| 41 |
tipo_movimiento: str,
|
| 42 |
paciente_id: int,
|
|
|
|
| 37 |
) is not None
|
| 38 |
|
| 39 |
|
| 40 |
+
def notify_resultado_solicitud(
|
| 41 |
+
solicitud_hce_id: str,
|
| 42 |
+
resultado: str,
|
| 43 |
+
motivo: str | None = None,
|
| 44 |
+
) -> bool:
|
| 45 |
+
"""Notifica a M1 el resultado (APROBADA / RECHAZADA) de una solicitud. Retorna True si OK."""
|
| 46 |
+
if settings.mock_external_services:
|
| 47 |
+
return True
|
| 48 |
+
payload = {
|
| 49 |
+
"resultado": resultado,
|
| 50 |
+
"motivo": motivo,
|
| 51 |
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
| 52 |
+
}
|
| 53 |
+
return _post(
|
| 54 |
+
f"{settings.m1_hce_url}/api/v1/hce/solicitudes/{solicitud_hce_id}/resultado", payload
|
| 55 |
+
) is not None
|
| 56 |
+
|
| 57 |
+
|
| 58 |
def notify_movimiento(
|
| 59 |
tipo_movimiento: str,
|
| 60 |
paciente_id: int,
|
app/main.py
CHANGED
|
@@ -18,6 +18,7 @@ import app.models.solicitud # noqa: F401
|
|
| 18 |
import app.models.reserva # noqa: F401
|
| 19 |
|
| 20 |
from app.routers import camas, solicitudes, webhooks
|
|
|
|
| 21 |
|
| 22 |
logger = logging.getLogger(__name__)
|
| 23 |
|
|
@@ -64,6 +65,7 @@ PREFIX = "/api/v1"
|
|
| 64 |
app.include_router(camas.router, prefix=PREFIX)
|
| 65 |
app.include_router(solicitudes.router, prefix=PREFIX)
|
| 66 |
app.include_router(webhooks.router, prefix=PREFIX)
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
# βββ Endpoint de auth local (mock de M10 β solo para desarrollo) βββββββββββ
|
|
|
|
| 18 |
import app.models.reserva # noqa: F401
|
| 19 |
|
| 20 |
from app.routers import camas, solicitudes, webhooks
|
| 21 |
+
from app.routers.webhooks import router_turnos
|
| 22 |
|
| 23 |
logger = logging.getLogger(__name__)
|
| 24 |
|
|
|
|
| 65 |
app.include_router(camas.router, prefix=PREFIX)
|
| 66 |
app.include_router(solicitudes.router, prefix=PREFIX)
|
| 67 |
app.include_router(webhooks.router, prefix=PREFIX)
|
| 68 |
+
app.include_router(router_turnos, prefix=PREFIX)
|
| 69 |
|
| 70 |
|
| 71 |
# βββ Endpoint de auth local (mock de M10 β solo para desarrollo) βββββββββββ
|
app/routers/webhooks.py
CHANGED
|
@@ -23,6 +23,7 @@ from app.schemas.reserva import (
|
|
| 23 |
from app.services import solicitud_service, cama_service
|
| 24 |
|
| 25 |
router = APIRouter(prefix="/webhooks", tags=["Webhooks Entrantes"])
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
# βββ Desde M1 (HCE) ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -107,8 +108,8 @@ def recibir_cirugia_urgente(
|
|
| 107 |
|
| 108 |
# βββ Desde M2 (Turnos) βββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 109 |
|
| 110 |
-
@
|
| 111 |
-
"/turnos/{turno_id}/cancelacion
|
| 112 |
response_model=CancelacionQuirofanoResponse,
|
| 113 |
summary="[M2] Cancelar reserva de quirΓ³fano por turno",
|
| 114 |
responses={401: {"description": "No autenticado"}, 404: {"description": "Reserva no encontrada"}, 409: {"description": "Reserva no cancelable"}},
|
|
|
|
| 23 |
from app.services import solicitud_service, cama_service
|
| 24 |
|
| 25 |
router = APIRouter(prefix="/webhooks", tags=["Webhooks Entrantes"])
|
| 26 |
+
router_turnos = APIRouter(tags=["Webhooks Entrantes"])
|
| 27 |
|
| 28 |
|
| 29 |
# βββ Desde M1 (HCE) ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 108 |
|
| 109 |
# βββ Desde M2 (Turnos) βββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 110 |
|
| 111 |
+
@router_turnos.post(
|
| 112 |
+
"/turnos/{turno_id}/cancelacion",
|
| 113 |
response_model=CancelacionQuirofanoResponse,
|
| 114 |
summary="[M2] Cancelar reserva de quirΓ³fano por turno",
|
| 115 |
responses={401: {"description": "No autenticado"}, 404: {"description": "Reserva no encontrada"}, 409: {"description": "Reserva no cancelable"}},
|
app/schemas/cama.py
CHANGED
|
@@ -64,7 +64,7 @@ class AsignacionCamaResponse(BaseModel):
|
|
| 64 |
mensaje: str
|
| 65 |
cama_id: int
|
| 66 |
paciente_id: int
|
| 67 |
-
tipo:
|
| 68 |
cama_origen_id: Optional[int] = None
|
| 69 |
timestamp: datetime
|
| 70 |
|
|
|
|
| 64 |
mensaje: str
|
| 65 |
cama_id: int
|
| 66 |
paciente_id: int
|
| 67 |
+
tipo: Literal["INGRESO", "TRASLADO"]
|
| 68 |
cama_origen_id: Optional[int] = None
|
| 69 |
timestamp: datetime
|
| 70 |
|
app/schemas/enums.py
CHANGED
|
@@ -44,9 +44,11 @@ class AccionResolucionEnum(str, Enum):
|
|
| 44 |
|
| 45 |
|
| 46 |
class PrioridadSolicitudEnum(str, Enum):
|
|
|
|
| 47 |
BAJA = "BAJA"
|
| 48 |
MEDIA = "MEDIA"
|
| 49 |
ALTA = "ALTA"
|
|
|
|
| 50 |
URGENTE = "URGENTE"
|
| 51 |
|
| 52 |
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
class PrioridadSolicitudEnum(str, Enum):
|
| 47 |
+
MUY_BAJA = "MUY_BAJA"
|
| 48 |
BAJA = "BAJA"
|
| 49 |
MEDIA = "MEDIA"
|
| 50 |
ALTA = "ALTA"
|
| 51 |
+
MUY_ALTA = "MUY_ALTA"
|
| 52 |
URGENTE = "URGENTE"
|
| 53 |
|
| 54 |
|
app/services/cama_service.py
CHANGED
|
@@ -84,7 +84,11 @@ def update_cama(db: Session, cama_id: int, data: CamaUpdateRequest, rol: str) ->
|
|
| 84 |
if data.estado is not None:
|
| 85 |
nuevo_estado = data.estado.value
|
| 86 |
|
| 87 |
-
if nuevo_estado in (
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
raise HTTPException(
|
| 89 |
status_code=409,
|
| 90 |
detail={
|
|
@@ -177,6 +181,8 @@ def asignar_cama(db: Session, cama_id: int, tipo: str, paciente_id: int, cama_or
|
|
| 177 |
cama_origen.ultimo_movimiento_tipo = "TRASLADO"
|
| 178 |
cama_origen.ultima_actualizacion = datetime.now(timezone.utc)
|
| 179 |
hce.notify_movimiento("TRASLADO", paciente_id, cama_id, cama_origen_id)
|
|
|
|
|
|
|
| 180 |
else:
|
| 181 |
hce.notify_movimiento("INGRESO", paciente_id, cama_id)
|
| 182 |
monitoreo.notify_alta(paciente_id)
|
|
|
|
| 84 |
if data.estado is not None:
|
| 85 |
nuevo_estado = data.estado.value
|
| 86 |
|
| 87 |
+
if nuevo_estado in (
|
| 88 |
+
EstadoCamaEnum.OCUPADA.value,
|
| 89 |
+
EstadoCamaEnum.CODIGO_ROJO.value,
|
| 90 |
+
EstadoCamaEnum.EN_LIMPIEZA.value,
|
| 91 |
+
):
|
| 92 |
raise HTTPException(
|
| 93 |
status_code=409,
|
| 94 |
detail={
|
|
|
|
| 181 |
cama_origen.ultimo_movimiento_tipo = "TRASLADO"
|
| 182 |
cama_origen.ultima_actualizacion = datetime.now(timezone.utc)
|
| 183 |
hce.notify_movimiento("TRASLADO", paciente_id, cama_id, cama_origen_id)
|
| 184 |
+
monitoreo.notify_baja(paciente_id)
|
| 185 |
+
monitoreo.notify_alta(paciente_id)
|
| 186 |
else:
|
| 187 |
hce.notify_movimiento("INGRESO", paciente_id, cama_id)
|
| 188 |
monitoreo.notify_alta(paciente_id)
|
app/services/solicitud_service.py
CHANGED
|
@@ -135,7 +135,7 @@ def _rechazar(sol: Solicitud, motivo: str | None, resuelto_por: int) -> None:
|
|
| 135 |
sol.motivo = motivo
|
| 136 |
sol.resuelto_por = resuelto_por
|
| 137 |
sol.timestamp_resolucion = datetime.now(timezone.utc)
|
| 138 |
-
hce.
|
| 139 |
|
| 140 |
|
| 141 |
def _aprobar_internacion(
|
|
@@ -169,6 +169,7 @@ def _aprobar_internacion(
|
|
| 169 |
sol.timestamp_resolucion = datetime.now(timezone.utc)
|
| 170 |
|
| 171 |
hce.notify_movimiento("INGRESO", sol.paciente_id, cama_id)
|
|
|
|
| 172 |
monitoreo.notify_alta(sol.paciente_id)
|
| 173 |
|
| 174 |
|
|
@@ -209,6 +210,9 @@ def _aprobar_traslado(
|
|
| 209 |
sol.timestamp_resolucion = datetime.now(timezone.utc)
|
| 210 |
|
| 211 |
hce.notify_movimiento("TRASLADO", sol.paciente_id, dest_id, sol.cama_origen_id)
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
|
| 214 |
# βββ Alta mΓ©dica (desde HCE M1) ββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -239,7 +243,10 @@ def procesar_alerta_emergencia(db: Session, paciente_id: int) -> Cama:
|
|
| 239 |
)
|
| 240 |
cama.estado = EstadoCamaEnum.CODIGO_ROJO.value
|
| 241 |
cama.ultima_actualizacion = datetime.now(timezone.utc)
|
| 242 |
-
|
|
|
|
|
|
|
|
|
|
| 243 |
|
| 244 |
|
| 245 |
def procesar_alerta_resuelta(db: Session, paciente_id: int) -> Cama:
|
|
|
|
| 135 |
sol.motivo = motivo
|
| 136 |
sol.resuelto_por = resuelto_por
|
| 137 |
sol.timestamp_resolucion = datetime.now(timezone.utc)
|
| 138 |
+
hce.notify_resultado_solicitud(sol.solicitud_hce_id, "RECHAZADA", motivo)
|
| 139 |
|
| 140 |
|
| 141 |
def _aprobar_internacion(
|
|
|
|
| 169 |
sol.timestamp_resolucion = datetime.now(timezone.utc)
|
| 170 |
|
| 171 |
hce.notify_movimiento("INGRESO", sol.paciente_id, cama_id)
|
| 172 |
+
hce.notify_resultado_solicitud(sol.solicitud_hce_id, "APROBADA")
|
| 173 |
monitoreo.notify_alta(sol.paciente_id)
|
| 174 |
|
| 175 |
|
|
|
|
| 210 |
sol.timestamp_resolucion = datetime.now(timezone.utc)
|
| 211 |
|
| 212 |
hce.notify_movimiento("TRASLADO", sol.paciente_id, dest_id, sol.cama_origen_id)
|
| 213 |
+
hce.notify_resultado_solicitud(sol.solicitud_hce_id, "APROBADA")
|
| 214 |
+
monitoreo.notify_baja(sol.paciente_id)
|
| 215 |
+
monitoreo.notify_alta(sol.paciente_id)
|
| 216 |
|
| 217 |
|
| 218 |
# βββ Alta mΓ©dica (desde HCE M1) ββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 243 |
)
|
| 244 |
cama.estado = EstadoCamaEnum.CODIGO_ROJO.value
|
| 245 |
cama.ultima_actualizacion = datetime.now(timezone.utc)
|
| 246 |
+
cama_crud.save(db, cama)
|
| 247 |
+
# episodio_id se resolverΓ‘ cuando se implemente la entidad Episodio
|
| 248 |
+
hce.notify_evento_episodio(0, "CODIGO_ROJO", f"Alerta de emergencia detectada para paciente {paciente_id}")
|
| 249 |
+
return cama
|
| 250 |
|
| 251 |
|
| 252 |
def procesar_alerta_resuelta(db: Session, paciente_id: int) -> Cama:
|