From ba024772485de150a40585f31056c10840a809b2 Mon Sep 17 00:00:00 2001 From: Fabio-Ramirez Date: Tue, 23 Jun 2026 15:18:43 -0300 Subject: [PATCH 1/2] Accesos a la HUDS --- modules/huds/hudsAccesos.controller.ts | 13 ++++++++++++- modules/huds/hudsAccesos.schema.ts | 1 + modules/huds/motivosHuds/motivosHuds.schema.ts | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/huds/hudsAccesos.controller.ts b/modules/huds/hudsAccesos.controller.ts index d579bc82fe..d4cff3251f 100644 --- a/modules/huds/hudsAccesos.controller.ts +++ b/modules/huds/hudsAccesos.controller.ts @@ -16,11 +16,13 @@ export async function search(filtros) { if (filtros.fechaDesde) { fechas.push({ 'accesos.fecha': { $gte: new Date(filtros.fechaDesde) } }); filtros['$and'] = fechas; + match['accesos.fecha'] = { $gte: new Date(filtros.fechaDesde) }; } if (filtros.fechaHasta) { fechas.push({ 'accesos.fecha': { $lte: new Date(filtros.fechaHasta) } }); filtros['$and'] = fechas; + match['accesos.fecha'] = { $lte: new Date(filtros.fechaHasta) }; } if (filtros.paciente) { @@ -59,6 +61,15 @@ export async function search(filtros) { { $unwind: '$accesos', }, + { + $lookup: { + from: 'motivosHuds', + localField: 'accesos.motivoAcceso', + foreignField: 'key', + as: 'motivoHudsData' + } + }, + { $sort: { 'accesos.fecha': -1 } }, @@ -76,12 +87,12 @@ export async function search(filtros) { motivoAcceso: '$accesos.motivoAcceso', organizacion: '$accesos.organizacion', detalleMotivo: '$accesos.detalleMotivo', + labelPaciente: { $arrayElemAt: ['$motivoHudsData.labelPaciente', 0] } } } ]; return await HudsAcceso.aggregate(aggregate); - } export const HudsAccesosCtr = { diff --git a/modules/huds/hudsAccesos.schema.ts b/modules/huds/hudsAccesos.schema.ts index 6c6c243274..7d9682d4a0 100644 --- a/modules/huds/hudsAccesos.schema.ts +++ b/modules/huds/hudsAccesos.schema.ts @@ -22,6 +22,7 @@ export const HudsAccesoSchema = new Schema({ matricula: String, motivoAcceso: String, detalleMotivo: String, + labelPaciente: String, turno: SchemaTypes.ObjectId, prestacion: SchemaTypes.ObjectId, organizacion: SchemaTypes.Mixed, diff --git a/modules/huds/motivosHuds/motivosHuds.schema.ts b/modules/huds/motivosHuds/motivosHuds.schema.ts index 324d7f10ad..9e953cac88 100644 --- a/modules/huds/motivosHuds/motivosHuds.schema.ts +++ b/modules/huds/motivosHuds/motivosHuds.schema.ts @@ -17,6 +17,10 @@ export const MotivosHudsSchema = new Schema({ descripcion: { type: String, required: false + }, + labelPaciente: { + type: String, + required: false } }); From 6eca4ea3b2af5833338b75ed31ed9b0feb26c070 Mon Sep 17 00:00:00 2001 From: Fabio-Ramirez Date: Wed, 22 Jul 2026 12:21:30 -0300 Subject: [PATCH 2/2] Se agrega cambios para el labelPaciente --- modules/huds/hudsAccesos.controller.ts | 13 ++++++++++++- modules/huds/motivosHuds/motivosHuds.routes.ts | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/modules/huds/hudsAccesos.controller.ts b/modules/huds/hudsAccesos.controller.ts index d4cff3251f..6aaa61d4a3 100644 --- a/modules/huds/hudsAccesos.controller.ts +++ b/modules/huds/hudsAccesos.controller.ts @@ -87,7 +87,18 @@ export async function search(filtros) { motivoAcceso: '$accesos.motivoAcceso', organizacion: '$accesos.organizacion', detalleMotivo: '$accesos.detalleMotivo', - labelPaciente: { $arrayElemAt: ['$motivoHudsData.labelPaciente', 0] } + labelPaciente: { + $ifNull: [ + '$accesos.labelPaciente', + { + $ifNull: [ + { $arrayElemAt: ['$motivoHudsData.labelPaciente', 0] }, + { $arrayElemAt: ['$motivoHudsData.label', 0] } + ] + } + ] + } + } } ]; diff --git a/modules/huds/motivosHuds/motivosHuds.routes.ts b/modules/huds/motivosHuds/motivosHuds.routes.ts index f36239b8c6..627c790997 100644 --- a/modules/huds/motivosHuds/motivosHuds.routes.ts +++ b/modules/huds/motivosHuds/motivosHuds.routes.ts @@ -8,8 +8,10 @@ class MotivosHudsResource extends ResourceBase { label: MongoQuery.partialString, key: MongoQuery.partialString, descripcion: MongoQuery.partialString, - moduloDefault: MongoQuery.partialString + moduloDefault: MongoQuery.partialString, + labelPaciente: MongoQuery.partialString }; } + export const MotivosHudsCtr = new MotivosHudsResource({}); export const MotivosHudsRouter = MotivosHudsCtr.makeRoutes();