Fix profesional/especialidad: use MEDICO.CODIGO first, add config defaults

- SQL query now prioritizes MEDICO.CODIGO over RECEPCION.USUARIO as profesional
  (USUARIO is the billing clerk; MEDICO is the medical professional)
- Add profesional_default and especialidad_default config keys for when
  Firebird data is empty or contains invalid values (e.g. especialidad = ".")
- generar_rda_paciente accepts default_profesional and default_especialidad params
- ensure_defaults in queries.py now updates existing query records on startup

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-26 16:12:16 -05:00
co-authored by Claude Sonnet 4.6
parent fbdce1c790
commit c70f0f1062
5 changed files with 22 additions and 9 deletions
+3 -3
View File
@@ -96,7 +96,7 @@ def agrupar_por_recepcion(rows: list) -> dict:
return grupos
def generar_rda_paciente(rows: list) -> dict:
def generar_rda_paciente(rows: list, default_profesional: str = "", default_especialidad: str = "") -> dict:
if not rows:
return {}
h = rows[0]
@@ -126,8 +126,8 @@ def generar_rda_paciente(rows: list) -> dict:
"porcentajeIva": 0,
"impConsumo": 0,
"observacion": "",
"profesional": str(h.get("profesional") or "").strip(),
"especialidad": (lambda e: e if e not in (".", "-", "0", "00") else "")(str(row.get("COD_ESPECIALIDAD") or "").strip()),
"profesional": str(row.get("profesional") or "").strip() or default_profesional,
"especialidad": (lambda e: e if e not in (".", "-", "0", "00") else default_especialidad)(str(row.get("COD_ESPECIALIDAD") or "").strip()),
"diagnosticoprincipal": str(h.get("DIAG_PPAL") or "").strip(),
"fechaHoraRealizacion": fecha_real or egreso,
})