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
29 changes: 23 additions & 6 deletions src/controllers/prescription.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class PrescriptionController implements BaseController {
};

public create = async (req: Request, res: Response): Promise<Response> => {
const { professional, patient, date, supplies, trimestral, ambito } = req.body;
const { professional, patient, date, supplies, trimestral, ambito, organizacion } = req.body;
const myProfessional: IUser | null = await User.findOne({ _id: professional });
let myPatient: IPatient | null;
if (ambito === 'publico') {
Expand Down Expand Up @@ -188,12 +188,13 @@ class PrescriptionController implements BaseController {
profesion: pg.profesion,
codigoProfesion: pg.codigoProfesion,
numeroMatricula: pg.numeroMatricula
})) : []
})) : [],
},
date,
supplies: [sup],
ambito,
trimestral
trimestral,
organizacion: organizacion || undefined
});
let createAndes = false;
if (ambito === 'publico') {
Expand All @@ -219,11 +220,18 @@ class PrescriptionController implements BaseController {
businessName: myProfessional?.businessName,
cuil: myProfessional?.cuil,
enrollment: myProfessional?.enrollment,
profesionGrado: myProfessional?.profesionGrado?.length ? myProfessional.profesionGrado.map((pg: any) => ({
profesion: pg.profesion,
codigoProfesion: pg.codigoProfesion,
numeroMatricula: pg.numeroMatricula
})) : [],
},
date: moment(date).add(30, 'days').toDate(),
supplies: [sup],
ambito,
trimestral,
organizacion: organizacion || undefined

});
await newPrescription2.save();
allPrescription.push(newPrescription2);
Expand All @@ -234,11 +242,18 @@ class PrescriptionController implements BaseController {
businessName: myProfessional?.businessName,
cuil: myProfessional?.cuil,
enrollment: myProfessional?.enrollment,
profesionGrado: myProfessional?.profesionGrado?.length ? myProfessional.profesionGrado.map((pg: any) => ({
profesion: pg.profesion,
codigoProfesion: pg.codigoProfesion,
numeroMatricula: pg.numeroMatricula
})) : [],
},
date: moment(date).add(60, 'days').toDate(),
supplies: [sup],
ambito,
trimestral,
organizacion: organizacion || undefined

});
await newPrescription3.save();
allPrescription.push(newPrescription3);
Expand Down Expand Up @@ -271,7 +286,7 @@ class PrescriptionController implements BaseController {
const prescriptionAndes = {
idPrestacion: newPrescription._id.toString(),
idRegistro: newPrescription._id.toString(),
fechaRegistro: newPrescription.date.toString(),
fechaRegistro: newPrescription.date.toISOString(),
paciente: {
id: patient.idMPI,
nombre: patient.firstName,
Expand All @@ -281,10 +296,12 @@ class PrescriptionController implements BaseController {
obraSocial: patient.obraSocial || null,
},
profesional: {
id: profesional?.idAndes ? profesional.idAndes : ''
id: profesional?.idAndes ? profesional.idAndes : '',
},
organizacion: {
nombre: 'Recetar',
_id: newPrescription.organizacion?._id || null,
nombre: newPrescription.organizacion?.nombre || 'Recetar',
direccion: newPrescription.organizacion?.direccion || null,
},
medicamento: {
diagnostico: newPrescription.supplies[0].diagnostic,
Expand Down
163 changes: 83 additions & 80 deletions src/controllers/professional.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,95 +2,98 @@ import { Request, Response } from 'express';
import Professional from '../models/professional.model';
import IProfessional from '../interfaces/professional.interface';
import { BaseController } from '../interfaces/classes/base-controllers.interface';
import axios from 'axios';

class ProfessionalController implements BaseController{
class ProfessionalController implements BaseController {

public index = async (req: Request, res: Response): Promise<Response> => {
const professionals: IProfessional[] = await Professional.find();
return res.status(200).json({professionals});
}
public index = async (req: Request, res: Response): Promise<Response> => {
const professionals: IProfessional[] = await Professional.find();
return res.status(200).json({ professionals });
};

public create = async (req: Request, res: Response): Promise<Response> => {
const { dni, last_name, first_name, sex, image } = req.body;
const newProfessional: IProfessional = new Professional({
dni,
last_name,
first_name,
sex,
image
});
try{
await newProfessional.save();
return res.status(200).json({ newProfessional });
}catch(err){
console.log(err);
return res.status(500).json('Server Error');
}
}
public create = async (req: Request, res: Response): Promise<Response> => {
const { dni, last_name, first_name, sex, image } = req.body;
const newProfessional: IProfessional = new Professional({
dni,
last_name,
first_name,
sex,
image
});
try {
await newProfessional.save();
return res.status(200).json({ newProfessional });
} catch (err) {
console.log(err);
return res.status(500).json('Server Error');
}
};

public show = async (req: Request, res: Response): Promise<Response> => {
try{
const id: string = req.params.id;
const professional: IProfessional | null = await Professional.findOne({_id: id});
return res.status(200).json(professional);
}catch(err){
console.log(err);
return res.status(500).json('Server Error');
}
}
public show = async (req: Request, res: Response): Promise<Response> => {
try {
const id: string = req.params.id;
const professional: IProfessional | null = await Professional.findOne({ _id: id });
return res.status(200).json(professional);
} catch (err) {
console.log(err);
return res.status(500).json('Server Error');
}
};

public getByDni = async (req: Request, res: Response): Promise<Response> => {
try{
const dni: string = req.params.dni;
const professional: IProfessional | null = await Professional.findOne({dni: dni});
return res.status(200).json(professional);
}catch(err){
console.log(err);
return res.status(500).json('Server Error');
}
}
public getByDni = async (req: Request, res: Response): Promise<Response> => {
try {
const dni: string = req.params.dni;
const professional: IProfessional | null = await Professional.findOne({ dni });
return res.status(200).json(professional);
} catch (err) {
console.log(err);
return res.status(500).json('Server Error');
}
};

public getByEnrollment = async (req: Request, res: Response): Promise<Response> => {
try{
const enrollment: string = req.params.enrollment;
const professional: IProfessional | null = await Professional.findOne({enrollment: enrollment});
return res.status(200).json(professional);
}catch(err){
console.log(err);
return res.status(500).json('Server Error');
}
}
public getByEnrollment = async (req: Request, res: Response): Promise<Response> => {
try {
const enrollment: string = req.params.enrollment;
const professional: IProfessional | null = await Professional.findOne({ enrollment });
return res.status(200).json(professional);
} catch (err) {
console.log(err);
return res.status(500).json('Server Error');
}
};

public update = async (req: Request, res: Response) => {
try{
const id: string = req.params.id;
const { dni, last_name, first_name, sex, image } = req.body;
await Professional.findByIdAndUpdate(id, {
dni,
last_name,
first_name,
sex,
image
});
const professional = await Professional.findOne({_id: id});
return res.status(200).json(professional);
} catch(err){
console.log(err);
return res.status(500).json('Server Error');
}
}
public update = async (req: Request, res: Response) => {
try {
const id: string = req.params.id;
const { dni, last_name, first_name, sex, image } = req.body;
await Professional.findByIdAndUpdate(id, {
dni,
last_name,
first_name,
sex,
image
});
const professional = await Professional.findOne({ _id: id });
return res.status(200).json(professional);
} catch (err) {
console.log(err);
return res.status(500).json('Server Error');
}
};

public delete = async (req: Request, res: Response): Promise<Response> => {
try {

const { id } = req.params;
await Professional.findByIdAndDelete(id);
return res.status(200).json('deleted');
} catch (err) {
console.log(err);
return res.status(500).json('Server Error');
}
};

public delete = async (req: Request, res: Response): Promise<Response> => {
try{

const { id } = req.params;
await Professional.findByIdAndDelete(id);
return res.status(200).json('deleted');
}catch(err){
console.log(err);
return res.status(500).json('Server Error');
}
}
}

export default new ProfessionalController();
25 changes: 23 additions & 2 deletions src/controllers/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Request, Response } from 'express';
import IUser from '../interfaces/user.interface';
import User from '../models/user.model';
import { renderHTML, MailOptions, sendMail } from '../utils/roboSender/sendEmail';
import axios from 'axios';

class UsersController {
public index = async (req: Request, res: Response): Promise<Response> => {
try {
Expand Down Expand Up @@ -32,10 +34,10 @@ class UsersController {
}

const result = await User.findOneAndUpdate({ _id: req.body._id }, req.body, { new: true, projection: { password: 0, refreshToken: 0, authenticationToken: 0 } }).populate('roles', 'role');

if (oldEmail && req.body.email && oldEmail !== req.body.email && result) {
// Ejecutar el envío de email de forma asíncrona para no bloquear la respuesta
this.sendEmailChangeNotification(result, oldEmail, req.body.email).catch(error => {
// eslint-disable-next-line no-console
console.error('Error enviando notificación de cambio de email:', error);
});
}
Expand Down Expand Up @@ -103,7 +105,8 @@ class UsersController {
createdAt: user.createdAt,
updatedAt: user.updatedAt,
lastLogin: user.lastLogin,
isActive: user.isActive
isActive: user.isActive,
organizaciones: user.organizaciones
});

} catch (err) {
Expand Down Expand Up @@ -156,6 +159,24 @@ class UsersController {
console.error('Error enviando notificación de cambio de email:', error);
}
};

/**
* Busca en la coleccion Organizaciones TM en Andes por nombre
* @param req - nombre en params
* @param res - response con el listado de organizaciones que machea con el nombre buscado
* @returns lista de organizaciones
*/
public organizacionesAndes = async (req: Request, res: Response): Promise<Response> => {
try {
if (!req.query.nombre) { return res.status(400).json('Parámetro nombre es requerido'); }
const resp = await axios.get(`${process.env.ANDES_ENDPOINT}/core/tm/organizaciones?nombre=${req.query.nombre}&activo=true`, { headers: { Authorization: `${process.env.JWT_MPI_TOKEN}` } });
return res.status(200).json(resp.data);
} catch (err) {
// eslint-disable-next-line no-console
console.log(err);
return res.status(500).json('Server Error');
}
};
};

export default new UsersController;
1 change: 1 addition & 0 deletions src/interfaces/patient.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export default interface IPatient extends Document {
updatedAt?: Date;
idLocalInMPI?: boolean; // Indica si el paciente tiene ID local en Array de identificadores de MPI
findOrCreate(patientParam: IPatient): Promise<IPatient>;
cuil?: string | null;
}
5 changes: 5 additions & 0 deletions src/interfaces/prescription.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ export default interface IPrescription extends Document {
updatedAt?: Date;
trimestral?: boolean;
ambito?: string;
organizacion?: {
_id: string;
nombre: string;
direccion: string;
};
}
3 changes: 2 additions & 1 deletion src/interfaces/prescriptionAndes.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export default interface IPrescriptionAndes extends Document {
valor: Number;
unidad: String;
};
cuil: String;
};
createdAt: Date;
createdBy: {
Expand All @@ -164,4 +165,4 @@ export default interface IPrescriptionAndes extends Document {
nombre: String;
};
};
}
};;;;;;;;;;;;;;;;;;;;
8 changes: 7 additions & 1 deletion src/interfaces/user.interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Document } from 'mongoose';
import IRole from './role.interface';
import IProfesionAutorizada from './profesionAutorizada.interface';
export default interface IUser extends Document{
export default interface IUser extends Document {
username: string;
email: string;
businessName: string;
Expand All @@ -16,6 +16,12 @@ export default interface IUser extends Document{
isActive: Boolean;
lastLogin?: Date;
profesionGrado?: IProfesionAutorizada[];
organizaciones: [{
_id: string;
nombre: string;
direccion: string;
}];
isValidPassword(thisUser: IUser, password: string): Promise<boolean>;
idAndes?: string;
// eslint-disable-next-line semi
}
7 changes: 6 additions & 1 deletion src/models/patient.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ export const patientSchema = new Schema({
idLocalInMPI: {
type: Boolean,
default: false
},
cuil: {
type: String,
default: null
}
});

Expand Down Expand Up @@ -130,7 +134,8 @@ const mapAndesPatientToLocal = (andesPatient: any): Partial<IPatient> => {
idMPI: andesPatient.id || andesPatient._id,
tipoDocumentoExtranjero: andesPatient.tipoIdentificacion || '',
nroDocumentoExtranjero: andesPatient.numeroIdentificacion || '',
estado: andesPatient.estado
estado: andesPatient.estado,
cuil: andesPatient.cuil || null
};
};

Expand Down
Loading