F2a: TEA indicators after the 3 Dec review

Changed:
- Summary: the time sentences say "La mediana de..." and the footnote is gone (nothing else used it); "se evaluaron" is now "se registraron en el tamizaje".
- boxFigure: the median, Q3 and Q1 are text annotations to the right of the box; the hover is off so nothing else is labelled.
- M23 is titled "Pacientes en tamizaje por resultado diagnostico" on the page and in Trazabilidad.
- M21/M22 ageShare: the bar text is "p % (n/N)" from numerator and denominator of strata.age_sex, and the hover reuses it.
- M28 Sankey: every node label ends with its count ("M-CHAT · 18"), the "Se quedo en..." nodes included; link labels stay without it.
- M31: the bars plot the rate per 10,000 for the selected period, one bar per sex, with the rate as bar text and confirmed of total children in the hover. The card shows a headline number that follows the sex toggle (total when both sexes). Trazabilidad plots the rate as a line per sex plus the total (new 'rate' panel kind replaces the stacked counts).
- reading() carries the per-stratum measureScore as Reading.rates; the group measureScore is the total rate.

Choices the spec left open:
- Q3, median and Q1 sit at a fixed 56 px right of the box, anchored top/middle/bottom so they do not overlap when the three values are equal.
- Headline detail line: "por 10 000 niños · n confirmados de N niños".
- The selected-sex outline on the M31 bars is black, since the bars are one trace now.
- e2e pages.spec.ts:23 already expects no toggle on the M23 card, which is what the page renders, so it stays; it now also asserts the new M23 heading.
This commit is contained in:
2026-12-03 13:55:14 -06:00
parent 98eda5bc28
commit 72d5d07d67
7 changed files with 292 additions and 76 deletions
+150 -25
View File
@@ -4,14 +4,17 @@ import { teaSteps } from '../paciente/tea-data';
import {
ageShare,
ageStack,
boxFigure,
historyFigure,
nestedDonut,
prevalenceHeadline,
sexCountBars,
shareDonut,
teaAlterations,
teaSankey,
teaSexBars,
} from './figures';
import { reading } from './measures';
import type { Catalog } from './pages';
import {
ageMonths,
@@ -369,35 +372,145 @@ describe('TEA clinical figures', () => {
});
});
it('groups prevalence bars by sex and uses transparency for unconfirmed diagnoses', () => {
const figure = teaSexBars({
populations: { 'initial-population': 7 },
it('carries the count in every node label, including the stops', () => {
const figure = teaSankey({
populations: { 'initial-population': 18 },
strata: {
sex: { female: { 'initial-population': 3 }, male: { 'initial-population': 3 } },
'sex-category': {
'female|confirmed': { 'initial-population': 2 },
'female|in_population': { 'initial-population': 1 },
'male|confirmed': { 'initial-population': 1 },
'male|in_population': { 'initial-population': 2 },
'no_data|in_population': { 'initial-population': 1 },
category: {
mchat_only: { 'initial-population': 6 },
psychology: { 'initial-population': 2 },
neuropediatrics: { 'initial-population': 5 },
eeg: { 'initial-population': 5 },
},
},
});
expect(figure.layout?.barmode).toBe('group');
expect(figure.data).toMatchObject([
{
type: 'bar',
x: ['Masculino', 'Femenino'],
y: [1, 2],
marker: { color: ['#4269C2', '#C24269'] },
},
{
type: 'bar',
x: ['Masculino', 'Femenino'],
y: [2, 1],
marker: { color: ['rgba(66,105,194,0.25)', 'rgba(194,66,105,0.25)'] },
expect(figure.data[0]).toMatchObject({
node: {
label: [
'M-CHAT · 18',
'Evaluación<br>psicológica · 12',
'Evaluación<br>neuropediátrica · 10',
'EEG de<br>buena calidad · 5',
'Se quedó en evaluación<br>neuropediátrica · 5',
'Se quedó en evaluación<br>psicológica · 2',
'Se quedó en M-CHAT · 6',
],
},
});
});
it('annotates only the median and the quartiles on the box', () => {
const figure = boxFigure({ populations: {}, score: 12.5, low: 8, high: 20 }, '2025-S1');
expect(figure.layout?.annotations?.map((a) => a.text)).toEqual([
'Q3 20',
'Mediana 12.5',
'Q1 8',
]);
expect(figure.data[0]).toMatchObject({ hoverinfo: 'skip' });
});
const prevalence = {
populations: { 'initial-population': 12 },
score: 3333.3333,
unit: 'por 10 000',
strata: {
category: { confirmed: { 'initial-population': 4 } },
sex: {
female: { 'initial-population': 4 },
male: { 'initial-population': 6 },
no_data: { 'initial-population': 2 },
},
'sex-category': {
'female|confirmed': { 'initial-population': 1 },
'female|in_population': { 'initial-population': 3 },
'male|confirmed': { 'initial-population': 3 },
'male|in_population': { 'initial-population': 3 },
'no_data|in_population': { 'initial-population': 2 },
},
},
rates: { sex: { female: 2500, male: 5000, no_data: 0 } },
};
it('shows the prevalence rate per 10,000 as the bar text and the counts in the hover', () => {
const figure = teaSexBars(prevalence, 'female');
expect(figure.layout?.barmode).toBeUndefined();
expect(figure.data).toHaveLength(1);
expect(figure.data[0]).toMatchObject({
type: 'bar',
x: ['Masculino', 'Femenino'],
y: [5000, 2500],
text: ['5,000', '2,500'],
customdata: [
[3, 6],
[1, 4],
],
marker: { color: ['#4269C2', '#C24269'], line: { width: [0, 2] } },
});
expect(figure.data[0]).toMatchObject({
hovertemplate: expect.stringContaining(
'%{customdata[0]} confirmados de %{customdata[1]} niños',
),
});
});
it('puts the total or the chosen sex rate in the headline', () => {
expect(prevalenceHeadline(prevalence)).toEqual({
value: '3,333.3',
detail: 'por 10 000 niños · 4 confirmados de 12 niños',
});
expect(prevalenceHeadline(prevalence, 'male')).toEqual({
value: '5,000',
detail: 'por 10 000 niños · 3 confirmados de 6 niños',
});
expect(prevalenceHeadline({ populations: {}, strata: {} })).toBeUndefined();
});
it('reads the rate of each stratum from the report', () => {
const r = reading({
resourceType: 'MeasureReport',
status: 'complete',
type: 'summary',
measure: 'M31',
period: { start: '2025-01-01', end: '2025-06-30' },
group: [
{
measureScore: { value: 3333.3, unit: 'por 10 000' },
stratifier: [
{
code: [{ coding: [{ code: 'sex' }] }],
stratum: [
{ value: { text: 'male' }, measureScore: { value: 5000 } },
{ value: { text: 'female' }, measureScore: { value: 2500 } },
],
},
{
code: [{ coding: [{ code: 'category' }] }],
stratum: [{ value: { text: 'confirmed' } }],
},
],
},
],
});
expect(r).toMatchObject({ score: 3333.3, unit: 'por 10 000' });
expect(r?.rates).toEqual({ sex: { male: 5000, female: 2500 } });
});
it('plots the prevalence rate over time as one line per sex and one for the total', () => {
const figure = historyFigure(
{ title: 'Prevalencia', measure: 'M31', kind: 'rate', axis: 'Casos por 10 000 niños' },
[
{ label: 'Ene', r: prevalence },
{ label: 'Feb', r: undefined },
],
'#9C42C2',
'Mes',
);
expect(figure.data).toMatchObject([
{ name: 'Total', y: [3333.3333, null], mode: 'lines+markers' },
{ name: 'Masculino', y: [5000, null] },
{ name: 'Femenino', y: [2500, null] },
]);
expect(figure.layout?.yaxis?.title).toMatchObject({ text: 'Casos por 10 000 niños' });
});
it('groups diagnostic results by sex using crossed counts', () => {
@@ -474,8 +587,20 @@ describe('TEA clinical figures', () => {
const figure = ageShare(byAgeAndSex, '% de pacientes con EEG');
expect(figure.layout?.barmode).toBe('group');
expect(figure.data).toMatchObject([
{ name: 'Masculino', x: ageGroups, y: [25, 100], marker: { color: '#4269C2' } },
{ name: 'Femenino', x: ageGroups, y: [50, null], marker: { color: '#C24269' } },
{
name: 'Masculino',
x: ageGroups,
y: [25, 100],
text: ['25 % (1/4)', '100 % (1/1)'],
marker: { color: '#4269C2' },
},
{
name: 'Femenino',
x: ageGroups,
y: [50, null],
text: ['50 % (1/2)', ''],
marker: { color: '#C24269' },
},
]);
});