Skip to content
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
9 changes: 8 additions & 1 deletion core-v2/mpi/paciente/paciente.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const PacienteSubSchema: mongoose.Schema = new mongoose.Schema({
}, { _id: false });


PacienteSchema.pre('save', function (next) {
PacienteSchema.pre('save', async function (next) {
const user: any = this;
const words = [];
if (user.isModified('nombre')) {
Expand Down Expand Up @@ -222,6 +222,13 @@ PacienteSchema.pre('save', function (next) {
words.push(user.numeroIdentificacion.toLowerCase());
}
user.tokens = words.map(replaceChars);
// hack hasta que se actualice eventCore y poder popular y/o fhir
if (user.relaciones?.length) {
await user.populate({
path: 'relaciones.referencia',
select: 'nombre apellido documento numeroIdentificacion fechaNacimiento fechaFallecimiento activo'
}).execPopulate();
}
next();

});
Expand Down
31 changes: 29 additions & 2 deletions modules/webhook/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,34 @@ const trasform = {
fhir: Patient.encode
};

// hack momentaneo hasta corregir librería fhir
async function normalizePatientEvent(event: string, body: any) {

if ((event === 'mpi:pacientes:create' || event === 'mpi:pacientes:update') && body.relaciones?.length) {
const plainBody = typeof body.toObject === 'function' ? body.toObject() : body;

plainBody.relaciones = await Promise.all(plainBody.relaciones.map(async (r: any) => {
const referencia = r.referencia || {};
const newRelacion: any = {
referencia: referencia._id || referencia,
nombre: referencia.nombre,
apellido: referencia.apellido,
documento: referencia.documento || null,
numeroIdentificacion: referencia.numeroIdentificacion,
fechaNacimiento: referencia.fechaNacimiento
};
return newRelacion;
}));
plainBody.genero = plainBody.sexo;

if (!plainBody.createdBy?.organizacion) {
plainBody.createdBy = { organizacion: { nombre: '', id: '', _id: '' } };
}
return plainBody;
}
return body;
}


EventCore.on(/.*/, async function (body) {
const event = this.event;
Expand All @@ -21,12 +49,11 @@ EventCore.on(/.*/, async function (body) {

subscriptions.forEach(async (sub: any) => {

body.relaciones = undefined; // Se elimina relaciones ya que los datos son referencias a ids de pacientes propios
const valid = await verificarFiltros(sub, body);
if (!valid) {
return;
}

body = await normalizePatientEvent(sub.event, body);
const bodyTransform = trasform[sub.trasform] ? trasform[sub.trasform](body) : body;

const data = {
Expand Down
Loading