Fix param validation errors and add TNS config section
- terceros/transaccion: return clear error when required params (doc_num, num_factura) are missing instead of passing empty dict to Firebird causing Column unknown error - transaccion: remove prefijo from 'por factura' query; parse num_factura as int when digit - automation: add /preview endpoint to show patient/reception counts before sending; update UI with preview step and disabled run button until preview loads - config: add TNS credentials section (tns_empresa, tns_usuario, tns_password, api_sucursal) with test-connection button - config: add POST /config/test-tns endpoint Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
3755a51562
commit
b4a7271d8d
@@ -76,6 +76,57 @@ async def automation_page(request: Request, user: dict = Depends(get_current_use
|
||||
})
|
||||
|
||||
|
||||
@router.post("/preview")
|
||||
async def preview_automation(
|
||||
request: Request,
|
||||
user: dict = Depends(get_current_user),
|
||||
fecha: str = Form(...),
|
||||
):
|
||||
conn = get_connection()
|
||||
configs = {row["key"]: row["value"] for row in conn.execute("SELECT * FROM config").fetchall()}
|
||||
conn.close()
|
||||
|
||||
fb, fb_ok, fb_msg = get_firebird_from_config(configs)
|
||||
if not fb_ok:
|
||||
return JSONResponse({"success": False, "message": f"Error Firebird: {fb_msg}"})
|
||||
|
||||
fecha_ini = f"{fecha} 00:00:00"
|
||||
fecha_fin = f"{fecha} 23:59:59"
|
||||
params = {"fecha_ini": fecha_ini, "fecha_fin": fecha_fin}
|
||||
|
||||
ok1, err1, rows_pac = fb.execute_query(_SQL_PACIENTES, params)
|
||||
if not ok1:
|
||||
fb.disconnect()
|
||||
return JSONResponse({"success": False, "message": f"Error BD pacientes: {err1}"})
|
||||
|
||||
ok2, err2, rows_rda = fb.execute_query(_SQL_RDA, params)
|
||||
fb.disconnect()
|
||||
if not ok2:
|
||||
return JSONResponse({"success": False, "message": f"Error BD RDA: {err2}"})
|
||||
|
||||
grupos = agrupar_por_recepcion(rows_rda)
|
||||
total_examenes = sum(len(v) for v in grupos.values())
|
||||
|
||||
pacientes_preview = [
|
||||
{
|
||||
"doc": str(p.get("DOCIDENT", "")),
|
||||
"nombre": f"{p.get('NOMBRES', '')} {p.get('APELLIDOS', '')}".strip(),
|
||||
"tipo": str(p.get("TIPOIDENT", "")),
|
||||
}
|
||||
for p in rows_pac[:10]
|
||||
]
|
||||
|
||||
return JSONResponse({
|
||||
"success": True,
|
||||
"fecha": fecha,
|
||||
"pacientes": len(rows_pac),
|
||||
"recepciones": len(grupos),
|
||||
"examenes": total_examenes,
|
||||
"pacientes_preview": pacientes_preview,
|
||||
"hay_mas": len(rows_pac) > 10,
|
||||
})
|
||||
|
||||
|
||||
@router.post("/run")
|
||||
async def run_automation(
|
||||
request: Request,
|
||||
|
||||
Reference in New Issue
Block a user