-
Notifications
You must be signed in to change notification settings - Fork 12
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fechaRegistro y fechaPrestacion no serían siempre las mismas? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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' ?
There was a problem hiding this comment.
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