Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IN - Modificar carga de OS en alta de internación capa estadística #1994

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion modules/rup/internacion/camas.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import { Types } from 'mongoose';
import { CamaEstados } from './cama-estados.schema';
import { Camas } from './camas.schema';
import { internacionCamaEstadosLog as logger } from './internacion.log';
import { updateFinanciador, updateObraSocial } from '../../../core-v2/mpi/paciente/paciente.controller';
import { PacienteCtr } from '../../../core-v2/mpi/paciente/paciente.routes';
import { Prestacion } from '../../rup/schemas/prestacion';
import { userScheduler } from '../../../config.private';
const dataLog: any = new Object(userScheduler);
dataLog.body = { _id: null };

const router = express.Router();

Expand Down Expand Up @@ -133,6 +139,23 @@ router.patch('/camas/:id', Auth.authenticate(), capaMiddleware, asyncHandler(asy

/** Edita los estados de una cama */
router.patch('/camaEstados/:idCama', Auth.authenticate(), capaMiddleware, asyncHandler(async (req: Request, res: Response, next) => {
if (req.body.extras.ingreso) {
const pacienteMPI = await PacienteCtr.findById(req.body.paciente.id);
const obraSocialUpdated = await updateObraSocial(pacienteMPI);
const financiador = updateFinanciador(obraSocialUpdated, req.body.paciente.obraSocial);
pacienteMPI.financiador = financiador;
await PacienteCtr.update(pacienteMPI.id, pacienteMPI, dataLog);
await Prestacion.update(
{ _id: req.body.idInternacion },
{
$set: {
'ejecucion.registros.$[elemento].valor.informeIngreso.obraSocial': req.body.paciente.obraSocial
}
},
{ arrayFilters: [{ 'elemento.valor.informeIngreso.fechaIngreso': moment(req.body.fechaIngreso).toDate() }] }
);
}

const organizacion = {
_id: Auth.getOrganization(req),
nombre: Auth.getOrganization(req, 'nombre')
Expand All @@ -150,7 +173,6 @@ router.patch('/camaEstados/:idCama', Auth.authenticate(), capaMiddleware, asyncH
};
await logger.error('patchCamaEstados', dataErr, err, req);
}

if (result) {
return res.json(result);
} else {
Expand Down
Loading