F2c: risk page after the 3 Dec review
Replace the risk introduction with the reviewed text, name severe ADOS-2 probabilities in the risk section and record table, and place the TEA clarification below the risk probability table through section content. Use one shared decimal log-axis builder in the patient forest and both governance OR charts. Add builder and patient logic coverage and update the page case for the section, column headers and clarification. Choices left open by the spec: - Name the builder logAxis and mirror valueAxis's iterable input signature; put its logic spec in indicadores/figures.spec.ts beside the builder. - Generate the 1-2-3-5-7 sequence from the floor of the minimum log10 to the ceiling of the maximum log10, including only 1 in the last decade. Whole-decade bounds retain labels for narrow and single-value ranges. - Ignore missing, nonfinite and nonpositive input; return empty tick arrays when no positive finite data remain. Discard generated zero or nonfinite ticks at floating-point limits. - Construct tick values from decimal exponent strings to avoid binary multiplication artifacts; use explicit array ticks and SHORT hovers. - Let the existing private decimal formatter accept optional Intl options, retaining its existing defaults. For log labels use its es-MX locale, one significant digit and no grouping, preserving small decimals and avoiding scientific notation and trailing zeros. - Include estimates and confidence bounds in each chart's input, plus 1 in the two charts that draw the reference line. - Represent the risk table note as a following text block so the existing page and PDF renderers both place it below the table. - Cover decimal sequences, whole-decade bounds, singleton and iterable input, invalid input, small and large labels, patient confidence bounds, probability labels and the clarification's PDF inclusion in logic tests. Add page assertions for the probability headers and clarification. Validation: ruff check . passed; ruff format --check . passed (144 files); git diff --check passed. A Node smoke check of the source logAxis function passed nine assertions. Prettier was skipped because this worktree has no WebApp/node_modules/.bin/prettier. Angular tests/build and Playwright page tests were not run here, as the spec reserves them for milkpc/the VM. Python imports and the API did not change; lint-imports and API generation were not needed.
This commit is contained in:
+7
-1
@@ -195,8 +195,14 @@ test('tea complete child: every screen has data', async ({ page }) => {
|
|||||||
section('Razones de momios por par').locator('app-plot .point').first(),
|
section('Razones de momios por par').locator('app-plot .point').first(),
|
||||||
).toBeAttached();
|
).toBeAttached();
|
||||||
await expect(
|
await expect(
|
||||||
section('Probabilidad frente a la referencia').locator('tbody tr').first(),
|
section('Probabilidad de un puntaje ADOS-2 severo').locator('tbody tr').first(),
|
||||||
).toBeVisible();
|
).toBeVisible();
|
||||||
|
await expect(
|
||||||
|
section('Probabilidad de un puntaje ADOS-2 severo').getByRole('columnheader'),
|
||||||
|
).toHaveText(['Par', 'Prob. ADOS-2 severo', 'Referencia']);
|
||||||
|
await expect(section('Probabilidad de un puntaje ADOS-2 severo').locator('p')).toHaveText(
|
||||||
|
'No es la probabilidad de TEA.',
|
||||||
|
);
|
||||||
await expect(section('Probabilidad según z').locator('app-plot .point').first()).toBeAttached();
|
await expect(section('Probabilidad según z').locator('app-plot .point').first()).toBeAttached();
|
||||||
await expect(section('Limitaciones').locator('p').first()).toHaveText(/cohorte/);
|
await expect(section('Limitaciones').locator('p').first()).toHaveText(/cohorte/);
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import type { Analysis } from '../api/models/analysis';
|
|||||||
import type { Figure } from '../plot';
|
import type { Figure } from '../plot';
|
||||||
import { PALETTE } from '../plot';
|
import { PALETTE } from '../plot';
|
||||||
import { BIOMARKER_NAMES, OUTCOME_NAMES, ZONE_NAMES } from '../eeg-labels';
|
import { BIOMARKER_NAMES, OUTCOME_NAMES, ZONE_NAMES } from '../eeg-labels';
|
||||||
|
import { logAxis } from '../indicadores/figures';
|
||||||
|
|
||||||
interface Band {
|
interface Band {
|
||||||
x: number[];
|
x: number[];
|
||||||
@@ -245,7 +246,16 @@ export function interpretabilityFigures(
|
|||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
layout: {
|
layout: {
|
||||||
xaxis: { type: 'log', title: { text: 'OR (IC 95 %)' } },
|
xaxis: {
|
||||||
|
...logAxis(
|
||||||
|
(report['rows'] as AssociationRow[]).flatMap((row) => [
|
||||||
|
row.odds_ratio,
|
||||||
|
row.ci_low,
|
||||||
|
row.ci_high,
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
title: { text: 'OR (IC 95 %)' },
|
||||||
|
},
|
||||||
yaxis: { type: 'category', automargin: true },
|
yaxis: { type: 'category', automargin: true },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -358,7 +368,10 @@ export function interpretabilityFigures(
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
layout: {
|
layout: {
|
||||||
xaxis: { title: { text: 'Razón de momios (escala log)' }, type: 'log' },
|
xaxis: {
|
||||||
|
...logAxis([1, ...rows.flatMap((r) => [r.odds_ratio, r.ci_low, r.ci_high])]),
|
||||||
|
title: { text: 'Razón de momios (escala log)' },
|
||||||
|
},
|
||||||
yaxis: { automargin: true, autorange: 'reversed' },
|
yaxis: { automargin: true, autorange: 'reversed' },
|
||||||
shapes: [
|
shapes: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
import { logAxis } from './figures';
|
||||||
|
|
||||||
|
describe('logAxis', () => {
|
||||||
|
it('uses the 1-2-3-5-7 sequence across decades with decimal labels', () => {
|
||||||
|
expect(logAxis([0.1, 10])).toMatchObject({
|
||||||
|
type: 'log',
|
||||||
|
tickmode: 'array',
|
||||||
|
tickvals: [0.1, 0.2, 0.3, 0.5, 0.7, 1, 2, 3, 5, 7, 10],
|
||||||
|
ticktext: ['0.1', '0.2', '0.3', '0.5', '0.7', '1', '2', '3', '5', '7', '10'],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('covers the data range with whole decades', () => {
|
||||||
|
expect(logAxis(new Set([4.5, 1.2])).tickvals).toEqual([1, 2, 3, 5, 7, 10]);
|
||||||
|
expect(logAxis([1]).tickvals).toEqual([1]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps small decimal ticks distinct and large ticks out of scientific notation', () => {
|
||||||
|
expect(logAxis([0.001, 0.01]).ticktext).toEqual([
|
||||||
|
'0.001',
|
||||||
|
'0.002',
|
||||||
|
'0.003',
|
||||||
|
'0.005',
|
||||||
|
'0.007',
|
||||||
|
'0.01',
|
||||||
|
]);
|
||||||
|
expect(logAxis([1e21, 1e22]).ticktext).toEqual([
|
||||||
|
'1000000000000000000000',
|
||||||
|
'2000000000000000000000',
|
||||||
|
'3000000000000000000000',
|
||||||
|
'5000000000000000000000',
|
||||||
|
'7000000000000000000000',
|
||||||
|
'10000000000000000000000',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ignores missing, nonfinite and nonpositive values', () => {
|
||||||
|
const invalid = [null, undefined, NaN, Infinity, -Infinity, -1, 0];
|
||||||
|
expect(logAxis([...invalid, 0.1, 10])).toEqual(logAxis([0.1, 10]));
|
||||||
|
expect(logAxis(invalid)).toMatchObject({ tickvals: [], ticktext: [] });
|
||||||
|
expect(logAxis([])).toMatchObject({ tickvals: [], ticktext: [] });
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -251,7 +251,8 @@ export function rateDots(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const decimal = (n: number) => n.toLocaleString('es-MX', { maximumFractionDigits: 2 });
|
const decimal = (n: number, options: Intl.NumberFormatOptions = { maximumFractionDigits: 2 }) =>
|
||||||
|
n.toLocaleString('es-MX', options);
|
||||||
|
|
||||||
export function fill(template: string, r: Reading): string {
|
export function fill(template: string, r: Reading): string {
|
||||||
const p = r.populations;
|
const p = r.populations;
|
||||||
@@ -450,6 +451,29 @@ export function valueAxis(values: Iterable<number | null | undefined>) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function logAxis(values: Iterable<number | null | undefined>) {
|
||||||
|
const found = [...values].filter((v): v is number => v != null && Number.isFinite(v) && v > 0);
|
||||||
|
const tickvals: number[] = [];
|
||||||
|
if (found.length) {
|
||||||
|
const first = Math.floor(Math.log10(Math.min(...found)));
|
||||||
|
const last = Math.ceil(Math.log10(Math.max(...found)));
|
||||||
|
for (let decade = first; decade <= last; decade++) {
|
||||||
|
for (const multiplier of [1, 2, 3, 5, 7]) {
|
||||||
|
if (decade === last && multiplier > 1) continue;
|
||||||
|
const value = Number(`${multiplier}e${decade}`);
|
||||||
|
if (value > 0 && Number.isFinite(value)) tickvals.push(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
type: 'log' as const,
|
||||||
|
tickmode: 'array' as const,
|
||||||
|
tickvals,
|
||||||
|
ticktext: tickvals.map((v) => decimal(v, { maximumSignificantDigits: 1, useGrouping: false })),
|
||||||
|
hoverformat: SHORT,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function historyFigure(
|
export function historyFigure(
|
||||||
panel: HistoryPanel,
|
panel: HistoryPanel,
|
||||||
series: { label: string; r: Reading | undefined }[],
|
series: { label: string; r: Reading | undefined }[],
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { bandFill, type Centile } from '../gobernanza/figures';
|
import { bandFill, type Centile } from '../gobernanza/figures';
|
||||||
import { valueAxis } from '../indicadores/figures';
|
import { logAxis, valueAxis } from '../indicadores/figures';
|
||||||
import { Figure, PALETTE } from '../plot';
|
import { Figure, PALETTE } from '../plot';
|
||||||
import { Metric, Pair, Site, Study, TeaStep, zoneLabel } from './tea-data';
|
import { Metric, Pair, Site, Study, TeaStep, zoneLabel } from './tea-data';
|
||||||
|
|
||||||
@@ -281,7 +281,10 @@ export function forest(pairs: Pair[], alteredOnly: boolean): SingleTrace {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
layout: {
|
layout: {
|
||||||
xaxis: { type: 'log', title: { text: 'Razón de momios (OR) · IC 95 %' } },
|
xaxis: {
|
||||||
|
...logAxis([1, ...visible.flatMap((p) => [p.odds, p.low, p.high])]),
|
||||||
|
title: { text: 'Razón de momios (OR) · IC 95 %' },
|
||||||
|
},
|
||||||
yaxis: { autorange: 'reversed', automargin: true },
|
yaxis: { autorange: 'reversed', automargin: true },
|
||||||
shapes: [
|
shapes: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -157,13 +157,28 @@ describe('Figuras del paciente TEA', () => {
|
|||||||
const pairs = [pair, { ...pair, title: 'Zona normal', altered: false, odds: 2 }];
|
const pairs = [pair, { ...pair, title: 'Zona normal', altered: false, odds: 2 }];
|
||||||
expect(forest(pairs, false).data[0].x).toEqual([3, 2]);
|
expect(forest(pairs, false).data[0].x).toEqual([3, 2]);
|
||||||
const filtered = forest(pairs, true);
|
const filtered = forest(pairs, true);
|
||||||
expect(filtered.layout?.xaxis?.type).toBe('log');
|
expect(filtered.layout?.xaxis).toMatchObject({
|
||||||
|
type: 'log',
|
||||||
|
tickvals: [1, 2, 3, 5, 7, 10],
|
||||||
|
ticktext: ['1', '2', '3', '5', '7', '10'],
|
||||||
|
});
|
||||||
expect(filtered.data[0]).toMatchObject({
|
expect(filtered.data[0]).toMatchObject({
|
||||||
x: [3],
|
x: [3],
|
||||||
error_x: { array: [1.5], arrayminus: [1.8] },
|
error_x: { array: [1.5], arrayminus: [1.8] },
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('incluye los intervalos y la referencia en los ticks decimales del bosque', () => {
|
||||||
|
const figure = forest([{ ...pair, odds: 0.3, low: 0.12, high: 7 }], false);
|
||||||
|
expect(figure.layout?.xaxis).toMatchObject({
|
||||||
|
tickvals: [0.1, 0.2, 0.3, 0.5, 0.7, 1, 2, 3, 5, 7, 10],
|
||||||
|
ticktext: ['0.1', '0.2', '0.3', '0.5', '0.7', '1', '2', '3', '5', '7', '10'],
|
||||||
|
});
|
||||||
|
expect(forest([{ ...pair, low: 2, high: 30 }], false).layout?.xaxis?.tickvals).toEqual([
|
||||||
|
1, 2, 3, 5, 7, 10, 20, 30, 50, 70, 100,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it('marca la banda de z entre −2 y 2', () => {
|
it('marca la banda de z entre −2 y 2', () => {
|
||||||
const figure = zBars(eeg);
|
const figure = zBars(eeg);
|
||||||
expect(figure.data[0]).toMatchObject({
|
expect(figure.data[0]).toMatchObject({
|
||||||
@@ -273,6 +288,19 @@ describe('Expediente TEA', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('identifica la probabilidad del ADOS-2 severo en la tabla del expediente', () => {
|
||||||
|
const section = recordSections(record, new Map()).find(
|
||||||
|
(section) => section.title === 'Relación con el ADOS-2',
|
||||||
|
);
|
||||||
|
expect(section?.blocks[0].table?.headers).toEqual([
|
||||||
|
'Par',
|
||||||
|
'OR',
|
||||||
|
'IC 95 %',
|
||||||
|
'Prob. ADOS-2 severo',
|
||||||
|
'Referencia',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it('dibuja la línea del tiempo como un Gantt con rombos, no como tabla', () => {
|
it('dibuja la línea del tiempo como un Gantt con rombos, no como tabla', () => {
|
||||||
const [section] = recordSections(record, new Map());
|
const [section] = recordSections(record, new Map());
|
||||||
expect(section.title).toBe('Línea del tiempo');
|
expect(section.title).toBe('Línea del tiempo');
|
||||||
@@ -362,7 +390,7 @@ describe('Análisis de riesgo TEA', () => {
|
|||||||
'Qué calcula',
|
'Qué calcula',
|
||||||
'Puntuaciones z por métrica y zona',
|
'Puntuaciones z por métrica y zona',
|
||||||
forestTitle,
|
forestTitle,
|
||||||
'Probabilidad frente a la referencia',
|
'Probabilidad de un puntaje ADOS-2 severo',
|
||||||
probabilityTitle,
|
probabilityTitle,
|
||||||
'Limitaciones',
|
'Limitaciones',
|
||||||
]);
|
]);
|
||||||
@@ -374,6 +402,24 @@ describe('Análisis de riesgo TEA', () => {
|
|||||||
expect(effects?.blocks[0].chart?.figure.data[0]).toMatchObject({ x: [3] });
|
expect(effects?.blocks[0].chart?.figure.data[0]).toMatchObject({ x: [3] });
|
||||||
const chosen = sections.find((section) => section.title === probabilityTitle);
|
const chosen = sections.find((section) => section.title === probabilityTitle);
|
||||||
expect(chosen?.blocks[0].chart?.title).toBe(pair.title);
|
expect(chosen?.blocks[0].chart?.title).toBe(pair.title);
|
||||||
|
expect(sections[0].blocks[0].text).toBe(
|
||||||
|
'Para cada alteración del EEG y región cerebral, el modelo da la probabilidad de que un ítem, un área o el puntaje total (CSS) del ADOS-2 salga severo, comparado con un niño en la referencia (z = 0).',
|
||||||
|
);
|
||||||
|
const probability = sections.find(
|
||||||
|
(section) => section.title === 'Probabilidad de un puntaje ADOS-2 severo',
|
||||||
|
);
|
||||||
|
expect(probability?.blocks).toEqual([
|
||||||
|
{
|
||||||
|
table: {
|
||||||
|
headers: ['Par', 'Prob. ADOS-2 severo', 'Referencia'],
|
||||||
|
rows: [['Husos N2 · Central · CSS (principal)', '70%', '20%']],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ text: 'No es la probabilidad de TEA.' },
|
||||||
|
]);
|
||||||
|
expect(teaPdfContent('Análisis de riesgo TEA', sections, [])).toContain(
|
||||||
|
'No es la probabilidad de TEA.',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export const forestTitle = 'Razones de momios por par';
|
|||||||
export const probabilityTitle = 'Probabilidad según z';
|
export const probabilityTitle = 'Probabilidad según z';
|
||||||
|
|
||||||
const calculation =
|
const calculation =
|
||||||
'El modelo estima, para cada par de métrica o zona del EEG y resultado del ADOS-2, la probabilidad de un puntaje elevado de severidad calibrada (CSS) o de un ítem alterado. La razón de momios corresponde al cambio asociado con una unidad de z. La probabilidad de referencia corresponde a z = 0, la edad media y el módulo más frecuente de la cohorte.';
|
'Para cada alteración del EEG y región cerebral, el modelo da la probabilidad de que un ítem, un área o el puntaje total (CSS) del ADOS-2 salga severo, comparado con un niño en la referencia (z = 0).';
|
||||||
const limitations =
|
const limitations =
|
||||||
'Las estimaciones dependen de la cohorte de referencia, de la calidad del EEG y de la disponibilidad de mediciones y pares. Las asociaciones no establecen causalidad. Las probabilidades no sustituyen la evaluación clínica ni establecen un diagnóstico.';
|
'Las estimaciones dependen de la cohorte de referencia, de la calidad del EEG y de la disponibilidad de mediciones y pares. Las asociaciones no establecen causalidad. Las probabilidades no sustituyen la evaluación clínica ni establecen un diagnóstico.';
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ export function recordSections(patient: TeaPatient, norms: ReadonlyMap<string, C
|
|||||||
blocks: [
|
blocks: [
|
||||||
{
|
{
|
||||||
table: {
|
table: {
|
||||||
headers: ['Par', 'OR', 'IC 95 %', 'Probabilidad', 'Referencia'],
|
headers: ['Par', 'OR', 'IC 95 %', 'Prob. ADOS-2 severo', 'Referencia'],
|
||||||
rows: associationRows(patient.pairs),
|
rows: associationRows(patient.pairs),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -133,8 +133,11 @@ export function riskSections(patient: TeaPatient, alteredOnly: boolean, pair?: P
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Probabilidad frente a la referencia',
|
title: 'Probabilidad de un puntaje ADOS-2 severo',
|
||||||
blocks: [{ table: probabilityRows(patient.pairs) }],
|
blocks: [
|
||||||
|
{ table: probabilityRows(patient.pairs) },
|
||||||
|
{ text: 'No es la probabilidad de TEA.' },
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: probabilityTitle,
|
title: probabilityTitle,
|
||||||
@@ -146,7 +149,7 @@ export function riskSections(patient: TeaPatient, alteredOnly: boolean, pair?: P
|
|||||||
|
|
||||||
function probabilityRows(pairs: Pair[]): Table {
|
function probabilityRows(pairs: Pair[]): Table {
|
||||||
return {
|
return {
|
||||||
headers: ['Par', 'Probabilidad', 'Referencia'],
|
headers: ['Par', 'Prob. ADOS-2 severo', 'Referencia'],
|
||||||
rows: pairs.map((p) => [
|
rows: pairs.map((p) => [
|
||||||
p.headline ? `${p.title} (principal)` : p.title,
|
p.headline ? `${p.title} (principal)` : p.title,
|
||||||
percent(p.probability),
|
percent(p.probability),
|
||||||
|
|||||||
Reference in New Issue
Block a user