fix: JSON preview recepciones via store (evita innerHTML injection)
feat: paso 1 registra terceros EPS de pre-servicios junto a particulares - _rdaJsonStore guarda JSON por key, toggleRdaJson usa textContent - escHtml() para caracteres especiales en diagnostico - _SQL_PACIENTES_EPS obtiene pacientes de PRESSERV_DIAN - rows_pac_todos fusiona particulares + EPS deduplicando por CODIGO Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
ef02303dde
commit
e6860a6957
@@ -86,6 +86,30 @@ ORDER BY r.IDRECEPCION
|
||||
"""
|
||||
|
||||
|
||||
_SQL_PACIENTES_EPS = """
|
||||
SELECT DISTINCT
|
||||
p.CODIGO,
|
||||
p.TIPOIDENT,
|
||||
p.DOCIDENT,
|
||||
p.NOMBRES,
|
||||
p.APELLIDOS,
|
||||
p.DIRECCION,
|
||||
p.CIUDAD AS COD_CIUDAD,
|
||||
c.NOMBRE AS NOM_CIUDAD,
|
||||
p.TELEFONOS,
|
||||
p.EMAIL,
|
||||
p.F_NACIMIENTO,
|
||||
p.SEXO,
|
||||
p.TIPORES,
|
||||
p.CODETNIA
|
||||
FROM PACIENTE p
|
||||
JOIN RECEPCION r ON r.COD_PACIENTE = p.CODIGO
|
||||
JOIN PRESSERV_DIAN ps ON ps.ID_RECEP = r.IDRECEPCION
|
||||
LEFT JOIN CIUDAD c ON c.CODIGO = p.CIUDAD
|
||||
WHERE r.FECHA_RECEPCION BETWEEN :fecha_ini AND :fecha_fin
|
||||
AND (ps.PS_ANULADA IS NULL OR ps.PS_ANULADA = 'F')
|
||||
"""
|
||||
|
||||
_SQL_PRESERV = """
|
||||
SELECT
|
||||
ps.ID_PS,
|
||||
@@ -357,7 +381,7 @@ async def run_automation(
|
||||
|
||||
sql_pac, sql_rda = _build_sql(contrato.strip())
|
||||
|
||||
# ── Paso 1: obtener pacientes únicos ─────────────────────────────────────
|
||||
# ── Paso 1: obtener pacientes únicos (particulares) ───────────────────────
|
||||
ok1, err1, rows_pac = fb.execute_query(sql_pac, params)
|
||||
if not ok1:
|
||||
fb.disconnect()
|
||||
@@ -371,10 +395,20 @@ async def run_automation(
|
||||
|
||||
# ── Paso 3: obtener pre-servicios ─────────────────────────────────────────
|
||||
ok3, err3, rows_ps = fb.execute_query(_SQL_PRESERV, {"fecha_ini": fecha_ini, "fecha_fin": fecha_fin})
|
||||
fb.disconnect()
|
||||
if not ok3:
|
||||
fb.disconnect()
|
||||
return JSONResponse({"success": False, "message": f"Error Firebird Pre-servicios: {err3}"})
|
||||
|
||||
# ── Pacientes EPS (para registrar terceros en paso 1) ─────────────────────
|
||||
ok4, err4, rows_pac_eps = fb.execute_query(_SQL_PACIENTES_EPS, {"fecha_ini": fecha_ini, "fecha_fin": fecha_fin})
|
||||
fb.disconnect()
|
||||
if not ok4:
|
||||
return JSONResponse({"success": False, "message": f"Error Firebird pacientes EPS: {err4}"})
|
||||
|
||||
# Fusionar pacientes: particulares + EPS, deduplicando por CODIGO
|
||||
codigos_vistos = {str(r.get("CODIGO")) for r in rows_pac}
|
||||
rows_pac_todos = list(rows_pac) + [r for r in rows_pac_eps if str(r.get("CODIGO")) not in codigos_vistos]
|
||||
|
||||
if not rows_pac and not rows_rda:
|
||||
return JSONResponse({"success": False, "message": f"No hay datos para la fecha {fecha}"})
|
||||
|
||||
@@ -398,9 +432,9 @@ async def run_automation(
|
||||
"paso3_preserv": {"enviados": 0, "errores": 0, "detalle": []},
|
||||
}
|
||||
|
||||
# ── PASO 1: Enviar Terceros ───────────────────────────────────────────────
|
||||
# ── PASO 1: Enviar Terceros (particulares + EPS) ─────────────────────────
|
||||
async with httpx.AsyncClient(timeout=timeout) as client:
|
||||
for row in rows_pac:
|
||||
for row in rows_pac_todos:
|
||||
tercero_json = generar_tercero_api(row)
|
||||
doc = tercero_json["nit"]
|
||||
nombre = tercero_json["nombre"]
|
||||
|
||||
Reference in New Issue
Block a user