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.
This commit is contained in:
@@ -0,0 +1,480 @@
|
||||
import { type Figure, PALETTE } from '../plot';
|
||||
import { name, type Reading } from './measures';
|
||||
import type { Catalog, Category, HistoryPanel } from './pages';
|
||||
|
||||
const OLIVE = '#A8C243';
|
||||
const ROSE = '#C24269';
|
||||
|
||||
const count = (n: number) => n.toLocaleString('es-MX');
|
||||
const percent = (n: number) => (Math.round(n * 10) / 10).toLocaleString('es-MX');
|
||||
function rgba(hex: string, alpha: number): string {
|
||||
const v = parseInt(hex.slice(1), 16);
|
||||
return `rgba(${v >> 16},${(v >> 8) & 255},${v & 255},${alpha})`;
|
||||
}
|
||||
|
||||
/** The screening route: each step's median days from the sample, with Q1–Q3. */
|
||||
export function routeFigure(steps: { label: string; r: Reading | undefined }[]): Figure {
|
||||
const shown = steps.filter((s) => s.r?.score !== undefined);
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
type: 'bar',
|
||||
orientation: 'h',
|
||||
y: shown.map(
|
||||
(s) => `${s.label}<br>n = ${count(s.r!.populations['measure-observation'] ?? 0)}`,
|
||||
),
|
||||
x: shown.map((s) => s.r!.score!),
|
||||
marker: { color: OLIVE },
|
||||
error_x: {
|
||||
type: 'data',
|
||||
symmetric: false,
|
||||
thickness: 1.5,
|
||||
width: 6,
|
||||
array: shown.map((s) => (s.r!.high ?? s.r!.score!) - s.r!.score!),
|
||||
arrayminus: shown.map((s) => s.r!.score! - (s.r!.low ?? s.r!.score!)),
|
||||
},
|
||||
hovertemplate: '%{y}<br>mediana %{x} días<extra></extra>',
|
||||
} as Partial<Plotly.Data>,
|
||||
],
|
||||
layout: {
|
||||
showlegend: false,
|
||||
xaxis: { title: { text: 'Días' }, rangemode: 'tozero', zeroline: false },
|
||||
yaxis: { autorange: 'reversed', type: 'category', automargin: true },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** A category's count in the report (the composition's `category` stratum). */
|
||||
function counted(r: Reading, code: string): number {
|
||||
return r.strata['category']?.[code]?.['initial-population'] ?? 0;
|
||||
}
|
||||
|
||||
/** Groups inside, their categories outside, the total in the centre. */
|
||||
export function nestedDonut(r: Reading, catalog: Catalog, center: string): Figure {
|
||||
const values = catalog.categories.map((c) => counted(r, c.code));
|
||||
const total = values.reduce((a, b) => a + b, 0);
|
||||
const groups = catalog.groups.map((g) =>
|
||||
catalog.categories.reduce((n, c, i) => n + (c.group === g.id ? values[i] : 0), 0),
|
||||
);
|
||||
const faded = new Set(catalog.faded ?? []);
|
||||
const share = (n: number) => (total ? `${percent((100 * n) / total)} %` : '');
|
||||
const common = {
|
||||
type: 'pie',
|
||||
sort: false,
|
||||
direction: 'clockwise',
|
||||
rotation: 0,
|
||||
showlegend: false,
|
||||
textinfo: 'text',
|
||||
textposition: 'inside',
|
||||
insidetextorientation: 'horizontal',
|
||||
};
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
...common,
|
||||
name: 'centro',
|
||||
values: [1],
|
||||
labels: ['centro'],
|
||||
domain: { x: [0.32, 0.68], y: [0.32, 0.68] },
|
||||
text: [`<b>${count(total)}</b><br>${center}`],
|
||||
marker: { colors: ['#FFFFFF'] },
|
||||
hoverinfo: 'skip',
|
||||
},
|
||||
{
|
||||
...common,
|
||||
name: 'grupos',
|
||||
values: groups,
|
||||
labels: catalog.groups.map((g) => g.label),
|
||||
hole: 0.62,
|
||||
domain: { x: [0.16, 0.84], y: [0.16, 0.84] },
|
||||
text: groups.map((n, i) =>
|
||||
total && n / total >= 0.05 ? `${catalog.groups[i].label}<br>${share(n)}` : '',
|
||||
),
|
||||
marker: {
|
||||
colors: catalog.groups.map((g) =>
|
||||
rgba(
|
||||
g.color,
|
||||
catalog.categories.some((c) => c.group === g.id && !faded.has(c.code)) ? 1 : 0.3,
|
||||
),
|
||||
),
|
||||
line: { color: '#FFFFFF', width: 2 },
|
||||
},
|
||||
hovertemplate: '%{label}<br>%{value} (%{percent})<extra></extra>',
|
||||
},
|
||||
{
|
||||
...common,
|
||||
name: 'categorias',
|
||||
values,
|
||||
labels: catalog.categories.map((c) => c.label),
|
||||
hole: 0.74,
|
||||
domain: { x: [0, 1], y: [0, 1] },
|
||||
// along the thin ring, so a label fits its slice
|
||||
insidetextorientation: 'tangential',
|
||||
text: values.map((n, i) => (total && n / total >= 0.05 ? catalog.categories[i].label : '')),
|
||||
marker: {
|
||||
colors: catalog.categories.map((c) => rgba(c.color, faded.has(c.code) ? 0.3 : 1)),
|
||||
line: { color: '#FFFFFF', width: 2 },
|
||||
},
|
||||
hovertemplate: '%{label}<br>%{value} (%{percent})<extra></extra>',
|
||||
},
|
||||
] as Partial<Plotly.Data>[],
|
||||
layout: { margin: { t: 10, l: 10, r: 10, b: 10 } },
|
||||
};
|
||||
}
|
||||
|
||||
/** Each clinical scenario's results as shares of its patients, one stacked bar each. */
|
||||
export function scenarioBars(
|
||||
r: Reading,
|
||||
catalog: Catalog,
|
||||
stratum: string,
|
||||
label: (code: string) => string,
|
||||
): Figure {
|
||||
const cells = r.strata[`${stratum}-category`] ?? {};
|
||||
const scenarios = [...new Set(Object.keys(cells).map((k) => k.split('|')[0]))].sort((a, b) =>
|
||||
label(a).localeCompare(label(b), 'es'),
|
||||
);
|
||||
const n = (s: string, c: string) => cells[`${s}|${c}`]?.['initial-population'] ?? 0;
|
||||
const totals = scenarios.map((s) => catalog.categories.reduce((t, c) => t + n(s, c.code), 0));
|
||||
const y = scenarios.map(label);
|
||||
return {
|
||||
data: catalog.categories.map((c) => ({
|
||||
type: 'bar',
|
||||
orientation: 'h',
|
||||
name: c.label,
|
||||
y,
|
||||
x: scenarios.map((s, i) => (totals[i] ? (100 * n(s, c.code)) / totals[i] : 0)),
|
||||
customdata: scenarios.map((s) => n(s, c.code)),
|
||||
marker: { color: c.color },
|
||||
hovertemplate: `${c.label}<br>%{y}: %{customdata} (%{x:.1f} %)<extra></extra>`,
|
||||
})) as Partial<Plotly.Data>[],
|
||||
layout: {
|
||||
barmode: 'stack',
|
||||
xaxis: {
|
||||
title: { text: '% de pacientes del escenario con resultado' },
|
||||
ticksuffix: ' %',
|
||||
range: [0, 100.5],
|
||||
dtick: 20,
|
||||
},
|
||||
yaxis: {
|
||||
type: 'category',
|
||||
autorange: 'reversed',
|
||||
categoryorder: 'array',
|
||||
categoryarray: y,
|
||||
automargin: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** Wilson score interval at 95 %, in percent. */
|
||||
export function wilson(k: number, n: number): [number, number] {
|
||||
const z = 1.959963984540054;
|
||||
const p = k / n;
|
||||
const d = 1 + (z * z) / n;
|
||||
const c = (p + (z * z) / (2 * n)) / d;
|
||||
const h = (z * Math.sqrt((p * (1 - p)) / n + (z * z) / (4 * n * n))) / d;
|
||||
return [100 * (c - h), 100 * (c + h)];
|
||||
}
|
||||
|
||||
/** Per cytology result: of the women with a biopsy, the share whose biopsy is a positive,
|
||||
* with its 95 % interval; a result nobody had a biopsy for is named, not drawn. */
|
||||
export function rateDots(
|
||||
r: Reading,
|
||||
spec: { stratum: string; rows: Category[]; positive: string[]; axis: string; colored?: boolean },
|
||||
): Figure {
|
||||
const cells = r.strata[`${spec.stratum}-category`] ?? {};
|
||||
const rows = spec.rows.map((row) => {
|
||||
const of = Object.entries(cells).filter(([k]) => k.split('|')[0] === row.code);
|
||||
const biopsied = of.filter(([k]) => !['no_biopsy', 'no_data'].includes(k.split('|')[1]));
|
||||
const den = biopsied.reduce((t, [, c]) => t + (c['initial-population'] ?? 0), 0);
|
||||
const k = biopsied
|
||||
.filter(([key]) => spec.positive.includes(key.split('|')[1]))
|
||||
.reduce((t, [, c]) => t + (c['initial-population'] ?? 0), 0);
|
||||
const rate = den ? (100 * k) / den : null;
|
||||
const [low, high] = den ? wilson(k, den) : [null, null];
|
||||
return { row, k, den, rate, low, high };
|
||||
});
|
||||
const y = rows.map((x) => x.row.label);
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
type: 'scatter',
|
||||
mode: 'markers',
|
||||
name: 'tasas',
|
||||
y,
|
||||
x: rows.map((x) => x.rate),
|
||||
marker: { size: 12, color: spec.colored ? rows.map((x) => x.row.color) : ROSE },
|
||||
cliponaxis: false,
|
||||
error_x: {
|
||||
type: 'data',
|
||||
symmetric: false,
|
||||
color: ROSE,
|
||||
thickness: 2,
|
||||
width: 6,
|
||||
array: rows.map((x) => (x.rate === null ? 0 : x.high! - x.rate)),
|
||||
arrayminus: rows.map((x) => (x.rate === null ? 0 : x.rate - x.low!)),
|
||||
},
|
||||
hovertemplate: '%{y}: %{x:.1f} %<extra></extra>',
|
||||
} as Partial<Plotly.Data>,
|
||||
],
|
||||
layout: {
|
||||
showlegend: false,
|
||||
margin: { t: 24, r: 110, b: 56, l: 56 },
|
||||
yaxis: {
|
||||
type: 'category',
|
||||
categoryorder: 'array',
|
||||
categoryarray: [...y].reverse(),
|
||||
automargin: true,
|
||||
},
|
||||
xaxis: { range: [0, 100], ticksuffix: ' %', zeroline: false, title: { text: spec.axis } },
|
||||
annotations: rows.map((x) => ({
|
||||
x: 1,
|
||||
xref: 'paper',
|
||||
xanchor: 'left',
|
||||
xshift: 8,
|
||||
y: x.row.label,
|
||||
yref: 'y',
|
||||
showarrow: false,
|
||||
align: 'left',
|
||||
text: x.den
|
||||
? `<b>${percent(x.rate!)} %</b><br>${x.k}/${x.den}`
|
||||
: spec.colored
|
||||
? 'Sin pacientes'
|
||||
: 'Sin biopsias',
|
||||
})),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const decimal = (n: number) => n.toLocaleString('es-MX', { maximumFractionDigits: 2 });
|
||||
|
||||
/** A card's template filled from its measure's reading in the period: {n} counted, {obs}
|
||||
* measured, {median} {q1} {q3} days, {num} {den} {pct}. */
|
||||
export function fill(template: string, r: Reading): string {
|
||||
const p = r.populations;
|
||||
const values: Record<string, string> = {
|
||||
n: count(p['initial-population'] ?? 0),
|
||||
obs: count(p['measure-observation'] ?? 0),
|
||||
median: r.score === undefined ? '' : decimal(r.score),
|
||||
q1: decimal(r.low ?? r.score ?? 0),
|
||||
q3: decimal(r.high ?? r.score ?? 0),
|
||||
num: count(p['numerator'] ?? 0),
|
||||
den: count(p['denominator'] ?? 0),
|
||||
pct: r.score === undefined ? '' : percent(r.score * 100),
|
||||
};
|
||||
return template.replace(/\{(\w+)\}/g, (_, k) => values[k] ?? '');
|
||||
}
|
||||
|
||||
/** A duration's quartile box in the period. */
|
||||
export function boxFigure(r: Reading, period: string): Figure {
|
||||
const q1 = r.low ?? r.score!;
|
||||
const q3 = r.high ?? r.score!;
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
type: 'box',
|
||||
name: 'Total',
|
||||
x: [period],
|
||||
q1: [q1],
|
||||
median: [r.score!],
|
||||
q3: [q3],
|
||||
lowerfence: [q1],
|
||||
upperfence: [q3],
|
||||
marker: { color: '#4269C2' },
|
||||
fillcolor: 'rgba(66,105,194,0.55)',
|
||||
hovertemplate: `Q1 ${decimal(q1)} · mediana ${decimal(r.score!)} · Q3 ${decimal(q3)} días<extra></extra>`,
|
||||
} as Partial<Plotly.Data>,
|
||||
],
|
||||
layout: { showlegend: false, yaxis: { title: { text: 'días' }, rangemode: 'tozero' } },
|
||||
};
|
||||
}
|
||||
|
||||
/** One ring: the categories' shares, the total in the centre. */
|
||||
export function shareDonut(r: Reading, catalog: Catalog, center: string): Figure {
|
||||
const values = catalog.categories.map((c) => counted(r, c.code));
|
||||
const total = values.reduce((a, b) => a + b, 0);
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
type: 'pie',
|
||||
hole: 0.54,
|
||||
sort: false,
|
||||
direction: 'clockwise',
|
||||
labels: catalog.categories.map((c) => c.label),
|
||||
values,
|
||||
marker: {
|
||||
colors: catalog.categories.map((c) => c.color),
|
||||
line: { color: '#FFFFFF', width: 2 },
|
||||
},
|
||||
// an empty slice says nothing (its label would sit on its neighbours')
|
||||
texttemplate: values.map((v) => (v ? '%{label}<br>%{percent}' : '')),
|
||||
textposition: 'outside',
|
||||
hovertemplate: '%{label}<br>%{value} (%{percent})<extra></extra>',
|
||||
} as Partial<Plotly.Data>,
|
||||
],
|
||||
layout: {
|
||||
showlegend: false,
|
||||
margin: { t: 30, l: 60, r: 60, b: 30 },
|
||||
annotations: [
|
||||
{
|
||||
text: `<b>${count(total)}</b><br>${center}`,
|
||||
showarrow: false,
|
||||
x: 0.5,
|
||||
y: 0.5,
|
||||
xref: 'paper',
|
||||
yref: 'paper',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** A category's count per bar, one bar each, in the period. */
|
||||
export function countBars(r: Reading, catalog: Catalog, axis: string, period: string): Figure {
|
||||
const y = catalog.categories.map((c) => c.label);
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
type: 'bar',
|
||||
orientation: 'h',
|
||||
name: period,
|
||||
y,
|
||||
x: catalog.categories.map((c) => counted(r, c.code)),
|
||||
marker: { color: catalog.categories.map((c) => c.color) },
|
||||
texttemplate: '%{x}',
|
||||
textposition: 'outside',
|
||||
hovertemplate: '%{y}: %{x}<extra></extra>',
|
||||
} as Partial<Plotly.Data>,
|
||||
],
|
||||
layout: {
|
||||
showlegend: false,
|
||||
xaxis: { title: { text: axis }, rangemode: 'tozero' },
|
||||
yaxis: { type: 'category', autorange: 'reversed', automargin: true },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const AGE_COLORS = ['#A8C243', '#42C29C', '#9C42C2', '#4269C2'];
|
||||
/** "16-23" as the screens say it: "16 a 23 meses". */
|
||||
export const ageLabel = (band: string) => band.replace(/^(\d+)-(\d+)$/, '$1 a $2 meses');
|
||||
|
||||
function ages(r: Reading): [string, Record<string, number>][] {
|
||||
return Object.entries(r.strata['age_group'] ?? {}).sort(
|
||||
([a], [b]) => parseInt(a, 10) - parseInt(b, 10),
|
||||
);
|
||||
}
|
||||
|
||||
/** By age group: the numerator and the rest of the denominator, stacked. */
|
||||
export function ageStack(r: Reading, names: [string, string]): Figure {
|
||||
const rows = ages(r);
|
||||
const x = rows.map(([a]) => ageLabel(a));
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
type: 'bar',
|
||||
name: names[0],
|
||||
x,
|
||||
y: rows.map(([, c]) => c['numerator'] ?? 0),
|
||||
marker: { color: AGE_COLORS[0] },
|
||||
},
|
||||
{
|
||||
type: 'bar',
|
||||
name: names[1],
|
||||
x,
|
||||
y: rows.map(([, c]) => (c['denominator'] ?? 0) - (c['numerator'] ?? 0)),
|
||||
marker: { color: AGE_COLORS[1] },
|
||||
},
|
||||
] as Partial<Plotly.Data>[],
|
||||
layout: {
|
||||
barmode: 'stack',
|
||||
xaxis: { title: { text: 'Grupo de edad' }, type: 'category' },
|
||||
yaxis: { title: { text: 'Pacientes' }, rangemode: 'tozero' },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** By age group: the numerator's share of the denominator, one bar each. */
|
||||
export function ageShare(r: Reading, axis: string): Figure {
|
||||
const rows = ages(r);
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
type: 'bar',
|
||||
x: rows.map(([a]) => ageLabel(a)),
|
||||
y: rows.map(([, c]) =>
|
||||
c['denominator'] ? (100 * (c['numerator'] ?? 0)) / c['denominator'] : 0,
|
||||
),
|
||||
marker: { color: rows.map((_, i) => AGE_COLORS[i % AGE_COLORS.length]) },
|
||||
texttemplate: '%{y:.1f} %',
|
||||
textposition: 'outside',
|
||||
hovertemplate: '%{x}: %{y:.1f} %<extra></extra>',
|
||||
} as Partial<Plotly.Data>,
|
||||
],
|
||||
layout: {
|
||||
showlegend: false,
|
||||
xaxis: { title: { text: 'Grupo de edad' }, type: 'category' },
|
||||
yaxis: { title: { text: axis }, range: [0, 100], ticksuffix: ' %' },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** A Trazabilidad panel's figure (pages.HISTORY), as the old tab drew it: stacked bars by
|
||||
* category, or a line with its band (95 % interval, or first to third quartile) drawn as one
|
||||
* closed shape. */
|
||||
export function historyFigure(
|
||||
panel: HistoryPanel,
|
||||
series: { label: string; r: Reading | undefined }[],
|
||||
line: string,
|
||||
xTitle: string,
|
||||
): Figure {
|
||||
const x = series.map((s) => s.label);
|
||||
const layout = (y: string) => ({
|
||||
xaxis: { title: { text: xTitle }, type: 'category' as const },
|
||||
yaxis: { title: { text: y } },
|
||||
});
|
||||
if (panel.kind === 'stack') {
|
||||
const found = [...new Set(series.flatMap((s) => Object.keys(s.r?.strata['category'] ?? {})))];
|
||||
const declared = panel.series ?? [];
|
||||
const named = [
|
||||
...declared,
|
||||
...found
|
||||
.filter((c) => !declared.some((d) => d.code === c))
|
||||
.map((c, i) => ({ code: c, label: name(c), color: PALETTE[i % PALETTE.length] })),
|
||||
];
|
||||
return {
|
||||
data: named.map((c) => ({
|
||||
type: 'bar',
|
||||
name: c.label,
|
||||
x,
|
||||
y: series.map((s) => s.r?.strata['category']?.[c.code]?.['initial-population'] ?? 0),
|
||||
marker: { color: c.color },
|
||||
})),
|
||||
layout: { ...layout(panel.axis ?? 'Pacientes'), barmode: 'stack' },
|
||||
};
|
||||
}
|
||||
const k = panel.kind === 'percent' ? 100 : 1;
|
||||
const at = (v?: number) => (v === undefined ? null : v * k);
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
x: [...x, ...[...x].reverse()],
|
||||
y: [...series.map((s) => at(s.r?.high)), ...[...series].reverse().map((s) => at(s.r?.low))],
|
||||
mode: 'lines',
|
||||
fill: 'toself',
|
||||
fillcolor: line + '33',
|
||||
line: { width: 0 },
|
||||
name: panel.kind === 'percent' ? 'Intervalo de confianza' : 'Primer a tercer cuartil',
|
||||
hoverinfo: 'skip',
|
||||
},
|
||||
{
|
||||
x,
|
||||
y: series.map((s) => at(s.r?.score)),
|
||||
mode: 'lines+markers',
|
||||
name: panel.kind === 'percent' ? 'Porcentaje' : 'Mediana',
|
||||
line: { color: line },
|
||||
marker: { color: line },
|
||||
},
|
||||
],
|
||||
layout: layout(panel.kind === 'percent' ? 'Porcentaje' : 'Días'),
|
||||
};
|
||||
}
|
||||
@@ -147,11 +147,12 @@ export interface CamaRow {
|
||||
status: string;
|
||||
priority: string;
|
||||
ageGroup: string;
|
||||
mammogram: { date: string; birads?: string };
|
||||
/** `days`: from the mammogram to its diagnosis, when known by the cut-off. */
|
||||
mammogram: { date: string; birads?: string; days?: number };
|
||||
biopsy?: { date: string; histology?: string };
|
||||
}
|
||||
|
||||
const CAMA_AGE_GROUPS: [number, number][] = [
|
||||
export const CAMA_AGE_GROUPS: [number, number][] = [
|
||||
[40, 49],
|
||||
[50, 59],
|
||||
[60, 69],
|
||||
@@ -197,6 +198,7 @@ export function camaRows(page: Bundle, cutoff: string): CamaRow[] {
|
||||
birads: mammogram
|
||||
? code(results(mammogram).get('mammography.birads')?.valueCodeableConcept)
|
||||
: undefined,
|
||||
days: mammogram ? ext(mammogram, 'days-to-diagnosis')?.valueInteger : undefined,
|
||||
},
|
||||
biopsy: biopsy && {
|
||||
date: reported(biopsy)!,
|
||||
|
||||
@@ -11,11 +11,13 @@ import { TabIndicadores } from './tab-indicadores';
|
||||
import { TabRiesgos } from './tab-riesgos';
|
||||
import { TabSeguimiento } from './tab-seguimiento';
|
||||
import { TabTrazabilidad } from './tab-trazabilidad';
|
||||
import { Loading } from '../loading';
|
||||
|
||||
/** A domain's indicator page: four tabs over its FHIR measures and patients. */
|
||||
@Component({
|
||||
selector: 'app-indicadores',
|
||||
imports: [
|
||||
Loading,
|
||||
MatTabsModule,
|
||||
ReportButton,
|
||||
TabIndicadores,
|
||||
@@ -26,15 +28,11 @@ import { TabTrazabilidad } from './tab-trazabilidad';
|
||||
],
|
||||
template: `
|
||||
<section class="page">
|
||||
<header class="page-header">
|
||||
<h1>{{ title() }}</h1>
|
||||
<app-report-button />
|
||||
</header>
|
||||
<p class="subtitle">
|
||||
Indicadores de calidad y oportunidad del tamizaje, a partir de los datos cargados.
|
||||
</p>
|
||||
<h1>{{ title() }}</h1>
|
||||
<p class="subtitle">Explora los indicadores de {{ title().toLowerCase() }}.</p>
|
||||
<app-report-button />
|
||||
@if (measures.isLoading()) {
|
||||
<p class="muted">Cargando indicadores…</p>
|
||||
<app-loading what="los indicadores" />
|
||||
} @else if (measures.error()) {
|
||||
<p class="muted" role="alert">No se pudieron leer los indicadores.</p>
|
||||
} @else if (!measures.value()?.length) {
|
||||
@@ -72,7 +70,7 @@ import { TabTrazabilidad } from './tab-trazabilidad';
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
} @else if (domain() === 'cama') {
|
||||
<mat-tab label="Seguimiento">
|
||||
<mat-tab label="Análisis de riesgos">
|
||||
<ng-template matTabContent>
|
||||
<app-tab-seguimiento [domain]="domain()" />
|
||||
</ng-template>
|
||||
@@ -91,17 +89,25 @@ import { TabTrazabilidad } from './tab-trazabilidad';
|
||||
:host {
|
||||
display: block;
|
||||
}
|
||||
.page-header {
|
||||
position: relative;
|
||||
display: grid;
|
||||
justify-items: center;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
h1 {
|
||||
text-align: center;
|
||||
font-size: 28px;
|
||||
font-weight: 500;
|
||||
margin: 16px 0 8px;
|
||||
}
|
||||
.subtitle {
|
||||
text-align: center;
|
||||
font-size: 16px;
|
||||
margin: 0 0 24px;
|
||||
}
|
||||
::ng-deep .mat-mdc-tab-header {
|
||||
background: var(--color-surface);
|
||||
border-top: 2px solid var(--color-primary);
|
||||
}
|
||||
::ng-deep .mat-mdc-tab .mdc-tab__text-label {
|
||||
font-size: 16px;
|
||||
font-weight: 400;
|
||||
}
|
||||
::ng-deep .mat-mdc-tab.mdc-tab--active .mdc-tab__text-label {
|
||||
font-weight: 700;
|
||||
}
|
||||
.empty {
|
||||
padding: 48px 0;
|
||||
|
||||
@@ -66,9 +66,15 @@ export function reading(report: MeasureReport | undefined): Reading | undefined
|
||||
const score = group.measureScore;
|
||||
const strata: Reading['strata'] = {};
|
||||
for (const s of group.stratifier ?? []) {
|
||||
const name = code(s.code?.[0]) ?? s.code?.[0]?.text ?? '';
|
||||
// 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) => [x.value?.text ?? '', counts(x)]),
|
||||
(s.stratum ?? []).map((x) => [
|
||||
x.component?.length
|
||||
? x.component.map((c) => c.value?.text ?? '').join('|')
|
||||
: (x.value?.text ?? ''),
|
||||
counts(x),
|
||||
]),
|
||||
);
|
||||
}
|
||||
return {
|
||||
@@ -82,7 +88,7 @@ export function reading(report: MeasureReport | undefined): Reading | undefined
|
||||
}
|
||||
|
||||
/** Codes as the screens name them. */
|
||||
const LABELS: Record<string, string> = {
|
||||
export const LABELS: Record<string, string> = {
|
||||
NILM: 'Normal (NILM)',
|
||||
LSIL: 'LIEBG',
|
||||
HSIL: 'LIEAG',
|
||||
@@ -342,70 +348,3 @@ 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,
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,630 @@
|
||||
/** A domain's Indicadores page as the old app showed it (tests/fixtures/reference/<domain>/ui):
|
||||
* the timeliness cards with their own words, then the clinical sections and their figures.
|
||||
* Measures are named by their code (`Measure.name`). */
|
||||
export interface Page {
|
||||
kpis: Kpi[];
|
||||
/** Under the cards, before the clinical indicators (CaMa's timeliness boxes). */
|
||||
opportunity?: Section[];
|
||||
clinical: Section[];
|
||||
/** The measure whose data decides the default period. */
|
||||
anchor: string;
|
||||
}
|
||||
/** A card: its measure (none: not published yet), its title, and its value and note as
|
||||
* templates (figures.fill). */
|
||||
export interface Kpi {
|
||||
measure?: string;
|
||||
title: string;
|
||||
value?: string;
|
||||
note?: string;
|
||||
}
|
||||
export type Section =
|
||||
| { kind: 'route'; title: string; steps: { label: string; measure: string }[] }
|
||||
| { kind: 'figures'; title?: string; figures: FigureSpec[] }
|
||||
| {
|
||||
kind: 'boxes';
|
||||
/** none: the boxes stand alone (TEA) */
|
||||
title?: string;
|
||||
cards: { measure?: string; title: string }[];
|
||||
/** the measure's own title under each card's (CaMa) */
|
||||
subtitles?: boolean;
|
||||
}
|
||||
/** Each figure in its own card, titled, two to a row (TEA). */
|
||||
| { kind: 'grid'; figures: FigureSpec[] }
|
||||
/** TEA's period summary in words, its numbers from the measures. */
|
||||
| { kind: 'tea-summary' }
|
||||
| ({ kind: 'card' } & Kpi);
|
||||
/** Figure titles may carry `{p}`, the applied period. */
|
||||
export type FigureSpec =
|
||||
| {
|
||||
kind: 'donut' | 'share-donut';
|
||||
title: string;
|
||||
measure: string;
|
||||
catalog: Catalog;
|
||||
center: string;
|
||||
}
|
||||
| { kind: 'scenario-bars'; title: string; measure: string; catalog: Catalog; stratum: string }
|
||||
| { kind: 'counts'; title: string; measure: string; catalog: Catalog; axis: string }
|
||||
| {
|
||||
kind: 'age-stack' | 'age-share';
|
||||
title: string;
|
||||
measure: string;
|
||||
/** the numerator's and the rest's names (stack), or the axis (share) */
|
||||
names: [string, string];
|
||||
}
|
||||
| {
|
||||
kind: 'rates';
|
||||
title: string;
|
||||
measure: string;
|
||||
stratum: string;
|
||||
rows: Category[];
|
||||
/** each row in its category's colour (else all rose) */
|
||||
colored?: boolean;
|
||||
/** the categories (of the measure) that count as a positive */
|
||||
positive: string[];
|
||||
axis: string;
|
||||
};
|
||||
|
||||
export interface Category {
|
||||
code: string;
|
||||
label: string;
|
||||
color: string;
|
||||
group: string;
|
||||
}
|
||||
export interface Catalog {
|
||||
groups: { id: string; label: string; color: string }[];
|
||||
categories: Category[];
|
||||
/** categories drawn faded (not the ones the figure is about) */
|
||||
faded?: string[];
|
||||
}
|
||||
|
||||
const OLIVE = '#A8C243';
|
||||
const ROSE = '#C24269';
|
||||
|
||||
/** Bethesda results as the old app grouped and coloured them. */
|
||||
const CYTOLOGY: Catalog = {
|
||||
groups: [
|
||||
{ id: 'normal', label: 'Sin anomalía', color: OLIVE },
|
||||
{ id: 'abnormal', label: 'Anormal', color: ROSE },
|
||||
],
|
||||
categories: [
|
||||
{ code: 'NILM', label: 'Normal', color: '#A8C243', group: 'normal' },
|
||||
{ code: 'ASC-US', label: 'ASC-US', color: '#92324F', group: 'abnormal' },
|
||||
{ code: 'LSIL', label: 'LIEBG', color: '#AA3A5C', group: 'abnormal' },
|
||||
{ code: 'ASC-H', label: 'ASC-H', color: '#C24269', group: 'abnormal' },
|
||||
{ code: 'HSIL', label: 'LIEAG', color: '#C54C71', group: 'abnormal' },
|
||||
{ code: 'CIS', label: 'Carcinoma in situ', color: '#C9577A', group: 'abnormal' },
|
||||
],
|
||||
};
|
||||
|
||||
/** Biopsy grades: below high grade, and high grade or worse (what confirmation counts). */
|
||||
const BIOPSY: Catalog = {
|
||||
groups: [
|
||||
{ id: 'low', label: 'Menor que LIEAG', color: OLIVE },
|
||||
{ id: 'high', label: 'LIEAG o más', color: ROSE },
|
||||
],
|
||||
categories: [
|
||||
{ code: 'normal', label: 'Normal', color: '#7E9232', group: 'low' },
|
||||
{ code: 'LSIL', label: 'LIEBG (CIN 1)', color: '#B2C958', group: 'low' },
|
||||
{ code: 'HSIL', label: 'LIEAG (CIN 2 y 3)', color: '#92324F', group: 'high' },
|
||||
{ code: 'CIS', label: 'Carcinoma in situ', color: '#C24269', group: 'high' },
|
||||
{ code: 'carcinoma', label: 'Carcinoma invasor', color: '#C9577A', group: 'high' },
|
||||
],
|
||||
faded: ['normal', 'LSIL'],
|
||||
};
|
||||
|
||||
const CACU_DAYS = {
|
||||
value: '{median} días (mediana)',
|
||||
note: '{obs} citologías; primer cuartil: {q1} días; tercer cuartil: {q3} días.',
|
||||
};
|
||||
const CAMA_DAYS = {
|
||||
value: '{median} días (mediana)',
|
||||
note: '{obs} mastografías; Q1 a Q3: {q1} a {q3} días.',
|
||||
};
|
||||
const PENDING = 'Indicador no publicado en el catálogo institucional.';
|
||||
|
||||
/** BI-RADS 4 to 6 as the old app named and coloured them. */
|
||||
const BIRADS: Catalog = {
|
||||
groups: [],
|
||||
categories: [
|
||||
{ code: '4', label: 'BI-RADS 4 (sin subcategoría)', color: '#C24269', group: '' },
|
||||
{ code: '4A', label: 'BI-RADS 4A', color: '#9C42C2', group: '' },
|
||||
{ code: '4B', label: 'BI-RADS 4B', color: '#5C42C2', group: '' },
|
||||
{ code: '4C', label: 'BI-RADS 4C', color: '#C2429C', group: '' },
|
||||
{ code: '5', label: 'BI-RADS 5', color: '#8E2F62', group: '' },
|
||||
{ code: '6', label: 'BI-RADS 6', color: '#7A3496', group: '' },
|
||||
],
|
||||
};
|
||||
const BREAST_BIOPSY: Catalog = {
|
||||
groups: [
|
||||
{ id: 'benign', label: 'No maligno', color: '#42C29C' },
|
||||
{ id: 'malignant', label: 'Maligno', color: ROSE },
|
||||
],
|
||||
categories: [
|
||||
{ code: 'benign', label: 'Benigno', color: OLIVE, group: 'benign' },
|
||||
{ code: 'in_situ', label: 'Carcinoma in situ', color: '#9C42C2', group: 'malignant' },
|
||||
{ code: 'invasive', label: 'Carcinoma invasor', color: '#5C42C2', group: 'malignant' },
|
||||
],
|
||||
};
|
||||
|
||||
export const PAGES: Record<string, Page> = {
|
||||
tea: {
|
||||
anchor: 'M23_PACIENTES_EVALUADOS',
|
||||
kpis: [],
|
||||
opportunity: [
|
||||
{ kind: 'tea-summary' },
|
||||
{
|
||||
kind: 'boxes',
|
||||
cards: [
|
||||
{ measure: 'M26_DIAS_MCHAT_ADOS2', title: 'Días de M-CHAT a ADOS-2' },
|
||||
{ measure: 'M27_DIAS_ADOS2_DIAGNOSTICO', title: 'Días de ADOS-2 a diagnóstico' },
|
||||
{ measure: 'M25_DIAS_MCHAT_DIAGNOSTICO', title: 'Días de M-CHAT a diagnóstico positivo' },
|
||||
],
|
||||
},
|
||||
],
|
||||
clinical: [
|
||||
{
|
||||
kind: 'grid',
|
||||
figures: [
|
||||
{
|
||||
kind: 'counts',
|
||||
title: 'Pacientes evaluados por resultado diagnóstico',
|
||||
measure: 'M23_PACIENTES_EVALUADOS',
|
||||
axis: 'Conteo (paciente)',
|
||||
catalog: {
|
||||
groups: [],
|
||||
categories: [
|
||||
{ code: 'confirmed', label: 'Diagnóstico confirmado', color: OLIVE, group: '' },
|
||||
{ code: 'in_process', label: 'En proceso', color: '#B8433A', group: '' },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
kind: 'age-stack',
|
||||
title: 'Porcentaje de confirmación diagnóstica',
|
||||
measure: 'M24_CONFIRMACION_DIAGNOSTICO',
|
||||
names: ['Diagnóstico confirmado', 'En proceso'],
|
||||
},
|
||||
{
|
||||
kind: 'age-share',
|
||||
title: 'Porcentaje de pacientes con diagnóstico de TEA con EEG',
|
||||
measure: 'M21_DIAGNOSTICADOS_CON_EEG',
|
||||
names: ['% de pacientes con EEG', ''],
|
||||
},
|
||||
{
|
||||
kind: 'age-share',
|
||||
title: 'Porcentaje de pacientes con diagnóstico de TEA sin EEG',
|
||||
measure: 'M22_DIAGNOSTICADOS_SIN_EEG',
|
||||
names: ['% de pacientes sin EEG', ''],
|
||||
},
|
||||
{
|
||||
kind: 'counts',
|
||||
title: 'Casos por estatus',
|
||||
measure: 'M28_CASOS_POR_ESTADO',
|
||||
axis: 'Conteo (paciente)',
|
||||
catalog: {
|
||||
groups: [],
|
||||
categories: [
|
||||
{ code: 'mchat_only', label: 'Solo M-CHAT', color: '#B8433A', group: '' },
|
||||
{
|
||||
code: 'psychology',
|
||||
label: 'Hasta evaluación psicológica',
|
||||
color: '#42C29C',
|
||||
group: '',
|
||||
},
|
||||
{
|
||||
code: 'neuropediatrics',
|
||||
label: 'Hasta evaluación neuropediátrica',
|
||||
color: '#7184A2',
|
||||
group: '',
|
||||
},
|
||||
{ code: 'eeg', label: 'Con EEG', color: OLIVE, group: '' },
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
kind: 'counts',
|
||||
title: 'Calidad del EEG',
|
||||
measure: 'M29_CALIDAD_EEG',
|
||||
axis: 'Conteo (examen)',
|
||||
catalog: {
|
||||
groups: [],
|
||||
categories: [
|
||||
{ code: 'good', label: 'Bueno', color: OLIVE, group: '' },
|
||||
{ code: 'bad', label: 'No aceptable', color: '#B8433A', group: '' },
|
||||
{ code: 'not_analyzed', label: 'Sin analizar', color: '#C9CDD2', group: '' },
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
cama: {
|
||||
anchor: 'CAMA_BIRADS456_PACIENTE',
|
||||
kpis: [
|
||||
{
|
||||
measure: 'CAMA_BIRADS456_PACIENTE',
|
||||
title: 'Pacientes evaluadas con BI-RADS 4, 5 o 6',
|
||||
value: '{n} pacientes',
|
||||
note: 'Pacientes con mastografía BI-RADS 4, 5 o 6 en el periodo.',
|
||||
},
|
||||
{
|
||||
measure: 'CAMA_TASA_DETECCION_HISTOPATOLOGICA',
|
||||
title: 'Tasa de confirmación histopatológica',
|
||||
value: '{pct} %',
|
||||
note: '{num} de {den} biopsias con riesgo a carcinoma.',
|
||||
},
|
||||
{
|
||||
measure: 'CAMA_EU38A',
|
||||
title: 'Tiempo de toma de mastografía a interpretación radiológica',
|
||||
...CAMA_DAYS,
|
||||
},
|
||||
{
|
||||
measure: 'CAMA_DIAS_RESULTADO_DIAGNOSTICO',
|
||||
title: 'Tiempo de interpretación radiológica a diagnóstico',
|
||||
...CAMA_DAYS,
|
||||
},
|
||||
{
|
||||
title: 'Tiempo de diagnóstico a tratamiento',
|
||||
value: 'Indicador no disponible',
|
||||
note: PENDING,
|
||||
},
|
||||
],
|
||||
opportunity: [
|
||||
{
|
||||
kind: 'boxes',
|
||||
title: 'Tiempo de tamizaje a diagnóstico',
|
||||
subtitles: true,
|
||||
cards: [
|
||||
{
|
||||
measure: 'CAMA_EU38A',
|
||||
title: 'Tiempo de toma de mastografía a interpretación radiológica',
|
||||
},
|
||||
{
|
||||
measure: 'CAMA_DIAS_RESULTADO_DIAGNOSTICO',
|
||||
title: 'Tiempo de interpretación radiológica a diagnóstico',
|
||||
},
|
||||
{ title: 'Tiempo de interpretación radiológica a resultado de biopsia' },
|
||||
{ title: 'Tiempo de diagnóstico a tratamiento' },
|
||||
{ measure: 'CAMA_DIAS_TOMA_DIAGNOSTICO', title: 'Tiempo de tamizaje a diagnóstico' },
|
||||
],
|
||||
},
|
||||
],
|
||||
clinical: [
|
||||
{
|
||||
kind: 'figures',
|
||||
figures: [
|
||||
{
|
||||
kind: 'share-donut',
|
||||
title: 'Porcentaje de mastografías con resultado BI-RADS 4, 5 ó 6 en {p}',
|
||||
measure: 'CAMA_BIRADS456_MASTOGRAFIA',
|
||||
catalog: BIRADS,
|
||||
center: 'mastografías',
|
||||
},
|
||||
{
|
||||
kind: 'share-donut',
|
||||
title: 'Porcentaje de pacientes con resultados BI-RADS 4, 5 ó 6 en {p}',
|
||||
measure: 'CAMA_BIRADS456_PACIENTE',
|
||||
catalog: BIRADS,
|
||||
center: 'pacientes',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
kind: 'figures',
|
||||
title: 'Resultado histopatológico por categoría BI-RADS',
|
||||
figures: [
|
||||
{
|
||||
kind: 'rates',
|
||||
title: 'Por categoría BI-RADS, {p}',
|
||||
measure: 'CAMA_HISTOPATOLOGIA_BIRADS',
|
||||
stratum: 'birads',
|
||||
rows: BIRADS.categories,
|
||||
colored: true,
|
||||
positive: ['in_situ', 'invasive'],
|
||||
axis: 'Porcentaje con resultado maligno',
|
||||
},
|
||||
{
|
||||
kind: 'donut',
|
||||
title: 'Resultado de la biopsia, {p}',
|
||||
measure: 'CAMA_HISTOPATOLOGIA_BIRADS',
|
||||
catalog: BREAST_BIOPSY,
|
||||
center: 'con resultado',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
kind: 'card',
|
||||
measure: 'CAMA_CONFIRMACION_BIRADS45',
|
||||
title: 'Tasa de confirmación histopatológica',
|
||||
value: '{pct} %',
|
||||
note: '{num} de {den} mastografías BI-RADS 4 y 5 con reporte de biopsia.',
|
||||
},
|
||||
],
|
||||
},
|
||||
cacu: {
|
||||
anchor: 'CACU_EU7',
|
||||
kpis: [
|
||||
{
|
||||
measure: 'CACU_EU7',
|
||||
title: 'Pacientes evaluadas',
|
||||
value: '{n} pacientes',
|
||||
note: 'Pacientes con citología tomada en el periodo.',
|
||||
},
|
||||
{
|
||||
measure: 'CACU_EU_TIEMPO_REPORTE',
|
||||
title: 'Tiempo desde la toma de muestra al resultado',
|
||||
...CACU_DAYS,
|
||||
},
|
||||
{
|
||||
measure: 'CACU_DIAS_TOMA_DIAGNOSTICO',
|
||||
title: 'Tiempo de tamizaje a diagnóstico',
|
||||
...CACU_DAYS,
|
||||
},
|
||||
{
|
||||
measure: 'CACU_DIAS_TOMA_TRATAMIENTO',
|
||||
title: 'Tiempo de tamizaje a tratamiento',
|
||||
...CACU_DAYS,
|
||||
},
|
||||
{
|
||||
measure: 'CACU_DIAS_DIAGNOSTICO_TRATAMIENTO',
|
||||
title: 'Tiempo de diagnóstico a tratamiento',
|
||||
...CACU_DAYS,
|
||||
},
|
||||
],
|
||||
clinical: [
|
||||
{
|
||||
kind: 'route',
|
||||
title: 'Tiempos de la ruta del tamizaje',
|
||||
steps: [
|
||||
{ label: 'Resultado de citología', measure: 'CACU_EU_TIEMPO_REPORTE' },
|
||||
{ label: 'Resultado de colposcopía', measure: 'CACU_DIAS_TOMA_COLPOSCOPIA' },
|
||||
{ label: 'Resultado de biopsia', measure: 'CACU_DIAS_TOMA_BIOPSIA' },
|
||||
{ label: 'Diagnóstico', measure: 'CACU_DIAS_TOMA_DIAGNOSTICO' },
|
||||
],
|
||||
},
|
||||
{
|
||||
kind: 'figures',
|
||||
title: 'Distribución de resultados citológicos',
|
||||
figures: [
|
||||
{
|
||||
kind: 'donut',
|
||||
title: 'Distribución de resultados, {p}',
|
||||
measure: 'CACU_EU7',
|
||||
catalog: CYTOLOGY,
|
||||
center: 'pacientes',
|
||||
},
|
||||
{
|
||||
kind: 'scenario-bars',
|
||||
title: 'TOTAL por escenario clínico, {p}',
|
||||
measure: 'CACU_EU7',
|
||||
catalog: CYTOLOGY,
|
||||
stratum: 'follow_up_status',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
kind: 'figures',
|
||||
title: 'Tasa de confirmación histopatológica',
|
||||
figures: [
|
||||
{
|
||||
kind: 'rates',
|
||||
title: 'Por resultado de la citología, {p}',
|
||||
measure: 'CACU_CONFIRMACION_CITOLOGIA',
|
||||
stratum: 'result',
|
||||
rows: CYTOLOGY.categories.filter((c) => ['ASC-H', 'HSIL', 'CIS'].includes(c.code)),
|
||||
positive: ['HSIL', 'CIS', 'carcinoma'],
|
||||
axis: 'Verdaderos positivos (valor predictivo positivo)',
|
||||
},
|
||||
{
|
||||
kind: 'donut',
|
||||
title: 'Resultado de la biopsia, {p}',
|
||||
measure: 'CACU_CONFIRMACION_CITOLOGIA',
|
||||
catalog: BIOPSY,
|
||||
center: 'con biopsia',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
/** One panel of Trazabilidad (tests/fixtures/reference/<domain>/ui, tab "Trazabilidad"): a
|
||||
* measure month by month, as stacked counts by category, a percentage with its 95 % interval,
|
||||
* or a median with its quartiles. `group` heads a run of panels (TEA's "Tiempos del tamizaje"). */
|
||||
export interface HistoryPanel {
|
||||
title: string;
|
||||
measure: string;
|
||||
kind: 'stack' | 'percent' | 'median';
|
||||
/** stack: the categories, in the old order, with their names and colours */
|
||||
series?: { code: string; label: string; color: string }[];
|
||||
/** stack: the y axis */
|
||||
axis?: string;
|
||||
group?: string;
|
||||
}
|
||||
export interface History {
|
||||
panels: HistoryPanel[];
|
||||
/** the line's colour (percent and median) */
|
||||
line: string;
|
||||
/** how many of the latest months the tab opens with (none: from the first with data) */
|
||||
months?: number;
|
||||
}
|
||||
|
||||
const GREY = '#C9CDD2';
|
||||
const stack = (
|
||||
title: string,
|
||||
measure: string,
|
||||
axis: string,
|
||||
series: [string, string, string][],
|
||||
): HistoryPanel => ({
|
||||
title,
|
||||
measure,
|
||||
kind: 'stack',
|
||||
axis,
|
||||
series: series.map(([code, label, color]) => ({ code, label, color })),
|
||||
});
|
||||
const BIRADS_SERIES: [string, string, string][] = [
|
||||
['4A', 'BI-RADS 4A', '#C24269'],
|
||||
['4B', 'BI-RADS 4B', '#9C42C2'],
|
||||
['4C', 'BI-RADS 4C', '#5C42C2'],
|
||||
['5', 'BI-RADS 5', '#C2429C'],
|
||||
['6', 'BI-RADS 6', '#8E2F62'],
|
||||
['4', 'BI-RADS 4 (sin subcategoría)', '#7A3496'],
|
||||
];
|
||||
|
||||
export const HISTORY: Record<string, History> = {
|
||||
cacu: {
|
||||
line: '#6A8000',
|
||||
months: 5,
|
||||
panels: [
|
||||
stack('Distribución de resultados citológicos', 'CACU_EU7', 'Pacientes', [
|
||||
['NILM', 'Normal', '#9DBFE3'],
|
||||
['ASC-US', 'ASC-US', '#2F6DB3'],
|
||||
['LSIL', 'LIEBG', '#9C42C2'],
|
||||
['ASC-H', 'ASC-H', '#5C42C2'],
|
||||
['HSIL', 'LIEAG', '#C2429C'],
|
||||
['CIS', 'Carcinoma in situ', '#8E2F62'],
|
||||
['no_data', 'Sin dato', GREY],
|
||||
]),
|
||||
{ title: 'Pacientes con citología anómala', measure: 'IND1', kind: 'percent' },
|
||||
{ title: 'Tasa de detección histopatológica', measure: 'CACU_EU13', kind: 'percent' },
|
||||
stack(
|
||||
'Resultado de biopsia tras citología de alto grado',
|
||||
'CACU_CONFIRMACION_CITOLOGIA',
|
||||
'Pacientes',
|
||||
[
|
||||
['normal', 'Normal', '#9DBFE3'],
|
||||
['LSIL', 'LIEBG (CIN 1)', '#69C242'],
|
||||
['HSIL', 'LIEAG (CIN 2 y 3)', '#C24269'],
|
||||
['CIS', 'Carcinoma in situ', '#9C42C2'],
|
||||
['carcinoma', 'Carcinoma invasor', '#5C42C2'],
|
||||
['no_biopsy', 'Sin biopsia aún', GREY],
|
||||
['no_data', 'Biopsia sin grado', GREY],
|
||||
],
|
||||
),
|
||||
{
|
||||
title: 'Días de la toma de la citología a su resultado',
|
||||
measure: 'CACU_EU_TIEMPO_REPORTE',
|
||||
kind: 'median',
|
||||
},
|
||||
{
|
||||
title: 'Tiempo de tamizaje a diagnóstico',
|
||||
measure: 'CACU_DIAS_TOMA_DIAGNOSTICO',
|
||||
kind: 'median',
|
||||
},
|
||||
{
|
||||
title: 'Tiempo de tamizaje a tratamiento',
|
||||
measure: 'CACU_DIAS_TOMA_TRATAMIENTO',
|
||||
kind: 'median',
|
||||
},
|
||||
{
|
||||
title: 'Tiempo de diagnóstico a tratamiento',
|
||||
measure: 'CACU_DIAS_DIAGNOSTICO_TRATAMIENTO',
|
||||
kind: 'median',
|
||||
},
|
||||
{
|
||||
title: 'Riesgo CIN2+ por banda',
|
||||
measure: 'CACU_RIESGO_BANDA',
|
||||
kind: 'stack',
|
||||
axis: 'Pacientes',
|
||||
},
|
||||
],
|
||||
},
|
||||
cama: {
|
||||
line: '#9C42C2',
|
||||
panels: [
|
||||
{
|
||||
title: 'Días de la toma de la mastografía a su resultado',
|
||||
measure: 'CAMA_EU38A',
|
||||
kind: 'median',
|
||||
},
|
||||
{
|
||||
title: 'Días del resultado de la mastografía al diagnóstico',
|
||||
measure: 'CAMA_DIAS_RESULTADO_DIAGNOSTICO',
|
||||
kind: 'median',
|
||||
},
|
||||
{
|
||||
title: 'Días de tamizaje a diagnóstico',
|
||||
measure: 'CAMA_DIAS_TOMA_DIAGNOSTICO',
|
||||
kind: 'median',
|
||||
},
|
||||
stack(
|
||||
'Porcentaje de mastografías con resultado BI-RADS 4, 5 ó 6',
|
||||
'CAMA_BIRADS456_MASTOGRAFIA',
|
||||
'Mastografías',
|
||||
BIRADS_SERIES,
|
||||
),
|
||||
stack(
|
||||
'Pacientes con resultado BI-RADS 4, 5 ó 6',
|
||||
'CAMA_BIRADS456_PACIENTE',
|
||||
'Pacientes',
|
||||
BIRADS_SERIES,
|
||||
),
|
||||
stack('Resultado histopatológico', 'CAMA_HISTOPATOLOGIA_BIRADS', 'Pacientes', [
|
||||
['benign', 'Benigno', '#9DBFE3'],
|
||||
['in_situ', 'Carcinoma in situ', '#C24269'],
|
||||
['invasive', 'Carcinoma invasor', '#9C42C2'],
|
||||
['no_biopsy', 'Sin biopsia reportada', GREY],
|
||||
['no_data', 'Sin dato', GREY],
|
||||
]),
|
||||
{
|
||||
title: 'Tasa de confirmación histopatológica',
|
||||
measure: 'CAMA_CONFIRMACION_BIRADS45',
|
||||
kind: 'percent',
|
||||
},
|
||||
],
|
||||
},
|
||||
tea: {
|
||||
line: '#9C42C2',
|
||||
panels: [
|
||||
{
|
||||
group: 'Tiempos del tamizaje',
|
||||
title: 'Días de M-CHAT a ADOS-2',
|
||||
measure: 'M26_DIAS_MCHAT_ADOS2',
|
||||
kind: 'median',
|
||||
},
|
||||
{
|
||||
group: 'Tiempos del tamizaje',
|
||||
title: 'Días de ADOS-2 a diagnóstico',
|
||||
measure: 'M27_DIAS_ADOS2_DIAGNOSTICO',
|
||||
kind: 'median',
|
||||
},
|
||||
{
|
||||
group: 'Tiempos del tamizaje',
|
||||
title: 'Días de M-CHAT a diagnóstico positivo',
|
||||
measure: 'M25_DIAS_MCHAT_DIAGNOSTICO',
|
||||
kind: 'median',
|
||||
},
|
||||
stack('Progresión del proceso diagnóstico', 'M23_PACIENTES_EVALUADOS', 'Pacientes', [
|
||||
['confirmed', 'Diagnóstico confirmado', '#A8C243'],
|
||||
['in_process', 'En proceso', '#B8433A'],
|
||||
]),
|
||||
{
|
||||
title: 'Porcentaje de confirmación diagnóstica',
|
||||
measure: 'M24_CONFIRMACION_DIAGNOSTICO',
|
||||
kind: 'percent',
|
||||
},
|
||||
{
|
||||
title: 'Porcentaje de pacientes con diagnóstico de TEA con EEG',
|
||||
measure: 'M21_DIAGNOSTICADOS_CON_EEG',
|
||||
kind: 'percent',
|
||||
},
|
||||
{
|
||||
title: 'Porcentaje de pacientes con diagnóstico de TEA sin EEG',
|
||||
measure: 'M22_DIAGNOSTICADOS_SIN_EEG',
|
||||
kind: 'percent',
|
||||
},
|
||||
stack('Flujo del proceso diagnóstico y estudios de EEG', 'M28_CASOS_POR_ESTADO', 'Casos', [
|
||||
['mchat_only', 'Solo M-CHAT', '#B8433A'],
|
||||
['psychology', 'Hasta evaluación psicológica', '#42C29C'],
|
||||
['neuropediatrics', 'Hasta evaluación neuropediátrica', '#7184A2'],
|
||||
['eeg', 'Con EEG', '#A8C243'],
|
||||
]),
|
||||
stack('Calidad del EEG', 'M29_CALIDAD_EEG', 'Estudios de EEG', [
|
||||
['good', 'Bueno', '#A8C243'],
|
||||
['bad', 'No aceptable', '#B8433A'],
|
||||
['not_analyzed', 'Sin analizar', GREY],
|
||||
]),
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
import { matchesSearch, patientSearch } from './patient-search';
|
||||
|
||||
describe('patient search', () => {
|
||||
it('asks the API by identifier for one word with a digit, else by name', () => {
|
||||
expect(patientSearch(' IARM800101MNLBVR09 ')).toEqual({ identifier: 'IARM800101MNLBVR09' });
|
||||
expect(patientSearch('0451A')).toEqual({ identifier: '0451A' });
|
||||
expect(patientSearch('martha ibarra')).toEqual({ name: 'martha ibarra' });
|
||||
expect(patientSearch('')).toEqual({});
|
||||
});
|
||||
|
||||
it('matches in the browser by word starts, case and accents ignored', () => {
|
||||
const texts = ['IBARRA RIVERA MARTHA', 'd5a6a924-f2ad', 'N0183'];
|
||||
expect(matchesSearch('már riv', texts)).toBe(true);
|
||||
expect(matchesSearch('d5a6', texts)).toBe(true);
|
||||
expect(matchesSearch('n0183', texts)).toBe(true);
|
||||
expect(matchesSearch('arth', texts)).toBe(false);
|
||||
expect(matchesSearch('', texts)).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,83 @@
|
||||
import { Component, model, output, signal } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
|
||||
/** A search box's text as FHIR Patient search parameters: one word with a digit is an
|
||||
* identifier (a CURP or a record number); anything else is her name. */
|
||||
export function patientSearch(text: string): { name?: string; identifier?: string } {
|
||||
const t = text.trim();
|
||||
if (!t) return {};
|
||||
return /\d/.test(t) && !/\s/.test(t) ? { identifier: t } : { name: t };
|
||||
}
|
||||
|
||||
const fold = (s: string) => s.normalize('NFKD').replace(/\p{M}/gu, '').toLowerCase();
|
||||
|
||||
/** Whether a row matches the search in the browser (lists loaded whole): each word starts a
|
||||
* word of one of its texts (a name, an identifier, the pseudonymous id). */
|
||||
export function matchesSearch(text: string, texts: (string | undefined)[]): boolean {
|
||||
const words = fold(text).split(/\s+/).filter(Boolean);
|
||||
if (!words.length) return true;
|
||||
const known = texts.filter((t): t is string => !!t).map((t) => fold(t).split(/\s+/));
|
||||
return known.some((parts) => words.every((w) => parts.some((p) => p.startsWith(w))));
|
||||
}
|
||||
|
||||
/** "Buscar paciente": applied on Enter or the search button, cleared with the cross. */
|
||||
@Component({
|
||||
selector: 'app-patient-search',
|
||||
imports: [FormsModule, MatButtonModule, MatFormFieldModule, MatIconModule, MatInputModule],
|
||||
template: `
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic" class="patient-search">
|
||||
<mat-label>Buscar paciente</mat-label>
|
||||
<input
|
||||
matInput
|
||||
type="search"
|
||||
name="patient-search"
|
||||
[placeholder]="hint"
|
||||
[ngModel]="draft()"
|
||||
[ngModelOptions]="{ standalone: true }"
|
||||
(ngModelChange)="draft.set($event)"
|
||||
(keydown.enter)="$event.preventDefault(); apply()"
|
||||
/>
|
||||
@if (value()) {
|
||||
<button
|
||||
mat-icon-button
|
||||
matSuffix
|
||||
type="button"
|
||||
aria-label="Limpiar búsqueda"
|
||||
(click)="clear()"
|
||||
>
|
||||
<mat-icon>close</mat-icon>
|
||||
</button>
|
||||
} @else {
|
||||
<button mat-icon-button matSuffix type="button" aria-label="Buscar" (click)="apply()">
|
||||
<mat-icon>search</mat-icon>
|
||||
</button>
|
||||
}
|
||||
</mat-form-field>
|
||||
`,
|
||||
styles: `
|
||||
.patient-search {
|
||||
min-width: 18rem;
|
||||
}
|
||||
`,
|
||||
})
|
||||
export class PatientSearch {
|
||||
/** The search as applied. */
|
||||
readonly value = model('');
|
||||
readonly searched = output<string>();
|
||||
protected readonly draft = signal('');
|
||||
protected readonly hint = 'Nombre, CURP o expediente';
|
||||
|
||||
protected apply(): void {
|
||||
const text = this.draft().trim();
|
||||
this.value.set(text);
|
||||
this.searched.emit(text);
|
||||
}
|
||||
protected clear(): void {
|
||||
this.draft.set('');
|
||||
this.apply();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { Component, input } from '@angular/core';
|
||||
import { Component, computed, input } from '@angular/core';
|
||||
import type { Measure } from 'fhir/r4';
|
||||
import { DOMAINS } from '../app';
|
||||
import type { Domain } from '../api/models/domain';
|
||||
import { code, label } from '../fhir';
|
||||
import { periodTypes, STRATA } from './measures';
|
||||
|
||||
@@ -14,60 +16,120 @@ const IMPROVEMENT: Record<string, string> = {
|
||||
};
|
||||
const PERIODS: Record<string, string> = { semester: 'Semestral', month: 'Mensual' };
|
||||
|
||||
/** What each measure is: how it scores, which way is better, its periods and strata. */
|
||||
/** "Datos y definiciones" as the old tab: the domain's information, then its catalog, each
|
||||
* indicator opening to what it is (how it scores, which way is better, its periods and
|
||||
* strata). */
|
||||
@Component({
|
||||
selector: 'app-tab-definiciones',
|
||||
template: `
|
||||
@if (domain() === 'tea') {
|
||||
<section class="card">
|
||||
<h2>Periodicidades</h2>
|
||||
<dl>
|
||||
@for (m of measures(); track m.id) {
|
||||
<dt>{{ m.title }}</dt>
|
||||
<dd>{{ types(m) || '—' }}</dd>
|
||||
}
|
||||
</dl>
|
||||
</section>
|
||||
}
|
||||
<table class="plain card">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Indicador</th>
|
||||
<th>Clave</th>
|
||||
<th>Cálculo</th>
|
||||
<th>Mejora</th>
|
||||
<th>Periodos</th>
|
||||
<th>Estratos</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (m of measures(); track m.id) {
|
||||
<tr>
|
||||
<td>{{ m.title }}</td>
|
||||
<td>
|
||||
<code>{{ m.name }}</code> v{{ m.version }}
|
||||
</td>
|
||||
<td>{{ scoring[code(m.scoring) ?? ''] }}</td>
|
||||
<td>{{ improvement[code(m.improvementNotation) ?? ''] ?? '—' }}</td>
|
||||
<td>{{ types(m) }}</td>
|
||||
<td>{{ strata(m) }}</td>
|
||||
</tr>
|
||||
<section class="card">
|
||||
<h2>Datos y definiciones de {{ domainName() }}</h2>
|
||||
<section aria-labelledby="domain-info-title">
|
||||
<h3 id="domain-info-title">Información del dominio</h3>
|
||||
@if (domain() === 'cacu') {
|
||||
<p>
|
||||
Pacientes evaluadas incluye a las pacientes con citología tomada en el periodo cuyo
|
||||
espécimen fue insatisfactorio.
|
||||
</p>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
@if (available().length) {
|
||||
<p>Periodicidad disponible: {{ available().join(', ') }}.</p>
|
||||
} @else {
|
||||
<p>Periodicidad: pendiente de información.</p>
|
||||
}
|
||||
</section>
|
||||
<section aria-labelledby="definitions-catalog-title">
|
||||
<h3 id="definitions-catalog-title">Catálogo de indicadores</h3>
|
||||
<p>Consulta las gráficas disponibles y la periodicidad de cada indicador.</p>
|
||||
@for (m of measures(); track m.id) {
|
||||
<details>
|
||||
<summary>{{ m.title || 'Nombre pendiente de publicación' }}</summary>
|
||||
<div class="indicator-detail">
|
||||
@if (m.description) {
|
||||
<p>{{ m.description }}</p>
|
||||
}
|
||||
<h4>Cálculo</h4>
|
||||
<p>
|
||||
{{ scoring[code(m.scoring) ?? ''] }}
|
||||
@if (improvement[code(m.improvementNotation) ?? '']; as better) {
|
||||
· {{ better }}
|
||||
}
|
||||
</p>
|
||||
<h4>Tipos de periodo admitidos</h4>
|
||||
@if (types(m).length) {
|
||||
<ul>
|
||||
@for (t of types(m); track t) {
|
||||
<li>{{ t }}</li>
|
||||
}
|
||||
</ul>
|
||||
} @else {
|
||||
<p>Pendiente de información.</p>
|
||||
}
|
||||
<h4>Estratos</h4>
|
||||
<p>{{ strata(m) }}</p>
|
||||
<p class="muted">
|
||||
Clave <code>{{ m.name }}</code> · versión {{ m.version }}
|
||||
</p>
|
||||
</div>
|
||||
</details>
|
||||
} @empty {
|
||||
<p role="status">
|
||||
No hay indicadores disponibles en el catálogo. Las definiciones están pendientes de
|
||||
información.
|
||||
</p>
|
||||
}
|
||||
</section>
|
||||
</section>
|
||||
`,
|
||||
styles: `
|
||||
:host {
|
||||
display: block;
|
||||
padding-top: 16px;
|
||||
}
|
||||
.card {
|
||||
background: var(--mat-sys-surface);
|
||||
border: 1px solid var(--mat-sys-outline-variant);
|
||||
border-radius: 12px;
|
||||
padding: 16px 20px;
|
||||
}
|
||||
h2,
|
||||
h3 {
|
||||
font-size: 20px;
|
||||
font-weight: 500;
|
||||
}
|
||||
h4 {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
margin: 12px 0 4px;
|
||||
}
|
||||
details {
|
||||
border-bottom: 1px solid var(--mat-sys-outline-variant);
|
||||
padding: 8px 0;
|
||||
}
|
||||
summary {
|
||||
cursor: pointer;
|
||||
font-weight: 500;
|
||||
}
|
||||
.indicator-detail {
|
||||
padding: 4px 0 8px 16px;
|
||||
}
|
||||
`,
|
||||
styles: ':host { display: block; padding-top: 16px; overflow-x: auto; }',
|
||||
})
|
||||
export class TabDefiniciones {
|
||||
readonly domain = input<string>();
|
||||
readonly domain = input.required<string>();
|
||||
readonly measures = input.required<Measure[]>();
|
||||
protected readonly scoring = SCORING;
|
||||
protected readonly improvement = IMPROVEMENT;
|
||||
protected readonly code = code;
|
||||
protected types(m: Measure): string {
|
||||
return periodTypes(m)
|
||||
.map((p) => PERIODS[p] ?? p)
|
||||
.join(', ');
|
||||
protected readonly domainName = computed(
|
||||
() => DOMAINS[this.domain() as Domain]?.toLocaleLowerCase('es-MX') ?? this.domain(),
|
||||
);
|
||||
/** The periodicities any of its indicators admits. */
|
||||
protected readonly available = computed(() =>
|
||||
[...new Set(this.measures().flatMap((m) => periodTypes(m)))].map((p) => PERIODS[p] ?? p),
|
||||
);
|
||||
protected types(m: Measure): string[] {
|
||||
return periodTypes(m).map((p) => PERIODS[p] ?? p);
|
||||
}
|
||||
protected strata(m: Measure): string {
|
||||
const names = (m.group?.[0]?.stratifier ?? []).map((s) => code(s.code) ?? label(s.code));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<div class="filters card">
|
||||
<h2 class="filters-title">Filtros</h2>
|
||||
<div class="field">
|
||||
<span class="label">Intervalo de análisis</span>
|
||||
<mat-button-toggle-group
|
||||
@@ -14,7 +15,7 @@
|
||||
<mat-label>Periodo seleccionado</mat-label>
|
||||
<mat-select [value]="chosen()" (selectionChange)="chosen.set($event.value)">
|
||||
@for (p of options(); track p) {
|
||||
<mat-option [value]="p">{{ label(p) }}</mat-option>
|
||||
<mat-option [value]="p">{{ p }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
@@ -25,56 +26,207 @@
|
||||
>
|
||||
Aplicar
|
||||
</button>
|
||||
<span class="print-only"
|
||||
>Intervalo de análisis: {{ type() === 'month' ? 'Mensual' : 'Semestral' }}</span
|
||||
>
|
||||
@if (chosen(); as selected) {
|
||||
<span class="print-only">Periodo seleccionado: {{ label(selected) }}</span>
|
||||
}
|
||||
@if (applied(); as p) {
|
||||
<span class="muted applied">Mostrando {{ label(p) }}</span>
|
||||
}
|
||||
</div>
|
||||
|
||||
@if (reports.isLoading()) {
|
||||
<p class="muted">Calculando…</p>
|
||||
<app-loading what="los indicadores" text="Calculando los indicadores…" />
|
||||
}
|
||||
|
||||
@if (domain() === 'tea') {
|
||||
<h2>Indicadores de oportunidad</h2>
|
||||
<p>{{ opportunity() }}</p>
|
||||
<div class="clinical">
|
||||
@for (item of teaFigures(); track item.measure.id) {
|
||||
<mat-card appearance="outlined" class="clinical-card" [attr.data-measure]="item.measure.name">
|
||||
<mat-card-header>
|
||||
<mat-card-title>{{ item.measure.title }}</mat-card-title>
|
||||
<mat-card-subtitle
|
||||
>{{ score(item.measure) }} · {{ detail(item.measure) }}</mat-card-subtitle
|
||||
>
|
||||
<app-card-actions [measures]="[item.measure]" />
|
||||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
@for (f of item.figures; track f.title) {
|
||||
<h3 class="figure-title">{{ f.title }}</h3>
|
||||
<app-plot [figure]="f.figure" [height]="320" />
|
||||
} @empty {
|
||||
<p class="muted">Sin datos en el periodo.</p>
|
||||
}
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
}
|
||||
@if (reports.error()) {
|
||||
<div class="load-error" role="alert">
|
||||
<p>No se obtuvieron los indicadores del periodo.</p>
|
||||
<button mat-stroked-button (click)="reports.reload()">Reintentar</button>
|
||||
</div>
|
||||
}
|
||||
@if (page(); as pg) {
|
||||
@if (applied(); as period) {
|
||||
<section class="card opportunity" aria-labelledby="opportunity-title">
|
||||
<div class="section-head">
|
||||
<h2 id="opportunity-title">Indicadores de oportunidad</h2>
|
||||
<span class="period">Periodo {{ period }}</span>
|
||||
</div>
|
||||
<div class="kpis">
|
||||
@for (k of pg.kpis; track k.title) {
|
||||
<mat-card appearance="outlined" class="kpi" [attr.data-measure]="k.measure ?? null">
|
||||
<mat-card-content>
|
||||
<h3 class="kpi-title">{{ k.title }}</h3>
|
||||
@if (reports.isLoading() && k.measure) {
|
||||
<app-loading [what]="k.title.toLowerCase()" />
|
||||
} @else {
|
||||
<div class="kpi-value" [class.pending]="!k.measure">
|
||||
@let v = kpiParts(kpiValue(k));
|
||||
{{ v[0] }}
|
||||
@if (v[1]) {
|
||||
<span class="kpi-qualifier">{{ v[1] }}</span>
|
||||
}
|
||||
</div>
|
||||
<div class="kpi-detail">{{ kpiNote(k) }}</div>
|
||||
}
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
}
|
||||
</div>
|
||||
@for (section of pg.opportunity ?? []; track $index) {
|
||||
<ng-container
|
||||
*ngTemplateOutlet="sectionView; context: { $implicit: section, period: period }"
|
||||
/>
|
||||
}
|
||||
</section>
|
||||
|
||||
<section class="card clinical-page" aria-labelledby="clinical-title">
|
||||
<h2 id="clinical-title">Indicadores clínicos</h2>
|
||||
@for (section of pg.clinical; track $index) {
|
||||
<ng-container
|
||||
*ngTemplateOutlet="sectionView; context: { $implicit: section, period: period }"
|
||||
/>
|
||||
}
|
||||
</section>
|
||||
}
|
||||
|
||||
<ng-template #sectionView let-section let-period="period">
|
||||
@switch (section.kind) {
|
||||
@case ('route') {
|
||||
<h3 class="route-title">{{ section.title }}</h3>
|
||||
@if (reports.isLoading()) {
|
||||
<app-loading what="los tiempos de la ruta" [figure]="true" />
|
||||
} @else if (routeOf(section); as fig) {
|
||||
<app-plot [figure]="fig" [height]="300" />
|
||||
} @else {
|
||||
<p class="state">Sin tiempos publicados en el periodo.</p>
|
||||
}
|
||||
}
|
||||
@case ('tea-summary') {
|
||||
@if (teaSummary(); as t) {
|
||||
<mat-card appearance="outlined" class="summary">
|
||||
<mat-card-content>
|
||||
<h2 class="box-title">Resumen</h2>
|
||||
<p>
|
||||
Al cierre del periodo <mark>{{ period }}</mark>, se evaluaron
|
||||
<mark>{{ t.evaluated }}</mark> niños entre 16 y 36 meses;
|
||||
<mark>{{ t.mchatOnly }}</mark> únicamente tienen M-CHAT,
|
||||
<mark>{{ t.psychology }}</mark> hasta la evaluación psicológica y
|
||||
<mark>{{ t.neuropediatrics }}</mark> presentan evaluación neuropediátrica. En este
|
||||
periodo el <mark>{{ t.confirmed }}</mark> de los pacientes tiene diagnóstico
|
||||
confirmado de TEA (CIE-10 F84.0). Las ventanas de tiempo<sup>*</sup> de tamizaje
|
||||
son: <mark>{{ t.toAdos }}</mark> de M-CHAT (psicología) a ADOS-2,
|
||||
<mark>{{ t.toDiagnosis }}</mark> de ADOS-2 a diagnóstico. El tiempo<sup>*</sup> de
|
||||
tamizaje completo de M-CHAT a diagnóstico fue de <mark>{{ t.whole }}</mark>.
|
||||
</p>
|
||||
<p>
|
||||
De los <mark>{{ t.diagnosed }}</mark> niños con diagnóstico confirmado en este
|
||||
periodo, <mark>{{ t.eeg }}</mark> presentan estudio de EEG y faltan
|
||||
<mark>{{ t.missing }}</mark> por realizarlo. <mark>{{ t.unusable }}</mark> estudios
|
||||
de EEG no son aceptables para un análisis.
|
||||
</p>
|
||||
<p class="state">*tomando la mediana de los tiempos</p>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
} @else if (reports.isLoading()) {
|
||||
<app-loading what="el resumen del periodo" />
|
||||
}
|
||||
}
|
||||
@case ('grid') {
|
||||
<div class="grid-figures">
|
||||
@for (f of section.figures; track f.title) {
|
||||
<mat-card appearance="outlined" class="figure-card" [attr.data-figure]="f.kind">
|
||||
<mat-card-content>
|
||||
<h2 class="box-title">{{ f.title }}</h2>
|
||||
<p class="state">Filtro general aplicado: {{ period }}</p>
|
||||
@if (reports.isLoading()) {
|
||||
<app-loading what="la figura" [figure]="true" />
|
||||
} @else if (figureOf(f); as fig) {
|
||||
<app-plot [figure]="fig" [height]="320" />
|
||||
} @else {
|
||||
<div class="empty-figure">Sin datos publicados</div>
|
||||
}
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
@case ('boxes') {
|
||||
@if (section.title) {
|
||||
<h3 class="boxes-title">{{ section.title }}</h3>
|
||||
}
|
||||
<div class="box-grid" [class.standalone]="!section.title">
|
||||
@for (b of section.cards; track b.title) {
|
||||
<mat-card
|
||||
appearance="outlined"
|
||||
class="box-card"
|
||||
[attr.data-measure]="b.measure ?? null"
|
||||
>
|
||||
<mat-card-content>
|
||||
<h2 class="box-title">{{ b.title }}</h2>
|
||||
@if (!b.measure) {
|
||||
<p class="state">{{ pending }}</p>
|
||||
<div class="empty-figure">Sin datos publicados</div>
|
||||
} @else {
|
||||
<p class="state">Filtro general aplicado: {{ period }}</p>
|
||||
@if (section.subtitles) {
|
||||
<h2 class="box-subtitle">{{ measureTitle(b.measure) }}</h2>
|
||||
<p class="state">Figura: Caja de cuartiles</p>
|
||||
}
|
||||
@if (reports.isLoading()) {
|
||||
<app-loading what="la figura" [figure]="true" />
|
||||
} @else if (boxOf(b.measure); as fig) {
|
||||
<app-plot [figure]="fig" [height]="320" />
|
||||
} @else {
|
||||
<div class="empty-figure">Sin datos publicados</div>
|
||||
}
|
||||
}
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
@case ('card') {
|
||||
<mat-card appearance="outlined" class="kpi closing" [attr.data-measure]="section.measure">
|
||||
<mat-card-content>
|
||||
<h3 class="kpi-title">{{ section.title }}</h3>
|
||||
<div class="kpi-value">
|
||||
@let w = kpiParts(kpiValue(section));
|
||||
{{ w[0] }}
|
||||
@if (w[1]) {
|
||||
<span class="kpi-qualifier">{{ w[1] }}</span>
|
||||
}
|
||||
</div>
|
||||
<div class="kpi-detail">{{ kpiNote(section) }}</div>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
}
|
||||
@default {
|
||||
<mat-card appearance="outlined" class="figure-card">
|
||||
<mat-card-content>
|
||||
@if (section.title) {
|
||||
<h2 class="figure-card-title">{{ section.title }}</h2>
|
||||
}
|
||||
<div class="figure-row">
|
||||
@for (f of section.figures; track f.title) {
|
||||
<div class="figure" [attr.data-figure]="f.kind">
|
||||
<h3 [class.light]="f.kind === 'share-donut'">{{ titled(f.title) }}</h3>
|
||||
@if (reports.isLoading()) {
|
||||
<app-loading what="la figura" [figure]="true" />
|
||||
} @else if (figureOf(f); as fig) {
|
||||
<app-plot [figure]="fig" [height]="360" />
|
||||
} @else {
|
||||
<p class="state">Sin datos en el periodo.</p>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
}
|
||||
}
|
||||
</ng-template>
|
||||
} @else {
|
||||
@if (kpis().length) {
|
||||
<h2>Indicadores de oportunidad</h2>
|
||||
<div class="kpis">
|
||||
@for (m of kpis(); track m.id) {
|
||||
<mat-card appearance="outlined" class="kpi" [attr.data-measure]="m.name">
|
||||
<mat-card-header>
|
||||
<div class="kpi-title">{{ m.title }}</div>
|
||||
<app-card-actions [measures]="[m]" />
|
||||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
<div class="kpi-title">{{ m.title }}</div>
|
||||
<div class="kpi-value">{{ score(m) }}</div>
|
||||
<div class="kpi-detail muted">{{ detail(m) }}</div>
|
||||
</mat-card-content>
|
||||
@@ -87,10 +239,6 @@
|
||||
<mat-card appearance="outlined" class="route">
|
||||
<mat-card-header>
|
||||
<mat-card-title>Ruta del tamizaje</mat-card-title>
|
||||
<app-card-actions [measures]="routeMeasures()" />
|
||||
<span class="print-only">
|
||||
{{ routeView() === 'sample' ? 'Acumulado desde la toma' : 'Por pasos' }}
|
||||
</span>
|
||||
<mat-button-toggle-group
|
||||
[value]="routeView()"
|
||||
(change)="routeView.set($event.value)"
|
||||
|
||||
@@ -61,6 +61,14 @@ h2 {
|
||||
font-size: 2rem;
|
||||
font-weight: 500;
|
||||
margin: var(--space-2) 0;
|
||||
line-height: 1.15;
|
||||
}
|
||||
|
||||
.kpi-qualifier {
|
||||
display: block;
|
||||
font-size: 14px;
|
||||
font-weight: 400;
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
.kpi-detail {
|
||||
@@ -97,3 +105,203 @@ h2 {
|
||||
font-weight: 500;
|
||||
margin: var(--space-3) 0 0;
|
||||
}
|
||||
|
||||
/* The old app's page: white sections with a title, cards inside. */
|
||||
.card.opportunity,
|
||||
.card.clinical-page {
|
||||
background: var(--color-surface);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 8px;
|
||||
margin-bottom: 24px;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.section-head {
|
||||
align-items: baseline;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
|
||||
.period {
|
||||
color: var(--color-text-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.card h2 {
|
||||
font-size: 20px;
|
||||
font-weight: 500;
|
||||
margin: 0 0 20px;
|
||||
}
|
||||
|
||||
h3.kpi-title {
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
margin: 0;
|
||||
min-height: 2.6em;
|
||||
}
|
||||
|
||||
.kpi-detail {
|
||||
color: var(--color-text-secondary);
|
||||
}
|
||||
|
||||
h3.route-title {
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
margin: 24px 0 8px;
|
||||
}
|
||||
|
||||
.figure-card {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
h2.figure-card-title {
|
||||
font-size: 18px;
|
||||
font-weight: 500;
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
|
||||
.figure-row {
|
||||
display: grid;
|
||||
gap: 24px;
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
@media (min-width: 1100px) {
|
||||
.figure-row {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
.figure h3 {
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
|
||||
.state {
|
||||
color: var(--color-text-secondary);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.filters {
|
||||
background: var(--color-surface);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 8px;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
h2.filters-title {
|
||||
flex-basis: 100%;
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
h3.boxes-title {
|
||||
font-size: 18px;
|
||||
font-weight: 500;
|
||||
margin: 24px 0 12px;
|
||||
}
|
||||
|
||||
.box-grid {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
@media (min-width: 1000px) {
|
||||
.box-grid {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
h2.box-title {
|
||||
font-size: 18px;
|
||||
font-weight: 500;
|
||||
margin: 0 0 4px;
|
||||
}
|
||||
|
||||
h2.box-subtitle {
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
margin: 8px 0 0;
|
||||
}
|
||||
|
||||
.empty-figure {
|
||||
align-items: center;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 8px;
|
||||
color: var(--color-text-secondary);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
min-height: 120px;
|
||||
}
|
||||
|
||||
.kpi-value.pending {
|
||||
font-size: 14px;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.figure h3.light {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.kpi.closing {
|
||||
margin-top: 24px;
|
||||
}
|
||||
|
||||
.summary {
|
||||
margin-bottom: 24px;
|
||||
|
||||
p {
|
||||
font-size: 20px;
|
||||
line-height: 2.1;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
p.state {
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
mark {
|
||||
background: #f1f5df;
|
||||
border: 1px solid #d8e3a8;
|
||||
border-radius: 4px;
|
||||
font-weight: 700;
|
||||
padding: 1px 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.grid-figures {
|
||||
display: grid;
|
||||
gap: 24px;
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
@media (min-width: 1100px) {
|
||||
.grid-figures {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1000px) {
|
||||
.box-grid.standalone {
|
||||
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
.load-error {
|
||||
align-items: center;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
margin-bottom: 16px;
|
||||
padding: 12px 16px;
|
||||
|
||||
p {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,28 @@
|
||||
import { Component, computed, effect, inject, input, resource, signal } from '@angular/core';
|
||||
import { NgTemplateOutlet } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatButtonToggleModule } from '@angular/material/button-toggle';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import type { Measure, MeasureReport } from 'fhir/r4';
|
||||
import { CardActions } from '../card-actions';
|
||||
import { Fhir, resources } from '../fhir';
|
||||
import { Figure, Plot } from '../plot';
|
||||
import { LAYOUTS } from './layout';
|
||||
import {
|
||||
boxes,
|
||||
ageShare,
|
||||
ageStack,
|
||||
boxFigure,
|
||||
countBars,
|
||||
fill,
|
||||
nestedDonut,
|
||||
rateDots,
|
||||
routeFigure,
|
||||
scenarioBars,
|
||||
shareDonut,
|
||||
} from './figures';
|
||||
import { FigureSpec, Kpi, PAGES, Section } from './pages';
|
||||
import {
|
||||
detail,
|
||||
donut,
|
||||
formatScore,
|
||||
@@ -21,19 +33,20 @@ import {
|
||||
PeriodType,
|
||||
reading,
|
||||
Reading,
|
||||
Ring,
|
||||
scoring,
|
||||
STRATA,
|
||||
strataBars,
|
||||
} from './measures';
|
||||
import { Loading } from '../loading';
|
||||
|
||||
/** The period's indicators: the timeliness KPIs, the screening route, and a card per
|
||||
* clinical measure with its figures. */
|
||||
@Component({
|
||||
selector: 'app-tab-indicadores',
|
||||
imports: [
|
||||
CardActions,
|
||||
Loading,
|
||||
FormsModule,
|
||||
NgTemplateOutlet,
|
||||
MatButtonModule,
|
||||
MatButtonToggleModule,
|
||||
MatCardModule,
|
||||
@@ -58,6 +71,9 @@ export class TabIndicadores {
|
||||
protected readonly layout = computed(
|
||||
() => LAYOUTS[this.domain()] ?? { kpis: [], route: [], anchor: '' },
|
||||
);
|
||||
protected readonly pending = 'Indicador no publicado en el catálogo institucional.';
|
||||
/** The old app's page for this domain, when it is rebuilt as it was (else today's). */
|
||||
protected readonly page = computed(() => PAGES[this.domain()]);
|
||||
private readonly byName = computed(() => new Map(this.measures().map((m) => [m.name!, m])));
|
||||
protected readonly kpis = computed(() =>
|
||||
this.layout()
|
||||
@@ -76,7 +92,7 @@ export class TabIndicadores {
|
||||
private readonly latest = resource({
|
||||
params: () => ({
|
||||
domain: this.domain(),
|
||||
anchor: this.byName().get(this.layout().anchor) ?? this.measures()[0],
|
||||
anchor: this.byName().get(this.page()?.anchor ?? this.layout().anchor) ?? this.measures()[0],
|
||||
all: this.options(),
|
||||
}),
|
||||
loader: async ({ params }) => {
|
||||
@@ -109,6 +125,12 @@ export class TabIndicadores {
|
||||
},
|
||||
});
|
||||
|
||||
/** The period's readings; none while they load or when reading them failed (an errored
|
||||
* resource throws on `value()`). */
|
||||
protected loaded(): Map<string, Reading | undefined> | undefined {
|
||||
return this.reports.hasValue() ? this.reports.value() : undefined;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const latest = this.latest.value();
|
||||
@@ -122,7 +144,7 @@ export class TabIndicadores {
|
||||
protected readonly label = periodLabel;
|
||||
protected readonly strataNames = STRATA;
|
||||
protected r(m: Measure): Reading | undefined {
|
||||
return this.reports.value()?.get(m.name!);
|
||||
return this.loaded()?.get(m.name!);
|
||||
}
|
||||
protected score(m: Measure): string {
|
||||
return formatScore(m, this.r(m));
|
||||
@@ -136,14 +158,6 @@ export class TabIndicadores {
|
||||
this.chosen.set(this.options()[0]);
|
||||
}
|
||||
|
||||
protected readonly routeMeasures = computed(() => {
|
||||
const view = this.routeView();
|
||||
const measures = this.layout()
|
||||
.route.map((step) => this.byName().get(view === 'sample' ? step.fromSample : step.fromStep))
|
||||
.filter((measure) => !!measure);
|
||||
return [...new Set(measures)];
|
||||
});
|
||||
|
||||
protected readonly route = computed<Figure>(() => {
|
||||
const view = this.routeView();
|
||||
return medians(
|
||||
@@ -157,16 +171,14 @@ export class TabIndicadores {
|
||||
/** Each clinical card's figures, built once per loaded period. */
|
||||
protected readonly figureSets = computed(
|
||||
() =>
|
||||
new Map(
|
||||
this.clinical().map((m) => [m.name!, this.build(m, this.reports.value()?.get(m.name!))]),
|
||||
),
|
||||
new Map(this.clinical().map((m) => [m.name!, this.build(m, this.loaded()?.get(m.name!))])),
|
||||
);
|
||||
|
||||
/** A clinical card's figures: the overall split, then one per stratum. */
|
||||
private build(m: Measure, r: Reading | undefined): { title: string; figure: Figure }[] {
|
||||
if (!r || !(r.populations['initial-population'] ?? 0)) return [];
|
||||
const strata = Object.keys(r.strata).filter(
|
||||
(s) => s !== 'category' && Object.keys(r.strata[s]).length,
|
||||
(s) => s !== 'category' && !s.includes('-') && Object.keys(r.strata[s]).length,
|
||||
);
|
||||
const kind = scoring(m);
|
||||
if (kind === 'continuous-variable')
|
||||
@@ -179,63 +191,103 @@ export class TabIndicadores {
|
||||
})),
|
||||
];
|
||||
}
|
||||
protected readonly opportunity = computed(() => {
|
||||
const [m26, m27, m25] = this.kpis()
|
||||
.slice(0, 3)
|
||||
.map((m) => {
|
||||
const score = this.r(m)?.score;
|
||||
return score === undefined ? '—' : this.score(m);
|
||||
});
|
||||
return `La mediana del tiempo del M-CHAT al ADOS-2 fue de ${m26 ?? '—'}, del ADOS-2 a la valoración neuropediátrica de ${m27 ?? '—'} y del M-CHAT al diagnóstico positivo de ${m25 ?? '—'}.`;
|
||||
});
|
||||
|
||||
protected readonly teaFigures = computed(() =>
|
||||
this.kpis().map((measure) => {
|
||||
const r = this.r(measure);
|
||||
const figures: { title: string; figure: Figure }[] = [];
|
||||
if (!r || !r.populations['initial-population']) return { measure, figures };
|
||||
if (scoring(measure) === 'continuous-variable') {
|
||||
const figure = boxes([{ label: measure.title ?? '', r }]);
|
||||
if (figure.data.length) figures.push({ title: 'Mediana y cuartiles', figure });
|
||||
} else if (measure.name === 'M24_CONFIRMACION_DIAGNOSTICO') {
|
||||
const bySex: Reading['strata'][string] = {};
|
||||
const outer: Ring = { labels: [], values: [] };
|
||||
const cells = Object.entries(r.strata['age_sex'] ?? {}).sort(
|
||||
([a], [b]) => a.split('|')[1].localeCompare(b.split('|')[1]) || a.localeCompare(b),
|
||||
);
|
||||
for (const [value, counts] of cells) {
|
||||
const [age, sex] = value.split('|');
|
||||
const total = (bySex[sex] ??= { denominator: 0, numerator: 0 });
|
||||
total['denominator'] += counts['denominator'] ?? 0;
|
||||
total['numerator'] += counts['numerator'] ?? 0;
|
||||
outer.labels.push(`${name(sex)} · ${name(age)}`);
|
||||
outer.values.push(counts['denominator'] ?? 0);
|
||||
}
|
||||
const inner: Ring = {
|
||||
labels: Object.keys(bySex).map(name),
|
||||
values: Object.values(bySex).map((c) => c['denominator']),
|
||||
};
|
||||
figures.push(
|
||||
{ title: 'Por grupo de edad', figure: strataBars(measure, r, 'age_group') },
|
||||
{
|
||||
title: 'Por sexo',
|
||||
figure: strataBars(measure, { ...r, strata: { sex: bySex } }, 'sex'),
|
||||
},
|
||||
{
|
||||
title: 'Distribución por sexo',
|
||||
figure: donut(measure, r, 'category', undefined, inner),
|
||||
},
|
||||
{
|
||||
title: 'Distribución por sexo y grupo de edad',
|
||||
figure: donut(measure, r, 'category', inner, outer),
|
||||
},
|
||||
);
|
||||
} else {
|
||||
figures.push({ title: 'Distribución', figure: donut(measure, r) });
|
||||
}
|
||||
return { measure, figures };
|
||||
}),
|
||||
);
|
||||
|
||||
protected readonly name = name;
|
||||
|
||||
/** A measure's reading in the applied period, by code. */
|
||||
protected rd(code: string): Reading | undefined {
|
||||
return this.loaded()?.get(code);
|
||||
}
|
||||
protected kpi(code: string): Measure | undefined {
|
||||
return this.byName().get(code);
|
||||
}
|
||||
/** A card's value and note, from its templates (a card with no measure: its words). */
|
||||
/** "27 días (mediana)" as the value and its qualifier, shown smaller beneath it. */
|
||||
protected kpiParts(text: string): [string, string] {
|
||||
const found = /^(.*?)\s*(\([^)]*\))$/.exec(text);
|
||||
return found ? [found[1], found[2]] : [text, ''];
|
||||
}
|
||||
|
||||
protected kpiValue(k: Kpi): string {
|
||||
if (!k.measure) return k.value ?? '';
|
||||
const r = this.rd(k.measure);
|
||||
return r && r.score !== undefined && k.value ? fill(k.value, r) : '';
|
||||
}
|
||||
protected kpiNote(k: Kpi): string {
|
||||
if (!k.measure) return k.note ?? '';
|
||||
const r = this.rd(k.measure);
|
||||
if (!r || r.score === undefined) return 'Sin valor disponible';
|
||||
return k.note ? fill(k.note, r) : '';
|
||||
}
|
||||
/** A figure's title, with the applied period in it. */
|
||||
protected titled(title: string): string {
|
||||
return title.replace('{p}', this.applied() ?? '');
|
||||
}
|
||||
/** A duration's box, or nothing to draw. */
|
||||
protected boxOf(measure: string | undefined): Figure | undefined {
|
||||
const r = measure ? this.rd(measure) : undefined;
|
||||
return r && r.score !== undefined ? boxFigure(r, this.applied() ?? '') : undefined;
|
||||
}
|
||||
/** TEA's summary of the period: its numbers from the measures (none: no summary). */
|
||||
protected readonly teaSummary = computed(() => {
|
||||
const rd = (c: string) => this.loaded()?.get(c);
|
||||
const status = rd('M28_CASOS_POR_ESTADO');
|
||||
if (!status) return undefined;
|
||||
const n = (r: Reading | undefined, pop: string) => r?.populations[pop] ?? 0;
|
||||
const cat = (r: Reading | undefined, c: string) =>
|
||||
r?.strata['category']?.[c]?.['initial-population'] ?? 0;
|
||||
const days = (c: string) => {
|
||||
const v = rd(c)?.score;
|
||||
return v === undefined
|
||||
? '—'
|
||||
: `${v.toLocaleString('es-MX', { maximumFractionDigits: 1 })} días`;
|
||||
};
|
||||
const confirmed = rd('M24_CONFIRMACION_DIAGNOSTICO')?.score;
|
||||
const withEeg = rd('M21_DIAGNOSTICADOS_CON_EEG');
|
||||
return {
|
||||
evaluated: n(status, 'initial-population'),
|
||||
mchatOnly: cat(status, 'mchat_only'),
|
||||
psychology: cat(status, 'psychology'),
|
||||
neuropediatrics: cat(status, 'neuropediatrics') + cat(status, 'eeg'),
|
||||
confirmed:
|
||||
confirmed === undefined
|
||||
? '—'
|
||||
: `${(confirmed * 100).toLocaleString('es-MX', { maximumFractionDigits: 1 })}%`,
|
||||
toAdos: days('M26_DIAS_MCHAT_ADOS2'),
|
||||
toDiagnosis: days('M27_DIAS_ADOS2_DIAGNOSTICO'),
|
||||
whole: days('M25_DIAS_MCHAT_DIAGNOSTICO'),
|
||||
diagnosed: n(withEeg, 'denominator'),
|
||||
eeg: n(withEeg, 'numerator'),
|
||||
missing: n(rd('M22_DIAGNOSTICADOS_SIN_EEG'), 'numerator'),
|
||||
unusable: cat(rd('M29_CALIDAD_EEG'), 'bad'),
|
||||
};
|
||||
});
|
||||
protected measureTitle(code: string | undefined): string {
|
||||
return (code && this.byName().get(code)?.title) || '';
|
||||
}
|
||||
/** A clinical section's route or figures, drawn from the applied period's reports. */
|
||||
protected routeOf(section: Section): Figure | undefined {
|
||||
if (section.kind !== 'route') return undefined;
|
||||
const steps = section.steps.map((s) => ({ label: s.label, r: this.rd(s.measure) }));
|
||||
return steps.some((s) => s.r?.score !== undefined) ? routeFigure(steps) : undefined;
|
||||
}
|
||||
protected figureOf(spec: FigureSpec): Figure | undefined {
|
||||
const r = this.rd(spec.measure);
|
||||
if (!r || !(r.populations['initial-population'] ?? 0)) return undefined;
|
||||
switch (spec.kind) {
|
||||
case 'donut':
|
||||
return nestedDonut(r, spec.catalog, spec.center);
|
||||
case 'share-donut':
|
||||
return shareDonut(r, spec.catalog, spec.center);
|
||||
case 'counts':
|
||||
return countBars(r, spec.catalog, spec.axis, this.applied() ?? '');
|
||||
case 'age-stack':
|
||||
return ageStack(r, spec.names);
|
||||
case 'age-share':
|
||||
return ageShare(r, spec.names[0]);
|
||||
case 'scenario-bars':
|
||||
return scenarioBars(r, spec.catalog, spec.stratum, name);
|
||||
case 'rates':
|
||||
return rateDots(r, spec);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<app-tea-list [risk]="true" />
|
||||
} @else {
|
||||
<form class="filters card" (submit)="$event.preventDefault()">
|
||||
<app-patient-search [(value)]="search" />
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Fecha de corte</mat-label>
|
||||
<input
|
||||
@@ -13,7 +14,7 @@
|
||||
/>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Ventana</mat-label>
|
||||
<mat-label>Ventana de meses</mat-label>
|
||||
<mat-select [value]="window()" (selectionChange)="window.set($event.value)">
|
||||
@for (m of [1, 3, 6, 12]; track m) {
|
||||
<mat-option [value]="m">{{ m }} {{ m === 1 ? 'mes' : 'meses' }}</mat-option>
|
||||
@@ -21,7 +22,7 @@
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Estatus</mat-label>
|
||||
<mat-label>Estatus de seguimiento</mat-label>
|
||||
<mat-select [value]="status()" (selectionChange)="status.set($event.value)">
|
||||
<mat-option value="">Todos</mat-option>
|
||||
@for (s of statuses; track s) {
|
||||
@@ -30,7 +31,7 @@
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Horizonte</mat-label>
|
||||
<mat-label>Horizonte de la probabilidad</mat-label>
|
||||
<mat-select [value]="horizon()" (selectionChange)="horizon.set($event.value)">
|
||||
@for (h of [1, 2, 3, 4, 5]; track h) {
|
||||
<mat-option [value]="h">{{ h }} {{ h === 1 ? 'año' : 'años' }}</mat-option>
|
||||
@@ -38,7 +39,7 @@
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Orden</mat-label>
|
||||
<mat-label>Ordenar por</mat-label>
|
||||
<mat-select [value]="sort()" (selectionChange)="sort.set($event.value)">
|
||||
<mat-option value="-recent">Estudio más reciente</mat-option>
|
||||
<mat-option value="-risk-cin2">Mayor riesgo de LIEAG+</mat-option>
|
||||
@@ -46,7 +47,7 @@
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Por página</mat-label>
|
||||
<mat-label>Registros por página</mat-label>
|
||||
<mat-select [value]="size()" (selectionChange)="size.set($event.value)">
|
||||
@for (n of [20, 50, 100]; track n) {
|
||||
<mat-option [value]="n">{{ n }}</mat-option>
|
||||
@@ -56,22 +57,33 @@
|
||||
</form>
|
||||
|
||||
@if (error()) {
|
||||
<p class="muted" role="alert">No se pudo leer la lista de seguimiento.</p>
|
||||
<p class="muted" role="alert">
|
||||
No se pudo leer la lista de seguimiento.
|
||||
<button mat-button type="button" (click)="retry()">Reintentar seguimiento</button>
|
||||
</p>
|
||||
} @else if (!page() || loading()) {
|
||||
<app-loading what="seguimiento" />
|
||||
} @else if (applied()) {
|
||||
<p class="muted window">Ventana consultada: {{ start() }} al {{ applied() }}.</p>
|
||||
}
|
||||
|
||||
<div class="table-wrap card">
|
||||
<table class="plain worklist">
|
||||
<caption>
|
||||
Resultados disponibles por paciente
|
||||
</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Paciente</th>
|
||||
<th>Grupo de edad</th>
|
||||
<th>Estatus</th>
|
||||
<th>Estatus de seguimiento</th>
|
||||
<th>Última citología</th>
|
||||
<th>VPH</th>
|
||||
<th>Biopsia</th>
|
||||
<th>Riesgo LIEAG+ ({{ horizon() }} a)</th>
|
||||
<th>Riesgo cáncer ({{ horizon() }} a)</th>
|
||||
<th>Días toma → diagnóstico</th>
|
||||
<th>Último resultado de VPH</th>
|
||||
<th>Última biopsia</th>
|
||||
<th>Probabilidad a LIEAG+ a {{ horizon() }} {{ horizon() === 1 ? 'año' : 'años' }} (%)</th>
|
||||
<th>Probabilidad a cáncer a {{ horizon() }} {{ horizon() === 1 ? 'año' : 'años' }} (%)</th>
|
||||
<th>Estudio más reciente</th>
|
||||
<th>Días de toma a diagnóstico</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -89,7 +101,6 @@
|
||||
<td>{{ name(row.status) }}</td>
|
||||
<td>
|
||||
@if (row.cytology; as c) {
|
||||
{{ c.date }} ·
|
||||
{{
|
||||
c.result
|
||||
? name(c.result)
|
||||
@@ -97,44 +108,61 @@
|
||||
? 'Insatisfactoria'
|
||||
: 'Pendiente'
|
||||
}}
|
||||
<small>Fecha: {{ c.date }}</small>
|
||||
<small>Calidad: {{ c.adequacy ? name(c.adequacy) : '—' }}</small>
|
||||
} @else {
|
||||
—
|
||||
No disponible
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
@if (row.hpv; as h) {
|
||||
{{ h.positive ? 'Positivo' : 'Negativo' }}{{ h.types1618 ? ' (16/18)' : '' }}
|
||||
{{ h.positive ? 'Positivo' : 'Negativo' }}
|
||||
<small>Fecha: {{ h.date }}</small>
|
||||
<small
|
||||
>Genotipo 16/18:
|
||||
{{
|
||||
h.types1618 === undefined
|
||||
? 'No disponible'
|
||||
: h.types1618
|
||||
? 'Presente'
|
||||
: 'No detectado'
|
||||
}}</small
|
||||
>
|
||||
} @else {
|
||||
—
|
||||
No disponible
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
@if (row.biopsy; as b) {
|
||||
{{ b.date }} · {{ name(b.histology ?? '') || 'Sin dato' }}
|
||||
{{ name(b.histology ?? '') || 'Sin grado' }}
|
||||
<small>Fecha: {{ b.date }}</small>
|
||||
} @else {
|
||||
—
|
||||
No disponible
|
||||
}
|
||||
</td>
|
||||
<td class="num">
|
||||
{{
|
||||
row.risk.cin2 === undefined ? '—' : (row.risk.cin2 * 100 | number: '1.1-1') + ' %'
|
||||
row.risk.cin2 === undefined
|
||||
? 'No disponible'
|
||||
: (row.risk.cin2 * 100 | number: '1.1-1') + ' %'
|
||||
}}
|
||||
</td>
|
||||
<td class="num">
|
||||
{{
|
||||
row.risk.cancer === undefined
|
||||
? '—'
|
||||
? 'No disponible'
|
||||
: (row.risk.cancer * 100 | number: '1.1-1') + ' %'
|
||||
}}
|
||||
</td>
|
||||
<td class="num">{{ row.daysToDiagnosis ?? '—' }}</td>
|
||||
<td>{{ latest(row) ?? 'No disponible' }}</td>
|
||||
<td class="num">{{ row.daysToDiagnosis ?? 'No disponible' }}</td>
|
||||
</tr>
|
||||
} @empty {
|
||||
<tr>
|
||||
<td colspan="9" class="muted">
|
||||
{{ page() ? 'Nadie en la lista con estos filtros.' : 'Cargando…' }}
|
||||
</td>
|
||||
</tr>
|
||||
@if (page() && !loading()) {
|
||||
<tr>
|
||||
<td colspan="10" class="muted">No hay registros para los filtros aplicados.</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -143,8 +171,7 @@
|
||||
<div class="pager">
|
||||
<span class="muted">
|
||||
@if (page()?.total; as total) {
|
||||
{{ offset() + 1 }}–{{ offset() + rows().length }} de {{ total }} pacientes · corte
|
||||
{{ applied() }}
|
||||
Página {{ pageNumber() }} de {{ pageCount() }}, {{ total }} registros
|
||||
}
|
||||
</span>
|
||||
<button mat-stroked-button (click)="go('previous')" [disabled]="!has('previous') || loading()">
|
||||
|
||||
@@ -10,6 +10,11 @@
|
||||
margin-bottom: var(--space-4);
|
||||
}
|
||||
|
||||
// a field as wide as its label ("Horizonte de la probabilidad")
|
||||
.filters mat-form-field {
|
||||
min-width: 14.5rem;
|
||||
}
|
||||
|
||||
.table-wrap {
|
||||
overflow-x: auto;
|
||||
padding: 0;
|
||||
@@ -40,3 +45,18 @@ a {
|
||||
.pager .muted {
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.worklist td small {
|
||||
display: block;
|
||||
white-space: nowrap;
|
||||
color: var(--mat-sys-on-surface-variant);
|
||||
font-size: 0.8em;
|
||||
}
|
||||
.worklist caption {
|
||||
text-align: left;
|
||||
font-weight: 500;
|
||||
padding: 8px 0;
|
||||
}
|
||||
.window {
|
||||
margin: 4px 0 8px;
|
||||
}
|
||||
|
||||
@@ -8,8 +8,10 @@ import { MatSelectModule } from '@angular/material/select';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import type { Bundle } from 'fhir/r4';
|
||||
import { Fhir } from '../fhir';
|
||||
import { rows, windowStart } from './follow-up';
|
||||
import { Row, rows, windowStart } from './follow-up';
|
||||
import { PatientSearch, patientSearch } from './patient-search';
|
||||
import { TeaList } from './tea-list';
|
||||
import { Loading } from '../loading';
|
||||
import { name } from './measures';
|
||||
|
||||
const STATUSES = ['case', 'pre_colposcopy', 'post_colposcopy', 'post_treatment'];
|
||||
@@ -19,8 +21,10 @@ const STATUSES = ['case', 'pre_colposcopy', 'post_colposcopy', 'post_treatment']
|
||||
@Component({
|
||||
selector: 'app-tab-riesgos',
|
||||
imports: [
|
||||
PatientSearch,
|
||||
DecimalPipe,
|
||||
FormsModule,
|
||||
Loading,
|
||||
MatButtonModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
@@ -41,6 +45,8 @@ export class TabRiesgos {
|
||||
protected readonly horizon = signal(5);
|
||||
protected readonly sort = signal('-recent');
|
||||
protected readonly size = signal(20);
|
||||
/** "Buscar paciente": her name, CURP or record number, as applied. */
|
||||
protected readonly search = signal('');
|
||||
/** A page the user moved to (`next`/`previous`), else the first. */
|
||||
private readonly moved = signal<Bundle | undefined>(undefined);
|
||||
|
||||
@@ -54,6 +60,7 @@ export class TabRiesgos {
|
||||
: {
|
||||
domain: this.domain(),
|
||||
'follow-up-window': this.window(),
|
||||
...patientSearch(this.search()),
|
||||
'follow-up-cutoff': this.cutoff() || undefined,
|
||||
'follow-up-status': this.status() || undefined,
|
||||
'risk-horizon': this.horizon(),
|
||||
@@ -70,7 +77,9 @@ export class TabRiesgos {
|
||||
},
|
||||
});
|
||||
protected readonly loading = signal(false);
|
||||
protected readonly page = computed(() => this.moved() ?? this.first.value());
|
||||
protected readonly page = computed(
|
||||
() => this.moved() ?? (this.first.hasValue() ? this.first.value() : undefined),
|
||||
);
|
||||
/** The cut-off as applied (the server's default when none is given). */
|
||||
protected readonly applied = computed(() => {
|
||||
const self = this.page()?.link?.find((l) => l.relation === 'self')?.url;
|
||||
@@ -89,6 +98,26 @@ export class TabRiesgos {
|
||||
});
|
||||
protected readonly error = computed(() => this.first.error());
|
||||
|
||||
/** "Ventana consultada": the window's first day for the applied cut-off. */
|
||||
protected readonly start = computed(() =>
|
||||
this.applied() ? windowStart(this.applied(), this.window()) : '',
|
||||
);
|
||||
protected readonly pageNumber = computed(() => Math.floor(this.offset() / this.size()) + 1);
|
||||
protected readonly pageCount = computed(() =>
|
||||
Math.max(1, Math.ceil((this.page()?.total ?? 0) / this.size())),
|
||||
);
|
||||
/** "Estudio más reciente": her latest cytology or HPV sample. */
|
||||
protected latest(row: Row): string | undefined {
|
||||
return [row.cytology?.date, row.hpv?.date]
|
||||
.filter((d) => !!d)
|
||||
.sort()
|
||||
.at(-1)
|
||||
?.slice(0, 10);
|
||||
}
|
||||
protected retry(): void {
|
||||
this.first.reload();
|
||||
}
|
||||
|
||||
protected has(relation: 'next' | 'previous'): boolean {
|
||||
return !!this.page()?.link?.some((l) => l.relation === relation);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<app-tea-list [patientId]="patientId()" />
|
||||
} @else {
|
||||
<form class="filters card" (submit)="$event.preventDefault()">
|
||||
<app-patient-search [(value)]="search" />
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Fecha de corte</mat-label>
|
||||
<input
|
||||
@@ -13,7 +14,7 @@
|
||||
/>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Ventana</mat-label>
|
||||
<mat-label>Ventana de meses</mat-label>
|
||||
<mat-select [value]="window()" (selectionChange)="window.set($event.value)">
|
||||
@for (m of [1, 3, 6, 12]; track m) {
|
||||
<mat-option [value]="m">{{ m }} {{ m === 1 ? 'mes' : 'meses' }}</mat-option>
|
||||
@@ -21,7 +22,7 @@
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Estatus</mat-label>
|
||||
<mat-label>Estatus de seguimiento</mat-label>
|
||||
<mat-select [value]="status()" (selectionChange)="status.set($event.value)">
|
||||
<mat-option value="">Todos</mat-option>
|
||||
@for (s of statuses; track s) {
|
||||
@@ -30,7 +31,7 @@
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Por página</mat-label>
|
||||
<mat-label>Registros por página</mat-label>
|
||||
<mat-select [value]="size()" (selectionChange)="size.set($event.value)">
|
||||
@for (n of [20, 50, 100]; track n) {
|
||||
<mat-option [value]="n">{{ n }}</mat-option>
|
||||
@@ -40,18 +41,28 @@
|
||||
</form>
|
||||
|
||||
@if (error()) {
|
||||
<p class="muted" role="alert">No se pudo leer la lista de seguimiento.</p>
|
||||
<p class="muted" role="alert">
|
||||
No se pudo leer la lista de seguimiento.
|
||||
<button mat-button type="button" (click)="retry()">Reintentar seguimiento</button>
|
||||
</p>
|
||||
} @else if (!page() || loading()) {
|
||||
<app-loading what="seguimiento" />
|
||||
} @else if (applied()) {
|
||||
<p class="muted window">Ventana consultada: {{ start() }} al {{ applied() }}.</p>
|
||||
}
|
||||
|
||||
<div class="table-wrap card">
|
||||
<table class="plain worklist">
|
||||
<caption>
|
||||
Resultados disponibles por paciente
|
||||
</caption>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Paciente</th>
|
||||
<th>Grupo de edad</th>
|
||||
<th>Mastografía</th>
|
||||
<th>Biopsia</th>
|
||||
<th>Estatus</th>
|
||||
<th>Última mastografía</th>
|
||||
<th>Última biopsia</th>
|
||||
<th>Estatus de seguimiento</th>
|
||||
<th>Prioridad</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -59,31 +70,37 @@
|
||||
@for (row of rows(); track row.patient.id) {
|
||||
<tr>
|
||||
<td>
|
||||
<a [routerLink]="['/indicadores', domain(), 'pacientes', row.patient.id]">{{
|
||||
row.name ?? row.patient.id!.slice(0, 10)
|
||||
}}</a>
|
||||
<a
|
||||
[routerLink]="['/indicadores', domain(), 'pacientes', row.patient.id]"
|
||||
[queryParams]="{ ventana: window(), corte: applied() }"
|
||||
>{{ row.name ?? row.patient.id!.slice(0, 10) }}</a
|
||||
>
|
||||
@if (row.curp) {
|
||||
<div class="muted curp">{{ row.curp }}</div>
|
||||
}
|
||||
</td>
|
||||
<td>{{ row.ageGroup }}</td>
|
||||
<td>{{ row.mammogram.date }} · {{ name(row.mammogram.birads ?? '') || 'Sin dato' }}</td>
|
||||
<td>
|
||||
{{ name(row.mammogram.birads ?? '') || 'Sin dato' }}
|
||||
<small>Fecha: {{ row.mammogram.date }}</small>
|
||||
</td>
|
||||
<td>
|
||||
@if (row.biopsy; as b) {
|
||||
{{ b.date }} · {{ name(b.histology ?? '') || 'Sin resultado' }}
|
||||
{{ name(b.histology ?? '') || 'Sin resultado' }}
|
||||
<small>Fecha: {{ b.date }}</small>
|
||||
} @else {
|
||||
—
|
||||
No disponible
|
||||
}
|
||||
</td>
|
||||
<td>{{ name(row.status) }}</td>
|
||||
<td>{{ priority(row.priority) }}</td>
|
||||
</tr>
|
||||
} @empty {
|
||||
<tr>
|
||||
<td colspan="6" class="muted">
|
||||
{{ page() ? 'Nadie en la lista con estos filtros.' : 'Cargando…' }}
|
||||
</td>
|
||||
</tr>
|
||||
@if (page() && !loading()) {
|
||||
<tr>
|
||||
<td colspan="6" class="muted">No hay registros para los filtros aplicados.</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -92,8 +109,7 @@
|
||||
<div class="pager">
|
||||
<span class="muted">
|
||||
@if (page()?.total; as total) {
|
||||
{{ offset() + 1 }}–{{ offset() + rows().length }} de {{ total }} pacientes · corte
|
||||
{{ applied() }}
|
||||
Página {{ pageNumber() }} de {{ pageCount() }}, {{ total }} registros
|
||||
}
|
||||
</span>
|
||||
<button mat-stroked-button (click)="go('previous')" [disabled]="!has('previous') || loading()">
|
||||
|
||||
@@ -7,8 +7,10 @@ import { MatSelectModule } from '@angular/material/select';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import type { Bundle } from 'fhir/r4';
|
||||
import { Fhir } from '../fhir';
|
||||
import { camaRows } from './follow-up';
|
||||
import { camaRows, windowStart } from './follow-up';
|
||||
import { PatientSearch, patientSearch } from './patient-search';
|
||||
import { TeaList } from './tea-list';
|
||||
import { Loading } from '../loading';
|
||||
import { name, PRIORITY } from './measures';
|
||||
|
||||
const STATUSES = ['cancer', 'pending_biopsy', 'biopsy_no_result', 'benign_biopsy'];
|
||||
@@ -18,7 +20,9 @@ const STATUSES = ['cancer', 'pending_biopsy', 'biopsy_no_result', 'benign_biopsy
|
||||
@Component({
|
||||
selector: 'app-tab-seguimiento',
|
||||
imports: [
|
||||
PatientSearch,
|
||||
FormsModule,
|
||||
Loading,
|
||||
MatButtonModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
@@ -38,6 +42,8 @@ export class TabSeguimiento {
|
||||
protected readonly window = signal(3);
|
||||
protected readonly status = signal<string>('');
|
||||
protected readonly size = signal(20);
|
||||
/** "Buscar paciente": her name, CURP or record number, as applied. */
|
||||
protected readonly search = signal('');
|
||||
private readonly moved = signal<Bundle | undefined>(undefined);
|
||||
|
||||
protected readonly statuses = STATUSES;
|
||||
@@ -51,6 +57,7 @@ export class TabSeguimiento {
|
||||
: {
|
||||
domain: this.domain(),
|
||||
'follow-up-window': this.window(),
|
||||
...patientSearch(this.search()),
|
||||
'follow-up-cutoff': this.cutoff() || undefined,
|
||||
'follow-up-status': this.status() || undefined,
|
||||
_count: this.size(),
|
||||
@@ -65,7 +72,9 @@ export class TabSeguimiento {
|
||||
},
|
||||
});
|
||||
protected readonly loading = signal(false);
|
||||
protected readonly page = computed(() => this.moved() ?? this.first.value());
|
||||
protected readonly page = computed(
|
||||
() => this.moved() ?? (this.first.hasValue() ? this.first.value() : undefined),
|
||||
);
|
||||
protected readonly applied = computed(() => {
|
||||
const self = this.page()?.link?.find((l) => l.relation === 'self')?.url;
|
||||
return self ? (new URL(self).searchParams.get('follow-up-cutoff') ?? '') : '';
|
||||
@@ -81,6 +90,17 @@ export class TabSeguimiento {
|
||||
});
|
||||
protected readonly error = computed(() => this.first.error());
|
||||
|
||||
protected readonly start = computed(() =>
|
||||
this.applied() ? windowStart(this.applied(), this.window()) : '',
|
||||
);
|
||||
protected readonly pageNumber = computed(() => Math.floor(this.offset() / this.size()) + 1);
|
||||
protected readonly pageCount = computed(() =>
|
||||
Math.max(1, Math.ceil((this.page()?.total ?? 0) / this.size())),
|
||||
);
|
||||
protected retry(): void {
|
||||
this.first.reload();
|
||||
}
|
||||
|
||||
protected has(relation: 'next' | 'previous'): boolean {
|
||||
return !!this.page()?.link?.some((l) => l.relation === relation);
|
||||
}
|
||||
|
||||
@@ -1,93 +1,62 @@
|
||||
import { Component, computed, inject, input, resource, signal } from '@angular/core';
|
||||
import { MatButtonToggleModule } from '@angular/material/button-toggle';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import type { Measure, MeasureReport, Parameters } from 'fhir/r4';
|
||||
import type { Measure, MeasureReport } from 'fhir/r4';
|
||||
import { Fhir, resources } from '../fhir';
|
||||
import { CardActions } from '../card-actions';
|
||||
import { Loading } from '../loading';
|
||||
import { Figure, Plot } from '../plot';
|
||||
import { TEA_STEPS } from './follow-up';
|
||||
import {
|
||||
history,
|
||||
periodLabel,
|
||||
periods,
|
||||
PeriodType,
|
||||
periodTypes,
|
||||
reading,
|
||||
sankey,
|
||||
strataBars,
|
||||
} from './measures';
|
||||
import { historyFigure } from './figures';
|
||||
import { periodLabel, periods, PeriodType, reading } from './measures';
|
||||
import { HISTORY, HistoryPanel } from './pages';
|
||||
|
||||
/** Each measure over time: every period of the chosen kind, oldest first. */
|
||||
interface Drawn {
|
||||
panel: HistoryPanel;
|
||||
/** the group's heading, on the first panel of its run */
|
||||
heading?: string;
|
||||
figure?: Figure;
|
||||
}
|
||||
|
||||
/** Trazabilidad as the old tab: the domain's declared panels (pages.HISTORY), in their order,
|
||||
* each measure period by period. */
|
||||
@Component({
|
||||
selector: 'app-tab-trazabilidad',
|
||||
imports: [MatButtonToggleModule, MatCardModule, Plot, CardActions],
|
||||
imports: [Loading, MatButtonToggleModule, Plot],
|
||||
template: `
|
||||
@if (domain() === 'tea') {
|
||||
@if (teaFlow.isLoading() || alterations.isLoading()) {
|
||||
<p class="muted">Calculando…</p>
|
||||
}
|
||||
@if (teaFlow.error() || alterations.error()) {
|
||||
<p role="alert">No se pudo leer la trazabilidad.</p>
|
||||
}
|
||||
<div class="grid">
|
||||
@if (alterations.hasValue() && alterations.value(); as item) {
|
||||
<mat-card appearance="outlined" [attr.data-measure]="item.measure.name">
|
||||
<mat-card-header>
|
||||
<mat-card-title>{{ item.measure.title }}</mat-card-title>
|
||||
<app-card-actions [measures]="[item.measure]" />
|
||||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
<p>{{ item.period }}</p>
|
||||
<app-plot [figure]="item.figure" />
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
}
|
||||
@if (teaFlow.hasValue() && teaFlow.value(); as flow) {
|
||||
<mat-card appearance="outlined">
|
||||
<mat-card-header
|
||||
><mat-card-title>Progresión del proceso diagnóstico</mat-card-title></mat-card-header
|
||||
>
|
||||
<mat-card-content>
|
||||
<dl>
|
||||
@for (step of flow.steps; track step.label) {
|
||||
<dt>{{ step.label }}</dt>
|
||||
<dd>{{ step.count }}</dd>
|
||||
}
|
||||
</dl>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
<mat-card appearance="outlined">
|
||||
<mat-card-header>
|
||||
<mat-card-title>Flujo del proceso diagnóstico y estudios de EEG</mat-card-title>
|
||||
</mat-card-header>
|
||||
<mat-card-content><app-plot [figure]="flow.figure" [height]="420" /></mat-card-content>
|
||||
</mat-card>
|
||||
}
|
||||
</div>
|
||||
<section class="card filters" aria-labelledby="history-filters">
|
||||
<h2 id="history-filters" class="filters-title">Filtros</h2>
|
||||
<mat-button-toggle-group
|
||||
[value]="type()"
|
||||
(change)="type.set($event.value)"
|
||||
aria-label="Intervalo de análisis"
|
||||
>
|
||||
<mat-button-toggle value="month">Mensual</mat-button-toggle>
|
||||
<mat-button-toggle value="semester">Semestral</mat-button-toggle>
|
||||
</mat-button-toggle-group>
|
||||
</section>
|
||||
@if (series.isLoading()) {
|
||||
<app-loading what="la trazabilidad" text="Cargando trazabilidad…" />
|
||||
} @else if (series.error()) {
|
||||
<p class="muted" role="alert">
|
||||
No se pudo cargar la trazabilidad.
|
||||
<button type="button" class="retry" (click)="series.reload()">Reintentar</button>
|
||||
</p>
|
||||
} @else {
|
||||
<div class="bar">
|
||||
<mat-button-toggle-group
|
||||
[value]="type()"
|
||||
(change)="type.set($event.value)"
|
||||
aria-label="Intervalo"
|
||||
>
|
||||
<mat-button-toggle value="month">Mensual</mat-button-toggle>
|
||||
<mat-button-toggle value="semester">Semestral</mat-button-toggle>
|
||||
</mat-button-toggle-group>
|
||||
</div>
|
||||
@if (series.isLoading()) {
|
||||
<p class="muted">Calculando…</p>
|
||||
}
|
||||
<div class="grid">
|
||||
@for (item of figures(); track item.measure.id) {
|
||||
<mat-card appearance="outlined" [attr.data-measure]="item.measure.name">
|
||||
<mat-card-header
|
||||
><mat-card-title>{{ item.measure.title }}</mat-card-title></mat-card-header
|
||||
>
|
||||
<mat-card-content><app-plot [figure]="item.figure" [height]="280" /></mat-card-content>
|
||||
</mat-card>
|
||||
@for (d of drawn(); track d.panel.measure) {
|
||||
@if (d.heading) {
|
||||
<h2 class="group-title">{{ d.heading }}</h2>
|
||||
}
|
||||
</div>
|
||||
<section class="card panel" [attr.data-measure]="d.panel.measure">
|
||||
@if (d.panel.group) {
|
||||
<h3 class="panel-title">{{ d.panel.title }}</h3>
|
||||
} @else {
|
||||
<h2 class="panel-title">{{ d.panel.title }}</h2>
|
||||
}
|
||||
@if (d.figure) {
|
||||
<app-plot [figure]="d.figure" [height]="320" />
|
||||
} @else {
|
||||
<p class="muted">Sin datos para el periodo.</p>
|
||||
}
|
||||
</section>
|
||||
}
|
||||
}
|
||||
`,
|
||||
styles: `
|
||||
@@ -95,18 +64,29 @@ import {
|
||||
display: block;
|
||||
padding-top: 16px;
|
||||
}
|
||||
.bar {
|
||||
.card {
|
||||
background: var(--mat-sys-surface);
|
||||
border: 1px solid var(--mat-sys-outline-variant);
|
||||
border-radius: 12px;
|
||||
padding: 16px 20px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.grid {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
grid-template-columns: 1fr;
|
||||
.filters-title {
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
@media (min-width: 1304px) {
|
||||
.grid {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
.panel-title,
|
||||
.group-title {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
h3.panel-title {
|
||||
font-size: 16px;
|
||||
}
|
||||
.group-title {
|
||||
margin: 24px 0 12px;
|
||||
}
|
||||
`,
|
||||
})
|
||||
@@ -114,84 +94,48 @@ export class TabTrazabilidad {
|
||||
private readonly fhir = inject(Fhir);
|
||||
readonly domain = input.required<string>();
|
||||
readonly measures = input.required<Measure[]>();
|
||||
protected readonly type = signal<PeriodType>('semester');
|
||||
protected readonly type = signal<PeriodType>('month');
|
||||
|
||||
protected readonly series = resource({
|
||||
params: () =>
|
||||
this.domain() === 'tea'
|
||||
? undefined
|
||||
: { domain: this.domain(), type: this.type(), measures: this.measures() },
|
||||
params: () => ({ domain: this.domain(), type: this.type(), measures: this.measures() }),
|
||||
loader: async ({ params }) => {
|
||||
const history = HISTORY[params.domain];
|
||||
if (!history) return [];
|
||||
const asked = periods(params.type).reverse();
|
||||
const shown = params.measures.filter((m) => periodTypes(m).includes(params.type));
|
||||
return Promise.all(
|
||||
shown.map(async (measure) => {
|
||||
history.panels.map(async (panel) => {
|
||||
const measure = params.measures.find((m) => m.name === panel.measure);
|
||||
if (!measure) return { panel, points: [] };
|
||||
const pages = await this.fhir.all(params.domain, 'MeasureReport', {
|
||||
measure: measure.id!,
|
||||
'reporting-period': asked.join(','),
|
||||
});
|
||||
// One report per period asked, in the order asked.
|
||||
const found = resources<MeasureReport>(pages, 'MeasureReport');
|
||||
return { measure, points: asked.map((period, i) => ({ period, r: reading(found[i]) })) };
|
||||
return { panel, points: asked.map((period, i) => ({ period, r: reading(found[i]) })) };
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
protected readonly teaFlow = resource({
|
||||
params: () => (this.domain() === 'tea' ? this.domain() : undefined),
|
||||
loader: async ({ params: domain }) => {
|
||||
const [pages, response] = await Promise.all([
|
||||
Promise.all(
|
||||
TEA_STEPS.map(({ code }) =>
|
||||
this.fhir.search(domain, 'Patient', { 'tea-step': code, _count: 1 }),
|
||||
),
|
||||
),
|
||||
this.fhir.search(domain, 'Patient/$eeg-summary', { 'tea-step': 'eeg' }),
|
||||
]);
|
||||
const parameters = (response as unknown as Parameters).parameter ?? [];
|
||||
const count = (name: string) => parameters.find((p) => p.name === name)?.valueInteger ?? 0;
|
||||
const latest = pages.map((page) => page.total ?? 0);
|
||||
return {
|
||||
steps: TEA_STEPS.map(({ label }, i) => ({
|
||||
label,
|
||||
count: latest.slice(i).reduce((sum, n) => sum + n, 0),
|
||||
})),
|
||||
figure: sankey(latest, {
|
||||
valid: count('valid'),
|
||||
normal: count('normal'),
|
||||
abnormal: count('abnormal'),
|
||||
}),
|
||||
};
|
||||
},
|
||||
protected readonly drawn = computed<Drawn[]>(() => {
|
||||
const history = HISTORY[this.domain()];
|
||||
const xTitle = this.type() === 'month' ? 'Mes y año' : 'Semestre';
|
||||
let group: string | undefined;
|
||||
if (!this.series.hasValue()) return [];
|
||||
return this.series.value().map(({ panel, points }) => {
|
||||
const heading = panel.group && panel.group !== group ? panel.group : undefined;
|
||||
group = panel.group;
|
||||
const has = (p: (typeof points)[number]) => (p.r?.populations['initial-population'] ?? 0) > 0;
|
||||
const first = points.findIndex(has);
|
||||
if (first < 0 || !history) return { panel, heading };
|
||||
const last = points.length - 1 - [...points].reverse().findIndex(has);
|
||||
const shown =
|
||||
history.months && this.type() === 'month'
|
||||
? points.slice(Math.max(first, last + 1 - history.months), last + 1)
|
||||
: points.slice(first, last + 1);
|
||||
const series = shown.map((p) => ({ label: periodLabel(p.period), r: p.r }));
|
||||
return { panel, heading, figure: historyFigure(panel, series, history.line, xTitle) };
|
||||
});
|
||||
});
|
||||
|
||||
protected readonly alterations = resource({
|
||||
params: () =>
|
||||
this.domain() === 'tea'
|
||||
? this.measures().find((m) => m.name === 'M30_RESULTADO_EEG')
|
||||
: undefined,
|
||||
loader: async ({ params: measure }) => {
|
||||
const asked = periods('semester');
|
||||
const pages = await this.fhir.all('tea', 'MeasureReport', {
|
||||
measure: measure.id!,
|
||||
'reporting-period': asked.join(','),
|
||||
});
|
||||
const readings = resources<MeasureReport>(pages, 'MeasureReport').map(reading);
|
||||
const index = readings.findIndex((r) => !!r?.populations['initial-population']);
|
||||
const r = readings[index];
|
||||
return {
|
||||
measure,
|
||||
period: index < 0 ? 'Sin datos en el periodo' : periodLabel(asked[index]),
|
||||
figure: r ? strataBars(measure, r, 'alteration', true) : { data: [] },
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
protected readonly figures = computed<{ measure: Measure; figure: Figure }[]>(() =>
|
||||
(this.series.value() ?? []).map(({ measure, points }) => {
|
||||
// From the first period with data on.
|
||||
const first = points.findIndex((p) => (p.r?.populations['initial-population'] ?? 0) > 0);
|
||||
return { measure, figure: history(measure, first < 0 ? [] : points.slice(first)) };
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import type {
|
||||
} from 'fhir/r4';
|
||||
import { EXT } from '../fhir';
|
||||
import { teaRows } from './follow-up';
|
||||
import { boxes, donut, sankey, type Reading } from './measures';
|
||||
import { donut, type Reading } from './measures';
|
||||
import { associationRows, teaParams, teaWorkbook } from './tea-list';
|
||||
|
||||
const measure: Measure = { resourceType: 'Measure', status: 'active' };
|
||||
@@ -99,39 +99,6 @@ function fixture(): Bundle {
|
||||
}
|
||||
|
||||
describe('TEA indicators', () => {
|
||||
it('uses reported quartiles and skips a measure without a distribution', () => {
|
||||
expect(
|
||||
boxes([
|
||||
{ label: 'M26', r },
|
||||
{ label: 'M27', r: undefined },
|
||||
]).data,
|
||||
).toEqual([expect.objectContaining({ type: 'box', q1: [7], median: [12], q3: [18] })]);
|
||||
});
|
||||
|
||||
it('links reached steps, departures and all three EEG outcomes', () => {
|
||||
expect(sankey([10, 5, 4, 6], { valid: 6, normal: 2, abnormal: 3 }).data[0]).toMatchObject({
|
||||
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: [15, 10, 6, 10, 5, 4, 2, 3, 1],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('builds two concentric rings from the supplied counts', () => {
|
||||
const inner = { labels: ['Femenino'], values: [3] };
|
||||
const outer = { labels: ['Femenino · 16-23', 'Femenino · 24-29'], values: [2, 1] };
|
||||
|
||||
Reference in New Issue
Block a user