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
@@ -8,6 +8,7 @@ from app.auth import get_current_user
|
||||
from app.services.firebird_service import get_firebird_from_config
|
||||
from app.services.json_generator import generar_tercero_api
|
||||
from app.services.api_client import get_tns_token, TNS_BASE
|
||||
from app.services.whatsapp_sync import sync_paciente
|
||||
|
||||
router = APIRouter(prefix="/terceros", tags=["terceros"])
|
||||
|
||||
@@ -183,9 +184,22 @@ async def send_terceros(
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
# ── Sync silencioso a WhatsApp Lab ───────────────────────────────────────
|
||||
wa_url = configs.get("whatsapp_url", "").rstrip("/")
|
||||
wa_key = configs.get("whatsapp_api_key", "")
|
||||
wa_sync = None
|
||||
if wa_url and wa_key and rows:
|
||||
ingest_url = f"{wa_url}/api/lab/ingest_paciente.php"
|
||||
try:
|
||||
wa_result = await sync_paciente(rows[0], ingest_url, wa_key)
|
||||
wa_sync = {"ok": wa_result["ok"], "action": wa_result["action"]}
|
||||
except Exception:
|
||||
wa_sync = {"ok": False, "action": "error"}
|
||||
|
||||
return JSONResponse({
|
||||
"success": resp_ok,
|
||||
"status_code": resp_code,
|
||||
"message": "Envío exitoso" if resp_ok else f"Error: {resp_text}",
|
||||
"cuv": resp_text[:200] if resp_ok else None,
|
||||
"wa_sync": wa_sync,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user