feat: filter exams by time window in SQL (last N minutes), default 10min
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
35859e8d75
commit
a880b7fb81
@@ -33,7 +33,7 @@ WHERE CAST(r.FECHA_RECEPCION AS DATE) = CURRENT_DATE
|
||||
AND r.NUM_FACTURA > 0
|
||||
"""
|
||||
|
||||
_SQL_EXAMENES_HOY = """
|
||||
_SQL_EXAMENES_VENTANA = """
|
||||
SELECT
|
||||
TRIM(p.DOCIDENT) AS DOCIDENT,
|
||||
r.IDRECEPCION,
|
||||
@@ -59,7 +59,7 @@ LEFT JOIN EMPRESA_SUB es ON TRIM(es.NIT_EMP) = TRIM(r.NIT_EMPRESA)
|
||||
AND TRIM(es.SUBGRUPO) = TRIM(r.SUBGRUPO)
|
||||
LEFT JOIN TARIFA t ON TRIM(t.COD_EXAMEN) = TRIM(rel.COD_EXAMEN)
|
||||
AND t.TARIFA = COALESCE(es.TARIFA, e.TARIFA)
|
||||
WHERE CAST(r.FECHA_RECEPCION AS DATE) = CURRENT_DATE
|
||||
WHERE r.HORAINICIORECEPCION >= CAST('NOW' AS TIMESTAMP) - ? MINUTE
|
||||
AND r.NUM_FACTURA > 0
|
||||
ORDER BY r.IDRECEPCION
|
||||
"""
|
||||
@@ -127,7 +127,7 @@ async def sync_recientes(ventana_min: int = 2) -> dict:
|
||||
return {"ok": False, "error": f"Firebird: {msg}"}
|
||||
|
||||
ok_pac, err_pac, rows_pac = fb.execute_query(_SQL_HOY, None)
|
||||
ok_ex, _, rows_ex = fb.execute_query(_SQL_EXAMENES_HOY, None)
|
||||
ok_ex, _, rows_ex = fb.execute_query(_SQL_EXAMENES_VENTANA, (ventana_min,))
|
||||
fb.disconnect()
|
||||
|
||||
if not ok_pac:
|
||||
@@ -148,9 +148,6 @@ async def sync_recientes(ventana_min: int = 2) -> dict:
|
||||
examenes_map: dict[str, list] = {}
|
||||
if ok_ex and rows_ex:
|
||||
for ex in rows_ex:
|
||||
h = _parse_hora(ex.get("HORAINICIORECEPCION"))
|
||||
if h is not None and h < limite:
|
||||
continue
|
||||
doc = str(ex.get("DOCIDENT") or "").strip()
|
||||
if not doc:
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user