Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class RecetaMedicaComponent extends HTMLComponent {
<th>Cantidad</th>
<th>Indicaciones</th>
<th>Diagnóstico</th>
<th>Obra Social</th>
</tr>
</thead>
<tbody>
Expand All @@ -63,9 +64,6 @@ export class RecetaMedicaComponent extends HTMLComponent {
{{/if}}
</td>
<td>
{{ unidades }} {{presentacion.term }}(s)
</td>
<td>
{{ cantEnvases}} envase(s) de {{ cantidad }} {{presentacion.term }}(s)
</td>
<td>
Expand All @@ -90,10 +88,20 @@ export class RecetaMedicaComponent extends HTMLComponent {
<td>
{{ diagnostico.term }}
</td>
<td>
{{#if obraSocial}}
{{obraSocial.nombre}}
{{#if obraSocial.numeroAfiliado}}
<br><small>Af. {{obraSocial.numeroAfiliado}}</small>
{{/if}}
{{else}}
Sin obra social
{{/if}}
</td>
</tr>
{{/each}}
<tr>
<td colspan="6" style="font-weight: bold;font-style: italic;">
<td colspan="5" style="font-weight: bold;font-style: italic;">
{{#if esReceta}}
Esta receta fue creada por emisor inscripto y valido en el Registro de Recetarios Electrónicos
del Ministerio de Salud de la Nación - RL-2025-24026558-APN-SSVEIYES#MS
Expand Down Expand Up @@ -152,8 +160,49 @@ del Ministerio de Salud de la Nación - RL-2025-24026558-APN-SSVEIYES#MS

const finalIdReceta = idReceta || this.registro.id;

let obraSocial = this.prestacion.paciente?.obraSocial || null;
if (Array.isArray(obraSocial)) {
obraSocial = obraSocial[0];
}
let obraSocialObj = null;
if (obraSocial) {
const nombreOS = typeof obraSocial === 'string' ? obraSocial : (obraSocial.nombre || obraSocial.financiador || '');
if (nombreOS && nombreOS !== 'Sin obra social') {
obraSocialObj = {
nombre: nombreOS,
numeroAfiliado: typeof obraSocial === 'object' ? (obraSocial.numeroAfiliado || '') : ''
};
}
}

const registroClone = this.registro.toObject ? this.registro.toObject() : JSON.parse(JSON.stringify(this.registro));
if (registroClone.valor?.medicamentos) {
registroClone.valor.medicamentos = registroClone.valor.medicamentos.map(med => {
let medOS = null;
if (med.obraSocial && typeof med.obraSocial === 'object') {
const nombreMedOS = med.obraSocial.nombre || med.obraSocial.financiador || '';
if (nombreMedOS && nombreMedOS !== 'Sin obra social') {
medOS = {
nombre: nombreMedOS,
numeroAfiliado: med.obraSocial.numeroAfiliado || ''
};
}
} else if (med.obraSocial === undefined && obraSocialObj) {
medOS = {
nombre: obraSocialObj.nombre,
numeroAfiliado: obraSocialObj.numeroAfiliado
};
}

return {
...med,
obraSocial: medOS
};
});
}

this.data = {
registro: this.registro,
registro: registroClone,
esReceta: this.depth ? 1 : 0, // Si es 0 no muestra el código de barras
idReceta: finalIdReceta,
estadoReceta,
Expand Down
4 changes: 4 additions & 0 deletions modules/recetas/receta-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ const medicamentoSubschema = new mongoose.Schema({
numero: {
type: Number,
required: false
},
obraSocial: {
type: mongoose.SchemaTypes.Mixed,
required: false
}
}, {
toJSON: { virtuals: true },
Expand Down
34 changes: 29 additions & 5 deletions modules/recetas/recetasController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ async function registrarAppNotificadas(req, recetas, sistema) {
return recetasUpdated.filter(r => r !== null);
}

function formatearRecetasParaAppExterna(recetas: any[]) {
return recetas.map(receta => {
const rec = receta.toObject ? receta.toObject() : JSON.parse(JSON.stringify(receta));
if (rec.paciente && rec.medicamento?.obraSocial !== undefined) {
rec.paciente.obraSocial = rec.medicamento.obraSocial;
}
return rec;
});
}

/**
* Se ontienen las recetas de un paciente segun filtros:
* @param pacienteId (optativo con documento y sexo)
Expand Down Expand Up @@ -221,6 +231,7 @@ export async function buscarRecetas(req) {
// si es un usuario de app y no tiene nombre de sistema asignado, no se envia recetas
const sistema = user.app.nombre.toLowerCase();
recetas = sistema ? await registrarAppNotificadas(req, recetas, sistema) : [];
recetas = formatearRecetasParaAppExterna(recetas);
}
return recetas;
} catch (err) {
Expand Down Expand Up @@ -338,6 +349,7 @@ export async function buscarRecetasConFiltros(req) {
// si es un usuario de app y no tiene nombre de sistema asignado, no se envia recetas
const sistema = user.app?.nombre ? user.app.nombre.toLowerCase() : '';
recetas = sistema ? await registrarAppNotificadas(req, recetas, sistema) : [];
recetas = formatearRecetasParaAppExterna(recetas);
}

return recetas;
Expand Down Expand Up @@ -697,7 +709,7 @@ export async function create(req) {
pacienteAndes.fechaNacimiento = fechaNacimientoReceta;
await pacienteAndes.save();
}
pacienteAndes.obraSocial = (!pacienteRecetar.obraSocial) ? null :
pacienteAndes.obraSocial = (!pacienteRecetar.obraSocial || pacienteRecetar.obraSocial.nombre === 'Sin obra social') ? null :
{
origen: pacienteRecetar.obraSocial.otraOS ? 'RECETAR' : 'PUCO',
nombre: pacienteRecetar.obraSocial.nombre,
Expand Down Expand Up @@ -727,7 +739,11 @@ export async function create(req) {
matricula: matriculaGrado
};
}
return await crearReceta(dataReceta, req);
const recetas: any = await crearReceta(dataReceta, req);
if (Array.isArray(recetas) && req.user?.type === 'app-token') {
return formatearRecetasParaAppExterna(recetas);
}
return recetas;
} catch (err) {
createLog.error('create', { dataReceta, pacienteRecetar, profRecetar }, err, req);
return err;
Expand All @@ -749,6 +765,8 @@ export async function crearReceta(dataReceta, req) {
const diag = medicamento.diagnostico;
receta.diagnostico = (typeof diag === 'string') ? { descripcion: diag } : diag;
const esMagistral = !!medicamento.esMagistral;
const obraSocialAux = (medicamento.obraSocial !== undefined) ? medicamento.obraSocial : (dataReceta.paciente?.obraSocial || null);
const obraSocialFinal = (obraSocialAux && obraSocialAux.nombre !== 'Sin obra social') ? obraSocialAux : null;
receta.medicamento = {
concepto: esMagistral ? null : (medicamento.concepto || medicamento.generico),
presentacion: medicamento.presentacion?.term || medicamento.presentacion,
Expand All @@ -770,11 +788,14 @@ export async function crearReceta(dataReceta, req) {
tipoReceta: medicamento.tipoReceta?.id || medicamento.tipoReceta || 'simple',
serie: medicamento.serie,
numero: medicamento.numero,
obraSocial: obraSocialFinal
};
receta.estados = i < 1 ? [{ tipo: 'vigente' }] : [{ tipo: 'pendiente' }];
receta.estadosDispensa = [{ tipo: 'sin-dispensa', fecha: moment().toDate() }];
receta.paciente = dataReceta.paciente;
receta.paciente.obraSocial = dataReceta.paciente.obraSocial;

const pacienteClone = dataReceta.paciente.toObject ? dataReceta.paciente.toObject() : JSON.parse(JSON.stringify(dataReceta.paciente));
receta.paciente = pacienteClone;
receta.paciente.obraSocial = null;
receta.paciente.id = dataReceta.paciente.id || dataReceta.paciente._id;
receta.profesional = dataReceta.profesional;
receta.profesional._id = dataReceta.profesional.id || dataReceta.profesional._id; // revisar como se generan ids en ambos casos
Expand Down Expand Up @@ -831,7 +852,10 @@ export async function buscarRecetasPorProfesional(req) {
filter['estadoActual.tipo'] = { $nin: estados };
}

const recetas = await Receta.find(filter);
let recetas: any = await Receta.find(filter);
if (req.user?.type === 'app-token') {
recetas = formatearRecetasParaAppExterna(recetas);
}
return recetas;
} catch (err) {
await informarLog.error('buscarRecetasPorProfesional', { params: req.params, query: req.query }, err);
Expand Down
6 changes: 6 additions & 0 deletions modules/rup/controllers/rup.events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,16 @@ EventCore.on('prestacion:receta:create', async ({ prestacion, registro }) => {
diagnostico: null,
};
dataRecetaBase.paciente.cuil = pacienteCUIL;
if (dataRecetaBase.paciente?.obraSocial?.nombre === 'Sin obra social') {
dataRecetaBase.paciente.obraSocial = null;
}

for (const medicamento of registro.valor.medicamentos) {
try {
const esMagistral = !!medicamento?.esMagistral;
if (medicamento.obraSocial?.nombre === 'Sin obra social') {
medicamento.obraSocial = null;
}
const conceptId = medicamento?.concepto?.conceptId || medicamento?.generico?.conceptId;

if (!conceptId && !esMagistral) {
Expand Down
Loading