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 @@ -46,6 +46,7 @@ export class RecetaMedicaComponent extends HTMLComponent {
<th>Medicamento</th>
<th>Cantidad</th>
<th>Indicaciones</th>
<th>Dosis diaria</th>
<th>Diagnóstico</th>
</tr>
</thead>
Expand All @@ -54,19 +55,24 @@ export class RecetaMedicaComponent extends HTMLComponent {
{{#each registro.valor.medicamentos}}
<tr>
<td>
{{#unless esMagistral}}
{{generico.term}}
{{/unless}}
{{#if esMagistralManual}}
{{ formulacionMagistral }}
{{else}}
{{#if esMagistral}}
{{ magistral.nombre }}
{{else}}
{{ generico.term }}
{{/if}}
{{/if}}
{{#if esMagistral}}
{{magistral.nombre}}
<br><b>(Preparación Magistral)</b>
<br><b>(Preparación Magistral{{#if esMagistralManual}} - Ingreso Manual{{/if}})</b>
{{/if}}
</td>
<td>
{{ unidades }} {{presentacion.term }}(s)
{{#if esMagistralManual}}-{{else}}{{ unidades }} {{presentacion.term }}(s){{/if}}
</td>
<td>
{{ cantEnvases}} envase(s) de {{ cantidad }} {{presentacion.term }}(s)
{{#if esMagistralManual}}-{{else}}{{ cantEnvases}} envase(s){{#if cantidad}} de {{ cantidad }} {{presentacion.term }}(s){{/if}}{{/if}}
</td>
<td>
{{#if dosisDiaria.dosis}}
Expand All @@ -93,7 +99,7 @@ export class RecetaMedicaComponent extends HTMLComponent {
</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
15 changes: 14 additions & 1 deletion modules/recetas/receta-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ const medicamentoSubschema = new mongoose.Schema({
presentacion: String,
unidades: String, // (mg, cc, etc.)
cantidad: Number,
cantEnvases: { type: Number, required: true },
cantEnvases: {
type: Number,
required(this: any) {
return !this.esMagistralManual;
}
},
dosisDiaria: {
dosis: { type: String, required: false },
intervalo: mongoose.SchemaTypes.Mixed,
Expand All @@ -117,6 +122,8 @@ const medicamentoSubschema = new mongoose.Schema({
},
tratamientoProlongado: Boolean,
esMagistral: { type: Boolean, default: false },
esMagistralManual: { type: Boolean, default: false },
formulacionMagistral: { type: String, required: false },
magistral: {
type: {
codigo: [
Expand Down Expand Up @@ -154,6 +161,9 @@ const medicamentoSubschema = new mongoose.Schema({
});

medicamentoSubschema.virtual('nombre').get(function (this: any) {
if (this.esMagistralManual) {
return this.formulacionMagistral || this.magistral?.nombre || '';
}
return this.esMagistral ? (this.magistral?.nombre || '') : (this.concepto?.term || '');
});

Expand Down Expand Up @@ -220,6 +230,9 @@ export const recetaSchema = new mongoose.Schema({
});

recetaSchema.virtual('nombre').get(function (this: any) {
if (this.medicamento?.esMagistralManual) {
return this.medicamento.formulacionMagistral || this.medicamento.magistral?.nombre || '';
}
return this.medicamento?.nombre || (this.medicamento?.esMagistral ? (this.medicamento?.magistral?.nombre || '') : (this.medicamento?.concepto?.term || ''));
});

Expand Down
11 changes: 8 additions & 3 deletions modules/recetas/recetasController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,10 +659,12 @@ export async function create(req) {
dataReceta.fechaRegistro = dataReceta.fechaRegistro ? moment(dataReceta.fechaRegistro).toDate() : moment().toDate();
dataReceta.fechaPrestacion = dataReceta.fechaPrestacion ? dataReceta.fechaPrestacion : dataReceta.fechaRegistro;
const isMagistral = !!req.body.medicamento?.esMagistral;
const isMagistralManual = !!req.body.medicamento?.esMagistralManual;
const medicamentoIncompleto = !req.body.medicamento ||
(!isMagistral && !req.body.medicamento.concepto?.conceptId) ||
(isMagistral && !req.body.medicamento.magistral?.nombre) ||
!req.body.medicamento.cantEnvases;
(isMagistral && !isMagistralManual && !req.body.medicamento.magistral?.nombre) ||
(isMagistralManual && !req.body.medicamento.formulacionMagistral && !req.body.medicamento.magistral?.nombre) ||
(!isMagistralManual && !req.body.medicamento.cantEnvases);
dataReceta.origenExterno = {
id: req.body.origenExterno?.id || '',
app: req.user.app?.nombre.toLowerCase() || '',
Expand All @@ -673,7 +675,7 @@ export async function create(req) {
} else {
const queryExistente: any = { idRegistro: dataReceta.idRegistro };
if (isMagistral) {
queryExistente['medicamento.magistral.nombre'] = dataReceta.medicamento.magistral?.nombre;
queryExistente['medicamento.magistral.nombre'] = dataReceta.medicamento.magistral?.nombre || dataReceta.medicamento.formulacionMagistral;
} else {
queryExistente['medicamento.concepto.conceptId'] = dataReceta.medicamento.concepto.conceptId;
}
Expand Down Expand Up @@ -749,6 +751,7 @@ export async function crearReceta(dataReceta, req) {
const diag = medicamento.diagnostico;
receta.diagnostico = (typeof diag === 'string') ? { descripcion: diag } : diag;
const esMagistral = !!medicamento.esMagistral;
const esMagistralManual = !!medicamento.esMagistralManual;
receta.medicamento = {
concepto: esMagistral ? null : (medicamento.concepto || medicamento.generico),
presentacion: medicamento.presentacion?.term || medicamento.presentacion,
Expand All @@ -764,6 +767,8 @@ export async function crearReceta(dataReceta, req) {
},
tratamientoProlongado,
esMagistral,
esMagistralManual,
formulacionMagistral: medicamento.formulacionMagistral || null,
magistral: esMagistral ? medicamento.magistral : null,
tiempoTratamiento: tratamientoProlongado ? medicamento.tiempoTratamiento : null,
ordenTratamiento: i,
Expand Down
6 changes: 4 additions & 2 deletions modules/rup/controllers/rup.events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,22 @@ EventCore.on('prestacion:receta:create', async ({ prestacion, registro }) => {
for (const medicamento of registro.valor.medicamentos) {
try {
const esMagistral = !!medicamento?.esMagistral;
const esMagistralManual = !!medicamento?.esMagistralManual;
const conceptId = medicamento?.concepto?.conceptId || medicamento?.generico?.conceptId;
const nombreMagistral = medicamento?.formulacionMagistral || medicamento?.magistral?.nombre;

if (!conceptId && !esMagistral) {
logger.error('prestacion:receta:create', { idRegistro, medicamento }, 'No se pudo identificar conceptId del medicamento');
continue;
}
if (esMagistral && !medicamento?.magistral?.nombre) {
if (esMagistral && !nombreMagistral) {
logger.error('prestacion:receta:create', { idRegistro, medicamento }, 'No se pudo identificar nombre del medicamento magistral');
continue;
}

const queryReceta: any = { idRegistro };
if (esMagistral) {
queryReceta['medicamento.magistral.nombre'] = medicamento.magistral.nombre;
queryReceta['medicamento.magistral.nombre'] = nombreMagistral;
} else {
queryReceta['medicamento.concepto.conceptId'] = conceptId;
}
Expand Down
Loading