Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(HUDS): optimiza código al recibir detalle de un protocolo #3122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,50 +28,10 @@ export class VistaLaboratorioComponent implements OnInit {

ngOnInit(): void {
const id = this.protocolo.data.idProtocolo;

this.laboratorioService.getByProtocolo(id).subscribe((resultados) => {
this.areasLaboratorio = this.agrupar(resultados[0].Data);

});
}

public agrupar(elementos) {
const setAreas = new Set(elementos.map(d => d.area));
const areasStr = Array.from(setAreas);

const areas = [];
const toItem = (e) => ({
nombre: e.item,
esTitulo: e.esTitulo === 'True' ? true : false,
resultado: e.Resultado || e.resultado,
unidadMedida: e.UnidadMedida || e.unidadMedida,
metodo: e.Metodo,
valorReferencia: e.valorReferencia,
firma: e.esTitulo === 'True' ? '' : e.userValida
});

areasStr.forEach(area => {
const detallesArea = elementos.filter(d => d.area === area);
const setGrupos = new Set(detallesArea.map(d => d.grupo));
const grupos = Array.from(setGrupos);
const item = {
area,
grupos: grupos.map(g => {
const detallesAreaGrupo = detallesArea.filter(da => da.grupo === g);
const res: any = {};
res.grupo = g;
if (detallesAreaGrupo.length === 1 && detallesAreaGrupo[0].grupo === g) {
res.items = [toItem(detallesAreaGrupo[0])];
} else {
res.items = detallesAreaGrupo.map(toItem);
}
this.areasLaboratorio = resultados;

return res;
})
};
areas.push(item);
});
return areas;
}

descargarLab() {
Expand Down
Loading