Skip to content

Commit

Permalink
AM - Visualizar los turnos liberados y fuera de agenda
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio-Ramirez committed May 17, 2024
1 parent 5a0a4d1 commit 5dcfae7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import moment = require('moment');
import { PacienteCtr } from '../../../../core-v2/mpi/paciente/paciente.routes';

export async function getHistorial(req) {
let historial;
if (req.query.sinLiberados) {
historial = await getHistorialPaciente(req);
} else {
const turnos = getHistorialPaciente(req);
const liberados = getLiberadosPaciente(req);
const fueraAgendas = getHistorialFueraAgendas(req.query.pacienteId);
const result = await Promise.all([turnos, liberados, fueraAgendas]);
historial = [...result[0], ...result[1], ...result[2]];
}

const turnos = getHistorialPaciente(req);
const liberados = getLiberadosPaciente(req);
const fueraAgendas = getHistorialFueraAgendas(req.query.pacienteId);
const result = await Promise.all([turnos, liberados, fueraAgendas]);
const historial = [...result[0], ...result[1], ...result[2]];

return historial;
}

Expand Down
85 changes: 45 additions & 40 deletions modules/turnos/controller/turnosController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,40 @@ export function getTurno(req) {
const turnos = [];
let turno;

pipelineTurno = [{
$match: {
estado: 'publicada'
}
},
pipelineTurno = [
{
$match: {
estado: 'publicada'
}
},
// Unwind cada array
{ $unwind: '$bloques' },
{ $unwind: '$bloques.turnos' },
{ $unwind: '$bloques' },
{ $unwind: '$bloques.turnos' },
// Filtra los elementos que matchean
{
$match: {
estado: 'publicada'
}
},
{
$group: {
_id: { id: '$_id', bloqueId: '$bloques._id' },
agenda_id: { $first: '$_id' },
organizacion: { $first: '$organizacion' },
profesionales: { $first: '$profesionales' },
turnos: { $push: '$bloques.turnos' }
}
},
{
$group: {
_id: '$_id.id',
agenda_id: { $first: '$agenda_id' },
bloque_id: { $first: '$_id.bloqueId' },
organizacion: { $first: '$organizacion' },
profesionales: { $first: '$profesionales' },
bloques: { $push: { _id: '$_id.bloqueId', turnos: '$turnos' } }
}
}];
{
$match: {
estado: 'publicada'
}
},
{
$group: {
_id: { id: '$_id', bloqueId: '$bloques._id' },
agenda_id: { $first: '$_id' },
organizacion: { $first: '$organizacion' },
profesionales: { $first: '$profesionales' },
turnos: { $push: '$bloques.turnos' }
}
},
{
$group: {
_id: '$_id.id',
agenda_id: { $first: '$agenda_id' },
bloque_id: { $first: '$_id.bloqueId' },
organizacion: { $first: '$organizacion' },
profesionales: { $first: '$profesionales' },
bloques: { $push: { _id: '$_id.bloqueId', turnos: '$turnos' } }
}
}];
// ver llamado, req.query
if (req.query && mongoose.Types.ObjectId.isValid(req.query.id)) {

Expand Down Expand Up @@ -171,7 +172,7 @@ export function getTurno(req) {
*/
export async function getHistorialPaciente(req) {
// console.warn('Deprecation warning: getHistorialPaciente is deprecated. Use getHistorialPaciente in core/mpi/controller/paciente');
if (req.query && req.query.pacienteId) {
if (req.query?.pacienteId) {
const idPaciente = new mongoose.Types.ObjectId(req.query.pacienteId);
const paciente: any = await PacienteCtr.findById(idPaciente);
try {
Expand Down Expand Up @@ -339,17 +340,21 @@ export async function getHistorialPaciente(req) {
}

export async function getLiberadosPaciente(req) {
if (req.query && req.query.pacienteId) {
if (req.query?.pacienteId) {
try {
const idPaciente = new mongoose.Types.ObjectId(req.query.pacienteId);
const paciente: any = await PacienteCtr.findById(idPaciente);
const resultado: any = await logPaciente.find(
{
paciente: { $in: paciente.vinculos },
operacion: 'turnos:liberar',
'dataTurno.turno.updatedBy.organizacion._id': req.user.organizacion._id
})
.exec();
const query = {
paciente: { $in: paciente.vinculos },
operacion: 'turnos:liberar'
};

if (req.user.organizacion?.id) {
query['dataTurno.turno.updatedBy.organizacion._id'] = req.user.organizacion.id;
}

const resultado: any = await logPaciente.find(query).exec();

let turno;
const turnos = [];
resultado.forEach(elem => {
Expand Down

0 comments on commit 5dcfae7

Please sign in to comment.