feat(tea): ficha de paciente en tres columnas y dona de M21 solo con EEG

- La ficha propia del paciente reparte los paneles en tres columnas
  (dos o una en pantallas más estrechas), con los puntajes por reactivo
  abiertos y un mapa más grande.
- La dona de M21 muestra solo a los pacientes con EEG por grupo de edad;
  el centro conserva el porcentaje total con EEG.
This commit is contained in:
2026-11-03 20:28:14 +00:00
parent 1771cb7ec6
commit 1ce8d98663
4 changed files with 54 additions and 17 deletions
@@ -43,14 +43,17 @@ describe('Dona de dos anillos para C1', () => {
expect(result.legend.map(e => e.label)).toEqual(['Con EEG', 'Sin EEG', '16 a 23 meses', '24 a 29 meses', '30 a 36 meses']);
expect(result.figure.layout['title']).toEqual({ text: 'Porcentaje de pacientes con diagnóstico de TEA con EEG, 2025-S2' });
});
it('dona por grupo de edad: sin anillo interior y con el porcentaje total al centro', () => {
it('dona por grupo de edad: solo los pacientes con el evento, con el porcentaje total al centro', () => {
const result = c1DonutFigure(datos(), { ...selection, figura: 'fig_c1_dona_edad' });
if (result.status !== 'supported') throw new Error(result.reason);
expect(result.figure.data).toHaveLength(1);
const [ring] = result.figure.data as { labels: string[]; values: number[] }[];
expect(ring.values).toEqual([16, 13, 17, 8, 5, 5]);
// Only the patients with EEG, by age group; each slice is its share of those 46 patients.
const [ring] = result.figure.data as { labels: string[]; values: number[]; text: string[] }[];
expect(ring.labels).toEqual(['16 a 23 meses', '24 a 29 meses', '30 a 36 meses']);
expect(ring.values).toEqual([16, 13, 17]);
expect(ring.text[0]).toMatch(/^16 a 23 meses<br>34.8/);
expect((result.figure.layout['annotations'] as { text: string }[])[0].text).toBe('<b>71.9 %</b>');
expect(result.legend.map(e => e.label)).toEqual(['Con EEG', 'Sin EEG', '16 a 23 meses', '24 a 29 meses', '30 a 36 meses']);
expect(result.legend.map(e => e.label)).toEqual(['16 a 23 meses', '24 a 29 meses', '30 a 36 meses']);
});
it('barras por grupo de edad: una barra por grupo con su porcentaje', () => {
const result = c1DonutFigure({ ...datos([fila('16-23', 8, 24), fila('24-29', 5, 18), fila('30-36', 5, 22)]), id: 'M22_diagnosticados_sin_eeg' },
@@ -7,7 +7,7 @@ import { FigureSelection, IndicadorDatos, PlotlyFigure } from './indicadores.mod
// Figures by age group for a C1 proportion over one semester, built from the age-stratified C1 rows:
// - fig_c1_donas: double donut drawn like CaCu's «Distribución de resultados citológicos»; the inner ring
// splits the denominator into patients with and without the event, the outer ring each of them by age group.
// - fig_c1_dona_edad: only that outer ring, with the overall percentage in the centre.
// - fig_c1_dona_edad: only the patients with the event, by age group, with the overall percentage in the centre.
// - fig_c1_barras_edad: one bar per age group with its percentage.
export const C1_DONUT = 'fig_c1_donas';
export const C1_RING = 'fig_c1_dona_edad';
@@ -92,11 +92,18 @@ export function c1DonutFigure(data: IndicadorDatos, selection: FigureSelection):
return n / total < .05 ? '' : escape(g.etiqueta) + '<br>' + percentNumber(100 * n / total) + ' %';
});
if (selection.figura === C1_RING) {
// Only the outer ring, wider, around the overall percentage of the event.
// Only the patients with the event, by age group, around the overall percentage of the event.
// Each slice is its age group's share of those patients.
const numerador = strata.reduce((sum, s) => sum + (s.numerador as number), 0);
figure.data = [{ ...outer, hole: .6 }];
figure.layout = { ...figure.layout, annotations: [{ x: .5, y: .5, xref: 'paper', yref: 'paper', showarrow: false,
const values = strata.map(s => s.numerador as number);
figure.data = [{ ...outer, hole: .6, values, labels: strata.map(s => escape(s.label)),
marker: { ...(outer['marker'] as object), colors: categorias.slice(0, strata.length).map(c => c.color) },
text: values.map((n, i) => !numerador || n / numerador < .05 ? '' : escape(strata[i].label) + '<br>' + shareText(n, numerador)),
customdata: values.map(n => [n, numerador ? percentNumber(100 * n / numerador) : '0']),
hovertemplate: '%{label}<br>%{customdata[0]} pacientes, %{customdata[1]} % de los ' + numerador + ' ' + escape(what(labels[0])) + '<extra></extra>' }];
figure.layout = { ...figure.layout, title, annotations: [{ x: .5, y: .5, xref: 'paper', yref: 'paper', showarrow: false,
text: '<b>' + percentNumber(100 * numerador / total) + ' %</b>', font: { size: 26, color: c2Theme(selection.tema).text } }] };
return { status: 'supported', figure, legend: strata.map((s, i) => ({ label: s.label, color: categorias[i].color })), total, notes };
}
}
figure.layout = { ...figure.layout, title };
@@ -106,12 +113,13 @@ export function c1DonutFigure(data: IndicadorDatos, selection: FigureSelection):
return { status: 'supported', figure, legend, total, notes };
}
// "Con EEG" -> "con EEG", to follow «pacientes».
const what = (label: string) => label.charAt(0).toLowerCase() + label.slice(1);
// One bar per age group: the share of its patients with the event.
function ageBars(strata: readonly { label: string; numerador: unknown; denominador: unknown }[], event: string, selection: FigureSelection): PlotlyFigure {
const theme = c2Theme(selection.tema);
const x = strata.map(s => escape(s.label));
const y = strata.map(s => (s.denominador as number) ? 100 * (s.numerador as number) / (s.denominador as number) : null);
const what = event.charAt(0).toLowerCase() + event.slice(1);
return { data: [{ type: 'bar', x, y, marker: { color: RING_COLORS[0], line: { color: theme.background, width: 1 } },
text: y.map(v => v === null ? '' : percentNumber(v) + ' %'), textposition: 'outside', cliponaxis: false,
customdata: strata.map(s => [s.numerador, s.denominador]),
@@ -119,6 +127,6 @@ function ageBars(strata: readonly { label: string; numerador: unknown; denominad
layout: { autosize: true, height: 400, margin: { t: 24, l: 72, r: 24, b: 64 }, showlegend: false,
paper_bgcolor: theme.background, plot_bgcolor: theme.background, font: { color: theme.text },
xaxis: { type: 'category', title: { text: 'Grupo de edad' }, automargin: true },
yaxis: { title: { text: '% de pacientes ' + escape(what) }, range: [0, 100], ticksuffix: ' %', gridcolor: theme.grid, zeroline: false } },
yaxis: { title: { text: '% de pacientes ' + escape(what(event)) }, range: [0, 100], ticksuffix: ' %', gridcolor: theme.grid, zeroline: false } },
config: { displayModeBar: false } };
}
@@ -4,8 +4,8 @@
<button type="button" (click)="load()">Reintentar resumen</button>
}
@if (status() === 'ready' && detalle(); as d) {
<div class="resumen" [class.amplio]="amplio">
<section class="panel" aria-label="Resumen ADOS-2">
<div class="resumen" [class.amplio]="amplio" [class.sin-eeg]="!d.eeg">
<section class="panel ados" aria-label="Resumen ADOS-2">
<h3>ADOS-2</h3>
@if (d.ados2; as a) {
<p class="meta">Módulo {{ a.modulo }} · {{ a.algoritmo }} · {{ a.fecha }}</p>
@@ -19,7 +19,8 @@
<span class="bar" aria-hidden="true"><span [style.width.%]="pct(dom.puntaje, dom.maximo)"></span></span>
</div>
}
<details>
<!-- In its own window there is room to show the item scores from the start. -->
<details [open]="amplio">
<summary>Puntajes por reactivo</summary>
<table class="reactivos">
<thead><tr><th scope="col">Reactivo</th><th scope="col">Puntaje</th><th scope="col">Algoritmo</th></tr></thead>
@@ -36,7 +37,7 @@
} @else { <p>Sin evaluación ADOS-2 registrada.</p> }
</section>
<section class="panel" aria-label="Calidad del EEG">
<section class="panel calidad" aria-label="Calidad del EEG">
<h3>Calidad del EEG</h3>
@if (d.eeg; as e) {
<p class="meta">{{ e.fecha }} · {{ e.duracion_min }} min · {{ e.canales }} canales</p>
@@ -86,7 +87,7 @@
<h3>Zonas más afectadas</h3>
<p class="meta">{{ e.mapa.metrica }} · mapa ilustrativo</p>
@if (figura) {
<app-plotly-chart [figure]="figura" [showNotes]="false" [style.--plot-height]="'260px'"
<app-plotly-chart [figure]="figura" [showNotes]="false" [style.--plot-height]="amplio ? '340px' : '260px'"
[label]="'Mapa topográfico del EEG del paciente ' + d.id_seudonimo" />
}
<ol class="regiones" aria-label="Regiones ordenadas por desviación">
@@ -1,6 +1,5 @@
:host { display: block; }
:host { display: block; container-type: inline-size; }
.resumen { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: .75rem; }
.resumen.amplio { grid-template-columns: repeat(auto-fit, minmax(26rem, 1fr)); gap: 1rem; }
.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); }
@@ -46,3 +45,29 @@ li[data-estado=no_evaluable] .estado { color: var(--issste-text-secondary); font
.efectos-titulo { margin: .3rem 0 .1rem; font-size: .8rem; font-weight: 600; }
.efectos { padding-inline-start: 1.1rem; list-style: disc; font-size: .8rem; }
button { min-height: 44px; padding: .6rem; border: 1px solid var(--issste-border); border-radius: 4px; background: var(--issste-surface); color: inherit; font: inherit; cursor: pointer; }
// Own window: three columns. ADOS-2 with its item scores on the left, EEG quality over its alterations
// in the middle, the map with its regions on the right. Narrower windows fall back to two, then one.
.resumen.amplio { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-areas: "ados calidad mapa" "ados alteraciones mapa";
grid-template-rows: auto 1fr; gap: 1rem; align-items: start; }
.resumen.amplio.sin-eeg { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-areas: "ados calidad"; grid-template-rows: auto; }
.resumen.amplio > .ados { grid-area: ados; }
.resumen.amplio > .calidad { grid-area: calidad; }
.resumen.amplio > .alteraciones { grid-area: alteraciones; }
.resumen.amplio > .mapa { grid-area: mapa; }
.resumen.amplio > .panel { padding: 1rem; }
.resumen.amplio h3 { font-size: 1.1rem; }
@container (max-width: 68rem) {
// The tall ADOS-2 panel spans both rows: the second one takes the leftover height, so no gap opens.
.resumen.amplio { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-areas: "ados calidad" "ados alteraciones" "mapa mapa"; grid-template-rows: auto 1fr auto; }
// The map spans the width: put its region list beside it.
.resumen.amplio > .mapa { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); grid-template-areas: "titulo titulo" "meta meta" "grafico lista"; column-gap: 1.5rem; align-items: center; }
.resumen.amplio > .mapa > h3 { grid-area: titulo; }
.resumen.amplio > .mapa > .meta { grid-area: meta; }
.resumen.amplio > .mapa > app-plotly-chart { grid-area: grafico; }
.resumen.amplio > .mapa > .regiones { grid-area: lista; }
}
@container (max-width: 42rem) {
.resumen.amplio, .resumen.amplio.sin-eeg { grid-template-columns: minmax(0, 1fr); grid-template-areas: "ados" "calidad" "alteraciones" "mapa"; grid-template-rows: auto; }
.resumen.amplio > .mapa { display: block; }
}