Skip to content

Commit

Permalink
feat(IN): implementa periodos censables en internacion (#1894)
Browse files Browse the repository at this point in the history
  • Loading branch information
ma7payne committed Jun 26, 2024
1 parent f159ad5 commit b33c37c
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 4 deletions.
65 changes: 65 additions & 0 deletions modules/rup/internacion/censo.controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,71 @@ test('Censo diario - Paciente tiene paseDe y tiene paseA', async () => {
});
});


test('Censo diario - Prestación con periodos censables incluyentes', async () => {
const nuevaPrestacion: any = new Prestacion(createInternacionPrestacion(cama.organizacion));
nuevaPrestacion.ejecucion.registros[0].valor.informeIngreso.fechaIngreso = moment().subtract(10, 'd').toDate();
nuevaPrestacion.ejecucion.registros[1].valor.InformeEgreso.fechaEgreso = null;
nuevaPrestacion.periodosCensables = [{ desde: moment().subtract(1, 'd'), hasta: moment().add(1, 'd') }];

Auth.audit(nuevaPrestacion, ({ user: {} }) as any);
const internacion = await nuevaPrestacion.save();

await CamasEstadosController.store(
{ organizacion, ambito, capa, cama: idCama },
estadoOcupada(moment().subtract(10, 'd').toDate(), internacion._id, cama.unidadOrganizativaOriginal),
REQMock
);

const resultado = await CensoController.censoDiario({ organizacion, timestamp: moment().toDate(), unidadOrganizativa });

expect(resultado.censo).toEqual({
existenciaALas0: 1,
ingresos: 0,
pasesDe: 0,
altas: 0,
defunciones: 0,
pasesA: 0,
existenciaALas24: 1,
ingresosYEgresos: 0,
pacientesDia: 1,
diasEstada: 0,
disponibles: 1
});
});

test('Censo diario - Prestación con periodos censables excluyentes', async () => {
const nuevaPrestacion: any = new Prestacion(createInternacionPrestacion(cama.organizacion));
nuevaPrestacion.ejecucion.registros[0].valor.informeIngreso.fechaIngreso = moment().subtract(10, 'd').toDate();
nuevaPrestacion.ejecucion.registros[1].valor.InformeEgreso.fechaEgreso = null;
nuevaPrestacion.periodosCensables = [{ desde: moment().add(1, 'd'), hasta: moment().add(3, 'd') }];

Auth.audit(nuevaPrestacion, ({ user: {} }) as any);
const internacion = await nuevaPrestacion.save();

await CamasEstadosController.store(
{ organizacion, ambito, capa, cama: idCama },
estadoOcupada(moment().subtract(10, 'd').toDate(), internacion._id, cama.unidadOrganizativaOriginal),
REQMock
);

const resultado = await CensoController.censoDiario({ organizacion, timestamp: moment().toDate(), unidadOrganizativa });

expect(resultado.censo).toEqual({
existenciaALas0: 0,
ingresos: 0,
pasesDe: 0,
altas: 0,
defunciones: 0,
pasesA: 0,
existenciaALas24: 0,
ingresosYEgresos: 0,
pacientesDia: 0,
diasEstada: 0,
disponibles: 1
});
});

function estadoDisponible(unidadOrganizativaEstado, cantidad, unidad) {
return {
fecha: moment().subtract(cantidad, unidad).toDate(),
Expand Down
40 changes: 37 additions & 3 deletions modules/rup/internacion/censo.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import * as moment from 'moment';
import * as mongoose from 'mongoose';
import { Organizacion } from '../../../core/tm/schemas/organizacion';
import { Prestacion } from '../schemas/prestacion';
import { InternacionResumen } from './resumen/internacion-resumen.schema';
import * as CamasEstadosController from './cama-estados.controller';
import { Camas } from './camas.schema';
import { Censo } from './censos.schema';
import { InternacionResumen } from './resumen/internacion-resumen.schema';

/**
* Agrupa por cierta key. Por cada valor genera un array de esos elementos
Expand Down Expand Up @@ -45,6 +45,27 @@ async function unificarMovimientos(snapshots, movimientos) {
return mapping;
}

function incluyePeriodo(prestacion, date) {
return prestacion.periodosCensables.length ? prestacion.periodosCensables?.some(periodo => periodo.hasta
? date.isBetween(periodo.desde, periodo.hasta, undefined, '[]')
: date.isSameOrAfter(periodo.desde)) : true;
}

function eliminarPeriodoEnEgreso(fechaEgreso, periodosCensables) {
if (!fechaEgreso) {
return periodosCensables;
}

const egreso = moment(fechaEgreso);

return periodosCensables.filter(periodo => {
if (periodo.hasta) {
return !(egreso.isBetween(periodo.desde, periodo.hasta) || egreso.isBefore(periodo.desde));
}
return false;
});
}

async function realizarConteo(internaciones, unidadOrganizativa, timestampStart, timestampEnd, capa) {
let prestaciones;
let resumenPrestacionMap: any = [];
Expand Down Expand Up @@ -89,8 +110,20 @@ async function realizarConteo(internaciones, unidadOrganizativa, timestampStart,

} else {
prestacion = prestaciones.find(p => String(p.id) === String(allMovimientos[0].idInternacion));
}

// filtra los periodos que se superponen con la fecha de egreso
const informes: any = getInformesInternacion(prestacion);
const fechaEgreso = informes?.egreso?.fechaEgreso;

if (fechaEgreso) {
prestacion.periodosCensables = eliminarPeriodoEnEgreso(fechaEgreso, prestacion.periodosCensables);
}

// verifica si la prestación tiene periodos que incluyan la fecha del censo
if (!incluyePeriodo(prestacion, timestampStart)) {
prestacion = null;
}
}

if (prestacion) {
const informesInternacion: any = getInformesInternacion(prestacion);
Expand Down Expand Up @@ -151,7 +184,7 @@ async function realizarConteo(internaciones, unidadOrganizativa, timestampStart,
return;
} else if (prestacion.ejecucion.registros[0].esCensable && indiceCama === -1) {
arrayCamas.push(ultimoMovimiento.idCama);
disponibles ++;
disponibles++;
}
const esPaseA = dataInternaciones[idInter]['esPaseA'];
const informesInternacion = dataInternaciones[idInter]['informesInternacion'];
Expand Down Expand Up @@ -333,6 +366,7 @@ export async function censoDiario({ organizacion, timestamp, unidadOrganizativa
const ultimoMov = camas[idCama][camas[idCama].length - 1];
const esDisponible = (ultimoMov.estado !== 'bloqueada' && ultimoMov.estado !== 'inactiva');
const estaUnidadOrganizativa = String(ultimoMov.unidadOrganizativa.conceptId) === unidadOrganizativa;

if (esDisponible && estaUnidadOrganizativa && ultimoMov.esCensable) {
resultado.censo.disponibles++;
}
Expand Down
4 changes: 4 additions & 0 deletions modules/rup/routes/prestacion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,10 @@ router.patch('/prestaciones/:id', (req: Request, res, next) => {
next(error);
}
break;
case 'periodosCensables':
data.periodosCensables = req.body.periodosCensables;
data.ejecucion.registros = req.body.registros;
break;
default:
return next(500);
}
Expand Down
3 changes: 2 additions & 1 deletion modules/rup/schemas/prestacion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ export const PrestacionSchema = new Schema({
// Historia de estado de la prestación
estados: [PrestacionEstadoSchema],
estadoActual: PrestacionEstadoSchema,
unidadOrganizativa: SnomedConcept
unidadOrganizativa: SnomedConcept,
periodosCensables: []
}, { usePushEach: true } as any);

// Esquema para prestaciones anuladas/modificadas
Expand Down

0 comments on commit b33c37c

Please sign in to comment.