T17: sweep of the WebApp after the feature-parity work
Removed the legacy indicator layout, unused chart helpers, styles and exports, the card-actions component, fetch-all and explanatory comments; one pager shared by the four worklists, shared filter-row styles, one FHIR name and CURP reader, downloads through export/, the concept-map editor on Material controls.
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
import type { Measure, MeasureReport, MeasureReportGroup } from 'fhir/r4';
|
||||
import { code, ext } from '../fhir';
|
||||
import { Figure, PALETTE } from '../plot';
|
||||
|
||||
export type PeriodType = 'semester' | 'month';
|
||||
export type Scoring = 'proportion' | 'continuous-variable' | 'cohort';
|
||||
|
||||
/** The periods back from today, most recent first: semesters (`2025-S1`) or months. */
|
||||
export function periods(type: PeriodType, years = 6, today = new Date()): string[] {
|
||||
const found: string[] = [];
|
||||
const year = today.getFullYear();
|
||||
@@ -32,17 +29,12 @@ export function periodLabel(period: string): string {
|
||||
return `${month} ${year}`;
|
||||
}
|
||||
|
||||
export function scoring(measure: Measure): Scoring {
|
||||
return code(measure.scoring) as Scoring;
|
||||
}
|
||||
|
||||
export function periodTypes(measure: Measure): PeriodType[] {
|
||||
return (measure.extension ?? [])
|
||||
.filter((e) => e.url.endsWith('/period-type'))
|
||||
.map((e) => e.valueCode as PeriodType);
|
||||
}
|
||||
|
||||
/** What one report says: its counts, its score and interval, and its strata. */
|
||||
export interface Reading {
|
||||
populations: Record<string, number>;
|
||||
score?: number;
|
||||
@@ -66,7 +58,6 @@ export function reading(report: MeasureReport | undefined): Reading | undefined
|
||||
const score = group.measureScore;
|
||||
const strata: Reading['strata'] = {};
|
||||
for (const s of group.stratifier ?? []) {
|
||||
// A crossed stratifier (several codes) is keyed `a-b`, its strata `valueA|valueB`.
|
||||
const name = (s.code ?? []).map((c) => code(c) ?? c.text ?? '').join('-');
|
||||
strata[name] = Object.fromEntries(
|
||||
(s.stratum ?? []).map((x) => [
|
||||
@@ -87,7 +78,6 @@ export function reading(report: MeasureReport | undefined): Reading | undefined
|
||||
};
|
||||
}
|
||||
|
||||
/** Codes as the screens name them. */
|
||||
export const LABELS: Record<string, string> = {
|
||||
NILM: 'Normal (NILM)',
|
||||
LSIL: 'LIEBG',
|
||||
@@ -136,7 +126,6 @@ export const LABELS: Record<string, string> = {
|
||||
['0', '1', '2', '3', '4', '4A', '4B', '4C', '5', '6'].map((c) => [c, `BI-RADS ${c}`]),
|
||||
),
|
||||
};
|
||||
/** A follow-up priority's label. */
|
||||
export const PRIORITY: Record<string, string> = { high: 'Alta', medium: 'Media', low: 'Baja' };
|
||||
export const STRATA: Record<string, string> = {
|
||||
category: 'Categoría',
|
||||
@@ -146,205 +135,3 @@ export const STRATA: Record<string, string> = {
|
||||
birads: 'BI-RADS de la mastografía',
|
||||
};
|
||||
export const name = (value: string) => LABELS[value] ?? value;
|
||||
|
||||
export function formatScore(measure: Measure, r: Reading | undefined): string {
|
||||
if (!r || r.score === undefined) return 'Sin dato';
|
||||
switch (scoring(measure)) {
|
||||
case 'proportion':
|
||||
return `${(r.score * 100).toFixed(1)} %`;
|
||||
case 'continuous-variable':
|
||||
return `${Math.round(r.score * 10) / 10} días`;
|
||||
default:
|
||||
return `${r.score}`;
|
||||
}
|
||||
}
|
||||
|
||||
export function detail(measure: Measure, r: Reading | undefined): string {
|
||||
if (!r) return '';
|
||||
const p = r.populations;
|
||||
switch (scoring(measure)) {
|
||||
case 'proportion':
|
||||
return r.score === undefined
|
||||
? 'Sin pacientes en el periodo.'
|
||||
: `${p['numerator']} de ${p['denominator']} pacientes. IC 95 %: ${pct(r.low)}–${pct(r.high)}.`;
|
||||
case 'continuous-variable':
|
||||
return r.score === undefined
|
||||
? `${p['initial-population'] ?? 0} sin medición en el periodo.`
|
||||
: `Mediana de ${p['measure-observation']} mediciones; cuartiles ${r.low}–${r.high} días.`;
|
||||
default:
|
||||
return `${p['initial-population'] ?? 0} pacientes.`;
|
||||
}
|
||||
}
|
||||
|
||||
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 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;
|
||||
labels = ['Numerador', 'Resto'];
|
||||
values = [numerator, denominator - numerator];
|
||||
} else {
|
||||
const cells = Object.entries(r.strata[stratifier] ?? {});
|
||||
labels = cells.map(([v]) => name(v));
|
||||
values = cells.map(([, c]) => c['initial-population'] ?? 0);
|
||||
}
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
type: 'pie',
|
||||
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,
|
||||
showCounts = false,
|
||||
): Figure {
|
||||
const cells = Object.entries(r.strata[stratifier] ?? {});
|
||||
const proportion = scoring(measure) === 'proportion';
|
||||
const values = cells.map(([, c]) =>
|
||||
proportion
|
||||
? c['denominator']
|
||||
? (100 * (c['numerator'] ?? 0)) / c['denominator']
|
||||
: 0
|
||||
: (c['initial-population'] ?? 0),
|
||||
);
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
type: 'bar',
|
||||
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] },
|
||||
},
|
||||
],
|
||||
layout: {
|
||||
xaxis: { title: { text: proportion ? '%' : 'Pacientes' } },
|
||||
yaxis: { automargin: true },
|
||||
margin: { t: 8, r: 16, b: 48, l: 8 },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** Horizontal median bars with their interquartile range, one per measure. */
|
||||
export function medians(rows: { label: string; r: Reading | undefined }[]): Figure {
|
||||
const shown = rows.filter((x) => x.r?.score !== undefined);
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
type: 'bar',
|
||||
orientation: 'h',
|
||||
y: shown.map((x) => x.label),
|
||||
x: shown.map((x) => x.r!.score!),
|
||||
error_x: {
|
||||
type: 'data',
|
||||
symmetric: false,
|
||||
array: shown.map((x) => (x.r!.high ?? x.r!.score!) - x.r!.score!),
|
||||
arrayminus: shown.map((x) => x.r!.score! - (x.r!.low ?? x.r!.score!)),
|
||||
color: '#17324d',
|
||||
},
|
||||
marker: { color: PALETTE[0] },
|
||||
hovertemplate: '%{y}: %{x} días<extra></extra>',
|
||||
},
|
||||
],
|
||||
layout: {
|
||||
xaxis: { title: { text: 'Días (mediana, Q1–Q3)' } },
|
||||
yaxis: { automargin: true, autorange: 'reversed' },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** A measure over time: % with its interval, median with its quartiles, or counts by category. */
|
||||
export function history(
|
||||
measure: Measure,
|
||||
series: { period: string; r: Reading | undefined }[],
|
||||
): Figure {
|
||||
const x = series.map((s) => periodLabel(s.period));
|
||||
const kind = scoring(measure);
|
||||
if (kind === 'cohort') {
|
||||
const categories = [
|
||||
...new Set(series.flatMap((s) => Object.keys(s.r?.strata['category'] ?? {}))),
|
||||
];
|
||||
return {
|
||||
data: categories.map((c, i) => ({
|
||||
type: 'bar',
|
||||
name: name(c),
|
||||
x,
|
||||
y: series.map((s) => s.r?.strata['category']?.[c]?.['initial-population'] ?? 0),
|
||||
marker: { color: PALETTE[i % PALETTE.length] },
|
||||
})),
|
||||
layout: { barmode: 'stack', yaxis: { title: { text: 'Pacientes' } } },
|
||||
};
|
||||
}
|
||||
const k = kind === 'proportion' ? 100 : 1;
|
||||
const value = (v?: number) => (v === undefined ? null : v * k);
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
x,
|
||||
y: series.map((s) => value(s.r?.high)),
|
||||
mode: 'lines',
|
||||
line: { width: 0 },
|
||||
showlegend: false,
|
||||
hoverinfo: 'skip',
|
||||
},
|
||||
{
|
||||
x,
|
||||
y: series.map((s) => value(s.r?.low)),
|
||||
mode: 'lines',
|
||||
line: { width: 0 },
|
||||
fill: 'tonexty',
|
||||
fillcolor: 'rgba(168,194,67,0.25)',
|
||||
name: kind === 'proportion' ? 'IC 95 %' : 'Q1–Q3',
|
||||
},
|
||||
{
|
||||
x,
|
||||
y: series.map((s) => value(s.r?.score)),
|
||||
mode: 'lines+markers',
|
||||
name: kind === 'proportion' ? '%' : 'Mediana',
|
||||
line: { color: PALETTE[0] },
|
||||
},
|
||||
],
|
||||
layout: { yaxis: { title: { text: kind === 'proportion' ? '%' : 'Días' } } },
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user