F1b: user fixes

Use the existing Plotly card and registered Sankey trace. Build transition totals from the remaining stages and omit zero-flow links. Build the prevalence donut from the report counts, with a grey slice for missing sex and controls to highlight each recorded sex. Use grouped bars for M23 and separate age and sex stacks for M24. Use the existing stacked history style for M31 and put the M30 figure behind one page flag. Cover the builders and the existing TEA page case.
This commit is contained in:
2026-12-01 11:33:06 -06:00
parent 7c98566579
commit c4920ed7eb
7 changed files with 451 additions and 57 deletions
+107 -1
View File
@@ -1,6 +1,14 @@
import type { Bundle, DiagnosticReport, Observation, Patient, RiskAssessment } from 'fhir/r4';
import { EXT } from '../fhir';
import { nestedDonut, shareDonut } from './figures';
import {
ageStack,
nestedDonut,
sexCountBars,
shareDonut,
teaAlterations,
teaSankey,
teaSexDonut,
} from './figures';
import type { Catalog } from './pages';
import {
ageMonths,
@@ -255,3 +263,101 @@ describe('TEA indicators', () => {
});
});
});
describe('TEA clinical figures', () => {
it('conserves children at each stage and omits empty stops', () => {
const figure = teaSankey({
populations: { 'initial-population': 9 },
strata: {
category: {
mchat_only: { 'initial-population': 2 },
neuropediatrics: { 'initial-population': 3 },
eeg: { 'initial-population': 4 },
},
},
});
expect(figure.data[0]).toMatchObject({
type: 'sankey',
link: { source: [0, 0, 1, 2, 2], target: [1, 4, 2, 3, 6], value: [7, 2, 7, 4, 3] },
});
});
it('splits prevalence by sex and diagnosis and includes children without a recorded sex', () => {
const r = {
populations: { 'initial-population': 7 },
strata: {
category: { confirmed: { 'initial-population': 3 } },
sex: { female: { 'initial-population': 3 }, male: { 'initial-population': 3 } },
'sex-category': {
'female|confirmed': { 'initial-population': 2 },
'male|confirmed': { 'initial-population': 1 },
},
},
};
const figure = teaSexDonut(r);
expect(figure.data[0]).toMatchObject({ type: 'pie', values: [2, 1, 1, 2, 1] });
expect(figure.layout?.annotations?.[0].text).toContain('3 de 7 niños');
expect(teaSexDonut(r, 'female').layout?.annotations?.[0].text).toContain('2 de 3 (femenino)');
});
it('uses crossed counts for diagnostic results and sex totals for confirmation', () => {
const catalog: Catalog = {
groups: [],
categories: [
{ code: 'confirmed', label: 'Confirmados', color: '#A8C243', group: '' },
{ code: 'in_process', label: 'En proceso', color: '#B8433A', group: '' },
],
};
const result = sexCountBars(
{
populations: {},
strata: {
'sex-category': {
'female|confirmed': { 'initial-population': 2 },
'female|in_process': { 'initial-population': 1 },
'male|in_process': { 'initial-population': 3 },
},
},
},
catalog,
'Pacientes',
'2025-S1',
);
expect(result.data).toMatchObject([
{ name: 'Femenino', x: [2, 1] },
{ name: 'Masculino', x: [0, 3] },
{ name: 'Sin dato', x: [0, 0] },
]);
const confirmation = ageStack(
{
populations: {},
strata: {
sex: { female: { numerator: 2, denominator: 3 }, male: { numerator: 0, denominator: 3 } },
},
},
['Confirmados', 'En proceso'],
'sex',
);
expect(confirmation.data).toMatchObject([
{ x: ['Femenino', 'Masculino'], y: [2, 0] },
{ x: ['Femenino', 'Masculino'], y: [1, 3] },
]);
});
it('includes the total and independent alteration rates', () => {
const figure = teaAlterations({
populations: { numerator: 3, denominator: 4 },
strata: {
alteration: {
posterior_rhythm: { numerator: 2, denominator: 4 },
spindles_n2: { numerator: 2, denominator: 4 },
},
},
});
expect(figure.data[0]).toMatchObject({
x: ['Alguna alteración', 'Ritmo posterior', 'Husos N2'],
y: [75, 50, 50],
});
});
});