Skip to content
Merged
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
10 changes: 7 additions & 3 deletions src/controllers/andesPrescription.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,16 @@ class AndesPrescriptionController implements BaseController {
};

public verificarReceta = async (req: Request, res: Response): Promise<Response> => {
const { dni, conceptId } = req.query;
const { dni, conceptId, sexo } = req.query;

if (!dni || !conceptId) {
return res.status(400).json({ mensaje: 'Se requieren los parámetros dni y conceptId' });
}

if (!sexo) {
return res.status(400).json({ mensaje: 'Se requiere el parámetro sexo del paciente' });
}

try {
// Consulta la DB local por DNI del paciente (identificador común entre sistemas)
const estadosValidos = ['vigente', 'pendiente'];
Expand All @@ -259,8 +263,8 @@ class AndesPrescriptionController implements BaseController {
'estadoDispensaActual.tipo': { $nin: estadosDispensaExcluidos }
}).lean();

// Consulta a Andes por documento y conceptId utilizando el endpoint especifico
const verificacionAndes = await AndesService.verificarRecetaExistente(dni as string, conceptId as string).catch(() => null);
// Consulta a Andes por documento, conceptId y sexo utilizando el endpoint especifico
const verificacionAndes = await AndesService.verificarRecetaExistente(dni as string, conceptId as string, sexo as string).catch(() => null);
const recetasAndes = verificacionAndes && verificacionAndes.existe && verificacionAndes.receta
? [verificacionAndes.receta]
: [];
Expand Down
7 changes: 2 additions & 5 deletions src/services/andesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,21 +319,18 @@ class AndesService {
/**
* Verifica si existe una receta vigente para un paciente y medicamento (por conceptId SNOMED) en ANDES
*/
public async verificarRecetaExistente(dni: string, conceptId: string): Promise<any> {
public async verificarRecetaExistente(dni: string, conceptId: string, sexo: string): Promise<any> {
try {
const url = `${this.baseURL}/modules/recetas/verificar`;
console.log('fullUrl', url);

const response: AxiosResponse<any> = await axios.get(url, {
params: { documento: dni, conceptId },
params: { documento: dni, conceptId, sexo },
headers: {
Authorization: this.token,
'Content-Type': 'application/json'
}
});

console.log('response', response.data);

return response.data;
} catch (error) {
// eslint-disable-next-line no-console
Expand Down
Loading