Skip to content

Commit d914dfd

Browse files
fix-Receta: Logs tramiento prolongado (#2209)
1 parent aebb735 commit d914dfd

1 file changed

Lines changed: 26 additions & 11 deletions

File tree

modules/rup/controllers/rup.events.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ EventCore.on('prestacion:receta:create', async ({ prestacion, registro }) => {
3434

3535
const pacienteCUIL = prestacion.paciente.cuil || generarCUIL(prestacion.paciente.documento, prestacion.paciente.sexo);
3636

37-
const dataReceta = {
37+
const dataRecetaBase = {
3838
idPrestacion: prestacion.id,
3939
idRegistro,
4040
fechaRegistro: prestacion.ejecucion.fecha || moment().toDate(),
@@ -45,18 +45,33 @@ EventCore.on('prestacion:receta:create', async ({ prestacion, registro }) => {
4545
medicamento: null,
4646
diagnostico: null,
4747
};
48-
49-
dataReceta.paciente.cuil = pacienteCUIL;
48+
dataRecetaBase.paciente.cuil = pacienteCUIL;
5049

5150
for (const medicamento of registro.valor.medicamentos) {
52-
const receta: any = await Receta.findOne({
53-
'medicamento.concepto.conceptId': medicamento.generico.conceptId,
54-
idRegistro
55-
});
56-
if (!receta) {
57-
dataReceta.medicamento = medicamento;
58-
dataReceta.diagnostico = medicamento.diagnostico;
59-
await crearReceta(dataReceta, prestacion.createdBy); // falta return
51+
try {
52+
const conceptId = medicamento?.concepto?.conceptId || medicamento?.generico?.conceptId;
53+
54+
if (!conceptId) {
55+
logger.error('prestacion:receta:create', { idRegistro, medicamento }, 'No se pudo identificar conceptId del medicamento');
56+
continue;
57+
}
58+
59+
const receta: any = await Receta.findOne({
60+
'medicamento.concepto.conceptId': conceptId,
61+
idRegistro
62+
});
63+
64+
if (!receta) {
65+
const dataReceta = {
66+
...dataRecetaBase,
67+
medicamento,
68+
diagnostico: medicamento?.diagnostico || null,
69+
};
70+
71+
await crearReceta(dataReceta, prestacion.createdBy);
72+
}
73+
} catch (errorMedicamento) {
74+
logger.error('prestacion:receta:create', { idRegistro, medicamento }, errorMedicamento);
6075
}
6176

6277
}

0 commit comments

Comments
 (0)