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

RUP - Nuevo esquema Receta #1978

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions modules/rup/controllers/rup.events.log.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Connections } from '../../../connections';
import { Logger } from '@andes/log';

export const rupEventsLog = new Logger({
connection: Connections.logs,
module: 'rup',
type: 'rup-events',
application: 'andes',
bucketBy: 'd',
bucketSize: 100,
expiredAt: '2 M'
});
86 changes: 86 additions & 0 deletions modules/rup/controllers/rup.events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { userScheduler } from '../../../config.private';
import { EventCore } from '@andes/event-bus';
import * as moment from 'moment';
import { Receta } from '../schemas/receta-schema';
import * as mongoose from 'mongoose';
import { rupEventsLog as logger } from './rup.events.log';

const conceptId = '16076005'; // Receta.

EventCore.on('prestacion:receta:create', async (prestacion) => {
try {
if (prestacion.prestacion) {
prestacion = prestacion.prestacion;
}
const idPrestacion = prestacion.id;
const registros = prestacion.ejecucion.registros;
const profPrestacion = prestacion.solicitud.profesional;
const profesional = {
id: profPrestacion.id,
nombre: profPrestacion.nombre,
apellido: profPrestacion.apellido,
documento: profPrestacion.documento,
profesion: 'medico',
especialidad: 'especialidad',
matricula: 123
};
const organizacion = {
id: prestacion.ejecucion.organizacion.id,
nombre: prestacion.ejecucion.organizacion.nombre
};

for (const registro of registros) {
if (registro.concepto.conceptId === conceptId) { // Si es receta.
for (const medicamento of registro.valor.medicamentos) {
let receta: any = await Receta.findOne({ idPrestacion: 0 });
if (!receta) {
receta = new Receta();
}
receta.organizacion = organizacion;
receta.profesional = profesional;
receta.fechaRegistro = moment().toDate();
receta.fechaPrestacion = moment(prestacion.ejecucion.fecha).toDate();
receta.idPrestacion = idPrestacion;
receta.idRegistro = registro._id;
receta.medicamento = {
conceptId: medicamento.generico.conceptId,
term: medicamento.generico.term,
presentacion: medicamento.presentacion.term,
unidades: medicamento.unidades,
cantidad: medicamento.cantidad,
cantEnvases: medicamento.cantEnvases,
dosisDiaria: {
dosis: medicamento.dosisDiaria.dosis,
frecuencia: medicamento.dosisDiaria.frecuencia,
dias: medicamento.dosisDiaria.dias,
notaMedica: medicamento.dosisDiaria.notaMedica
},
tratamientoProlongado: medicamento.tratamientoProlongado,
tiempoTratamiento: medicamento.tiempoTratamiento
};
receta.estados = [{ estado: 'vigente' }];
receta.paciente = prestacion.paciente;
receta.audit(userScheduler);
await receta.save();
}
}
}
} catch (err) {
logger.error('prestacion:receta:create', prestacion, err);
}
});

EventCore.on('prestacion:receta:delete', async (prestacion) => {
if (prestacion.prestacion) {
prestacion = prestacion.prestacion;
}
try {
const idPrestacion = prestacion.id;
const recetas = await Receta.find({ idPrestacion });
for (const receta of recetas) {
await Receta.findOneAndDelete({ _id: mongoose.Types.ObjectId(receta._id) });
}
} catch (err) {
logger.error('prestacion:receta:delete', prestacion, err);
}
});
5 changes: 3 additions & 2 deletions modules/rup/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import * as express from 'express';
import { ElementoRUPRouter } from './elementos-rup.controller';
import { CamasRouter, CensosRouter, EstadosRouter, InternacionResumenRouter, InternacionRouter, PlanIndicacionesEventosRouter, PlanIndicacionesRouter, SalaComunRouter } from './internacion';

require('./controllers/rup.events');

export function setup(app: express.Application) {
app.use('/api/modules/rup', ElementoRUPRouter);
app.use('/api/modules/rup/internacion', CamasRouter);
Expand All @@ -11,8 +14,6 @@ export function setup(app: express.Application) {
app.use('/api/modules/rup/internacion', InternacionResumenRouter);
app.use('/api/modules/rup/internacion', PlanIndicacionesRouter);
app.use('/api/modules/rup/internacion', PlanIndicacionesEventosRouter);


}

export { hudsPaciente } from './controllers/prestacion';
67 changes: 67 additions & 0 deletions modules/rup/schemas/receta-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { AuditPlugin } from '@andes/mongoose-plugin-audit';
import * as mongoose from 'mongoose';
import { PacienteSubSchema } from '../../../core-v2/mpi/paciente/paciente.schema';

const estadosSchema = new mongoose.Schema({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se podría considerar el estado 'anulada'/'cancelada' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Son los estados que vimos hasta ahora no es definitivo

estado: {
type: String,
enum: ['vigente', 'dispensada', 'vencida'],
required: true,
default: 'vigente'
},
});
estadosSchema.plugin(AuditPlugin);

export const recetaSchema = new mongoose.Schema({
organizacion: {
id: mongoose.SchemaTypes.ObjectId,
nombre: String
},
profesional: {
id: mongoose.SchemaTypes.ObjectId,
nombre: String,
apellido: String,
documento: String,
profesion: String,
especialidad: String,
matricula: Number
},
fechaRegistro: Date,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fechaRegistro y fechaPrestacion no serían siempre las mismas?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fecha registro puede variar si se rompe validación y se vuelve a prescribir la receta.

fechaPrestacion: Date,
idPrestacion: String,
idRegistro: String,
medicamento: {
conceptId: String,
term: String, // (Descripción)
presentacion: String,
unidades: String, // (mg, cc, etc.)
cantidad: Number,
cantEnvases: Number,
dosisDiaria: {
dosis: String,
frecuencia: mongoose.SchemaTypes.Mixed,
dias: Number,
notaMedica: String
},
tratamientoProlongado: Boolean,
tiempoTratamiento: mongoose.SchemaTypes.Mixed,
},
estados: [estadosSchema],
estadoActual: {
type: String,
required: true,
default: 'vigente'
},
paciente: PacienteSubSchema,
renovacion: String, // (referencia al registro original)
vinculoRecetar: String,
vinculoSifaho: String
});

recetaSchema.plugin(AuditPlugin);

recetaSchema.index({
idPrestacion: 1,
});

export const Receta = mongoose.model('receta', recetaSchema, 'receta');
Loading