Agrega campos demograficos paciente en RDA y Tercero (etnia, zona, identidadGenero, divPolitica, antecedentes, fechaNac, direccion)
- SQL RDA join PACIENTE para obtener datos demograficos - generar_rda_paciente: incluye etnia, identidadGenero, zona, divisionPoliticaAdministrativa, antecedentes, fechaNacimiento, direccion - generar_tercero_api: agrega identidadGenero, divisionPoliticaAdministrativa, antecedentes; default ciudad Cucuta 54001 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
bdc0e244fc
commit
58bdb4ae55
@@ -64,11 +64,18 @@ SELECT
|
|||||||
m.COD_ESPECIALIDAD,
|
m.COD_ESPECIALIDAD,
|
||||||
COALESCE(NULLIF(TRIM(m.CODIGO), ''), NULLIF(TRIM(r.USUARIO), ''), '') AS profesional,
|
COALESCE(NULLIF(TRIM(m.CODIGO), ''), NULLIF(TRIM(r.USUARIO), ''), '') AS profesional,
|
||||||
e.CODCONTRATO,
|
e.CODCONTRATO,
|
||||||
TRIM(m.DOCIDMEDICO) AS DOCIDMEDICO
|
TRIM(m.DOCIDMEDICO) AS DOCIDMEDICO,
|
||||||
|
p.F_NACIMIENTO AS F_NAC_PAC,
|
||||||
|
p.SEXO AS SEXO_PAC,
|
||||||
|
p.CODETNIA AS CODETNIA_PAC,
|
||||||
|
COALESCE(TRIM(p.DIRECCION), '') AS DIRECCION_PAC,
|
||||||
|
p.CIUDAD AS COD_CIUDAD_PAC,
|
||||||
|
p.TIPORES AS TIPORES_PAC
|
||||||
FROM RECEPCION r
|
FROM RECEPCION r
|
||||||
JOIN RELACION rel ON rel.IDRECEPCION = r.IDRECEPCION
|
JOIN RELACION rel ON rel.IDRECEPCION = r.IDRECEPCION
|
||||||
LEFT JOIN MEDICO m ON m.CODIGO = r.COD_MEDICO
|
LEFT JOIN MEDICO m ON m.CODIGO = r.COD_MEDICO
|
||||||
LEFT JOIN EMPRESA e ON e.NIT = r.NIT_EMPRESA
|
LEFT JOIN EMPRESA e ON e.NIT = r.NIT_EMPRESA
|
||||||
|
LEFT JOIN PACIENTE p ON p.CODIGO = r.COD_PACIENTE
|
||||||
WHERE r.FECHA_RECEPCION BETWEEN :fecha_ini AND :fecha_fin
|
WHERE r.FECHA_RECEPCION BETWEEN :fecha_ini AND :fecha_fin
|
||||||
AND r.NUM_FACTURA > 0
|
AND r.NUM_FACTURA > 0
|
||||||
{filtro_contrato_rda}
|
{filtro_contrato_rda}
|
||||||
|
|||||||
@@ -24,11 +24,18 @@ SELECT
|
|||||||
m.COD_ESPECIALIDAD,
|
m.COD_ESPECIALIDAD,
|
||||||
COALESCE(NULLIF(TRIM(m.CODIGO), ''), NULLIF(TRIM(r.USUARIO), ''), '') AS profesional,
|
COALESCE(NULLIF(TRIM(m.CODIGO), ''), NULLIF(TRIM(r.USUARIO), ''), '') AS profesional,
|
||||||
e.CODCONTRATO,
|
e.CODCONTRATO,
|
||||||
TRIM(m.DOCIDMEDICO) AS DOCIDMEDICO
|
TRIM(m.DOCIDMEDICO) AS DOCIDMEDICO,
|
||||||
|
p.F_NACIMIENTO AS F_NAC_PAC,
|
||||||
|
p.SEXO AS SEXO_PAC,
|
||||||
|
p.CODETNIA AS CODETNIA_PAC,
|
||||||
|
COALESCE(TRIM(p.DIRECCION), '') AS DIRECCION_PAC,
|
||||||
|
p.CIUDAD AS COD_CIUDAD_PAC,
|
||||||
|
p.TIPORES AS TIPORES_PAC
|
||||||
FROM RECEPCION r
|
FROM RECEPCION r
|
||||||
JOIN RELACION rel ON rel.IDRECEPCION = r.IDRECEPCION
|
JOIN RELACION rel ON rel.IDRECEPCION = r.IDRECEPCION
|
||||||
LEFT JOIN MEDICO m ON m.CODIGO = r.COD_MEDICO
|
LEFT JOIN MEDICO m ON m.CODIGO = r.COD_MEDICO
|
||||||
LEFT JOIN EMPRESA e ON e.NIT = r.NIT_EMPRESA
|
LEFT JOIN EMPRESA e ON e.NIT = r.NIT_EMPRESA
|
||||||
|
LEFT JOIN PACIENTE p ON p.CODIGO = r.COD_PACIENTE
|
||||||
WHERE {where}
|
WHERE {where}
|
||||||
AND r.NUM_FACTURA > 0
|
AND r.NUM_FACTURA > 0
|
||||||
AND e.CODCONTRATO IS NOT NULL
|
AND e.CODCONTRATO IS NOT NULL
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ def generar_tercero_api(row: dict) -> dict:
|
|||||||
tipo_doc = _TIPO_DOC_MAP.get(str(row.get("TIPOIDENT") or "CC").strip(), "C")
|
tipo_doc = _TIPO_DOC_MAP.get(str(row.get("TIPOIDENT") or "CC").strip(), "C")
|
||||||
zona = _ZONA_MAP.get(str(row.get("TIPORES") or "U").strip(), "01")
|
zona = _ZONA_MAP.get(str(row.get("TIPORES") or "U").strip(), "01")
|
||||||
|
|
||||||
|
sexo = str(row.get("SEXO") or "M").strip().upper()
|
||||||
|
identidad_genero = "1" if sexo == "M" else "2"
|
||||||
|
cod_ciudad = str(row.get("COD_CIUDAD") or "54001").strip() or "54001"
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"codigo": str(row.get("CODIGO") or "").strip(),
|
"codigo": str(row.get("CODIGO") or "").strip(),
|
||||||
"natJuridica": "N",
|
"natJuridica": "N",
|
||||||
@@ -64,8 +68,9 @@ def generar_tercero_api(row: dict) -> dict:
|
|||||||
"apellido1": apellidos[0] if apellidos else "",
|
"apellido1": apellidos[0] if apellidos else "",
|
||||||
"apellido2": apellidos[1] if len(apellidos) > 1 else "",
|
"apellido2": apellidos[1] if len(apellidos) > 1 else "",
|
||||||
"direccion": (row.get("DIRECCION") or "").strip(),
|
"direccion": (row.get("DIRECCION") or "").strip(),
|
||||||
"codigoCiudad": str(row.get("COD_CIUDAD") or "00").strip(),
|
"codigoCiudad": cod_ciudad,
|
||||||
"nombreCiudad": (row.get("NOM_CIUDAD") or "SIN CIUDAD").strip().upper(),
|
"nombreCiudad": (row.get("NOM_CIUDAD") or "CUCUTA").strip().upper(),
|
||||||
|
"divisionPoliticaAdministrativa": cod_ciudad,
|
||||||
"zona1": "00",
|
"zona1": "00",
|
||||||
"clasificacion": "00",
|
"clasificacion": "00",
|
||||||
"nomRegTri": nombre_completo,
|
"nomRegTri": nombre_completo,
|
||||||
@@ -77,9 +82,11 @@ def generar_tercero_api(row: dict) -> dict:
|
|||||||
"codigoBarrio": "00",
|
"codigoBarrio": "00",
|
||||||
"comision": 0,
|
"comision": 0,
|
||||||
"fechaNacimiento": _fmt_fecha(row.get("F_NACIMIENTO")),
|
"fechaNacimiento": _fmt_fecha(row.get("F_NACIMIENTO")),
|
||||||
"sexo": str(row.get("SEXO") or "M").strip(),
|
"sexo": sexo,
|
||||||
|
"identidadGenero": identidad_genero,
|
||||||
"zona": zona,
|
"zona": zona,
|
||||||
"etnia": str(row.get("CODETNIA") or "99").strip(),
|
"etnia": str(row.get("CODETNIA") or "99").strip(),
|
||||||
|
"antecedentes": "",
|
||||||
"cliente": "S",
|
"cliente": "S",
|
||||||
"enfermedadCronica": False,
|
"enfermedadCronica": False,
|
||||||
"noEnviarMinSalud": False,
|
"noEnviarMinSalud": False,
|
||||||
@@ -160,9 +167,18 @@ def generar_rda_paciente(rows: list, default_profesional: str = "", default_espe
|
|||||||
tipousu = str(h.get("TIPOUSU") or "").strip()
|
tipousu = str(h.get("TIPOUSU") or "").strip()
|
||||||
tipoususispro = _TIPOUSU_MAP.get(tipousu, "11")
|
tipoususispro = _TIPOUSU_MAP.get(tipousu, "11")
|
||||||
|
|
||||||
# viaIngreso y modalidadAtencion no existen en RECEPCION → valores fijos de laboratorio
|
# Datos demográficos del paciente (disponibles cuando el SQL hace JOIN PACIENTE)
|
||||||
via_ingreso = "01" # Demanda espontánea (pacientes llegan directo al lab)
|
sexo_pac = str(h.get("SEXO_PAC") or "M").strip().upper()
|
||||||
modalidad = "01" # Intramural (laboratorio en sede fija)
|
identidad_genero = "1" if sexo_pac == "M" else "2"
|
||||||
|
etnia_pac = str(h.get("CODETNIA_PAC") or "99").strip() or "99"
|
||||||
|
tipores_pac = str(h.get("TIPORES_PAC") or "U").strip()
|
||||||
|
zona_pac = _ZONA_MAP.get(tipores_pac, "01")
|
||||||
|
div_pol = str(h.get("COD_CIUDAD_PAC") or "54001").strip() or "54001"
|
||||||
|
fecha_nac_pac = _fmt_fecha(h.get("F_NAC_PAC"))
|
||||||
|
direccion_pac = str(h.get("DIRECCION_PAC") or "").strip()
|
||||||
|
|
||||||
|
via_ingreso = "01"
|
||||||
|
modalidad = "01"
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"codigoPrefijo": default_prefijo or str(h.get("PREFIJO") or "00").strip(),
|
"codigoPrefijo": default_prefijo or str(h.get("PREFIJO") or "00").strip(),
|
||||||
@@ -186,6 +202,13 @@ def generar_rda_paciente(rows: list, default_profesional: str = "", default_espe
|
|||||||
"esTerapia": False,
|
"esTerapia": False,
|
||||||
"esProcedimiento": False,
|
"esProcedimiento": False,
|
||||||
"numeroAutorizacion": autorizacion,
|
"numeroAutorizacion": autorizacion,
|
||||||
|
"etnia": etnia_pac,
|
||||||
|
"identidadGenero": identidad_genero,
|
||||||
|
"zona": zona_pac,
|
||||||
|
"divisionPoliticaAdministrativa": div_pol,
|
||||||
|
"antecedentes": "",
|
||||||
|
"fechaNacimiento": fecha_nac_pac,
|
||||||
|
"direccion": direccion_pac,
|
||||||
"detallePedido": detalle_pedido,
|
"detallePedido": detalle_pedido,
|
||||||
"detalleFormaPago": [{
|
"detalleFormaPago": [{
|
||||||
"codigoFormaPago": cod_forma_pago,
|
"codigoFormaPago": cod_forma_pago,
|
||||||
|
|||||||
Reference in New Issue
Block a user