feat: integración completa con API TNS v2

- api_client: agrega get_tns_token() — login en /v2/Acceso/Login y retorna JWT
- json_generator: campos en camelCase según swagger v2; agrega nomRegTri y
  email placeholder cuando el paciente no tiene correo
- terceros/transaccion routes: obtienen token TNS antes de cada envío,
  usan endpoints /v2/tablas/Tercero/Crear y /v2/rda/RdaPaciente/Insertar
- config: agrega tns_empresa, tns_usuario, tns_password

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-25 18:56:31 -05:00
co-authored by Claude Sonnet 4.6
parent 774ce7d728
commit 6d5a85c55f
6 changed files with 96 additions and 67 deletions
+3
View File
@@ -17,6 +17,9 @@ DEFAULT_KEYS = [
("api_timeout", "30"),
("api_version", "1"),
("api_sucursal", ""),
("tns_empresa", "9002787299"),
("tns_usuario", "DOCUXER"),
("tns_password", "Nicolas2796*+"),
("num_documento_obligado", ""),
("cod_prestador", ""),
]
+10 -7
View File
@@ -7,6 +7,7 @@ from app.database import get_connection
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
router = APIRouter(prefix="/terceros", tags=["terceros"])
@@ -137,14 +138,16 @@ async def send_terceros(
tercero_json = generar_tercero_api(rows[0])
api_url = configs.get("api_url", "")
api_version = configs.get("api_version", "1")
api_key = configs.get("api_key", "")
headers = {"Content-Type": "application/json"}
if api_key:
headers["Authorization"] = f"Bearer {api_key}"
token, token_err = await get_tns_token(
configs.get("tns_empresa", ""),
configs.get("tns_usuario", ""),
configs.get("tns_password", ""),
)
if not token:
return JSONResponse({"success": False, "message": f"Error login TNS: {token_err}"})
endpoint = f"{api_url}/v{api_version}/tablas/Tercero/Crear"
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {token}"}
endpoint = f"{TNS_BASE}/v2/tablas/Tercero/Crear"
resp_ok = False
resp_text = ""
+12 -8
View File
@@ -7,6 +7,7 @@ from app.database import get_connection
from app.auth import get_current_user
from app.services.firebird_service import get_firebird_from_config
from app.services.json_generator import generar_rda_paciente, agrupar_por_recepcion
from app.services.api_client import get_tns_token, TNS_BASE
router = APIRouter(prefix="/transaccion", tags=["transaccion"])
@@ -116,15 +117,18 @@ async def send_transaccion(
return JSONResponse({"success": False, "message": "No se encontraron datos"})
grupos = agrupar_por_recepcion(rows)
api_url = configs.get("api_url", "")
api_version = configs.get("api_version", "1")
api_sucursal = configs.get("api_sucursal", "")
api_key = configs.get("api_key", "")
headers = {"Content-Type": "application/json"}
if api_key:
headers["Authorization"] = f"Bearer {api_key}"
endpoint = f"{api_url}/v{api_version}/rda/RdaPaciente/Insertar"
token, token_err = await get_tns_token(
configs.get("tns_empresa", ""),
configs.get("tns_usuario", ""),
configs.get("tns_password", ""),
)
if not token:
return JSONResponse({"success": False, "message": f"Error login TNS: {token_err}"})
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {token}"}
api_sucursal = configs.get("api_sucursal", "")
endpoint = f"{TNS_BASE}/v2/rda/RdaPaciente/Insertar"
if api_sucursal:
endpoint += f"?codigosucursal={api_sucursal}"