Skip to content

Commit

Permalink
fix(mpi): quita la foto desde schema paciente
Browse files Browse the repository at this point in the history
  • Loading branch information
condorpiedra committed Jul 17, 2020
1 parent 7bbf9d2 commit 5d46671
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 36 deletions.
2 changes: 1 addition & 1 deletion core/mpi/controller/paciente.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export async function updateTurnosPaciente(pacienteModified) {
*/
export function buscarPaciente(id): Promise<{ db: String, paciente: any }> {
return new Promise((resolve, reject) => {
paciente.findById(id, (err, data) => {
paciente.findById(id, '+foto', (err, data) => {
if (err) {
reject(err);
} else {
Expand Down
48 changes: 14 additions & 34 deletions core/mpi/routes/paciente.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ router.get('/pacientes/auditoria/', (req, res, next) => {
if (err) {
return next(err);
}
data = data.map(elto => {
delete elto.foto;
return elto;
});

res.json(data);
});

Expand Down Expand Up @@ -122,11 +119,6 @@ router.get('/pacientes/auditoria/vinculados/', async (req, res, next) => {
};
try {
let listado = await paciente.find(filtro);
listado = listado.map(elto => {
const item = JSON.parse(JSON.stringify(elto));
delete item.foto;
return item;
});
res.json(listado);
} catch (error) {
return next(error);
Expand All @@ -139,11 +131,6 @@ router.get('/pacientes/inactivos/', async (req, res, next) => {
};
try {
let listado = await paciente.find(filtro);
listado = listado.map(elto => {
const item = JSON.parse(JSON.stringify(elto));
delete item.foto;
return item;
});
res.json(listado);
} catch (error) {
return next(error);
Expand All @@ -152,29 +139,31 @@ router.get('/pacientes/inactivos/', async (req, res, next) => {
});

// Search using filters
router.get('/pacientes/search', (req, res, next) => {
router.get('/pacientes/search', async (req, res, next) => {
if (!Auth.check(req, 'mpi:paciente:getbyId')) {
return next(403);
}
controller.matching({ type: 'search', filtros: req.query }).then(result => {
try {
const result = await controller.matching({ type: 'search', filtros: req.query });
res.send(result);
}).catch(error => {
return next(error);
});
} catch (err) {
next(err);
}
});


// Search
router.get('/pacientes', (req, res, next) => {
router.get('/pacientes', async (req, res, next) => {
if (!Auth.check(req, 'mpi:paciente:getbyId')) {
return next(403);
}

controller.matching(req.query).then(result => {
try {
const result = await controller.matching(req.query);
res.send(result);
}).catch(error => {
} catch (error) {
return next(error);
});
}

});


Expand All @@ -189,16 +178,7 @@ router.get('/pacientes/:id', async (req, res, next) => {
try {
const idPaciente = req.params.id;
const { paciente: pacienteFound } = await controller.buscarPaciente(idPaciente);
const pacienteAux = JSON.parse(JSON.stringify(pacienteFound));

delete pacienteAux.foto;
if (pacienteAux.relaciones?.length) {
pacienteAux.relaciones.map(rel => {
delete rel.foto;
return rel;
});
}
const pacienteBuscado: any = new paciente(pacienteAux);
const pacienteBuscado: any = new paciente(pacienteFound);
if (pacienteBuscado && pacienteBuscado.documento) {
let pacienteConOS = pacienteBuscado.toObject({ virtuals: true });
pacienteConOS.id = pacienteConOS._id;
Expand Down
5 changes: 4 additions & 1 deletion core/mpi/schemas/paciente.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export let pacienteSchema: mongoose.Schema = new mongoose.Schema({
},
fechaFallecimiento: Date,
estadoCivil: constantes.ESTADOCIVIL,
foto: String,
foto: {
type: String,
select: false
},
fotoMobile: String,
nacionalidad: String,
// ---------------------
Expand Down

0 comments on commit 5d46671

Please sign in to comment.