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"]
|
||||
|
||||
@@ -179,6 +179,11 @@
|
||||
|
||||
<script>
|
||||
let _previewData = null;
|
||||
let _rdaJsonStore = {};
|
||||
|
||||
function escHtml(s) {
|
||||
return s.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
||||
}
|
||||
|
||||
async function previewAutomation() {
|
||||
const fecha = document.getElementById('fecha-input').value;
|
||||
@@ -235,22 +240,27 @@ async function previewAutomation() {
|
||||
table.innerHTML = '<div class="p-4 text-gray-400 text-center">No hay pacientes para esta fecha</div>';
|
||||
showToast('No hay datos para esa fecha', 'warning');
|
||||
} else {
|
||||
_rdaJsonStore = {};
|
||||
table.innerHTML = data.pacientes_preview.map((p, i) => {
|
||||
const rdaRows = p.rda.map((r, j) => `
|
||||
const rdaRows = p.rda.map((r, j) => {
|
||||
const key = `rda-json-${i}-${j}`;
|
||||
_rdaJsonStore[key] = r.json;
|
||||
return `
|
||||
<div class="divide-y divide-blue-100">
|
||||
<div class="flex items-center gap-3 px-6 py-1.5 bg-blue-50 border-t border-blue-100 text-xs cursor-pointer hover:bg-blue-100 select-none"
|
||||
onclick="toggleRdaJson('rda-json-${i}-${j}', this)">
|
||||
onclick="toggleRdaJson('${key}', this)">
|
||||
<i class="fas fa-chevron-right text-blue-300 text-xs transition-transform duration-150" id="rdachev-${i}-${j}"></i>
|
||||
<span class="text-blue-400 w-4"><i class="fas fa-flask"></i></span>
|
||||
<span class="font-mono text-blue-700 w-28">${r.factura}</span>
|
||||
<span class="text-blue-600 w-24">${r.fecha}</span>
|
||||
<span class="font-mono bg-blue-100 text-blue-800 px-1.5 py-0.5 rounded w-14 text-center">${r.contrato || '—'}</span>
|
||||
<span class="text-blue-600 w-20">${r.examenes} examen(es)</span>
|
||||
<span class="text-blue-600 flex-1">${r.diag}</span>
|
||||
<span class="text-blue-600 flex-1">${escHtml(r.diag||'')}</span>
|
||||
<span class="text-blue-700 font-medium">$${Number(r.valor).toLocaleString('es-CO')}</span>
|
||||
</div>
|
||||
<div id="rda-json-${i}-${j}" class="hidden bg-gray-900 text-green-300 text-xs font-mono p-4 overflow-x-auto whitespace-pre">${JSON.stringify(r.json, null, 2)}</div>
|
||||
</div>`).join('');
|
||||
<div id="${key}" class="hidden bg-gray-900 text-green-300 text-xs font-mono p-4 overflow-x-auto whitespace-pre"></div>
|
||||
</div>`;
|
||||
}).join('');
|
||||
return `
|
||||
<div class="divide-y divide-gray-100">
|
||||
<div class="flex items-center gap-3 px-4 py-2.5 hover:bg-gray-50 cursor-pointer select-none"
|
||||
@@ -373,6 +383,9 @@ function toggleRdaJson(id, row) {
|
||||
const div = document.getElementById(id);
|
||||
const chev = row.querySelector('[id^="rdachev-"]');
|
||||
const hidden = div.classList.contains('hidden');
|
||||
if (hidden && _rdaJsonStore[id]) {
|
||||
div.textContent = JSON.stringify(_rdaJsonStore[id], null, 2);
|
||||
}
|
||||
div.classList.toggle('hidden', !hidden);
|
||||
if (chev) chev.style.transform = hidden ? 'rotate(90deg)' : '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user