-
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.
- Loading branch information
1 parent
ff92c6b
commit ceb4267
Showing
4 changed files
with
168 additions
and
2 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,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' | ||
}); |
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,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); | ||
} | ||
}); |
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
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,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({ | ||
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, | ||
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'); |