Optimizaciones de rendimiento: consultas paralelas en API, caché de Regex en parser de laboratorio y pre-cálculo de claves en sortCamas
This commit is contained in:
+78
-24
@@ -79,33 +79,87 @@ function generateUUID() {
|
||||
// ========== STATE ENDPOINT (initial load) ==========
|
||||
app.get('/api/state', async (req, res) => {
|
||||
try {
|
||||
const areasList = await getAllAreas();
|
||||
const usuariosList = await getAllUsuarios();
|
||||
const [
|
||||
pacientes,
|
||||
areasList,
|
||||
camas,
|
||||
internaciones,
|
||||
rawEvoluciones,
|
||||
rawLaboratorios,
|
||||
otrosLaboratorios,
|
||||
glucemias,
|
||||
acidosBase,
|
||||
cultivos,
|
||||
tiposCultivo,
|
||||
gruposDeterminacionesLab,
|
||||
estudiosComplementarios,
|
||||
rawInterconsultas,
|
||||
atb,
|
||||
indicaciones,
|
||||
movimientosIndicaciones,
|
||||
pendientes,
|
||||
usuariosList
|
||||
] = await Promise.all([
|
||||
getAllPacientes(),
|
||||
getAllAreas(),
|
||||
getAllCamas(),
|
||||
getAllInternaciones(),
|
||||
getAllEvoluciones(),
|
||||
getAllLaboratorios(),
|
||||
getAllOtrosLaboratorios(),
|
||||
getAllGlucemias(),
|
||||
getAllAcidosBase(),
|
||||
getAllCultivos(),
|
||||
getAllTiposCultivo(),
|
||||
getAllGruposLaboratorio(),
|
||||
getAllEstudiosComplementarios(),
|
||||
getAllInterconsultas(),
|
||||
getAllAtb(),
|
||||
getAllIndicaciones(),
|
||||
getAllMovimientosIndicaciones(),
|
||||
getAllPendientes(),
|
||||
getAllUsuarios()
|
||||
]);
|
||||
|
||||
const evoluciones = rawEvoluciones.map(e => ({
|
||||
...e,
|
||||
signosVitales: typeof e.signosVitales === 'string' ? JSON.parse(e.signosVitales) : e.signosVitales,
|
||||
examenFisico: typeof e.examenFisico === 'string' ? JSON.parse(e.examenFisico) : e.examenFisico
|
||||
}));
|
||||
|
||||
const laboratorios = rawLaboratorios.map(l => ({
|
||||
...l,
|
||||
resultados: typeof l.resultados === 'string' ? JSON.parse(l.resultados) : l.resultados
|
||||
}));
|
||||
|
||||
const interconsultas = rawInterconsultas.map(ic => ({
|
||||
...ic,
|
||||
realizada: !!ic.realizada
|
||||
}));
|
||||
|
||||
const usuarios = usuariosList.map(({ passwordHash, ...u }) => u);
|
||||
|
||||
const state = {
|
||||
pacientes: await getAllPacientes(),
|
||||
pacientes,
|
||||
areas: areasList,
|
||||
grupos: areasList,
|
||||
camas: await getAllCamas(),
|
||||
internaciones: await getAllInternaciones(),
|
||||
evoluciones: (await getAllEvoluciones()).map(e => ({
|
||||
...e,
|
||||
signosVitales: typeof e.signosVitales === 'string' ? JSON.parse(e.signosVitales) : e.signosVitales,
|
||||
examenFisico: typeof e.examenFisico === 'string' ? JSON.parse(e.examenFisico) : e.examenFisico
|
||||
})),
|
||||
laboratorios: (await getAllLaboratorios()).map(l => ({ ...l, resultados: typeof l.resultados === 'string' ? JSON.parse(l.resultados) : l.resultados })),
|
||||
otrosLaboratorios: await getAllOtrosLaboratorios(),
|
||||
glucemias: await getAllGlucemias(),
|
||||
acidosBase: await getAllAcidosBase(),
|
||||
cultivos: await getAllCultivos(),
|
||||
tiposCultivo: await getAllTiposCultivo(),
|
||||
gruposDeterminacionesLab: await getAllGruposLaboratorio(),
|
||||
estudiosComplementarios: await getAllEstudiosComplementarios(),
|
||||
interconsultas: (await getAllInterconsultas()).map(ic => ({ ...ic, realizada: !!ic.realizada })),
|
||||
atb: await getAllAtb(),
|
||||
indicaciones: await getAllIndicaciones(),
|
||||
movimientosIndicaciones: await getAllMovimientosIndicaciones(),
|
||||
pendientes: await getAllPendientes(),
|
||||
usuarios: usuariosList.map(({ passwordHash, ...u }) => u),
|
||||
camas,
|
||||
internaciones,
|
||||
evoluciones,
|
||||
laboratorios,
|
||||
otrosLaboratorios,
|
||||
glucemias,
|
||||
acidosBase,
|
||||
cultivos,
|
||||
tiposCultivo,
|
||||
gruposDeterminacionesLab,
|
||||
estudiosComplementarios,
|
||||
interconsultas,
|
||||
atb,
|
||||
indicaciones,
|
||||
movimientosIndicaciones,
|
||||
pendientes,
|
||||
usuarios,
|
||||
vistaActual: 'dashboard',
|
||||
currentInternacionId: null
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user