Agrega filtro convenio en automation/transaccion/test-rda y fix particular (contrato 12)
- automation: filtro contrato en SQL pacientes+RDA, numero LHXC en run() - transaccion: filtro contrato en preview/send-one/send - test-rda: filtro tipo_usuario (11/07/12), default contrato "12", acepta "12"/"012" - json_generator: detecta particular por CODCONTRATO "12"/"012" además de NIT_EMPRESA PART; fuerza tipousuario="12", codFormaPago="CLIP", plazoDias="0" Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
d7afbe9b7d
commit
69372a5673
+33
-11
@@ -84,7 +84,7 @@ async def get_enviados(request: Request, user: dict = Depends(get_current_user))
|
||||
@router.get("/candidatos")
|
||||
async def get_candidatos(request: Request, user: dict = Depends(get_current_user),
|
||||
contrato: str = "", factura: str = "", articulos: str = "",
|
||||
offset: int = 0):
|
||||
tipo_usuario: str = "", offset: int = 0):
|
||||
db = get_connection()
|
||||
cfg = {r[0]: r[1] for r in db.execute("SELECT key, value FROM config").fetchall()}
|
||||
db.close()
|
||||
@@ -93,23 +93,45 @@ async def get_candidatos(request: Request, user: dict = Depends(get_current_user
|
||||
if not fb_ok:
|
||||
return JSONResponse({"error": f"Error Firebird: {fb_msg}"})
|
||||
|
||||
# Artículos configurados con especialidad en TNS
|
||||
arts_default = "CH4,CREA,TGP,VSG,PCR,AU,FER,TPO,TSH,TGO,GLI,BUN,COL,TRI,HDL,LDL,HBA1,VB12,VITD,PO,K,NA,MG,URO,PRL,T4L,T3,T4,T3L,HIV,VDRL,PSA,AFP,CEA,CA125,CA199,FV,TP,TPT"
|
||||
arts_str = articulos.strip() if articulos.strip() else arts_default
|
||||
arts_list = [a.strip().upper() for a in arts_str.split(",") if a.strip()]
|
||||
arts_in = ", ".join(f"'{a}'" for a in arts_list)
|
||||
|
||||
filtros = [
|
||||
"r.NUM_FACTURA > 0",
|
||||
"e.CODCONTRATO IS NOT NULL",
|
||||
"TRIM(e.CODCONTRATO) <> ''",
|
||||
# Solo registros donde TODOS los exámenes están en el listado permitido
|
||||
f"NOT EXISTS (SELECT 1 FROM RELACION rx WHERE rx.IDRECEPCION = r.IDRECEPCION AND rx.COD_EXAMEN NOT IN ({arts_in}))",
|
||||
]
|
||||
es_particular = tipo_usuario.strip() == "12"
|
||||
|
||||
filtros = ["r.NUM_FACTURA > 0"]
|
||||
|
||||
if not es_particular:
|
||||
# Para convenios: solo registros con contrato registrado
|
||||
filtros += [
|
||||
"e.CODCONTRATO IS NOT NULL",
|
||||
"TRIM(e.CODCONTRATO) <> ''",
|
||||
]
|
||||
|
||||
# Solo exámenes configurados en TNS
|
||||
filtros.append(
|
||||
f"NOT EXISTS (SELECT 1 FROM RELACION rx WHERE rx.IDRECEPCION = r.IDRECEPCION AND rx.COD_EXAMEN NOT IN ({arts_in}))"
|
||||
)
|
||||
|
||||
params = {}
|
||||
if contrato:
|
||||
filtros.append("e.CODCONTRATO = :contrato")
|
||||
params["contrato"] = contrato
|
||||
c = contrato.strip()
|
||||
c_alt = c.lstrip("0") or c # "012" → "12", "12" → "12"
|
||||
c_pad = c.zfill(max(3, len(c))) # "12" → "012", "011" → "011"
|
||||
filtros.append("TRIM(e.CODCONTRATO) IN (:contrato, :contrato_alt, :contrato_pad)")
|
||||
params["contrato"] = c
|
||||
params["contrato_alt"] = c_alt
|
||||
params["contrato_pad"] = c_pad
|
||||
elif es_particular:
|
||||
# Particulares: NIT_EMPRESA es PART/PARTIC o sin contrato
|
||||
filtros.append(
|
||||
"(r.TIPOUSUSISPRO = '12' OR r.NIT_EMPRESA IN ('PART', 'PARTIC', 'PARTICULAR') "
|
||||
"OR COALESCE(TRIM(e.CODCONTRATO), '') = '')"
|
||||
)
|
||||
if tipo_usuario and not es_particular:
|
||||
filtros.append("r.TIPOUSUSISPRO = :tipo_usuario")
|
||||
params["tipo_usuario"] = tipo_usuario.strip()
|
||||
if factura:
|
||||
filtros.append("r.NUM_FACTURA = :factura")
|
||||
params["factura"] = int(factura)
|
||||
|
||||
Reference in New Issue
Block a user