TEA indicators: Resumen and Trazabilidad tabs, round help buttons, series chips, shared colours, summary box, three-per-row grid and three-significant-digit EEG values

This commit is contained in:
ulises
2026-11-22 22:01:50 -06:00
parent 34c6f2af3a
commit 329c0891ae
34 changed files with 625 additions and 226 deletions
@@ -1,4 +1,4 @@
import { Component, DestroyRef, ElementRef, inject, Input, OnInit, signal } from '@angular/core';
import { Component, DestroyRef, ElementRef, inject, Input, OnInit, output, signal } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { PlotlyChart } from '../../shared/plotly/plotly-chart';
import { PlotlyFigure } from './indicadores.models';
@@ -86,6 +86,10 @@ export function normaFigure(m: TeaEegAlteracion, edad: number): PlotlyFigure {
})
export class TeaPacienteResumen implements OnInit {
@Input({ required: true }) id = '';
/** `tarjetas`: four summary cards for a table row. `resumen`: the whole record as a summary with collapsible headers. */
@Input() modo: 'tarjetas' | 'resumen' = 'tarjetas';
/** The cards' button: the host shows the whole record in its own section. */
readonly completo = output<string>();
private readonly service = inject(TeaSeguimientoService);
private readonly destroy = inject(DestroyRef);
readonly status = signal<'loading' | 'ready' | 'error'>('loading');
@@ -101,8 +105,7 @@ export class TeaPacienteResumen implements OnInit {
}
return '#FFFFFF';
}
// The side panel shows the chosen metric's head map, its age norm, or both with a switch between them.
vista: 'zonas' | 'norma' = 'zonas';
// The chosen metric's head map and its age norm, whichever it has.
figuraNorma?: PlotlyFigure;
mapaActual(eeg: TeaEeg) { return eeg.mapas.find(m => m.codigo === this.mapaElegido); }
// The age norm can only be drawn with the curve, the patient's value and their age.
@@ -115,15 +118,13 @@ export class TeaPacienteResumen implements OnInit {
private mostrar(eeg: TeaEeg, codigo: string | undefined) {
const mapa = eeg.mapas.find(m => m.codigo === codigo), norma = this.conNorma(eeg, codigo);
this.mapaElegido = mapa || norma ? codigo : undefined;
this.vista = mapa ? 'zonas' : 'norma';
this.figura = mapa && mapaFigure(eeg, mapa, this.fondo());
this.figuraNorma = norma && normaFigure(norma, eeg.edad_meses as number);
}
elegirMapa(eeg: TeaEeg, codigo: string) {
// The chosen card closes the panel again, and the cards take the whole space back.
this.mostrar(eeg, codigo === this.mapaElegido ? undefined : codigo);
// In the cards' accordion the chosen metric closes its panel again; in the full summary the plots stay in view.
this.mostrar(eeg, this.modo === 'tarjetas' && codigo === this.mapaElegido ? undefined : codigo);
}
verVista(vista: 'zonas' | 'norma') { this.vista = vista; }
readonly clasificacion = CLASIFICACIONES_ADOS2;
readonly nivelCss = NIVEL_CSS;
readonly calidad = CALIDAD;
@@ -146,6 +147,8 @@ export class TeaPacienteResumen implements OnInit {
}
// The study-wide checks, then each bad channel.
delEstudio(eeg: TeaEeg) { return eeg.criterios_calidad.filter(c => c.electrodo === null); }
// Three significant digits, without trailing zeros.
cifras(n: number | null | undefined) { return typeof n === 'number' ? String(Number(n.toPrecision(3))) : ''; }
canalesMalos(eeg: TeaEeg) { return eeg.criterios_calidad.filter(c => c.electrodo !== null); }
valorDe(c: TeaCriterioCalidad) {
return c.valor === null ? '' : typeof c.valor === 'number' ? `${Math.round(c.valor * 100) / 100}${c.unidad ? ' ' + c.unidad : ''}` : c.valor;
@@ -155,6 +158,9 @@ export class TeaPacienteResumen implements OnInit {
return m.sin_evaluar === 'sin_valor' ? 'No se pudo medir en el estudio.' : 'Sin referencia para la edad del niño.';
}
clasificacionDe(a: TeaAdos2) { return a.clasificacion ? this.clasificacion[a.clasificacion] : 'Sin clasificación'; }
// How many of the study-wide checks are out of range, and how many metrics could be judged against the age norm.
reglasFuera(eeg: TeaEeg) { return this.delEstudio(eeg).filter(c => c.nivel === 'malo').length; }
evaluables(eeg: TeaEeg) { return eeg.alteraciones.filter(m => m.estado !== 'no_evaluable').length; }
alteradas(eeg: TeaEeg) { return eeg.alteraciones.filter(m => m.estado === 'aumentado' || m.estado === 'disminuido'); }
pct(value: number, max: number) { return max > 0 ? Math.round(100 * value / max) : 0; }
@@ -165,7 +171,7 @@ export class TeaPacienteResumen implements OnInit {
return f.or >= 1 ? 'A mayor z, mayor probabilidad' : 'A menor z, mayor probabilidad';
}
porcentaje(p: number) { return Math.round(100 * p); }
qTexto(q: number) { return q < 0.001 ? '< 0.001' : `= ${q.toFixed(3)}`; }
qTexto(q: number) { return q < 0.001 ? '< 0.001' : `= ${this.cifras(q)}`; }
observado(f: TeaRelacionAdos2) {
if (f.observado === null) return 'Sin dato';
if (f.tipo === 'item') return f.observado >= 1 ? `Alterado (${f.observado})` : 'Sin anormalidad (0)';