diff --git a/src/app/features/indicadores/indicador-ayuda.spec.ts b/src/app/features/indicadores/indicador-ayuda.spec.ts new file mode 100644 index 0000000..e177c77 --- /dev/null +++ b/src/app/features/indicadores/indicador-ayuda.spec.ts @@ -0,0 +1,50 @@ +// Covers the round "?" help of TEA's cards: hover or focus shows the text, a click keeps it until the next click. +// Fixture: a host component that projects one line of text into the button. +import { Component } from '@angular/core'; +import { TestBed } from '@angular/core/testing'; +import { IndicadorAyuda } from './indicador-ayuda'; + +@Component({ imports: [IndicadorAyuda], template: `Texto de ayuda` }) +class Host { aperturas = 0; } + +describe('Ayuda redonda', () => { + function crear() { + const fixture = TestBed.createComponent(Host); + fixture.detectChanges(); + const root: HTMLElement = fixture.nativeElement; + const boton = () => root.querySelector('.ayuda-boton')!; + const texto = () => root.querySelector('.ayuda-texto')?.textContent?.trim(); + const ayuda = root.querySelector('.ayuda')!; + return { fixture, boton, texto, ayuda }; + } + + it('muestra el texto al pasar el cursor y lo oculta al salir', () => { + // Fails if hovering stops showing the guide or leaving leaves it open when it was not pinned. + const { fixture, texto, ayuda } = crear(); + expect(texto()).toBeUndefined(); + ayuda.dispatchEvent(new MouseEvent('mouseenter')); fixture.detectChanges(); + expect(texto()).toBe('Texto de ayuda'); + ayuda.dispatchEvent(new MouseEvent('mouseleave')); fixture.detectChanges(); + expect(texto()).toBeUndefined(); + }); + + it('un clic fija el texto hasta el siguiente clic', () => { + // Fails if the click stops pinning the text, if leaving closes a pinned text, or if a second click does not close it. + const { fixture, boton, texto, ayuda } = crear(); + ayuda.dispatchEvent(new MouseEvent('mouseenter')); boton().click(); fixture.detectChanges(); + ayuda.dispatchEvent(new MouseEvent('mouseleave')); fixture.detectChanges(); + expect(texto()).toBe('Texto de ayuda'); + expect(boton().getAttribute('aria-expanded')).toBe('true'); + boton().click(); fixture.detectChanges(); + expect(texto()).toBeUndefined(); + expect(boton().getAttribute('aria-expanded')).toBe('false'); + }); + + it('avisa solo al abrirse con un clic y nombra el botón', () => { + // Fails if closing also reports an opening (the metadata would be requested again) or the accessible name is lost. + const { fixture, boton } = crear(); + boton().click(); boton().click(); boton().click(); fixture.detectChanges(); + expect(fixture.componentInstance.aperturas).toBe(2); + expect(boton().getAttribute('aria-label')).toBe('Cómo leer: prueba'); + }); +}); diff --git a/src/app/features/indicadores/indicador-ayuda.ts b/src/app/features/indicadores/indicador-ayuda.ts new file mode 100644 index 0000000..ffeb980 --- /dev/null +++ b/src/app/features/indicadores/indicador-ayuda.ts @@ -0,0 +1,39 @@ +import { Component, input, output, signal } from '@angular/core'; + +// Round "?" button at the top right of a card. Hover or focus shows its text; a click keeps it open until the next click. +@Component({ + selector: 'app-indicador-ayuda', + template: ` +
+ + @if (visible()) { + + } +
+ `, + styles: ` + :host { position: absolute; top: .5rem; right: .5rem; z-index: 2; } + .ayuda { position: relative; } + .ayuda-boton { display: inline-flex; align-items: center; justify-content: center; width: 1.75rem; height: 1.75rem; padding: 0; border: 0; + border-radius: 50%; background: transparent; box-shadow: inset 0 0 0 1.5px var(--issste-text-secondary); color: var(--issste-text); font: inherit; font-weight: 800; line-height: 1; cursor: pointer; } + .ayuda-boton:focus-visible { outline: 2px solid var(--issste-text); outline-offset: 3px; } + .ayuda-texto { position: absolute; top: calc(100% + .375rem); right: 0; width: min(22rem, 80vw); box-sizing: border-box; padding: var(--issste-space-3) var(--issste-space-4); + background: var(--issste-surface); color: var(--issste-text); border: 1px solid var(--issste-border); border-inline-start: 3px solid var(--issste-accent); + border-radius: var(--issste-radius); box-shadow: 0 4px 16px rgb(0 0 0 / .18); font: var(--mat-sys-body-small); line-height: 1.5; text-align: start; overflow-wrap: anywhere; } + `, +}) +export class IndicadorAyuda { + readonly etiqueta = input('Cómo leer'); + readonly opened = output(); + readonly sobre = signal(false); + readonly fijo = signal(false); + private static contador = 0; + readonly idPanel = 'ayuda-' + ++IndicadorAyuda.contador; + visible() { return this.sobre() || this.fijo(); } + alternar() { + const abre = !this.fijo(); + this.fijo.set(abre); + if (abre) this.opened.emit(); + } +} diff --git a/src/app/features/indicadores/indicador-catalog-card.ts b/src/app/features/indicadores/indicador-catalog-card.ts index d175696..2e21b53 100644 --- a/src/app/features/indicadores/indicador-catalog-card.ts +++ b/src/app/features/indicadores/indicador-catalog-card.ts @@ -24,16 +24,18 @@ import { parTiempos } from './indicadores-tiempos-pareados'; import { IndicadorConteosPareados } from './indicador-conteos-pareados'; import { parConteos } from './indicadores-conteos-pareados'; +const DOBLE_ANCHO_TEA: readonly string[] = ['M28_casos_por_estado', 'M23_pacientes_evaluados']; + @Component({ selector: 'app-indicador-catalog-card', - host: { '[class.dual-card]': 'isDual || isEu7 || isConfirmacion || isHistopatologia || !!tiempos || !!conteos' }, + host: { '[class.dual-card]': 'isDual || isEu7 || isConfirmacion || isHistopatologia || !!tiempos || !!conteos', '[class.doble]': 'ocupaDos' }, imports: [MatButtonModule, MatCardModule, MatIconModule, IndicadorFigurePanel, IndicadorEu7Escenario, IndicadorTiemposPareados, IndicadorConfirmacionCitologia, IndicadorHistopatologiaCama, IndicadorConteosPareados], template: ` @if (!conteos) {
-

{{ indicador.titulo }}

+

{{ indicador.titulo }}

} @@ -81,12 +83,13 @@ import { parConteos } from './indicadores-conteos-pareados'; `, styles: ` :host { display: flex; min-width: 0; margin: 0; } - mat-card { flex: 1; min-width: 0; padding: clamp(.75rem, 2vw, 1.5rem); background: var(--issste-surface); + mat-card { position: relative; flex: 1; min-width: 0; padding: clamp(.75rem, 2vw, 1.5rem); background: var(--issste-surface); color: var(--issste-text); border: 1px solid var(--issste-border); border-radius: var(--issste-radius); box-shadow: none; } header { display: grid; grid-template-columns: minmax(0, 1fr); align-items: start; gap: var(--issste-space-3); } .catalog-content { display: flex; flex-direction: column; flex: 1; min-width: 0; } .graphic-region { flex: 1; min-width: 0; } :host(.dual-card) { grid-column: 1 / -1; } + :host(.doble) { grid-column: span 2; } .graphic-region { display: grid; grid-template-columns: minmax(0, 1fr); } .representation-panel { display: grid; min-width: 0; grid-template-rows: auto minmax(0, 1fr); } .representation-panel > h3 { margin: 1rem 0 0; overflow-wrap: anywhere; } @@ -108,6 +111,7 @@ import { parConteos } from './indicadores-conteos-pareados'; .card-identity { min-width: 0; } h2, p { overflow-wrap: anywhere; } h2 { margin: 0; font-family: var(--issste-font-heading); font-weight: 500; font-size: 1.125rem; line-height: 1.3; } + h2.con-ayuda { padding-right: 2.5rem; } .pin-toggle { align-self: start; margin-top: var(--issste-space-1); max-width: 100%; height: auto; min-width: 48px; min-height: 48px; color: var(--issste-text); } .pin-toggle mat-icon { flex-shrink: 0; } @@ -137,6 +141,8 @@ export class IndicadorCatalogCard implements OnChanges, OnDestroy { } // Every domain follows CaMa's mockup: no pin, representation selector or figure count. get sobrio() { return true; } + // TEA's stacked case charts span two columns of its three-column grid. + get ocupaDos() { return this.dominio === 'tea' && DOBLE_ANCHO_TEA.includes(this.indicador.id); } get pair() { return dualFigures(this.indicador); } get isEu7() { return this.dominio === 'cacu' && this.indicador.id === 'cacu_eu7'; } get isConfirmacion() { return this.dominio === 'cacu' && this.indicador.id === ID_CONFIRMACION; } diff --git a/src/app/features/indicadores/indicador-figure-card.html b/src/app/features/indicadores/indicador-figure-card.html index 406c5c4..58e55a3 100644 --- a/src/app/features/indicadores/indicador-figure-card.html +++ b/src/app/features/indicadores/indicador-figure-card.html @@ -1,5 +1,12 @@ - -@if (selected) { + +@if (selected && ayudaRedonda) { + +
    @for (line of interpretation; track $index) {
  • {{ line }}
  • }
+ @if (state.status === 'ready' && state.footnotes?.length) { + @for (note of state.footnotes; track $index) {

{{ note }}

} + } +
+} @else if (selected) {
@for (row of highlightRows(h); track row.group?.id ?? '') { diff --git a/src/app/features/indicadores/indicador-figure-card.scss b/src/app/features/indicadores/indicador-figure-card.scss index 3fe56b0..8f2c09f 100644 --- a/src/app/features/indicadores/indicador-figure-card.scss +++ b/src/app/features/indicadores/indicador-figure-card.scss @@ -22,6 +22,7 @@ .methodology-toggle:focus-visible { outline: 2px solid var(--issste-text); outline-offset: 3px; } .figure-card { display: grid; grid-template-rows: auto auto auto minmax(0, 1fr) auto auto; overflow: visible; min-width: 0; border: 1px solid var(--issste-border); } +.figure-card.sin-marco { position: static; border: 0; box-shadow: none; background: transparent; --mat-card-outlined-outline-width: 0; --mat-card-elevated-container-elevation: none; } .figure-heading { grid-row: 2; min-width: 0; padding-bottom: .5rem; } .interpretation { grid-row: 1; } .figure-legend { grid-row: 3; min-width: 0; } @@ -117,6 +118,7 @@ .highlight-legend { display: grid; gap: .5rem; padding: .5rem .75rem .75rem; color: var(--issste-text); } .dark .highlight-legend { color: #eef1f7; } .highlight-status { margin: 0; font-weight: 600; } +.sin-estado .highlight-status { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } .highlight-back { justify-self: start; } .highlight-keys { display: flex; flex-wrap: wrap; gap: .5rem; } .highlight-legend button { display: inline-flex; align-items: center; gap: .4rem; min-height: 36px; padding: .3rem .75rem; text-align: start; @@ -126,3 +128,6 @@ .highlight-legend button:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; } .highlight-legend .legend-swatch { border-radius: 50%; } .highlight-legend .highlight-group { font-weight: 600; } + +.ayuda-lista { margin: 0; padding-left: 1.1rem; } +.ayuda-nota { margin: .5rem 0 0; } diff --git a/src/app/features/indicadores/indicador-figure-card.spec.ts b/src/app/features/indicadores/indicador-figure-card.spec.ts index d7b6cd9..be6bde9 100644 --- a/src/app/features/indicadores/indicador-figure-card.spec.ts +++ b/src/app/features/indicadores/indicador-figure-card.spec.ts @@ -515,4 +515,14 @@ describe('IndicadorFigureCard', () => { expect(JSON.stringify(original)).toBe(snapshot); expect(JSON.stringify(copy)).toBe(copySnapshot); }); + it('con la ayuda redonda no repite el título ni el nombre de la figura', () => { + // Fails if TEA's cards bring back the heading box with the title and «Figura: …» under the card's own title. + fixture.componentRef.setInput('ayudaRedonda', true); + ready({ data: [{ y: [1] }], layout: {} }); + const root: HTMLElement = fixture.nativeElement; + expect(root.querySelector('.figure-title')).toBeNull(); + expect(root.querySelector('.figure-id')).toBeNull(); + expect(root.querySelector('.ayuda-boton')).not.toBeNull(); + expect(root.querySelector('.interpretation')).toBeNull(); + }); }); diff --git a/src/app/features/indicadores/indicador-figure-card.ts b/src/app/features/indicadores/indicador-figure-card.ts index dc6f8cc..3e56541 100644 --- a/src/app/features/indicadores/indicador-figure-card.ts +++ b/src/app/features/indicadores/indicador-figure-card.ts @@ -10,6 +10,7 @@ import { figureDisplayName } from './indicadores-figure-labels'; import { CategoryLabel } from './indicadores-axis-labels'; import { figureIdentity, identityElementId } from './indicadores-identities'; import { PlotlyChart } from '../../shared/plotly/plotly-chart'; +import { IndicadorAyuda } from './indicador-ayuda'; import { figureInterpretation, PERIOD_INTERPRETATION } from './indicadores-methodology'; import { DonutHierarchy, DonutLegendEntry, DonutSelection, donutSimpleView, donutView } from './indicadores-donut-drilldown'; import { FigureHighlight, highlightAt, highlightFigure, highlightLabel, highlightRows, HighlightSelection, toggleHighlight } from './indicadores-highlight'; @@ -41,7 +42,7 @@ export interface FigureState { selector: 'app-indicador-figure-card', standalone: true, host: { '[class.methodology-expanded]': 'methodologyExpanded()' }, - imports: [MatButtonModule, MatIconModule, MatCardModule, MatProgressBarModule, MatTooltipModule, PlotlyChart], + imports: [MatButtonModule, MatIconModule, MatCardModule, MatProgressBarModule, MatTooltipModule, PlotlyChart, IndicadorAyuda], templateUrl: './indicador-figure-card.html', styleUrl: './indicador-figure-card.scss', }) @@ -142,6 +143,8 @@ export class IndicadorFigureCard implements OnChanges { if (point?.curveNumber === (this.activeParent ? 1 : 0) && typeof point.label === 'string') this.expandParent(point.label); else if (this.activeParent && point?.curveNumber === 0 && typeof point.label === 'string') this.selectCategory(point.label); } + // A round "?" button with the reading guide instead of the «Cómo leer» box. + @Input() ayudaRedonda = false; @Input() selected?: Indicador; @Input() metadata?: IndicadorMetadatos; @Input({ required: true }) figuraId!: string; diff --git a/src/app/features/indicadores/indicador-figure-panel.spec.ts b/src/app/features/indicadores/indicador-figure-panel.spec.ts index e34ec83..d858e65 100644 --- a/src/app/features/indicadores/indicador-figure-panel.spec.ts +++ b/src/app/features/indicadores/indicador-figure-panel.spec.ts @@ -33,6 +33,8 @@ describe('IndicadorFigurePanel', () => { fixture.componentRef.setInput('dominio', 'tea'); fixture.componentRef.setInput('indicador', catalog[0]); fixture.componentRef.setInput('figuraId', 'f1'); + // These tests cover the «Cómo leer» box shared by the domains; TEA's round help has its own spec. + fixture.componentRef.setInput('ayudaRedonda', false); fixture.componentRef.setInput('tema', 'claro'); state = TestBed.inject(IndicadoresMemory).restoreGlobal('tea', ['semestre']); fixture.componentRef.setInput('applied', state.applied); @@ -373,6 +375,7 @@ describe('IndicadorFigurePanel', () => { fixture = TestBed.createComponent(IndicadorFigurePanel); fixture.componentRef.setInput('dominio', 'tea'); fixture.componentRef.setInput('indicador', catalog[0]); fixture.componentRef.setInput('figuraId', 'f1'); fixture.componentRef.setInput('tema', 'claro'); + fixture.componentRef.setInput('ayudaRedonda', false); fixture.componentRef.setInput('applied', state.applied); page = fixture.componentInstance; load(); figure().flush({ data: [], layout: {} }); expect(JSON.stringify(state)).toBe(snapshot); diff --git a/src/app/features/indicadores/indicador-figure-panel.ts b/src/app/features/indicadores/indicador-figure-panel.ts index 0213b44..711c4c4 100644 --- a/src/app/features/indicadores/indicador-figure-panel.ts +++ b/src/app/features/indicadores/indicador-figure-panel.ts @@ -23,9 +23,10 @@ import { MatTooltipModule } from '@angular/material/tooltip'; @Component({ selector: 'app-indicador-figure-panel', + host: { '[class.ayuda-externa]': 'conAyudaRedonda' }, imports: [IndicadorFigureCard, MatTooltipModule], template: ` -
+

{{ dominio }}, {{ indicador.id }}, {{ indicador.titulo }}, {{ figuraId }}

@if (sidebar) {
+ } - - } - @if (d.relacion_ados2; as rel) { -
-

Relación con el ADOS-2 Datos de ejemplo

+ @if (d.relacion_ados2; as rel) { +
+

Relación con el ADOS-2 Datos de ejemplo

Modelo de asociación ajustado en la cohorte ({{ rel.n_cohorte }} niños, por edad y módulo del ADOS-2): qué tanto se asocia cada alteración del EEG por zona con {{ rel.nivel === 'item' ? 'un reactivo' : 'la severidad de un dominio' }} del ADOS-2. No es un diagnóstico ni indica qué causa qué.@if (!rel.validado) { Pendiente de validación médica.}

@@ -144,9 +211,9 @@ @for (f of filasRelacion(rel); track f.biomarcador + f.zona + f.resultado) { - {{ f.biomarcador }}{{ f.zona_etiqueta }} · z = {{ f.valor_z }}@if (zonaAlterada(f)) { · alterada} + {{ f.biomarcador }}{{ f.zona_etiqueta }} · z = {{ cifras(f.valor_z) }}@if (zonaAlterada(f)) { · alterada} {{ f.resultado_etiqueta }}{{ f.tipo === 'item' ? 'Reactivo' : 'Dominio' }} - OR {{ f.or }}IC 95 % {{ f.ic_inf }}–{{ f.ic_sup }} · q {{ qTexto(f.q) }}{{ direccion(f) }} + OR {{ cifras(f.or) }}IC 95 % {{ cifras(f.ic_inf) }}–{{ cifras(f.ic_sup) }} · q {{ qTexto(f.q) }}{{ direccion(f) }} {{ porcentaje(f.probabilidad) }} %
- } - + + } + + } } diff --git a/src/app/features/indicadores/tea-paciente-resumen.scss b/src/app/features/indicadores/tea-paciente-resumen.scss index f81cf4d..e0c20cd 100644 --- a/src/app/features/indicadores/tea-paciente-resumen.scss +++ b/src/app/features/indicadores/tea-paciente-resumen.scss @@ -1,5 +1,23 @@ :host { display: block; container: host / inline-size; } -.resumen { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: .75rem; } +// The four cards side by side in one row; two by two and then stacked as the row narrows. +.tarjetas { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; } +@container host (max-width: 64rem) { .tarjetas { grid-template-columns: repeat(2, minmax(0, 1fr)); } } +@container host (max-width: 36rem) { .tarjetas { grid-template-columns: minmax(0, 1fr); } } +.cifras { margin: 0; font-size: .85rem; } +.alteradas { margin: 0; padding: 0; list-style: none; font-size: .85rem; } +.alteradas li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .1rem 1rem; padding: .25rem 0; border-top: 1px solid var(--issste-border); font-weight: 600; } +.alteradas .estado { color: #B3261E; font-weight: 400; } +.principal { margin: 0; font-size: .85rem; } +button.completo { margin-top: .75rem; padding: .35rem .75rem; color: var(--issste-accent); font-weight: 600; } +// The full record: one collapsible section after another, no cards. +.documento { max-width: 64rem; } +.seccion { margin: 0; padding: .25rem 0 .75rem; border-bottom: 1px solid var(--issste-border); } +.seccion > summary { margin: 0; } +.seccion > summary h2 { margin: 0; font-size: 1.15rem; } +.seccion > :not(summary) { margin-inline-start: 1.25rem; } +.documento .metricas { grid-template-columns: minmax(0, 1fr); gap: 0; } +.documento .metricas > li { border: 0; border-top: 1px solid var(--issste-border); border-radius: 0; padding: .5rem 0 .5rem .6rem; } +.documento .metricas > li[data-estado=aumentado], .documento .metricas > li[data-estado=disminuido] { border-inline-start: 4px solid #B3261E; } .panel { min-width: 0; padding: .75rem; border: 1px solid var(--issste-border); border-radius: var(--issste-radius); background: var(--issste-surface); } h3 { margin: 0 0 .15rem; font-size: 1rem; } .meta { margin: 0 0 .5rem; font-size: .8rem; color: var(--issste-text-secondary); } @@ -47,17 +65,12 @@ h3 .mock { display: inline-block; white-space: nowrap; margin-inline-start: .5re font-size: .75rem; font-weight: 400; color: var(--issste-text-secondary); vertical-align: middle; } .sin-alteraciones { margin: 0 0 .75rem; font-weight: 600; } .metricas, .efectos { margin: 0; padding: 0; list-style: none; } -// The map has its final width from the start, because Plotly draws at the width it finds: its column only reveals it. -.alteraciones-zona { container: zona / inline-size; grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 0fr); align-items: start; transition: grid-template-columns 300ms ease; } -.alteraciones-zona.abierta { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; } -.marco-mapa { min-width: 0; overflow: hidden; } -.mapa { box-sizing: border-box; width: calc(50cqw - .5rem); padding-top: .75rem; animation: aparecer 300ms ease; } -.mapa h3 { margin-top: 0; } -@keyframes aparecer { from { opacity: 0; } } -@container (min-width: 68rem) { .alteraciones-zona { grid-column: span 2; } } -@container host (max-width: 42rem) { .mapa { width: 100cqw; } } -@container (max-width: 42rem) { .alteraciones-zona.abierta { grid-template-columns: minmax(0, 1fr); } } -@media (prefers-reduced-motion: reduce) { .alteraciones-zona { transition: none; } .mapa { animation: none; } } +// The full summary: the metric list on the left, the plots of the chosen metric on the right, always in view. +.alteraciones-lado { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 1.5rem; align-items: start } +@container host (max-width: 52rem) { .alteraciones-lado { grid-template-columns: minmax(0, 1fr); } } +.graficos { min-width: 0; display: grid; gap: 1rem; } +.grafico h3 { margin-top: 0; } +.sin-grafico { margin: 0; font-size: .9rem; color: var(--issste-text-secondary); } .metricas { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: .5rem; align-items: start; } .metricas > li { position: relative; padding: .5rem .6rem; border: 1px solid var(--issste-border); border-inline-start-width: 4px; border-radius: var(--issste-radius); transition: background-color 120ms ease; } .metricas > li:has(button:not(:disabled)):hover { background: color-mix(in srgb, var(--issste-accent) 8%, transparent); } @@ -65,7 +78,9 @@ h3 .mock { display: inline-block; white-space: nowrap; margin-inline-start: .5re .metricas > li[data-estado=aumentado], .metricas > li[data-estado=disminuido] { border-inline-start-color: #B3261E; } .metrica { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .1rem 1rem; font-size: .9rem; font-weight: 600; } li[data-estado=aumentado] .estado, li[data-estado=disminuido] .estado { color: #B3261E; } -li[data-estado=normal] .estado { color: var(--issste-text-secondary); font-weight: 400; } +li[data-estado=normal] .estado { color: #1B7F3B; font-weight: 600; } +:host-context([data-theme=dark]) li[data-estado=normal] .estado { color: #6FD38A; } +@media (prefers-color-scheme: dark) { :host-context(:root:not([data-theme=light])) li[data-estado=normal] .estado { color: #6FD38A; } } li[data-estado=no_evaluable] .estado { color: var(--issste-text-secondary); font-weight: 400; font-style: italic; } .valor { margin: .1rem 0 0; font-size: .8rem; color: var(--issste-text-secondary); font-variant-numeric: tabular-nums; } .efectos-titulo { margin: .3rem 0 .1rem; font-size: .8rem; font-weight: 600; } @@ -88,9 +103,4 @@ button { min-height: 44px; padding: .6rem; border: 1px solid var(--issste-border .barra .paciente { position: absolute; inset-block: 0; inset-inline-start: 0; border-radius: 999px; background: var(--issste-accent); } .barra .referencia { position: absolute; top: -.15rem; bottom: -.15rem; width: 2px; background: var(--issste-text-secondary); } .nota { margin: .5rem 0 0; font-size: .75rem; color: var(--issste-text-secondary); } -// The switch between the head map and the age norm, when the metric has both. -.vistas { display: inline-flex; margin-bottom: .5rem; border: 1px solid var(--issste-border); border-radius: var(--issste-radius); overflow: hidden; } -.vistas button { margin: 0; min-height: 0; padding: .3rem .75rem; border: 0; background: none; color: inherit; font: inherit; font-size: .8rem; cursor: pointer; } -.vistas button + button { border-inline-start: 1px solid var(--issste-border); } -.vistas button[aria-pressed=true] { background: color-mix(in srgb, var(--issste-accent) 14%, transparent); font-weight: 600; } .leyenda-norma { margin: .25rem 0 0; font-size: .8rem; color: var(--issste-text-secondary); } diff --git a/src/app/features/indicadores/tea-paciente-resumen.ts b/src/app/features/indicadores/tea-paciente-resumen.ts index 1f99f7a..80936dd 100644 --- a/src/app/features/indicadores/tea-paciente-resumen.ts +++ b/src/app/features/indicadores/tea-paciente-resumen.ts @@ -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(); 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)'; diff --git a/src/app/features/indicadores/tea-resumen-periodo.spec.ts b/src/app/features/indicadores/tea-resumen-periodo.spec.ts index c3cecf6..f5a0c27 100644 --- a/src/app/features/indicadores/tea-resumen-periodo.spec.ts +++ b/src/app/features/indicadores/tea-resumen-periodo.spec.ts @@ -37,11 +37,12 @@ describe('Resumen TEA por periodo', () => { expect(text).toContain('Al cierre del periodo 2025-S2, se evaluaron 100 niños entre 16 y 36 meses; 15 únicamente tienen M-CHAT, 15 hasta la evaluación psicológica y 70 presentan evaluación neuropediátrica.'); expect(text).toContain('En este periodo el 86.5% de los pacientes tiene diagnóstico confirmado de TEA (CIE-10 F84.0).'); expect(text).toContain('Las ventanas de tiempo* de tamizaje son: 8 días de M-CHAT (psicología) a ADOS-2, 14 días de ADOS-2 a diagnóstico. El tiempo* de tamizaje completo de M-CHAT a diagnóstico fue de 22.5 días.'); - expect(text).toContain('De los 57 niños con diagnóstico confirmado al cierre del periodo, 41 tienen un EEG de buena calidad y 16 aún no cuentan con uno de esa calidad. Del total de estudios de EEG del periodo, 25.0% tienen buena calidad.'); + expect(text).toContain('De los 57 niños con diagnóstico confirmado en este periodo, 41 presentan estudio de EEG y faltan 16 por realizarlo. De los 41 estudios de EEG, 25.0% tienen buena calidad.'); expect(text).toContain('*tomando la mediana de los tiempos'); expect(Array.from(root.querySelectorAll('.dato.listo')).map(e => e.textContent!.trim())) - .toEqual(['2025-S2', '100', '15', '15', '70', '86.5%', '8 días', '14 días', '22.5 días', '57', '41', '16', '25.0%']); + .toEqual(['2025-S2', '100', '15', '15', '70', '86.5%', '8 días', '14 días', '22.5 días', '57', '41', '16', '41', '25.0%']); expect(root.querySelector('button')).toBeNull(); + expect(root.querySelector('h2')!.textContent).toBe('Resumen'); }); it('no copia cifras de ejemplo: otros conteos cambian toda la redacción', () => { @@ -54,7 +55,7 @@ describe('Resumen TEA por periodo', () => { panel('M29_calidad_eeg', { ...listo(4), categorias: { BUENO: 1, MALO: 1, SIN_ANALIZAR: 2 } })]; const text = texto(render(paneles).nativeElement); expect(text).toContain('se evaluaron 3 niños entre 16 y 36 meses; 1 únicamente tienen M-CHAT, 1 hasta la evaluación psicológica y 1 presentan'); - expect(text).toContain('De los 1 niños con diagnóstico confirmado al cierre del periodo, 0 tienen un EEG de buena calidad y 1 aún no cuentan con uno de esa calidad. Del total de estudios de EEG del periodo, 25.0% tienen buena calidad.'); + expect(text).toContain('De los 1 niños con diagnóstico confirmado en este periodo, 0 presentan estudio de EEG y faltan 1 por realizarlo. De los 0 estudios de EEG, 25.0% tienen buena calidad.'); for (const ejemplo of ['47', '155.5', '18.6', '54 días', '97 días', '##']) expect(text).not.toContain(ejemplo); }); @@ -64,7 +65,7 @@ describe('Resumen TEA por periodo', () => { paneles[3].result.set(c1('0.0', 0, 57)); paneles[4].result.set(c1('100.0', 57, 57)); paneles[7].result.set({ ...listo(0), categorias: { BUENO: 0, MALO: 0, SIN_ANALIZAR: 0 } }); const root: HTMLElement = render(paneles).nativeElement; - expect(texto(root)).toContain('0 tienen un EEG de buena calidad y 57 aún no cuentan con uno de esa calidad. Del total de estudios de EEG del periodo, sin dato (Sin estudios de EEG en el periodo) tienen buena calidad.'); + expect(texto(root)).toContain('0 presentan estudio de EEG y faltan 57 por realizarlo. De los 0 estudios de EEG, sin dato (Sin estudios de EEG en el periodo) tienen buena calidad.'); expect(Array.from(root.querySelectorAll('.dato.listo')).map(e => e.textContent!.trim())).toContain('0'); }); @@ -85,7 +86,7 @@ describe('Resumen TEA por periodo', () => { paneles[4].result.set(c1('28.1', 16, 58)); const root: HTMLElement = render(paneles).nativeElement; expect(Array.from(root.querySelectorAll('.dato.sin-dato')).map(e => e.getAttribute('title'))) - .toEqual(Array(3).fill('Las poblaciones de M21 y M22 no coinciden')); + .toEqual(Array(4).fill('Las poblaciones de M21 y M22 no coinciden')); }); it('indica la carga y reintenta solo las consultas con error', () => { diff --git a/src/app/features/indicadores/tea-resumen-periodo.ts b/src/app/features/indicadores/tea-resumen-periodo.ts index 41f5298..5604f6b 100644 --- a/src/app/features/indicadores/tea-resumen-periodo.ts +++ b/src/app/features/indicadores/tea-resumen-periodo.ts @@ -16,7 +16,8 @@ const M21 = 'M21_diagnosticados_con_eeg', M22 = 'M22_diagnosticados_sin_eeg', M2 selector: 'app-tea-resumen-periodo', imports: [MatButtonModule, NgTemplateOutlet], template: ` -
+
+

Resumen

Al cierre del periodo {{ periodo }}, se evaluaron niños entre 16 y 36 meses; únicamente tienen M-CHAT, @@ -29,10 +30,10 @@ const M21 = 'M21_diagnosticados_con_eeg', M22 = 'M22_diagnosticados_sin_eeg', M2 El tiempo* de tamizaje completo de M-CHAT a diagnóstico fue de .
- De los niños con diagnóstico confirmado al cierre del periodo, - tienen un EEG de buena calidad y - aún no cuentan con uno de esa calidad. - Del total de estudios de EEG del periodo, + De los niños con diagnóstico confirmado en este periodo, + presentan estudio de EEG y faltan + por realizarlo. + De los estudios de EEG, tienen buena calidad.

*tomando la mediana de los tiempos

@@ -48,6 +49,7 @@ const M21 = 'M21_diagnosticados_con_eeg', M22 = 'M22_diagnosticados_sin_eeg', M2 :host { display: block; min-width: 0; } .resumen { box-sizing: border-box; padding: var(--issste-space-6); background: var(--issste-surface); color: var(--issste-text); border: 1px solid var(--issste-border); border-radius: var(--issste-radius); } + h2 { margin: 0 0 var(--issste-space-3); font-family: var(--issste-font-heading); font-weight: 500; font-size: 1.125rem; } p { margin: 0; font-family: var(--issste-font-heading); font-size: 1.25rem; line-height: 2.1; overflow-wrap: anywhere; } p + p { margin-top: var(--issste-space-4); } p.nota { margin-top: var(--issste-space-2); font-size: .95rem; line-height: 1.5; color: var(--issste-text-secondary); } diff --git a/src/app/features/indicadores/tea-seguimiento.spec.ts b/src/app/features/indicadores/tea-seguimiento.spec.ts index fb039d7..5ddd57a 100644 --- a/src/app/features/indicadores/tea-seguimiento.spec.ts +++ b/src/app/features/indicadores/tea-seguimiento.spec.ts @@ -2,7 +2,7 @@ import { TestBed } from '@angular/core/testing'; import { provideHttpClient } from '@angular/common/http'; import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing'; import { teaPacienteDetalle, teaSeguimientoResponse, TeaEeg, TeaEegMapa } from './tea-seguimiento.service'; -import { mapaFigure } from './tea-paciente-resumen'; +import { mapaFigure, TeaPacienteResumen } from './tea-paciente-resumen'; import { PLOTLY_LOADER } from '../../shared/plotly/plotly-runtime'; import { IndicadoresTracking } from './indicadores-tracking'; @@ -57,6 +57,16 @@ describe('Seguimiento TEA', () => { return fixture; } const request = () => http.expectOne(r => r.url === '/tea/seguimiento'); + // The patient's whole record, as the window opened from the patient id shows it. + function resumen(d: object, id = 'T-0001') { + const fixture = TestBed.createComponent(TeaPacienteResumen); + fixture.componentRef.setInput('id', id); fixture.componentRef.setInput('modo', 'resumen'); + fixture.detectChanges(); + http.expectOne(`/tea/seguimiento/${id}`).flush(d); fixture.detectChanges(); + return fixture; + } + const seccion = (root: HTMLElement, titulo: string) => + Array.from(root.querySelectorAll('details.seccion')).find(d => d.querySelector('summary h2')!.textContent!.trim().startsWith(titulo))!; it('muestra las siete columnas y los valores ausentes como No disponible', () => { const fixture = open(); request().flush(data); fixture.detectChanges(); @@ -146,17 +156,15 @@ describe('Seguimiento TEA', () => { expect(c.draft).toMatchObject({ estado_caso: 'completo', alteracion: 'picos_paroxisticos' }); http.verify(); }); - 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(); + it('el resumen muestra las alteraciones y sus gráficas lado a lado, siempre a la vista: elegir otra las cambia y repetirla las deja', () => { + const fixture = resumen(detalle); const root: HTMLElement = fixture.nativeElement; - root.querySelector('button.row-toggle')!.click(); fixture.detectChanges(); - http.expectOne('/tea/seguimiento/T-0001').flush(detalle); fixture.detectChanges(); + const lado = root.querySelector('.alteraciones-lado')!; + expect(lado.querySelector('ul.metricas')).not.toBeNull(); + expect(lado.querySelector('section.graficos')).not.toBeNull(); const tarjetas = root.querySelectorAll('button.nombre'); - expect(root.querySelector('.alteraciones-zona')!.classList.contains('abierta')).toBe(true); - expect(tarjetas[0].getAttribute('aria-expanded')).toBe('true'); - const panel = () => root.querySelector('section.mapa')!; - expect(panel().classList.contains('panel')).toBe(false); + const panel = () => root.querySelector('section.graficos')!; + expect(tarjetas[0].getAttribute('aria-pressed')).toBe('true'); expect(panel().textContent).toContain('Azul: menos actividad'); expect(panel().textContent).toContain('Rojo: más actividad'); expect(panel().querySelector('.meta')!.textContent).toContain('Ritmo posterior'); @@ -164,45 +172,38 @@ describe('Seguimiento TEA', () => { tarjetas[3].click(); fixture.detectChanges(); expect(panel().querySelector('.meta')!.textContent).toContain('Picos paroxísticos'); expect(panel().querySelector('.regiones')!.textContent).toContain('Occipital'); - expect(tarjetas[0].getAttribute('aria-expanded')).toBe('false'); + expect(tarjetas[0].getAttribute('aria-pressed')).toBe('false'); expect(tarjetas[1].disabled).toBe(true); - expect(tarjetas[1].hasAttribute('aria-expanded')).toBe(false); + expect(tarjetas[1].hasAttribute('aria-pressed')).toBe(false); + // Choosing the same metric again keeps its plots in view. 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(); + expect(panel().querySelector('.regiones')).not.toBeNull(); + expect(tarjetas[3].getAttribute('aria-pressed')).toBe('true'); http.verify(); }); - it('muestra la norma por edad con el paciente, con o sin mapa, y rechaza una curva cuyos percentiles se cruzan', () => { + it('muestra el mapa y la norma por edad juntos cuando la métrica tiene los dos, o solo la norma si no tiene mapa, y rechaza una curva cuyos percentiles se cruzan', () => { const curva = { fuente: 'Helsinki (HK1K, base pública)', estado: 'vigilia', edad_meses: [12, 24, 48], p5: [0.5, 0.6, 0.7], p25: [0.8, 1, 1.1], mediana: [1.2, 1.5, 1.6], p75: [1.6, 1.8, 2], p95: [2, 2.2, 2.4] }; const conCurva = detalle.eeg.alteraciones.map(m => m.codigo === 'ritmo_posterior' || m.codigo === 'gradiente_anteroposterior' ? { ...m, curva_referencia: curva } : m); const conNorma = { ...detalle, eeg: { ...detalle.eeg, edad_meses: 20.5, alteraciones: conCurva } }; - const fixture = open(); - request().flush(data); fixture.detectChanges(); + const fixture = resumen(conNorma); const root: HTMLElement = fixture.nativeElement; - root.querySelector('button.row-toggle')!.click(); fixture.detectChanges(); - http.expectOne('/tea/seguimiento/T-0001').flush(conNorma); fixture.detectChanges(); - const panel = () => root.querySelector('section.mapa')!; - const vistas = () => panel().querySelectorAll('.vistas button'); - // Ritmo has both: it opens on the map, and the switch moves to the norm with the patient's value and age. - expect(Array.from(vistas()).map(b => b.textContent)).toEqual(['Zonas de la cabeza', 'Norma por edad']); - expect(panel().textContent).toContain('Zonas más afectadas'); - vistas()[1].click(); fixture.detectChanges(); - expect(vistas()[1].getAttribute('aria-pressed')).toBe('true'); - expect(panel().querySelector('h3')!.textContent).toBe('Norma por edad'); + const panel = () => root.querySelector('section.graficos')!; + const titulos = () => Array.from(panel().querySelectorAll('h3')).map(h => h.textContent); + // Ritmo has both: the map and the norm show together, with the patient's value and age, and no switch between them. + expect(titulos()).toEqual(['Zonas más afectadas', 'Norma por edad']); + expect(panel().querySelector('.vistas')).toBeNull(); expect(panel().textContent).toContain('0.9 a los 20.5 meses (z = -2.4)'); - expect(panel().querySelector('.regiones')).toBeNull(); - // Gradiente has no map: its card opens the norm alone, without the switch. + expect(panel().querySelector('.regiones')).not.toBeNull(); + // Gradiente has no map: its norm shows alone. const tarjetas = root.querySelectorAll('button.nombre'); tarjetas[4].click(); fixture.detectChanges(); - expect(tarjetas[4].getAttribute('aria-expanded')).toBe('true'); - expect(vistas().length).toBe(0); + expect(tarjetas[4].getAttribute('aria-pressed')).toBe('true'); + expect(titulos()).toEqual(['Norma por edad']); expect(panel().textContent).toContain('Gradiente anteroposterior'); - const c = fixture.debugElement.query(d => d.name === 'app-tea-paciente-resumen').componentInstance; - const trazas = c.figuraNorma.data as { name: string; x: number[]; y: number[] }[]; + const c = fixture.componentInstance; + const trazas = c.figuraNorma!.data as { name: string; x: number[]; y: number[] }[]; expect(trazas.map(t => t.name)).toEqual(['Del 5 al 95 %', 'Del 25 al 75 %', 'Mediana', 'Este paciente']); expect([trazas[3].x[0], trazas[3].y[0]]).toEqual([20.5, 1.2]); const cruzada = conCurva.map(m => m.codigo === 'ritmo_posterior' ? { ...m, curva_referencia: { ...curva, p25: [0.8, 3, 1.1] } } : m); @@ -215,14 +216,55 @@ describe('Seguimiento TEA', () => { expect(marco('rgb(1, 2, 3)')).toBe('rgb(1, 2, 3)'); expect(marco()).toBe('#FFFFFF'); }); + it('redondea a tres cifras significativas', () => { + // Fails if the alterations show more than three significant digits or keep trailing zeros. + const c = TestBed.createComponent(TeaPacienteResumen).componentInstance; + expect([c.cifras(0.123456), c.cifras(12.3456), c.cifras(1234.5), c.cifras(2), c.cifras(null)]).toEqual(['0.123', '12.3', '1230', '2', '']); + }); + it('sin alteraciones abre con la primera métrica evaluable', () => { + const normales = detalle.eeg.alteraciones.map(m => m.codigo === 'ritmo_posterior' ? { ...m, estado: 'normal', efectos: [] } : m); + const fixture = resumen({ ...detalle, eeg: { ...detalle.eeg, alteraciones: normales } }); + const root: HTMLElement = fixture.nativeElement; + expect(root.querySelector('section.graficos .meta')!.textContent).toContain('Ritmo posterior'); + http.verify(); + }); + it('el identificador abre el resumen completo en su propia sección, sin desplegar la fila, y Volver regresa a la lista', () => { const fixture = open(); + const ficha = vi.fn(); fixture.componentInstance.fichaPacienteAbierta.subscribe(ficha); 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'); + const id = root.querySelector('tbody tr.tea-row button.patient-link')!; + expect(id.textContent!.trim()).toBe('T-0001'); + id.click(); fixture.detectChanges(); + http.expectOne('/tea/seguimiento/T-0001').flush(detalle); fixture.detectChanges(); + expect(ficha).toHaveBeenLastCalledWith(true); + expect(root.querySelector('tr.tea-detalle')).toBeNull(); + const seccionFicha = root.querySelector('section.ficha-tea')!; + expect(seccionFicha.querySelector('h2')!.textContent).toContain('T-0001'); + expect(seccionFicha.querySelectorAll('details.seccion').length).toBeGreaterThanOrEqual(4); + expect(root.querySelector('form')!.closest('[hidden]')).not.toBeNull(); + Array.from(seccionFicha.querySelectorAll('button')).find(b => b.textContent!.includes('Volver a Seguimiento'))!.click(); fixture.detectChanges(); + expect(ficha).toHaveBeenLastCalledWith(false); + expect(root.querySelector('section.ficha-tea')).toBeNull(); + expect(root.querySelector('form')!.closest('[hidden]')).toBeNull(); + expect(root.querySelectorAll('tbody tr.tea-row')).toHaveLength(2); + http.verify(); + }); + it('el resumen completo son secciones con encabezado plegable, abiertas, y los reactivos van plegados dentro del ADOS-2', () => { + const root: HTMLElement = resumen(detalle).nativeElement; + const secciones = Array.from(root.querySelectorAll('details.seccion')); + expect(secciones.map(d => d.querySelector('summary h2')!.textContent!.replace('Datos de ejemplo', '').trim())).toEqual( + ['Datos del paciente', 'ADOS-2', 'Calidad del EEG', 'Alteraciones del EEG']); + expect(secciones.every(d => d.open)).toBe(true); + expect(root.querySelector('.tarjetas, .panel')).toBeNull(); + expect(seccion(root, 'Datos del paciente').textContent).toContain('T-0001'); + expect(seccion(root, 'Datos del paciente').textContent).toContain('16-23 meses'); + const reactivos = seccion(root, 'ADOS-2').querySelector('details:not(.seccion)')!; + expect(reactivos.open).toBe(false); + expect(reactivos.textContent).toContain('A2 · Reactivo A2'); + secciones[1].open = false; + expect(secciones[1].open).toBe(false); http.verify(); }); it('sin filtros no envía sus parámetros', () => { @@ -258,22 +300,24 @@ describe('Seguimiento TEA', () => { expect(toggles[1].getAttribute('aria-expanded')).toBe('true'); http.expectOne('/tea/seguimiento/T-0002').flush({ ...detalle, id_seudonimo: 'T-0002' }); fixture.detectChanges(); const panel = root.querySelector('#tea-detalle-T-0002')!; + // Four summary cards, two by two, with the verdicts and no maps or item tables. + expect(Array.from(panel.querySelectorAll('.tarjetas > section')).map(c => c.getAttribute('aria-label'))).toEqual([ + 'Resumen ADOS-2', 'Calidad del EEG', 'Alteraciones del EEG', 'Relación de las alteraciones del EEG con el ADOS-2']); expect(panel.textContent).toContain('CSS 3'); expect(panel.textContent).toContain('Afecto social (AS)'); expect(panel.textContent).toContain('Válido'); - // 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); + expect(panel.querySelector('app-plotly-chart')).toBeNull(); + expect(panel.querySelector('details')).toBeNull(); const metricas = panel.querySelector('[aria-label="Alteraciones del EEG"]')!; expect(metricas.textContent).toContain('Datos de ejemplo'); + expect(metricas.textContent).toContain('1 de 4 métricas evaluadas fuera de la referencia'); + expect(metricas.textContent).toContain('Ritmo posterior'); expect(metricas.textContent).toContain('Disminuido'); - expect(metricas.textContent).toContain('Posibles efectos asociados'); - expect(metricas.textContent).toContain('Ritmo más lento de lo esperado para la edad.'); - expect(metricas.textContent).toContain('No se pudo medir en el estudio.'); - expect(Array.from(metricas.querySelectorAll('.nombre')).map(n => n.textContent)).toEqual( - ['Ritmo posterior', 'Husos de sueño N2', 'Husos de sueño N3', 'Picos paroxísticos', 'Gradiente anteroposterior']); - expect(metricas.textContent).not.toContain('Sin alteraciones en las métricas evaluadas.'); + expect(metricas.textContent).not.toContain('Husos de sueño N3'); + expect(panel.querySelector('[aria-label="Calidad del EEG"]')!.textContent).toContain('1 de 2 reglas del estudio fuera de rango · 1 canal descartado'); + // The whole record opens in its own section from the patient id and from the cards' button. + const enlace = panel.querySelector('button.completo')!; + expect(enlace.textContent).toContain('resumen completo'); (root.querySelectorAll('tbody tr.tea-row')[2] as HTMLElement).click(); fixture.detectChanges(); expect(root.querySelector('#tea-detalle-T-0002')).toBeNull(); http.expectOne('/tea/seguimiento/T-0004').flush({ ...detalle, id_seudonimo: 'T-0004', ados2: null, eeg: null }); fixture.detectChanges(); @@ -345,12 +389,7 @@ describe('Seguimiento TEA', () => { expect(() => teaPacienteDetalle({ ...detalle, eeg: { ...detalle.eeg, calidad: 'regular' } }, 'T-0001')).toThrow(); }); it('la calidad es el veredicto del análisis, con sus reglas y los canales descartados, y se valida', () => { - const fixture = open(); - request().flush(tres); fixture.detectChanges(); - const root: HTMLElement = fixture.nativeElement; - root.querySelectorAll('button.row-toggle')[0].click(); fixture.detectChanges(); - http.expectOne('/tea/seguimiento/T-0001').flush(detalle); fixture.detectChanges(); - const panel = root.querySelector('section.calidad')!; + const panel = seccion(resumen(detalle).nativeElement, 'Calidad del EEG'); const texto = (n: Element) => n.textContent!.replace(/\s+/g, ' ').trim(); expect(texto(panel.querySelector('.css')!)).toBe('Válido'); expect(Array.from(panel.querySelectorAll('dt, dd')).map(texto)).toEqual(['Ventanas limpias (decisiva)', '95 %', 'Ruido de la línea eléctrica', '48 dB']); @@ -392,12 +431,7 @@ describe('Seguimiento TEA', () => { expect(() => teaPacienteDetalle(rel([{ ...fila, probabilidad: 1.2 }]), 'T-0001')).toThrow(); expect(() => teaPacienteDetalle(rel([{ ...fila, ic_inf: 0.5 }]), 'T-0001')).toThrow(); expect(() => teaPacienteDetalle(rel([{ ...fila, tipo: 'zona' }]), 'T-0001')).toThrow(); - const fixture = open(); - request().flush(tres); fixture.detectChanges(); - const root: HTMLElement = fixture.nativeElement; - root.querySelectorAll('button.row-toggle')[0].click(); fixture.detectChanges(); - http.expectOne('/tea/seguimiento/T-0001').flush(rel([otra, fila])); fixture.detectChanges(); - const filas = Array.from(root.querySelectorAll('section.relacion tbody tr')); + const filas = Array.from(seccion(resumen(rel([otra, fila])).nativeElement, 'Relación con el ADOS-2').querySelectorAll('tbody tr')); expect(filas.length).toBe(1); expect(filas[0].classList.contains('alterada')).toBe(true); expect(filas[0].textContent).toContain('q < 0.001');