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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
9d87c3fa1c
commit
9d80279114
@@ -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) ─────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user