Files
WebApp/src/app/gobernanza/figures.spec.ts
T
alberto bd897baa2d Merge origin/rebuild into parity/T1-merge (WebApp)
rebuild's shell, auth and non-TEA pages; tea/parity's TEA pages on tea/parity's API.
- Routes: rebuild's signed-in tree; the TEA risk page joins it (domainAllowed reads the
  route's data domain when the path has no :domain).
- Indicadores: rebuild's header and its generic Resumen/Trazabilidad/Definiciones tabs
  (TEA as the reference page, fed by tea/parity's measures); TEA Seguimiento and Análisis
  de riesgo render tea/parity's tea-list inside rebuild's tab-seguimiento/tab-riesgos,
  which keep rebuild's CaCu/CaMa lists and patient search. rebuild's tab-riesgos-tea read
  rebuild's TEA Patient extensions, which are gone with its backend; tea-list already
  shows that list from tea/parity's FHIR search, so it is deleted rather than ported
  (its look is the base for T8/T9).
- Paciente: rebuild's record for CaCu/CaMa; TEA delegates to tea/parity's TeaRecord.
  rebuild's inline TEA sections read its EEG detail endpoint and are removed.
- Gobernanza: tea/parity's page (execution, models with checks/lineage, bundles, training,
  studies, preview) until T13; model headings use rebuild's model titles. figures.ts:
  rebuild's scenarios (drawn in the record) plus tea/parity's association forest.
- plot.ts: rebuild's layout helpers on tea/parity's partial Plotly bundle.
- Conectar: rebuild's KINDS/HELP with an entry for tea/parity's edf node.
- Dead code removed: measures boxes/sankey (tea/parity's old TEA tab), eeg-labels
  headMap/byDeviation/LEVEL_NAMES/METRIC_NAMES (rebuild's TEA record), e2e/layout.ts.
- e2e: tea/parity's TEA cases, signed in; rebuild's CaCu/CaMa/site cases need their
  hospitals loaded and come back with the page suite (T16).
- openapi.json and src/app/api: regenerated in the next commit.
2026-11-30 23:56:25 -06:00

156 lines
4.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { interpretabilityFigures, scenarioFigure, studyPoints } from './figures';
describe('governance figures', () => {
it('draws a survival report as curves with bands and the model points', () => {
const [found] = interpretabilityFigures({
kind: 'curves',
curves: [
{ name: 'Kaplan-Meier', months: [0, 6], survival: [1, 0.9], low: [1, 0.8], high: [1, 1] },
],
predicted: { name: 'Modelo', months: [6], survival: [0.92], low: [0.85], high: [0.97] },
});
expect(found.figure.data.length).toBe(3);
expect((found.figure.data[2] as any).error_y.array[0]).toBeCloseTo(0.05);
});
it('leaves the survival scenarios to the patient record, which draws them whole', () => {
const scenario = {
escenario: 'HER2+ · ≥60 años · estadio III–IV (Alto)',
n: 1142,
fallecidos: 308,
horizons_months: [6, 12, 18],
km: { months: [0, 12], S: [1, 0.8], low: [1, 0.75], high: [1, 0.85] },
weibull: { t: [0, 12], S: [1, 0.8] },
weibull_fractional: { t: [0, 12], S: [1, 0.79] },
points: { COMB: { S: [0.86, 0.8, 0.74], low: [0.85, 0.78, 0.72], high: [0.88, 0.82, 0.76] } },
};
const found = interpretabilityFigures({
kind: 'curves',
curves: [{ name: 'Kaplan-Meier', months: [0], survival: [1], low: [1], high: [1] }],
predicted: { name: 'Modelo', months: [6], survival: [0.9], low: [0.8], high: [0.95] },
escenarios: [scenario],
});
expect(found.length).toBe(1);
const drawn = scenarioFigure(scenario.escenario, scenario, scenario.horizons_months, 'S(t)');
expect(drawn.figure.data.length).toBe(5);
expect((drawn.figure.data[4] as any).x).toEqual([6, 12, 18]);
});
it('leaves recurrence scenarios to the patient record', () => {
const found = interpretabilityFigures({
kind: 'scenarios',
recurrencia: {
horizons_months: [12, 36],
escenarios: [
{
cohorte_nombre: 'METABRIC',
escenario: 'RE+',
n: 10,
recaidas: 3,
km: { months: [0, 12], S: [1, 0.9], low: [1, 0.8], high: [1, 1] },
weibull: { t: [0, 12], S: [1, 0.9] },
weibull_fractional: { t: [0, 12], S: [1, 0.91] },
points: { COMB: { S: [0.95, 0.8], low: [0.9, 0.7], high: [0.99, 0.9] } },
},
],
},
});
expect(found).toEqual([]);
});
it('draws an age curve with its centile band', () => {
const [found] = interpretabilityFigures({
kind: 'age_curves',
curves: {
value: {
kind: 'curves',
curve: { age_months: [16, 36], p5: [1, 2], median: [2, 3], p95: [3, 4] },
},
},
});
expect(found.figure.data.length).toBe(2);
});
it('overlays the matching analysed metric at each study age on the API centiles', () => {
const points = studyPoints(
[
{
id: 'one',
valid: true,
level: null,
age_months: 21,
checks: [],
regions: [],
metrics: [{ code: 'posterior_rhythm', value: 7, z: null, outside: null, model: null }],
},
{
id: 'two',
valid: true,
level: null,
age_months: null,
checks: [],
regions: [],
metrics: [{ code: 'posterior_rhythm', value: 9, z: null, outside: null, model: null }],
},
],
'eeg-posterior-rhythm',
'value',
);
const [found] = interpretabilityFigures(
{
kind: 'age_curves',
curves: { value: { kind: 'curves' } },
},
{
points,
centiles: [
{ age_months: 16, p5: 4, median: 6, p95: 8 },
{ age_months: 36, p5: 5, median: 7, p95: 9 },
],
},
);
expect(found.figure.data[1]).toMatchObject({ x: [16, 36], y: [6, 7] });
expect(found.figure.data[2]).toMatchObject({ mode: 'markers', x: [21], y: [7] });
});
it('plots one row per association pair on the log odds-ratio axis', () => {
const [found] = interpretabilityFigures({
kind: 'forest',
rows: [
{
biomarker: 'Spindles',
zone: 'F',
outcome_code: 'A1',
odds_ratio: 2,
ci_low: 1.5,
ci_high: 3,
q: 0.04,
},
{
biomarker: 'Spindles',
zone: 'O',
outcome_code: 'A1',
odds_ratio: 0.5,
ci_low: 0.25,
ci_high: 1,
q: 0.1,
},
],
});
expect(found.figure.layout?.xaxis?.type).toBe('log');
expect(found.figure.data).toHaveLength(2);
expect(found.figure.data[0]).toMatchObject({
x: [2],
y: ['Spindles · F · A1'],
error_x: { array: [1], arrayminus: [0.5] },
hovertemplate: expect.stringContaining('q: 0.04'),
});
});
it('draws nothing for a report it does not know', () => {
expect(interpretabilityFigures({ kind: 'other' })).toEqual([]);
});
});