Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion modules/huds/hudsAccesos.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 }
},
Expand All @@ -76,12 +87,23 @@ export async function search(filtros) {
motivoAcceso: '$accesos.motivoAcceso',
organizacion: '$accesos.organizacion',
detalleMotivo: '$accesos.detalleMotivo',
labelPaciente: {
$ifNull: [
'$accesos.labelPaciente',
{
$ifNull: [
{ $arrayElemAt: ['$motivoHudsData.labelPaciente', 0] },
{ $arrayElemAt: ['$motivoHudsData.label', 0] }
]
}
]
}

}
}
];

return await HudsAcceso.aggregate(aggregate);

}

export const HudsAccesosCtr = {
Expand Down
1 change: 1 addition & 0 deletions modules/huds/hudsAccesos.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion modules/huds/motivosHuds/motivosHuds.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
4 changes: 4 additions & 0 deletions modules/huds/motivosHuds/motivosHuds.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export const MotivosHudsSchema = new Schema({
descripcion: {
type: String,
required: false
},
labelPaciente: {
type: String,
required: false
}

});
Expand Down
Loading