feat(pacientes): sync de pacientes Firebird → WhatsApp Lab
- Nuevo servicio whatsapp_sync.py: mapeo de campos RIPS→lab_pacientes y cliente HTTP para /api/lab/ingest_paciente.php - Nueva ruta /pacientes con sync masiva por rango de fechas o todos - Hook en /terceros/send y /automation/run: sync silencioso a WhatsApp después de cada envío a TNS - Config: campos whatsapp_url y whatsapp_api_key + botón probar conexión Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
b4288ac899
commit
e7c6bc794a
@@ -13,6 +13,7 @@ from app.services.json_generator import (
|
||||
agrupar_por_recepcion,
|
||||
)
|
||||
from app.services.api_client import get_tns_token, TNS_BASE
|
||||
from app.services.whatsapp_sync import sync_paciente
|
||||
|
||||
router = APIRouter(prefix="/automation", tags=["automation"])
|
||||
|
||||
@@ -259,6 +260,18 @@ async def run_automation(
|
||||
|
||||
_guardar_envio(user["user_id"], "terceros", fecha, tercero_json, msg, ok)
|
||||
|
||||
# ── Sync paralelo a WhatsApp Lab (silencioso) ─────────────────────────────
|
||||
wa_url = configs.get("whatsapp_url", "").rstrip("/")
|
||||
wa_key = configs.get("whatsapp_api_key", "")
|
||||
if wa_url and wa_key and rows_pac:
|
||||
ingest_url = f"{wa_url}/api/lab/ingest_paciente.php"
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=timeout) as wa_client:
|
||||
for row in rows_pac:
|
||||
await sync_paciente(row, ingest_url, wa_key, wa_client)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# ── PASO 2: Enviar RDA Paciente ───────────────────────────────────────────
|
||||
grupos = agrupar_por_recepcion(rows_rda)
|
||||
endpoint = f"{TNS_BASE}/v2/rda/RdaPaciente/Insertar?codigosucursal={api_sucursal or '00'}"
|
||||
|
||||
Reference in New Issue
Block a user