Skip to content

Commit

Permalink
refactor(HUDS): optimiza codigo al recibir detalle de un protocolo (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
silviroa authored Jan 23, 2025
1 parent 2296fb9 commit c93ecc4
Showing 1 changed file with 1 addition and 41 deletions.
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

0 comments on commit c93ecc4

Please sign in to comment.