-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CITAS: Script corrige OS en turnos de pacientes (#1860)
* CITAS: script corrige OS en turnos de pacientes * fix(Prestaciones): se corrigen las OS de pacientes en prestaciones
- Loading branch information
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |