fix: combinar fecha+hora separados de Firebird en fechaHoraIngreso

HORAINICIORECEPCION es campo TIME en Firebird — fdb lo devuelve como
datetime.time sin fecha. _fmt_datetime recibía '06:08:29' y lo pasaba
tal cual al JSON. TNS rechazaba por formato inválido.

- _fmt_datetime ahora maneja entrada solo-fecha → agrega 00:00:00
- generar_rda_paciente combina HORAINICIORECEPCION + FECHA_RECEPCION
  antes de llamar _fmt_datetime cuando detecta hora sin fecha

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-30 20:50:01 -05:00
co-authored by Claude Sonnet 4.6
parent 9d80279114
commit 02c2f7a17b
+16 -8
View File
@@ -36,18 +36,20 @@ def _fmt_fecha(val) -> str:
def _fmt_datetime(val) -> str:
if not val:
return ""
# Convertir a string primero para poder limpiar espacios
if hasattr(val, "strftime"):
s = val.strftime("%d/%m/%Y %H:%M:%S")
else:
s = str(val)
s = _clean_dt(s)
s = _clean_dt(str(val))
s = s[:19].replace("T", " ")
parts = s.split(" ")
parts = s.strip().split()
if len(parts) == 2:
dp = parts[0].split("-")
if len(dp) == 3:
return f"{dp[2]}/{dp[1]}/{dp[0]} {parts[1]}"
return f"{parts[0]} {parts[1]}"
if len(parts) == 1:
dp = parts[0].split("-")
if len(dp) == 3:
# ponytail: solo fecha ISO → agregar hora 00:00:00
return f"{dp[2]}/{dp[1]}/{dp[0]} 00:00:00"
return f"{parts[0]} 00:00:00"
return s
@@ -129,7 +131,13 @@ def generar_rda_paciente(rows: list, default_profesional: str = "", default_espe
h = rows[0]
fecha = _fmt_fecha(h.get("FECHA_RECEPCION"))
ingreso = _fmt_datetime(h.get("HORAINICIORECEPCION") or h.get("FECHA_RECEPCION"))
_fecha_iso = str(h.get("FECHA_RECEPCION") or "")[:10]
_hora_raw = _clean_dt(str(h.get("HORAINICIORECEPCION") or "")).strip()
# ponytail: HORAINICIORECEPCION es campo TIME (sin fecha) → combinar con la fecha de FECHA_RECEPCION
if _hora_raw and len(_hora_raw) <= 8 and ":" in _hora_raw and _fecha_iso:
ingreso = _fmt_datetime(f"{_fecha_iso}T{_hora_raw}")
else:
ingreso = _fmt_datetime(_hora_raw or _fecha_iso)
recepcion_dt = _fmt_datetime(h.get("FECHA_RECEPCION"))
detalle_pedido = []