Mate11 Claude Sonnet 4.6 commited on
Commit ·
a3cbeab
1
Parent(s): 31c8dd6
Actualizar código y documentación según spec OpenAPI
Browse files- Agrega campo specialty_id al modelo Cama, schemas, CRUD, servicio y router
- Agrega función get_turno() en integración Turnos (M2)
- Agrega función notify_evento_episodio() en integración HCE (M1)
- Corrige openapi.yaml: descripciones de respuestas swapeadas, tipo camaId,
nota incorrecta en cama-lista, paths duplicados, nuevos endpoints EXT
(GET /turnos/{turnoId}, POST /hce/episodios/{episodioId}/eventos,
POST /auth/validate-token) y nuevos schemas
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- app/crud/cama.py +7 -1
- app/integrations/hce.py +18 -0
- app/integrations/turnos.py +9 -2
- app/models/cama.py +1 -0
- app/routers/camas.py +3 -1
- app/schemas/cama.py +2 -0
- app/services/cama_service.py +7 -2
- openapi.yaml +0 -0
app/crud/cama.py
CHANGED
|
@@ -44,6 +44,7 @@ def create(db: Session, data: CamaCreateRequest) -> Cama:
|
|
| 44 |
piso=data.piso,
|
| 45 |
sector=data.sector.value,
|
| 46 |
tipo=data.tipo.value,
|
|
|
|
| 47 |
hospital_id=data.hospital_id,
|
| 48 |
estado="DISPONIBLE",
|
| 49 |
contraindicaciones_incompatibles=data.contraindicaciones_incompatibles,
|
|
@@ -62,7 +63,10 @@ def save(db: Session, cama: Cama) -> Cama:
|
|
| 62 |
|
| 63 |
|
| 64 |
def get_quirofanos(
|
| 65 |
-
db: Session,
|
|
|
|
|
|
|
|
|
|
| 66 |
) -> list[Cama]:
|
| 67 |
excluidos = exclude_estados or ["FUERA_DE_SERVICIO", "BAJA_PERMANENTE"]
|
| 68 |
q = db.query(Cama).filter(
|
|
@@ -72,6 +76,8 @@ def get_quirofanos(
|
|
| 72 |
)
|
| 73 |
if hospital_id:
|
| 74 |
q = q.filter(Cama.hospital_id == hospital_id)
|
|
|
|
|
|
|
| 75 |
return q.all()
|
| 76 |
|
| 77 |
|
|
|
|
| 44 |
piso=data.piso,
|
| 45 |
sector=data.sector.value,
|
| 46 |
tipo=data.tipo.value,
|
| 47 |
+
specialty_id=data.specialty_id,
|
| 48 |
hospital_id=data.hospital_id,
|
| 49 |
estado="DISPONIBLE",
|
| 50 |
contraindicaciones_incompatibles=data.contraindicaciones_incompatibles,
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
def get_quirofanos(
|
| 66 |
+
db: Session,
|
| 67 |
+
hospital_id: str | None = None,
|
| 68 |
+
specialty_id: int | None = None,
|
| 69 |
+
exclude_estados: list[str] | None = None,
|
| 70 |
) -> list[Cama]:
|
| 71 |
excluidos = exclude_estados or ["FUERA_DE_SERVICIO", "BAJA_PERMANENTE"]
|
| 72 |
q = db.query(Cama).filter(
|
|
|
|
| 76 |
)
|
| 77 |
if hospital_id:
|
| 78 |
q = q.filter(Cama.hospital_id == hospital_id)
|
| 79 |
+
if specialty_id is not None:
|
| 80 |
+
q = q.filter(Cama.specialty_id == specialty_id)
|
| 81 |
return q.all()
|
| 82 |
|
| 83 |
|
app/integrations/hce.py
CHANGED
|
@@ -19,6 +19,24 @@ def get_contraindicaciones(paciente_id: int) -> list[str]:
|
|
| 19 |
return [d.get("descripcion", "") for d in data.get("detalle", [])]
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
def notify_movimiento(
|
| 23 |
tipo_movimiento: str,
|
| 24 |
paciente_id: int,
|
|
|
|
| 19 |
return [d.get("descripcion", "") for d in data.get("detalle", [])]
|
| 20 |
|
| 21 |
|
| 22 |
+
def notify_evento_episodio(
|
| 23 |
+
episodio_id: int,
|
| 24 |
+
tipo_evento: str,
|
| 25 |
+
descripcion: str | None = None,
|
| 26 |
+
) -> bool:
|
| 27 |
+
"""Registra un evento en el episodio de internación en HCE (M1). Retorna True si OK."""
|
| 28 |
+
if settings.mock_external_services:
|
| 29 |
+
return True
|
| 30 |
+
payload = {
|
| 31 |
+
"tipo_evento": tipo_evento,
|
| 32 |
+
"descripcion": descripcion,
|
| 33 |
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
| 34 |
+
}
|
| 35 |
+
return _post(
|
| 36 |
+
f"{settings.m1_hce_url}/api/v1/hce/episodios/{episodio_id}/eventos", payload
|
| 37 |
+
) is not None
|
| 38 |
+
|
| 39 |
+
|
| 40 |
def notify_movimiento(
|
| 41 |
tipo_movimiento: str,
|
| 42 |
paciente_id: int,
|
app/integrations/turnos.py
CHANGED
|
@@ -1,9 +1,16 @@
|
|
| 1 |
"""
|
| 2 |
-
M2 Turnos — notificación de resultado de quirófano.
|
| 3 |
"""
|
| 4 |
from datetime import datetime, timezone
|
| 5 |
from app.config import settings
|
| 6 |
-
from app.integrations._base import _post
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
def notify_resultado_quirofano(
|
|
|
|
| 1 |
"""
|
| 2 |
+
M2 Turnos — consulta de turno y notificación de resultado de quirófano.
|
| 3 |
"""
|
| 4 |
from datetime import datetime, timezone
|
| 5 |
from app.config import settings
|
| 6 |
+
from app.integrations._base import _get, _post
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def get_turno(turno_id: int) -> dict | None:
|
| 10 |
+
"""Obtiene el detalle de un turno quirúrgico en M2. Retorna None si falla."""
|
| 11 |
+
if settings.mock_external_services:
|
| 12 |
+
return {"id": turno_id, "estado": "CONFIRMADO"}
|
| 13 |
+
return _get(f"{settings.m2_turnos_url}/api/v1/turnos/{turno_id}")
|
| 14 |
|
| 15 |
|
| 16 |
def notify_resultado_quirofano(
|
app/models/cama.py
CHANGED
|
@@ -18,6 +18,7 @@ class Cama(Base):
|
|
| 18 |
tipo = Column(String(20), nullable=False)
|
| 19 |
# EstadoCamaEnum: DISPONIBLE | OCUPADA | EN_LIMPIEZA | FUERA_DE_SERVICIO | BAJA_PERMANENTE | CODIGO_ROJO
|
| 20 |
estado = Column(String(20), nullable=False, default="DISPONIBLE")
|
|
|
|
| 21 |
paciente_id = Column(Integer, nullable=True)
|
| 22 |
hospital_id = Column(String(50), nullable=False)
|
| 23 |
contraindicaciones_incompatibles = Column(ARRAY(String), nullable=False, default=list)
|
|
|
|
| 18 |
tipo = Column(String(20), nullable=False)
|
| 19 |
# EstadoCamaEnum: DISPONIBLE | OCUPADA | EN_LIMPIEZA | FUERA_DE_SERVICIO | BAJA_PERMANENTE | CODIGO_ROJO
|
| 20 |
estado = Column(String(20), nullable=False, default="DISPONIBLE")
|
| 21 |
+
specialty_id = Column(Integer, nullable=True)
|
| 22 |
paciente_id = Column(Integer, nullable=True)
|
| 23 |
hospital_id = Column(String(50), nullable=False)
|
| 24 |
contraindicaciones_incompatibles = Column(ARRAY(String), nullable=False, default=list)
|
app/routers/camas.py
CHANGED
|
@@ -37,10 +37,11 @@ def get_disponibilidad(
|
|
| 37 |
desde: datetime = Query(...),
|
| 38 |
hasta: datetime = Query(...),
|
| 39 |
hospital_id: Optional[str] = Query(None),
|
|
|
|
| 40 |
db: Session = Depends(get_db),
|
| 41 |
user: dict = Depends(require_roles("ADMINISTRATIVO", "MEDICO")),
|
| 42 |
):
|
| 43 |
-
quirofanos = cama_service.get_disponibilidad_quirofanos(db, desde, hasta, hospital_id)
|
| 44 |
result = []
|
| 45 |
for q in quirofanos:
|
| 46 |
reservas_resp = [ReservaQuirofanoResponse.model_validate(r) for r in q["reservas_en_rango"]]
|
|
@@ -50,6 +51,7 @@ def get_disponibilidad(
|
|
| 50 |
"piso": q["piso"],
|
| 51 |
"hospital_id": q["hospital_id"],
|
| 52 |
"estado": q["estado"],
|
|
|
|
| 53 |
"reservas_en_rango": [r.model_dump() for r in reservas_resp],
|
| 54 |
})
|
| 55 |
return {
|
|
|
|
| 37 |
desde: datetime = Query(...),
|
| 38 |
hasta: datetime = Query(...),
|
| 39 |
hospital_id: Optional[str] = Query(None),
|
| 40 |
+
specialty_id: Optional[int] = Query(None),
|
| 41 |
db: Session = Depends(get_db),
|
| 42 |
user: dict = Depends(require_roles("ADMINISTRATIVO", "MEDICO")),
|
| 43 |
):
|
| 44 |
+
quirofanos = cama_service.get_disponibilidad_quirofanos(db, desde, hasta, hospital_id, specialty_id)
|
| 45 |
result = []
|
| 46 |
for q in quirofanos:
|
| 47 |
reservas_resp = [ReservaQuirofanoResponse.model_validate(r) for r in q["reservas_en_rango"]]
|
|
|
|
| 51 |
"piso": q["piso"],
|
| 52 |
"hospital_id": q["hospital_id"],
|
| 53 |
"estado": q["estado"],
|
| 54 |
+
"specialty_id": q["specialty_id"],
|
| 55 |
"reservas_en_rango": [r.model_dump() for r in reservas_resp],
|
| 56 |
})
|
| 57 |
return {
|
app/schemas/cama.py
CHANGED
|
@@ -10,6 +10,7 @@ class CamaCreateRequest(BaseModel):
|
|
| 10 |
piso: int
|
| 11 |
sector: SectorEnum
|
| 12 |
tipo: TipoCamaEnum
|
|
|
|
| 13 |
hospital_id: str = Field(..., min_length=1, max_length=50)
|
| 14 |
contraindicaciones_incompatibles: list[str] = []
|
| 15 |
|
|
@@ -35,6 +36,7 @@ class CamaResponse(BaseModel):
|
|
| 35 |
piso: int
|
| 36 |
sector: SectorEnum
|
| 37 |
tipo: TipoCamaEnum
|
|
|
|
| 38 |
estado: EstadoCamaEnum
|
| 39 |
paciente_id: Optional[int] = None
|
| 40 |
hospital_id: str
|
|
|
|
| 10 |
piso: int
|
| 11 |
sector: SectorEnum
|
| 12 |
tipo: TipoCamaEnum
|
| 13 |
+
specialty_id: Optional[int] = None
|
| 14 |
hospital_id: str = Field(..., min_length=1, max_length=50)
|
| 15 |
contraindicaciones_incompatibles: list[str] = []
|
| 16 |
|
|
|
|
| 36 |
piso: int
|
| 37 |
sector: SectorEnum
|
| 38 |
tipo: TipoCamaEnum
|
| 39 |
+
specialty_id: Optional[int] = None
|
| 40 |
estado: EstadoCamaEnum
|
| 41 |
paciente_id: Optional[int] = None
|
| 42 |
hospital_id: str
|
app/services/cama_service.py
CHANGED
|
@@ -292,9 +292,13 @@ def update_reserva_estado(
|
|
| 292 |
|
| 293 |
|
| 294 |
def get_disponibilidad_quirofanos(
|
| 295 |
-
db: Session,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
) -> list[dict]:
|
| 297 |
-
quirofanos = cama_crud.get_quirofanos(db, hospital_id)
|
| 298 |
result = []
|
| 299 |
for q_cama in quirofanos:
|
| 300 |
reservas_en_rango = reserva_crud.get_superpuestas(db, q_cama.id, desde, hasta)
|
|
@@ -304,6 +308,7 @@ def get_disponibilidad_quirofanos(
|
|
| 304 |
"piso": q_cama.piso,
|
| 305 |
"hospital_id": q_cama.hospital_id,
|
| 306 |
"estado": q_cama.estado,
|
|
|
|
| 307 |
"reservas_en_rango": reservas_en_rango,
|
| 308 |
})
|
| 309 |
return result
|
|
|
|
| 292 |
|
| 293 |
|
| 294 |
def get_disponibilidad_quirofanos(
|
| 295 |
+
db: Session,
|
| 296 |
+
desde: datetime,
|
| 297 |
+
hasta: datetime,
|
| 298 |
+
hospital_id: str | None = None,
|
| 299 |
+
specialty_id: int | None = None,
|
| 300 |
) -> list[dict]:
|
| 301 |
+
quirofanos = cama_crud.get_quirofanos(db, hospital_id, specialty_id)
|
| 302 |
result = []
|
| 303 |
for q_cama in quirofanos:
|
| 304 |
reservas_en_rango = reserva_crud.get_superpuestas(db, q_cama.id, desde, hasta)
|
|
|
|
| 308 |
"piso": q_cama.piso,
|
| 309 |
"hospital_id": q_cama.hospital_id,
|
| 310 |
"estado": q_cama.estado,
|
| 311 |
+
"specialty_id": q_cama.specialty_id,
|
| 312 |
"reservas_en_rango": reservas_en_rango,
|
| 313 |
})
|
| 314 |
return result
|
openapi.yaml
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|