F1f: TEA indicator chart formats (sex by age group, men blue, women magenta)

Reuse the existing male blue and female magenta, in that order. Read the published sex-by-result and age-by-sex cells and omit unknown sex. Keep the report age labels and sort by the starting month. Use zero for absent count cells and omit rates without denominators.

Keep M24 count heights and percentage labels. Stack the two outcomes within each sex using Plotly offset groups. Use the previous prevalence alpha of 0.25 for both transparent outcomes. For M31, use the published outcome counts and keep the sex focus control by outlining the selected bars while preserving both fill colors. Use the standard chart card height and identify changed figures by measure in the page checks.

Prettier, targeted figure type checking, and the 23 indicator logic tests passed. Full application type checking requires the unavailable pdfmake dependencies in this checkout. Angular and Playwright runs are reserved for the test machines.
This commit is contained in:
2026-12-01 13:36:44 -06:00
parent 5bf022b36f
commit 789145b93c
6 changed files with 174 additions and 206 deletions
+74 -26
View File
@@ -2,13 +2,14 @@ import type { Bundle, DiagnosticReport, Observation, Patient, RiskAssessment } f
import { EXT } from '../fhir';
import { teaSteps } from '../paciente/tea-data';
import {
ageShare,
ageStack,
nestedDonut,
sexCountBars,
shareDonut,
teaAlterations,
teaSankey,
teaSexDonut,
teaSexBars,
} from './figures';
import type { Catalog } from './pages';
import {
@@ -354,25 +355,38 @@ describe('TEA clinical figures', () => {
expect(new Set(places).size).toBe(places.length);
});
it('splits prevalence by sex and diagnosis and includes children without a recorded sex', () => {
const r = {
it('groups prevalence bars by sex and uses transparency for unconfirmed diagnoses', () => {
const figure = teaSexBars({
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 },
'female|in_population': { 'initial-population': 1 },
'male|confirmed': { 'initial-population': 1 },
'male|in_population': { 'initial-population': 2 },
'no_data|in_population': { '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)');
});
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)'] },
},
]);
});
it('uses crossed counts for diagnostic results and sex totals for confirmation', () => {
it('groups diagnostic results by sex using crossed counts', () => {
const catalog: Catalog = {
groups: [],
categories: [
@@ -388,6 +402,7 @@ describe('TEA clinical figures', () => {
'female|confirmed': { 'initial-population': 2 },
'female|in_process': { 'initial-population': 1 },
'male|in_process': { 'initial-population': 3 },
'no_data|confirmed': { 'initial-population': 1 },
},
},
},
@@ -395,25 +410,58 @@ describe('TEA clinical figures', () => {
'Pacientes',
'2025-S1',
);
expect(result.layout?.barmode).toBe('group');
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 } },
},
name: 'Masculino',
x: [0, 3],
y: ['Confirmados', 'En proceso'],
marker: { color: '#4269C2' },
},
['Confirmados', 'En proceso'],
'sex',
);
expect(confirmation.data).toMatchObject([
{ x: ['Femenino', 'Masculino'], y: [2, 0] },
{ x: ['Femenino', 'Masculino'], y: [1, 3] },
{
name: 'Femenino',
x: [2, 1],
y: ['Confirmados', 'En proceso'],
marker: { color: '#C24269' },
},
]);
});
const byAgeAndSex = {
populations: {},
strata: {
age_sex: {
'24-36|male': { numerator: 1, denominator: 1 },
'16-23|female': { numerator: 1, denominator: 2 },
'16-23|male': { numerator: 1, denominator: 4 },
'37-48|no_data': { numerator: 1, denominator: 1 },
},
},
};
const ageGroups = ['16 a 23 meses', '24 a 36 meses'];
it('stacks diagnostic status in one bar per sex in each age group', () => {
const figure = ageStack(byAgeAndSex, ['Confirmados', 'En proceso']);
expect(figure.layout?.barmode).toBe('stack');
expect(figure.data).toMatchObject([
{ x: ageGroups, offsetgroup: 'male', y: [1, 1], marker: { color: '#4269C2' } },
{ x: ageGroups, offsetgroup: 'male', y: [3, 0], marker: { color: 'rgba(66,105,194,0.25)' } },
{ x: ageGroups, offsetgroup: 'female', y: [1, 0], marker: { color: '#C24269' } },
{
x: ageGroups,
offsetgroup: 'female',
y: [1, 0],
marker: { color: 'rgba(194,66,105,0.25)' },
},
]);
});
it('groups EEG percentages by age and sex and omits missing denominators', () => {
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' } },
]);
});