From 360ef0ec628592a4d28dc0c5ca66ff51f7dd3b0a Mon Sep 17 00:00:00 2001 From: ponjaBob Date: Fri, 31 Jul 2026 12:32:49 -0300 Subject: [PATCH] FEAT - Incluir financiadores p/Base --- core/tm/controller/consentimiento.ts | 26 ++++++++++++++++++-------- core/tm/routes/consentimiento.ts | 4 ++-- core/tm/schemas/consentimiento.ts | 8 ++++++++ 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/core/tm/controller/consentimiento.ts b/core/tm/controller/consentimiento.ts index 96f4ec680b..b37f777687 100644 --- a/core/tm/controller/consentimiento.ts +++ b/core/tm/controller/consentimiento.ts @@ -1,10 +1,9 @@ import { Types } from 'mongoose'; import { Paciente } from '../../../core-v2/mpi/paciente'; -import { calcularEdad } from '../../../core-v2/mpi/paciente/paciente.schema'; import { getObraSocial } from '../../../modules/obraSocial/controller/obraSocial'; -import { Consentimiento, PadronElectoral } from '../schemas/consentimiento'; +import { Consentimiento, ConsentimientoVersion, PadronElectoral } from '../schemas/consentimiento'; -async function validarPaciente(pacienteId: any, documento: any, sexo: any) { +async function validarPaciente(pacienteId: any, documento: any, sexo: any, programa: String, version: Number) { try { if (!pacienteId && (!documento || !sexo)) { return { status: 400, message: { mensaje: 'pacienteId o documento y sexo son requeridos' } }; @@ -22,9 +21,8 @@ async function validarPaciente(pacienteId: any, documento: any, sexo: any) { if (paciente.fechaFallecimiento && paciente.fechaFallecimiento !== null) { return { status: 200, message: { validado: false, mensaje: 'Paciente fallecido', Fecha: paciente.fechaFallecimiento } }; } - const edadPaciente = calcularEdad(paciente.fechaNacimiento, paciente.fechaFallecimiento); - if (edadPaciente && edadPaciente >= 65) { - const financiador = tieneFinanciador(paciente.financiador || await getObraSocial(paciente)); + if (paciente.edad && paciente.edad >= 65) { + const financiador = await tieneFinanciador(paciente.financiador && paciente.financiador.length ? paciente.financiador : await getObraSocial(paciente), programa, version); if (!financiador) { const matriculaNum = Number(paciente.documento); if (!isNaN(matriculaNum)) { @@ -44,8 +42,20 @@ async function validarPaciente(pacienteId: any, documento: any, sexo: any) { } } -function tieneFinanciador(financiador: any) { - return financiador && financiador.length > 0 && (financiador.some(f => f.nombre !== 'SUMAR')); +async function tieneFinanciador(financiador: any, programa: String, version: Number) { + const consentimientoVersion: any = await ConsentimientoVersion.findOne({ programa, version }); + const incluirFinanciador = consentimientoVersion.condiciones?.incluirFinanciador || ['SUMAR']; + const nombres: string[] = []; + const codigoPuco: number[] = []; + for (const financ of incluirFinanciador) { + if (financ.nombre) { + nombres.push(financ.nombre); + } + if (financ.codigoPuco) { + codigoPuco.push(financ.codigoPuco); + } + } + return financiador && financiador.length > 0 && (financiador.some(f => !nombres.includes(f.nombre) && !codigoPuco.includes(f.codigoPuco))); } async function guardarConsentimiento(programa: string, version: number, pacienteId: any, aceptacion: boolean) { diff --git a/core/tm/routes/consentimiento.ts b/core/tm/routes/consentimiento.ts index 63d4340e35..32bc33deb7 100644 --- a/core/tm/routes/consentimiento.ts +++ b/core/tm/routes/consentimiento.ts @@ -30,8 +30,8 @@ class PadronElectoralResource extends ResourceBase { } router.get('/validarPaciente', Auth.authenticate(), async (req: express.Request, res: express.Response) => { - const { pacienteId, documento, sexo } = req.query; - const resultado = await validarPaciente(pacienteId, documento, sexo); + const { pacienteId, documento, sexo, programa = 'Cuidar65', version = 1 } = req.query; + const resultado = await validarPaciente(pacienteId, documento, sexo, programa, version); res.status(resultado.status).json(resultado.message); }); diff --git a/core/tm/schemas/consentimiento.ts b/core/tm/schemas/consentimiento.ts index aa74bfe329..fdf19f4083 100644 --- a/core/tm/schemas/consentimiento.ts +++ b/core/tm/schemas/consentimiento.ts @@ -7,6 +7,14 @@ export const consentimientoVersionSchema = new Schema({ texto: { type: String, required: true }, activo: { type: Boolean, required: true }, formato: { type: String, required: true, enum: ['html', 'markdown', 'text'] }, + condiciones: { + incluirFinanciador: [ + { + codigoPuco: { type: Number, required: false }, + nombre: { type: String, required: true }, + } + ] + }, createdAt: { type: Date, default: Date.now }, createdBy: { type: Schema.Types.Mixed } });