From 3ead9b4ba124c30224d0fa2ffce0bba7d7a93e7e Mon Sep 17 00:00:00 2001 From: nicolasarana <90768149+nicolasarana@users.noreply.github.com> Date: Tue, 5 May 2026 10:48:55 -0300 Subject: [PATCH 1/2] LAB - Pisar cdas de protocolos de labos sil1 --- modules/cda/controller/CDAPatient.ts | 1 - modules/cda/routes/cda.ts | 27 ++++++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/modules/cda/controller/CDAPatient.ts b/modules/cda/controller/CDAPatient.ts index 9e72b6f6c8..5808de2406 100644 --- a/modules/cda/controller/CDAPatient.ts +++ b/modules/cda/controller/CDAPatient.ts @@ -429,7 +429,6 @@ export function findByMetadata(conds) { export async function CDAExists(id, fecha, orgId) { const existe = await findByMetadata({ 'metadata.extras.id': id, - 'metadata.fecha': fecha, 'metadata.extras.organizacion': Types.ObjectId(orgId), }); return existe; diff --git a/modules/cda/routes/cda.ts b/modules/cda/routes/cda.ts index 6ce4749136..b40ca841c8 100644 --- a/modules/cda/routes/cda.ts +++ b/modules/cda/routes/cda.ts @@ -112,14 +112,23 @@ router.post('/', async (req: any, res, next) => { cdaData.paciente.sexo = cdaData.paciente.sexo === 'M' ? 'masculino' : 'femenino'; const yaExiste = await cdaCtr.CDAExists(cdaData.id, cdaData.fecha, orgId); + const prestacion = await cdaCtr.matchCodeByLoinc(cdaData.loinc); + if (yaExiste) { - return next({ error: 'prestacion_existente' }); + const esLaboratorio = prestacion?.snomed?.semanticTag === 'procedimiento'; + const fechaCda = moment(yaExiste.metadata.fecha); + const haceUnMes = moment().subtract(1, 'month'); + + if (esLaboratorio && fechaCda.isAfter(haceUnMes)) { + await cdaCtr.deleteCda(yaExiste._id, null); + } else { + return next({ error: 'prestacion_existente' }); + } } const organizacion = await Organizacion.findById(orgId); const dataProfesional = req.body.profesional; - const prestacion = await cdaCtr.matchCodeByLoinc(cdaData.loinc); if (!prestacion) { // Es obligatorio que posea prestación return next({ error: 'prestacion_invalida' }); @@ -344,15 +353,23 @@ async function createCDA(req, res, next) { orgId = req.body.organizacion; } const yaExiste = await cdaCtr.CDAExists(idPrestacion, fecha, orgId); + const prestacion = await cdaCtr.matchCode(req.body.tipoPrestacion); + if (yaExiste) { - return res.json({ cda: yaExiste._id, paciente: yaExiste.paciente?._id }); + const esLaboratorio = prestacion?.snomed?.semanticTag === 'procedimiento'; + const fechaCda = moment(yaExiste.metadata.fecha); + const haceUnMes = moment().subtract(1, 'month'); + + if (esLaboratorio && fechaCda.isAfter(haceUnMes)) { + await cdaCtr.deleteCda(yaExiste._id, null); + } else { + return res.json({ cda: yaExiste._id, paciente: yaExiste.paciente?._id }); + } } const dataPaciente = req.body.paciente; const dataProfesional = req.body.profesional; - // Devuelve un Loinc asociado al código SNOMED - const prestacion = await cdaCtr.matchCode(req.body.tipoPrestacion); if (!prestacion) { // Es obligatorio que posea prestación return next(`prestacion_invalida ${req.body.tipoPrestacion}`); From 57285467ed87409d83d7c601687dfa744a84be79 Mon Sep 17 00:00:00 2001 From: nicolasarana <90768149+nicolasarana@users.noreply.github.com> Date: Wed, 8 Jul 2026 13:29:55 -0300 Subject: [PATCH 2/2] =?UTF-8?q?MISC=20-491:=20"Actualizaci=C3=B3n=20en=20g?= =?UTF-8?q?eneraci=C3=B3n=20de=20cdas=20(=20Si=20el=20CDA=20existe=20y=20s?= =?UTF-8?q?u=20fecha=20es=20<=201=20a=C3=B1o=20=E2=86=92=20se=20elimina=20?= =?UTF-8?q?y=20recrea)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/cda/routes/cda.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/cda/routes/cda.ts b/modules/cda/routes/cda.ts index b40ca841c8..fc351d6e8d 100644 --- a/modules/cda/routes/cda.ts +++ b/modules/cda/routes/cda.ts @@ -115,11 +115,10 @@ router.post('/', async (req: any, res, next) => { const prestacion = await cdaCtr.matchCodeByLoinc(cdaData.loinc); if (yaExiste) { - const esLaboratorio = prestacion?.snomed?.semanticTag === 'procedimiento'; const fechaCda = moment(yaExiste.metadata.fecha); - const haceUnMes = moment().subtract(1, 'month'); + const haceUnAnio = moment().subtract(1, 'year'); - if (esLaboratorio && fechaCda.isAfter(haceUnMes)) { + if (fechaCda.isAfter(haceUnAnio)) { await cdaCtr.deleteCda(yaExiste._id, null); } else { return next({ error: 'prestacion_existente' }); @@ -356,11 +355,10 @@ async function createCDA(req, res, next) { const prestacion = await cdaCtr.matchCode(req.body.tipoPrestacion); if (yaExiste) { - const esLaboratorio = prestacion?.snomed?.semanticTag === 'procedimiento'; const fechaCda = moment(yaExiste.metadata.fecha); - const haceUnMes = moment().subtract(1, 'month'); + const haceUnAnio = moment().subtract(1, 'year'); - if (esLaboratorio && fechaCda.isAfter(haceUnMes)) { + if (fechaCda.isAfter(haceUnAnio)) { await cdaCtr.deleteCda(yaExiste._id, null); } else { return res.json({ cda: yaExiste._id, paciente: yaExiste.paciente?._id });