Skip to content

Commit

Permalink
CITAS: Script corrige OS en turnos de pacientes (#1860)
Browse files Browse the repository at this point in the history
* CITAS: script corrige OS en turnos de pacientes

* fix(Prestaciones): se corrigen las OS de pacientes en prestaciones
  • Loading branch information
MCele committed Jan 16, 2024
1 parent ddf0605 commit 5243d0d
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
49 changes: 49 additions & 0 deletions scripts/corregir_os_prestaciones.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Prestacion } from '../modules/rup/schemas/prestacion';


async function run(done) {
const count = 1;
// se corrigen las prestaciones en donde las OS quedaron de forma incorrecta
const ultimasPrestaciones = {
// Fechas entre las que hubo problema con OS de pacientes
createdAt: {
$gte: new Date('2024-01-04 00:00:00.000-03:00'),
$lte: new Date('2024-01-06 00:00:00.000-03:00')
},
'paciente.obraSocial.nombre.nombre': { $exists: true }
};

const cursor = Prestacion.find(ultimasPrestaciones).cursor({ batchSize: 100 });
const actualizarTurnos = async (prestacion) => {
let obraSocial = {
nombre: '',
financiador: '',
prepaga: false,
codigoPuco: null
};

obraSocial = prestacion.paciente?.obraSocial?.nombre || null;

if (obraSocial.nombre) {
try {
if (prestacion.paciente.obraSocial) {
await Prestacion.updateOne(
{ _id: prestacion.id },
{
$set: { 'paciente.obraSocial': obraSocial }
}
);
}
} catch (error) {

}
}
};

await cursor.eachAsync(async (prestacion: any) => {
await actualizarTurnos(prestacion);
});
done();
}

export = run;
49 changes: 49 additions & 0 deletions scripts/corregir_os_turnos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Agenda } from '../modules/turnos/schemas/agenda';
import { Types } from 'mongoose';


async function run(done) {
// se corrigen turnos en donde las OS quedaron de forma incorrecta
const ultimasAgendas = {
// Fechas entre las que hubo problema con OS de pacientes
horaInicio: {
$gte: new Date('2024-01-04 00:00:00.000-03:00'),
$lte: new Date('2024-01-31 00:00:00.000-03:00')
},
'bloques.turnos.paciente.obraSocial.nombre.nombre': { $exists: true }
};
const cursor = Agenda.find(ultimasAgendas).cursor({ batchSize: 100 });
const actualizarTurnos = async (agenda) => {
let obraSocial = {
nombre: '',
financiador: '',
prepaga: false,
codigoPuco: null
};

for (const bloque of agenda.bloques) {
for (const turno of bloque.turnos) {
if (turno.estado === 'asignado') {
if (turno.paciente?.obraSocial?.nombre?.nombre) {
obraSocial = turno.paciente.obraSocial.nombre;
if (turno.paciente.obraSocial) {
await Agenda.update(
{ _id: agenda.id },
{
$set: { 'bloques.$[elemento1].turnos.$[elemento2].paciente.obraSocial': obraSocial }
},
{ arrayFilters: [{ 'elemento1._id': Types.ObjectId(bloque.id) }, { 'elemento2._id': Types.ObjectId(turno.id) }] }
);
}
}
}
}
}
};
await cursor.eachAsync(async (agenda: any) => {
await actualizarTurnos(agenda);
});
done();
}

export = run;

0 comments on commit 5243d0d

Please sign in to comment.