From 9d802791142c6642021c763c3b897d3c33fc32e0 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Tue, 30 Jun 2026 20:16:23 -0500 Subject: [PATCH] fix: strip spaces around colons in entire RDA JSON before returning Adds _clean_times() that recursively walks every string in the result dict and applies re.sub(r'\s*:\s*', ':'), guaranteeing no "12: 47: 37" spaces survive to the TNS API regardless of Firebird driver behaviour. Co-Authored-By: Claude Sonnet 4.6 --- app/services/json_generator.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/services/json_generator.py b/app/services/json_generator.py index ea320ef..b6a1306 100644 --- a/app/services/json_generator.py +++ b/app/services/json_generator.py @@ -7,10 +7,20 @@ from typing import Optional # ── helpers de formato de fecha ────────────────────────────────────────────── def _clean_dt(s: str) -> str: - """Elimina cualquier espacio alrededor de los dos puntos en horas.""" return _re.sub(r'\s*:\s*', ':', s) +def _clean_times(obj): + """Limpia recursivamente espacios alrededor de ':' en todos los strings del dict.""" + if isinstance(obj, str): + return _re.sub(r'\s*:\s*', ':', obj) if ':' in obj else obj + if isinstance(obj, dict): + return {k: _clean_times(v) for k, v in obj.items()} + if isinstance(obj, list): + return [_clean_times(i) for i in obj] + return obj + + def _fmt_fecha(val) -> str: if not val: return "" @@ -123,7 +133,6 @@ def generar_rda_paciente(rows: list, default_profesional: str = "", default_espe recepcion_dt = _fmt_datetime(h.get("FECHA_RECEPCION")) detalle_pedido = [] - import re as _re for row in rows: fecha_real = _fmt_datetime( row.get("FECHA_REPORTADO") if str(row.get("FECHA_REPORTADO") or "")[:4] != "1900" @@ -180,7 +189,7 @@ def generar_rda_paciente(rows: list, default_profesional: str = "", default_espe vigencia = 30 - return { + result = { "codigoPrefijo": default_prefijo or str(h.get("PREFIJO") or "00").strip(), "numero": numero_override if numero_override else ( str(h.get("NUM_FACTURA") or "").strip() if (h.get("NUM_FACTURA") or 0) != 0 else "" @@ -212,6 +221,7 @@ def generar_rda_paciente(rows: list, default_profesional: str = "", default_espe "valor": str(int(float(h.get("VALORTOTAL") or 0))), }], } + return _clean_times(result) # ── funciones legacy RIPS 2.0 (se mantienen) ─────────────────────────────────