fix: fechaHoraEgreso = fechaHoraRealizacion del ultimo examen
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
00bfbaee51
commit
dd4d012a4b
@@ -112,21 +112,15 @@ def generar_rda_paciente(rows: list, default_profesional: str = "", default_espe
|
||||
|
||||
fecha = _fmt_fecha(h.get("FECHA_RECEPCION"))
|
||||
ingreso = _fmt_datetime(h.get("HORAINICIORECEPCION") or h.get("FECHA_RECEPCION"))
|
||||
# Egreso = última fecha de reporte válida entre los exámenes, o fecha de recepción
|
||||
ultima_fecha = max(
|
||||
(r.get("FECHA_REPORTADO") for r in rows if str(r.get("FECHA_REPORTADO") or "")[:4] != "1900"),
|
||||
default=None,
|
||||
)
|
||||
egreso = _fmt_datetime(ultima_fecha or h.get("FECHA_RECEPCION"))
|
||||
recepcion_dt = _fmt_datetime(h.get("FECHA_RECEPCION"))
|
||||
|
||||
detalle_pedido = []
|
||||
import re as _re
|
||||
for row in rows:
|
||||
fecha_real = _fmt_datetime(
|
||||
row.get("FECHA_REPORTADO") if str(row.get("FECHA_REPORTADO") or "")[:4] != "1900"
|
||||
else h.get("FECHA_RECEPCION")
|
||||
)
|
||||
# TNS solo acepta dígitos en profesionalRemisionante; limpiar "9410/86" → "941086"
|
||||
import re as _re
|
||||
_doc = str(row.get("DOCIDMEDICO") or "").strip()
|
||||
cedula_medico = _re.sub(r"[^0-9]", "", _doc)
|
||||
detalle_pedido.append({
|
||||
@@ -143,9 +137,15 @@ def generar_rda_paciente(rows: list, default_profesional: str = "", default_espe
|
||||
"especialidad": default_especialidad or None,
|
||||
"profesionalRemisionante": cedula_medico or default_remisionante or None,
|
||||
"diagnosticoprincipal": str(h.get("DIAG_PPAL") or "").strip(),
|
||||
"fechaHoraRealizacion": fecha_real or egreso,
|
||||
"fechaHoraRealizacion": fecha_real or recepcion_dt,
|
||||
})
|
||||
|
||||
# Egreso = fechaHoraRealizacion del último examen en el detalle
|
||||
egreso = max(
|
||||
(d["fechaHoraRealizacion"] for d in detalle_pedido if d["fechaHoraRealizacion"]),
|
||||
default=recepcion_dt,
|
||||
)
|
||||
|
||||
nit_empresa = str(h.get("NIT_EMPRESA") or "").strip()
|
||||
cod_contrato_raw = str(h.get("CODCONTRATO") or "").strip()
|
||||
# Particular: por NIT_EMPRESA "PART" o por contrato "12"/"012"
|
||||
|
||||
Reference in New Issue
Block a user