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
4 changes: 2 additions & 2 deletions core-v2/mpi/paciente/paciente.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export const PacienteSubSchema: mongoose.Schema = new mongoose.Schema({
nombre: String,
apellido: String,
documento: String,
cuil: String,
fechaNacimiento: Date,
sexo: SEXO,
genero: String,
Expand All @@ -165,8 +166,7 @@ export const PacienteSubSchema: mongoose.Schema = new mongoose.Schema({
localidad: NombreSchemaV2,
zona: NombreSchemaV2,
areaPrograma: NombreSchemaV2,
addAt: Date

addAt: Date,

}, { _id: false });

Expand Down
2 changes: 1 addition & 1 deletion core-v2/mpi/validacion/validacion.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function identidadSinAcentos(ciudadano) {
* Busca en fuentes auntenticas los datos de un ciudadano.
*/

function generarCUIL(dni, sexo) {
export function generarCUIL(dni, sexo) {
const sexoNorm = (sexo || '')
.toString()
.trim()
Expand Down
5 changes: 3 additions & 2 deletions modules/recetas/receta-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const motivosRecetaSchema = new mongoose.Schema({
const estadosSchema = new mongoose.Schema({
tipo: {
type: String,
enum: ['pendiente', 'vigente', 'finalizada', 'vencida', 'suspendida', 'rechazada','eliminada'],
enum: ['pendiente', 'vigente', 'finalizada', 'vencida', 'suspendida', 'rechazada', 'eliminada'],
required: true,
default: 'vigente'
},
Expand Down Expand Up @@ -134,7 +134,8 @@ export const recetaSchema = new mongoose.Schema({
},
organizacion: {
id: mongoose.SchemaTypes.ObjectId,
nombre: String
nombre: String,
direccion: { type: String, required: false },
},
profesional: {
type: profesionalSubschema,
Expand Down
3 changes: 2 additions & 1 deletion modules/recetas/recetasController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,8 @@ export async function create(req) {
documento: profAndes.documento,
profesion: profesionGrado,
especialidad: especialidades,
matricula: matriculaGrado
matricula: matriculaGrado,
efector: profRecetar.efector || null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem anterior

};
}
return await crearReceta(dataReceta, req);
Expand Down
10 changes: 10 additions & 0 deletions modules/rup/controllers/rup.events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import * as moment from 'moment';
import { Receta } from '../../recetas/receta-schema';
import { rupEventsLog as logger } from './rup.events.log';
import { Profesional } from '../../../core/tm/schemas/profesional';
import { generarCUIL } from '../../../core-v2/mpi/validacion/validacion.controller';

EventCore.on('prestacion:receta:create', async ({ prestacion, registro }) => {
try {
const idRegistro = registro._id;
const documentoProfesional = prestacion.estadoActual.createdBy?.documento ? prestacion.estadoActual.createdBy?.documento : prestacion.solicitud.profesional.documento;
const profPrestacion = await Profesional.findOne({ documento: documentoProfesional });
if (!profPrestacion) {
logger.error('prestacion:receta:create', prestacion, `No se encontró el profesional con documento ${documentoProfesional}`);
return;
}
const { profesionGrado, matriculaGrado, especialidades } = await getProfesionActualizada(profPrestacion);

const profesional = {
Expand All @@ -27,6 +32,8 @@ EventCore.on('prestacion:receta:create', async ({ prestacion, registro }) => {
nombre: prestacion.ejecucion.organizacion.nombre
};

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

const dataReceta = {
idPrestacion: prestacion.id,
idRegistro,
Expand All @@ -38,6 +45,9 @@ EventCore.on('prestacion:receta:create', async ({ prestacion, registro }) => {
medicamento: null,
diagnostico: null,
};

dataReceta.paciente.cuil = pacienteCUIL;

for (const medicamento of registro.valor.medicamentos) {
const receta: any = await Receta.findOne({
'medicamento.concepto.conceptId': medicamento.generico.conceptId,
Expand Down