feat(contratos): tabla de contratos con tipo_usuario por contrato

Agrega tabla `contratos` en SQLite sembrada con los 17 contratos del
laboratorio. `generar_rda_paciente` consulta el mapa contrato→tipoUsuario
como primera prioridad antes de derivar de TIPOUSU/TIPOUSUSISPRO.
Incluye CRUD en /contratos con UI en sidebar.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-09 15:00:21 -05:00
co-authored by Claude Sonnet 4.6
parent 7d2a9df447
commit 0f3a760de4
8 changed files with 337 additions and 12 deletions
+7 -1
View File
@@ -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_rda_paciente, agrupar_por_recepcion
from app.services.api_client import get_tns_token, TNS_BASE
from app.routes.contratos import load_contrato_map
router = APIRouter(prefix="/transaccion", tags=["transaccion"])
@@ -96,11 +97,12 @@ async def preview_transaccion(
esp_def = cfg.get("especialidad_default", "")
remis_def = cfg.get("remisionante_default", "00")
prefijo_def = cfg.get("prefijo_tns_default", "00")
contrato_map = load_contrato_map()
items = []
for id_rec, grupo_rows in grupos.items():
enviado = _is_sent(id_rec)
rda = generar_rda_paciente(grupo_rows, prof_def, esp_def, remis_def, prefijo_def)
rda = generar_rda_paciente(grupo_rows, prof_def, esp_def, remis_def, prefijo_def, contrato_map=contrato_map)
items.append({
"idrecepcion": id_rec,
"factura": grupo_rows[0].get("NUM_FACTURA", ""),
@@ -166,6 +168,7 @@ async def send_one(
cfg.get("remisionante_default", "00"),
cfg.get("prefijo_tns_default", "00"),
numero_override_one,
contrato_map=load_contrato_map(),
)
raw_resp = ""
@@ -234,6 +237,8 @@ async def send_transaccion(
if solo_pendientes == "1":
grupos = {k: v for k, v in grupos.items() if not _is_sent(k)}
contrato_map = load_contrato_map()
token, token_err = await get_tns_token(
cfg.get("tns_empresa", ""), cfg.get("tns_usuario", ""), cfg.get("tns_password", "")
)
@@ -256,6 +261,7 @@ async def send_transaccion(
cfg.get("remisionante_default", "00"),
cfg.get("prefijo_tns_default", "00"),
numero_override,
contrato_map=contrato_map,
)
raw_resp = ""
ok_rda = False