Skip to content

Commit

Permalink
fix(cda): visualizar cda desde andes
Browse files Browse the repository at this point in the history
  • Loading branch information
liquid36 committed Apr 15, 2021
1 parent eb8a69d commit caccdd5
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions modules/cda/routes/cda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,27 +381,33 @@ router.get('/:id/:name', async (req: any, res, next) => {
if (req.user.type === 'user-token' && !Auth.check(req, 'cda:get')) {
return next(403);
}

const cda = await cdaCtr.getCDAById(req.params.id);
const idPaciente = cda.metadata.paciente;
let paciente: any = await findById(idPaciente);
const index = req.user.pacientes.findIndex(item => item.id === idPaciente);
let esFamiliar;
if (index < 0) {
const resultado = await findById((req as any).user.pacientes[0].id);
esFamiliar = resultado.relaciones.find(rel => {
return rel.referencia.toString() === paciente.id.toString();
});
}
if (req.user.type === 'paciente-token' && !(index >= 0 || esFamiliar)) {
return next(403);

if (req.user.type === 'paciente-token') {
const paciente: any = await findById(idPaciente);
const index = req.user.pacientes.findIndex(item => item.id === idPaciente);
let esFamiliar;
if (index < 0) {
const resultado = await findById((req as any).user.pacientes[0].id);
esFamiliar = resultado.relaciones.find(rel => {
return rel.referencia.toString() === paciente.id.toString();
});
}
if (!(index >= 0 || esFamiliar)) {
return next(403);
}
}

const realName = req.params.name.split('.')[0];
const cdaFile = await cdaCtr.getCdaAdjunto(cda, realName);
const contentType = cdaFile.file.contentType || cdaFile.file.mimetype;
const str = cdaFile.stream;
res.contentType(contentType);
str.pipe(res);
} catch (ex) {
console.log(ex);
return next(500);
}
});
Expand Down

0 comments on commit caccdd5

Please sign in to comment.