feat: queries reales Firebird y generadores JSON para API ERP
- json_generator: nuevas funciones generar_tercero_api y generar_rda_paciente mapeando PACIENTE/RECEPCION/RELACION al formato de los endpoints Tercero/Crear y RdaPaciente/Insertar - queries: reemplaza placeholders por consultas reales sobre PACIENTE, RECEPCION, RELACION, MEDICO y CIUDAD - config: agrega api_version y api_sucursal; actualiza url y credenciales Firebird - terceros/transaccion routes: usan nuevos generadores y endpoints correctos Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
26243aa2bc
commit
774ce7d728
@@ -6,7 +6,7 @@ from fastapi.responses import JSONResponse
|
||||
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_terceros
|
||||
from app.services.json_generator import generar_tercero_api
|
||||
|
||||
router = APIRouter(prefix="/terceros", tags=["terceros"])
|
||||
|
||||
@@ -93,7 +93,7 @@ async def preview_query(
|
||||
if not success:
|
||||
return JSONResponse({"success": False, "message": error})
|
||||
|
||||
json_result = generar_terceros(rows[0]) if rows else None
|
||||
json_result = generar_tercero_api(rows[0]) if rows else None
|
||||
|
||||
return JSONResponse({
|
||||
"success": True,
|
||||
@@ -135,26 +135,25 @@ async def send_terceros(
|
||||
if not rows:
|
||||
return JSONResponse({"success": False, "message": "No se encontraron datos"})
|
||||
|
||||
tercero_json = generar_terceros(rows[0])
|
||||
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", "")
|
||||
api_method = configs.get("api_method", "POST")
|
||||
headers = {"Content-Type": "application/json"}
|
||||
if api_key:
|
||||
headers["Authorization"] = f"Bearer {api_key}"
|
||||
|
||||
endpoint = f"{api_url}/v{api_version}/tablas/Tercero/Crear"
|
||||
|
||||
resp_ok = False
|
||||
resp_text = ""
|
||||
resp_code = 0
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=int(configs.get("api_timeout", 30))) as client:
|
||||
if api_method == "POST":
|
||||
resp = await client.post(api_url + "/terceros", json=tercero_json, headers=headers)
|
||||
else:
|
||||
resp = await client.put(api_url + "/terceros", json=tercero_json, headers=headers)
|
||||
resp = await client.post(endpoint, json=tercero_json, headers=headers)
|
||||
resp_ok = resp.is_success
|
||||
resp_text = resp.text
|
||||
resp_text = resp.text[:2000]
|
||||
resp_code = resp.status_code
|
||||
except Exception as e:
|
||||
resp_text = str(e)
|
||||
|
||||
Reference in New Issue
Block a user