diff --git a/app/routes/test_rda.py b/app/routes/test_rda.py index 4b0dd26..d853584 100644 --- a/app/routes/test_rda.py +++ b/app/routes/test_rda.py @@ -72,7 +72,7 @@ async def test_page(request: Request, user: dict = Depends(get_current_user)): @router.get("/candidatos") async def get_candidatos(request: Request, user: dict = Depends(get_current_user), - contrato: str = "", factura: str = ""): + contrato: str = "", factura: str = "", articulos: str = ""): db = get_connection() cfg = {r[0]: r[1] for r in db.execute("SELECT key, value FROM config").fetchall()} db.close() @@ -81,9 +81,19 @@ async def get_candidatos(request: Request, user: dict = Depends(get_current_user if not fb_ok: return JSONResponse({"error": f"Error Firebird: {fb_msg}"}) - sql = _SQL_CANDIDATOS + # Artículos configurados con especialidad en TNS + arts_default = "CH4,CREA,TGP,VSG,PCR,AU,FER,TPO,TSH,TGO,GLI,BUN,COL,TRI,HDL,LDL,HBA1,VB12,VITD,PO,FER,K,NA,MG,URO,PRL,TSH,T4L,T3,T4,T3L,HIV,VDRL,PSA,AFP,CEA,CA125,CA199,FV,TP,TPT" + arts_str = articulos.strip() if articulos.strip() else arts_default + arts_list = [a.strip().upper() for a in arts_str.split(",") if a.strip()] + arts_in = ", ".join(f"'{a}'" for a in arts_list) + + filtros = [ + "r.NUM_FACTURA > 0", + "e.CODCONTRATO IS NOT NULL", + "TRIM(e.CODCONTRATO) <> ''", + f"rel.COD_EXAMEN IN ({arts_in})", + ] params = {} - filtros = ["r.NUM_FACTURA > 0", "e.CODCONTRATO IS NOT NULL", "TRIM(e.CODCONTRATO) <> ''"] if contrato: filtros.append("e.CODCONTRATO = :contrato") params["contrato"] = contrato @@ -92,10 +102,11 @@ async def get_candidatos(request: Request, user: dict = Depends(get_current_user params["factura"] = int(factura) sql_final = """ - SELECT FIRST 100 + SELECT FIRST 10 r.IDRECEPCION, r.NUM_FACTURA, r.FECHA_RECEPCION, r.COD_PACIENTE, r.NIT_EMPRESA, - e.CODCONTRATO, LIST(DISTINCT rel.COD_EXAMEN, ', ') AS examenes, - COUNT(DISTINCT rel.COD_EXAMEN) AS total_examenes + e.CODCONTRATO, + LIST(DISTINCT rel.COD_EXAMEN, ', ') AS EXAMENES, + COUNT(DISTINCT rel.COD_EXAMEN) AS TOTAL_EXAMENES FROM RECEPCION r JOIN RELACION rel ON rel.IDRECEPCION = r.IDRECEPCION LEFT JOIN EMPRESA e ON e.NIT = r.NIT_EMPRESA @@ -119,8 +130,8 @@ async def get_candidatos(request: Request, user: dict = Depends(get_current_user "paciente": row.get("COD_PACIENTE", ""), "empresa": row.get("NIT_EMPRESA", ""), "contrato": row.get("CODCONTRATO", ""), - "examenes": row.get("examenes", ""), - "total": row.get("total_examenes", 0), + "examenes": row.get("EXAMENES", ""), + "total": row.get("TOTAL_EXAMENES", 0), }) return JSONResponse({"candidatos": candidatos}) diff --git a/app/templates/test_rda.html b/app/templates/test_rda.html index 4a4d9fe..0f5a1f4 100644 --- a/app/templates/test_rda.html +++ b/app/templates/test_rda.html @@ -8,11 +8,12 @@

Candidatos disponibles

-
+
- +