From 02c2f7a17b704129939b213c59c14c4a730592ac Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Tue, 30 Jun 2026 20:50:01 -0500 Subject: [PATCH] fix: combinar fecha+hora separados de Firebird en fechaHoraIngreso MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- app/services/json_generator.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/app/services/json_generator.py b/app/services/json_generator.py index b6a1306..9354d5c 100644 --- a/app/services/json_generator.py +++ b/app/services/json_generator.py @@ -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 = []