From a1ea31039e9c6f43663a9fe45a91e312c822f02d Mon Sep 17 00:00:00 2001 From: edgar Date: Fri, 6 Nov 2026 13:46:26 -0600 Subject: [PATCH] feat(tea): abrir las alteraciones del EEG con un mapa visible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Al desplegar un paciente se abre su primera alteración, o la primera métrica si no tiene alteraciones. Co-Authored-By: Claude Opus 5.5 --- .../indicadores/tea-paciente-resumen.ts | 8 ++++++- .../indicadores/tea-seguimiento.spec.ts | 23 +++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/app/features/indicadores/tea-paciente-resumen.ts b/src/app/features/indicadores/tea-paciente-resumen.ts index 1170859..2212c2c 100644 --- a/src/app/features/indicadores/tea-paciente-resumen.ts +++ b/src/app/features/indicadores/tea-paciente-resumen.ts @@ -81,7 +81,13 @@ export class TeaPacienteResumen implements OnInit { load() { this.status.set('loading'); this.service.detalle(this.id).pipe(takeUntilDestroyed(this.destroy)).subscribe({ - next: d => { this.mapaElegido = undefined; this.figura = undefined; this.detalle.set(d); this.status.set('ready'); }, + next: d => { + // Opens on the first altered metric, or on the first one if none is altered. + const e = d.eeg, inicial = e?.mapas.find(m => e.alteraciones.some(a => a.codigo === m.codigo && a.estado !== 'normal')) ?? e?.mapas[0]; + this.mapaElegido = inicial?.codigo; + this.figura = e && inicial ? mapaFigure(e, inicial, this.fondo()) : undefined; + this.detalle.set(d); this.status.set('ready'); + }, error: () => this.status.set('error'), }); } diff --git a/src/app/features/indicadores/tea-seguimiento.spec.ts b/src/app/features/indicadores/tea-seguimiento.spec.ts index 68f907f..5135e4d 100644 --- a/src/app/features/indicadores/tea-seguimiento.spec.ts +++ b/src/app/features/indicadores/tea-seguimiento.spec.ts @@ -139,17 +139,13 @@ describe('Seguimiento TEA', () => { expect(c.draft).toMatchObject({ estado_caso: 'completo', alteracion: 'picos_paroxisticos' }); http.verify(); }); - it('al elegir una alteración aparecen sus zonas, con la leyenda, y al repetirla se cierran', () => { + it('abre con las zonas de la primera alteración, cambia al elegir otra y se cierra al repetirla', () => { const fixture = open(); request().flush(data); fixture.detectChanges(); const root: HTMLElement = fixture.nativeElement; root.querySelector('button.row-toggle')!.click(); fixture.detectChanges(); http.expectOne('/tea/seguimiento/T-0001').flush(detalle); fixture.detectChanges(); const tarjetas = root.querySelectorAll('button.nombre'); - expect(root.querySelector('section.mapa')).toBeNull(); - expect(root.querySelector('.alteraciones-zona')!.classList.contains('abierta')).toBe(false); - expect(tarjetas[0].getAttribute('aria-expanded')).toBe('false'); - tarjetas[0].click(); fixture.detectChanges(); expect(root.querySelector('.alteraciones-zona')!.classList.contains('abierta')).toBe(true); expect(tarjetas[0].getAttribute('aria-expanded')).toBe('true'); const panel = () => root.querySelector('section.mapa')!; @@ -166,6 +162,9 @@ describe('Seguimiento TEA', () => { expect(tarjetas[1].hasAttribute('aria-expanded')).toBe(false); tarjetas[3].click(); fixture.detectChanges(); expect(root.querySelector('section.mapa')).toBeNull(); + expect(root.querySelector('.alteraciones-zona')!.classList.contains('abierta')).toBe(false); + tarjetas[0].click(); fixture.detectChanges(); + expect(root.querySelector('section.mapa')).not.toBeNull(); http.verify(); }); it('el mapa oculta lo que queda fuera de la cabeza con el color que tiene detrás', () => { @@ -174,6 +173,16 @@ describe('Seguimiento TEA', () => { expect(marco('rgb(1, 2, 3)')).toBe('rgb(1, 2, 3)'); expect(marco()).toBe('#FFFFFF'); }); + it('sin alteraciones abre con la primera métrica evaluable', () => { + const fixture = open(); + request().flush(data); fixture.detectChanges(); + const root: HTMLElement = fixture.nativeElement; + root.querySelector('button.row-toggle')!.click(); fixture.detectChanges(); + const normales = detalle.eeg.alteraciones.map(m => m.codigo === 'ritmo_posterior' ? { ...m, estado: 'normal', efectos: [] } : m); + http.expectOne('/tea/seguimiento/T-0001').flush({ ...detalle, eeg: { ...detalle.eeg, alteraciones: normales } }); fixture.detectChanges(); + expect(root.querySelector('section.mapa .meta')!.textContent).toContain('Ritmo posterior'); + http.verify(); + }); it('sin filtros no envía sus parámetros', () => { open(); expect(request().request.params.keys().sort()).toEqual(['meses', 'page', 'page_size']); @@ -210,8 +219,8 @@ describe('Seguimiento TEA', () => { expect(panel.textContent).toContain('CSS 3'); expect(panel.textContent).toContain('Afecto social (AS)'); expect(panel.textContent).toContain('Aceptable'); - // The map stays closed until an alteration is chosen. - expect(panel.querySelector('app-plotly-chart')).toBeNull(); + // Opens with the map of the first altered metric. + expect(panel.querySelector('app-plotly-chart')).not.toBeNull(); // Item scores start collapsed. expect(panel.querySelector('details')!.open).toBe(false); const metricas = panel.querySelector('[aria-label="Alteraciones del EEG"]')!;