From 6615c4609216b1c2ade34fc5e5a92ed538f55d7c Mon Sep 17 00:00:00 2001 From: aldoEMatamala Date: Thu, 5 Mar 2026 17:29:31 -0300 Subject: [PATCH] feat(COM-115): Agregar filtro por rango etario --- .../derivaciones.routes.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/modules/centroOperativoMedico/derivaciones.routes.ts b/modules/centroOperativoMedico/derivaciones.routes.ts index 1766644ef..845267630 100644 --- a/modules/centroOperativoMedico/derivaciones.routes.ts +++ b/modules/centroOperativoMedico/derivaciones.routes.ts @@ -54,6 +54,26 @@ class DerivacionesResource extends ResourceBase { }; }, cancelada: MongoQuery.equalMatch, + rangoEtario: (value) => { + const limiteDate = moment().subtract(14, 'years').toDate(); + const limiteString = moment().subtract(14, 'years').toISOString(); + if (value === 'pediatrico') { + return { + $or: [ + { 'paciente.fechaNacimiento': { $gt: limiteDate } }, + { 'paciente.fechaNacimiento': { $gt: limiteString } } + ] + }; + } else if (value === 'adultos') { + return { + $or: [ + { 'paciente.fechaNacimiento': { $lte: limiteDate } }, + { 'paciente.fechaNacimiento': { $lte: limiteString } } + ] + }; + } + return {}; + } }; }