Indicadores TEA: Resumen, Trazabilidad, Seguimiento, Análisis de riesgo, periodicities
This commit is contained in:
@@ -113,6 +113,16 @@ const LABELS: Record<string, string> = {
|
||||
psychology: 'Psicología (ADOS-2)',
|
||||
neuropediatrics: 'Neuropediatría',
|
||||
eeg: 'EEG',
|
||||
female: 'Femenino',
|
||||
male: 'Masculino',
|
||||
abnormal: 'Anormal',
|
||||
not_scored: 'Sin puntuar',
|
||||
no_valid_eeg: 'Sin EEG válido',
|
||||
posterior_rhythm: 'Ritmo posterior',
|
||||
spindles_n2: 'Husos N2',
|
||||
spindles_n3: 'Husos N3',
|
||||
paroxysmal_spikes: 'Puntas paroxísticas',
|
||||
anteroposterior_gradient: 'Gradiente anteroposterior',
|
||||
good: 'Bueno',
|
||||
bad: 'Malo',
|
||||
not_analyzed: 'Sin analizar',
|
||||
@@ -163,7 +173,15 @@ export function detail(measure: Measure, r: Reading | undefined): string {
|
||||
const pct = (v?: number) => (v === undefined ? '—' : `${(v * 100).toFixed(1)} %`);
|
||||
|
||||
/** A donut of one stratifier's counts (initial population), or of numerator vs the rest. */
|
||||
export function donut(measure: Measure, r: Reading, stratifier = 'category'): Figure {
|
||||
export type Ring = { labels: string[]; values: number[] };
|
||||
|
||||
export function donut(
|
||||
measure: Measure,
|
||||
r: Reading,
|
||||
stratifier = 'category',
|
||||
inner?: Ring,
|
||||
outer?: Ring,
|
||||
): Figure {
|
||||
let labels: string[], values: number[];
|
||||
if (scoring(measure) === 'proportion') {
|
||||
const { numerator = 0, denominator = 0 } = r.populations;
|
||||
@@ -178,20 +196,37 @@ export function donut(measure: Measure, r: Reading, stratifier = 'category'): Fi
|
||||
data: [
|
||||
{
|
||||
type: 'pie',
|
||||
hole: 0.62,
|
||||
labels,
|
||||
values,
|
||||
hole: inner ? 0.68 : 0.62,
|
||||
...(outer ?? { labels, values }),
|
||||
sort: false,
|
||||
textinfo: 'value+percent',
|
||||
marker: { colors: PALETTE },
|
||||
},
|
||||
...(inner
|
||||
? [
|
||||
{
|
||||
type: 'pie' as const,
|
||||
hole: 0.45,
|
||||
...inner,
|
||||
sort: false,
|
||||
textinfo: 'percent' as const,
|
||||
domain: { x: [0.17, 0.83] as [number, number], y: [0.17, 0.83] as [number, number] },
|
||||
marker: { colors: PALETTE },
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
layout: { showlegend: true, margin: { t: 32, r: 8, b: 32, l: 8 } },
|
||||
};
|
||||
}
|
||||
|
||||
/** Bars per stratum: the rate (proportion) or the count (others). */
|
||||
export function strataBars(measure: Measure, r: Reading, stratifier: string): Figure {
|
||||
export function strataBars(
|
||||
measure: Measure,
|
||||
r: Reading,
|
||||
stratifier: string,
|
||||
showCounts = false,
|
||||
): Figure {
|
||||
const cells = Object.entries(r.strata[stratifier] ?? {});
|
||||
const proportion = scoring(measure) === 'proportion';
|
||||
const values = cells.map(([, c]) =>
|
||||
@@ -208,6 +243,12 @@ export function strataBars(measure: Measure, r: Reading, stratifier: string): Fi
|
||||
orientation: 'h',
|
||||
y: cells.map(([v]) => name(v)),
|
||||
x: values,
|
||||
...(showCounts
|
||||
? {
|
||||
text: cells.map(([, c], i) => `${c['numerator'] ?? 0} (${values[i].toFixed(1)} %)`),
|
||||
hovertemplate: '%{y}: %{text}<extra></extra>',
|
||||
}
|
||||
: {}),
|
||||
marker: { color: PALETTE[0] },
|
||||
},
|
||||
],
|
||||
@@ -301,3 +342,70 @@ export function history(
|
||||
layout: { yaxis: { title: { text: kind === 'proportion' ? '%' : 'Días' } } },
|
||||
};
|
||||
}
|
||||
|
||||
export function boxes(rows: { label: string; r: Reading | undefined }[]): Figure {
|
||||
return {
|
||||
data: rows.flatMap(({ label, r }) =>
|
||||
r?.score === undefined || r.low === undefined || r.high === undefined
|
||||
? []
|
||||
: [
|
||||
{
|
||||
type: 'box' as const,
|
||||
orientation: 'h' as const,
|
||||
name: label,
|
||||
q1: [r.low],
|
||||
median: [r.score],
|
||||
q3: [r.high],
|
||||
lowerfence: [r.low],
|
||||
upperfence: [r.high],
|
||||
},
|
||||
],
|
||||
),
|
||||
layout: { xaxis: { title: { text: 'Días' } }, yaxis: { automargin: true } },
|
||||
};
|
||||
}
|
||||
|
||||
export function sankey(
|
||||
latest: readonly number[],
|
||||
eeg: { valid: number; normal: number; abnormal: number },
|
||||
): Figure {
|
||||
const [, psychology, neurology, reachedEeg] = latest.map((_, i) =>
|
||||
latest.slice(i).reduce((sum, count) => sum + count, 0),
|
||||
);
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
type: 'sankey',
|
||||
node: {
|
||||
label: [
|
||||
'M-CHAT',
|
||||
'Psicología',
|
||||
'Neuropediatría',
|
||||
'EEG',
|
||||
'Solo M-CHAT',
|
||||
'Hasta Psicología',
|
||||
'Sin EEG válido',
|
||||
'Normal',
|
||||
'Anormal',
|
||||
'Sin puntuar',
|
||||
],
|
||||
},
|
||||
link: {
|
||||
source: [0, 1, 2, 0, 1, 2, 3, 3, 3],
|
||||
target: [1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||
value: [
|
||||
psychology,
|
||||
neurology,
|
||||
reachedEeg,
|
||||
latest[0],
|
||||
latest[1],
|
||||
latest[2],
|
||||
eeg.normal,
|
||||
eeg.abnormal,
|
||||
eeg.valid - eeg.normal - eeg.abnormal,
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user