ISSSTELEON WebApp
This commit is contained in:
@@ -0,0 +1,456 @@
|
||||
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})`;
|
||||
}
|
||||
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 },
|
||||
},
|
||||
};
|
||||
}
|
||||
function counted(r: Reading, code: string): number {
|
||||
return r.strata['category']?.[code]?.['initial-population'] ?? 0;
|
||||
}
|
||||
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] },
|
||||
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 } },
|
||||
};
|
||||
}
|
||||
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,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
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)];
|
||||
}
|
||||
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 });
|
||||
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] ?? '');
|
||||
}
|
||||
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' } },
|
||||
};
|
||||
}
|
||||
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 },
|
||||
},
|
||||
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',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
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'];
|
||||
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),
|
||||
);
|
||||
}
|
||||
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' },
|
||||
},
|
||||
};
|
||||
}
|
||||
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: ' %' },
|
||||
},
|
||||
};
|
||||
}
|
||||
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'),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
import type { Bundle, DiagnosticReport, Observation, Patient, RiskAssessment } from 'fhir/r4';
|
||||
import { code, ext, resources } from '../fhir';
|
||||
export interface Row {
|
||||
patient: Patient;
|
||||
name?: string;
|
||||
curp?: string;
|
||||
status: string;
|
||||
ageGroup: string;
|
||||
cytology?: {
|
||||
date: string;
|
||||
result?: string;
|
||||
adequacy?: string;
|
||||
};
|
||||
hpv?: {
|
||||
date: string;
|
||||
positive: boolean;
|
||||
types1618?: boolean;
|
||||
};
|
||||
daysToDiagnosis?: number;
|
||||
biopsy?: {
|
||||
date: string;
|
||||
histology?: string;
|
||||
};
|
||||
risk: Record<'cin2' | 'cancer', number | undefined>;
|
||||
}
|
||||
export const CURP = 'https://isssteleon.org/fhir/sid/curp';
|
||||
const AGE_GROUPS: [number, number][] = [
|
||||
[25, 34],
|
||||
[35, 44],
|
||||
[45, 54],
|
||||
[55, 64],
|
||||
];
|
||||
export function ageGroup(
|
||||
birth: string | undefined,
|
||||
at: string,
|
||||
groups: [number, number][] = AGE_GROUPS,
|
||||
): string {
|
||||
if (!birth) return 'Sin dato';
|
||||
const [by, bm, bd] = birth.split('-').map(Number);
|
||||
const [y, m, d] = at.split('-').map(Number);
|
||||
const age = y - by - (m < bm || (m === bm && d < bd) ? 1 : 0);
|
||||
const found = groups.find(([lo, hi]) => lo <= age && age <= hi);
|
||||
if (found) return `${found[0]}-${found[1]}`;
|
||||
return age < groups[0][0] ? `<${groups[0][0]}` : `${groups.at(-1)![1] + 1}+`;
|
||||
}
|
||||
export function currentRisk(
|
||||
risks: RiskAssessment[],
|
||||
outcome: 'cin2' | 'cancer',
|
||||
horizon: number,
|
||||
): number | undefined {
|
||||
const mine = risks
|
||||
.filter((r) => code(r.method)?.startsWith(`cacu.${outcome}`))
|
||||
.flatMap((r) =>
|
||||
(r.prediction ?? [])
|
||||
.filter((p) => p.whenRange?.high?.value === horizon)
|
||||
.map((p) => ({ r, p })),
|
||||
);
|
||||
if (!mine.length) return undefined;
|
||||
const latest = mine
|
||||
.map((x) => x.r.occurrenceDateTime ?? '')
|
||||
.sort()
|
||||
.at(-1);
|
||||
return Math.max(
|
||||
...mine
|
||||
.filter((x) => x.r.occurrenceDateTime === latest)
|
||||
.map((x) => x.p.probabilityDecimal ?? 0),
|
||||
);
|
||||
}
|
||||
export function rows(page: Bundle, start: string, cutoff: string, horizon: number): Row[] {
|
||||
const reports = resources<DiagnosticReport>(page, 'DiagnosticReport');
|
||||
const observations = new Map(resources<Observation>(page, 'Observation').map((o) => [o.id, o]));
|
||||
const risks = resources<RiskAssessment>(page, 'RiskAssessment');
|
||||
const results = (r: DiagnosticReport) =>
|
||||
new Map(
|
||||
(r.result ?? [])
|
||||
.map((x) => observations.get(x.reference?.split('/')[1]))
|
||||
.filter((o) => !!o)
|
||||
.map((o) => [code(o!.code), o!]),
|
||||
);
|
||||
return resources<Patient>(page, 'Patient', 'match').map((patient) => {
|
||||
const mine = reports.filter((r) => r.subject?.reference === `Patient/${patient.id}`);
|
||||
const by = (kind: string) => mine.filter((r) => code(r.code) === kind);
|
||||
const cytologies = by('cervical_cytology')
|
||||
.filter((r) => start <= r.effectiveDateTime! && r.effectiveDateTime! <= cutoff)
|
||||
.sort((a, b) => a.effectiveDateTime!.localeCompare(b.effectiveDateTime!));
|
||||
const last = cytologies.at(-1);
|
||||
const lastResults = last ? results(last) : new Map();
|
||||
const hpv = cytologies.filter((r) => results(r).has('cervical_cytology.hpv')).at(-1);
|
||||
const hpvResults = hpv ? results(hpv) : new Map();
|
||||
const types = ['cervical_cytology.hpv_16', 'cervical_cytology.hpv_18']
|
||||
.filter((k) => hpvResults.has(k))
|
||||
.map((k) => hpvResults.get(k)!.valueBoolean);
|
||||
const biopsy = by('cervical_biopsy')
|
||||
.filter((r) => ext(r, 'report-date'))
|
||||
.sort((a, b) =>
|
||||
ext(a, 'report-date')!.valueDate!.localeCompare(ext(b, 'report-date')!.valueDate!),
|
||||
)
|
||||
.at(-1);
|
||||
const theirs = risks.filter((r) => r.subject?.reference === `Patient/${patient.id}`);
|
||||
return {
|
||||
patient,
|
||||
name: patient.name?.[0]?.text,
|
||||
curp: patient.identifier?.find((i) => i.system === CURP)?.value,
|
||||
status: ext(patient, 'follow-up-status')?.valueCoding?.code ?? '',
|
||||
ageGroup: ageGroup(patient.birthDate, cutoff),
|
||||
cytology: last && {
|
||||
date: last.effectiveDateTime!,
|
||||
result: code(lastResults.get('cervical_cytology.result')?.valueCodeableConcept),
|
||||
adequacy: code(lastResults.get('cervical_cytology.adequacy')?.valueCodeableConcept),
|
||||
},
|
||||
hpv: hpv && {
|
||||
date: hpv.effectiveDateTime!,
|
||||
positive: !!hpvResults.get('cervical_cytology.hpv')?.valueBoolean,
|
||||
types1618: types.length ? types.some((t) => t) : undefined,
|
||||
},
|
||||
daysToDiagnosis: last ? ext(last, 'days-to-diagnosis')?.valueInteger : undefined,
|
||||
biopsy: biopsy && {
|
||||
date: ext(biopsy, 'report-date')!.valueDate!,
|
||||
histology: code(results(biopsy).get('cervical_biopsy.histology')?.valueCodeableConcept),
|
||||
},
|
||||
risk: {
|
||||
cin2: currentRisk(theirs, 'cin2', horizon),
|
||||
cancer: currentRisk(theirs, 'cancer', horizon),
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
export function windowStart(cutoff: string, months: number): string {
|
||||
const [y, m, d] = cutoff.split('-').map(Number);
|
||||
const total = y * 12 + (m - 1) - months;
|
||||
const year = Math.floor(total / 12);
|
||||
const month = total % 12;
|
||||
const last = new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
|
||||
const day = new Date(Date.UTC(year, month, Math.min(d, last) + 1));
|
||||
return day.toISOString().slice(0, 10);
|
||||
}
|
||||
export interface CamaRow {
|
||||
patient: Patient;
|
||||
name?: string;
|
||||
curp?: string;
|
||||
status: string;
|
||||
priority: string;
|
||||
ageGroup: string;
|
||||
mammogram: {
|
||||
date: string;
|
||||
birads?: string;
|
||||
days?: number;
|
||||
};
|
||||
biopsy?: {
|
||||
date: string;
|
||||
histology?: string;
|
||||
};
|
||||
}
|
||||
export const CAMA_AGE_GROUPS: [number, number][] = [
|
||||
[40, 49],
|
||||
[50, 59],
|
||||
[60, 69],
|
||||
];
|
||||
export function camaRows(page: Bundle, cutoff: string): CamaRow[] {
|
||||
const reports = resources<DiagnosticReport>(page, 'DiagnosticReport');
|
||||
const observations = new Map(resources<Observation>(page, 'Observation').map((o) => [o.id, o]));
|
||||
const results = (r: DiagnosticReport) =>
|
||||
new Map(
|
||||
(r.result ?? [])
|
||||
.map((x) => observations.get(x.reference?.split('/')[1]))
|
||||
.filter((o) => !!o)
|
||||
.map((o) => [code(o!.code), o!]),
|
||||
);
|
||||
const reported = (r: DiagnosticReport) => ext(r, 'report-date')?.valueDate;
|
||||
return resources<Patient>(page, 'Patient', 'match').map((patient) => {
|
||||
const mine = reports.filter((r) => r.subject?.reference === `Patient/${patient.id}`);
|
||||
const mammogram = mine
|
||||
.filter((r) => code(r.code) === 'mammography' && (reported(r) ?? '9') <= cutoff)
|
||||
.sort((a, b) => a.effectiveDateTime!.localeCompare(b.effectiveDateTime!))
|
||||
.at(-1);
|
||||
const exam = mammogram?.effectiveDateTime ?? '';
|
||||
const biopsy = mine
|
||||
.filter(
|
||||
(r) =>
|
||||
code(r.code) === 'breast_biopsy' &&
|
||||
results(r).get('breast_biopsy.mammogram_exam_date')?.valueDateTime === exam &&
|
||||
exam <= (reported(r) ?? '') &&
|
||||
reported(r)! <= cutoff,
|
||||
)
|
||||
.sort((a, b) => reported(a)!.localeCompare(reported(b)!))
|
||||
.at(-1);
|
||||
return {
|
||||
patient,
|
||||
name: patient.name?.[0]?.text,
|
||||
curp: patient.identifier?.find((i) => i.system === CURP)?.value,
|
||||
status: ext(patient, 'follow-up-status')?.valueCoding?.code ?? '',
|
||||
priority: ext(patient, 'follow-up-priority')?.valueCoding?.code ?? '',
|
||||
ageGroup: ageGroup(patient.birthDate, cutoff, CAMA_AGE_GROUPS),
|
||||
mammogram: {
|
||||
date: exam,
|
||||
birads: mammogram
|
||||
? code(results(mammogram).get('mammography.birads')?.valueCodeableConcept)
|
||||
: undefined,
|
||||
days: mammogram ? ext(mammogram, 'days-to-diagnosis')?.valueInteger : undefined,
|
||||
},
|
||||
biopsy: biopsy && {
|
||||
date: reported(biopsy)!,
|
||||
histology: code(results(biopsy).get('breast_biopsy.histology')?.valueCodeableConcept),
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
import { Component, computed, inject, input, resource } from '@angular/core';
|
||||
import { MatTabsModule } from '@angular/material/tabs';
|
||||
import type { Measure } from 'fhir/r4';
|
||||
import { DOMAINS } from '../app';
|
||||
import { Fhir, resources } from '../fhir';
|
||||
import { TabDefiniciones } from './tab-definiciones';
|
||||
import { TabIndicadores } from './tab-indicadores';
|
||||
import { TabRiesgos } from './tab-riesgos';
|
||||
import { TabRiesgosTea } from './tab-riesgos-tea';
|
||||
import { TabSeguimiento } from './tab-seguimiento';
|
||||
import { TabTrazabilidad } from './tab-trazabilidad';
|
||||
import { Loading } from '../loading';
|
||||
@Component({
|
||||
selector: 'app-indicadores',
|
||||
imports: [
|
||||
Loading,
|
||||
MatTabsModule,
|
||||
TabIndicadores,
|
||||
TabTrazabilidad,
|
||||
TabRiesgos,
|
||||
TabRiesgosTea,
|
||||
TabSeguimiento,
|
||||
TabDefiniciones,
|
||||
],
|
||||
template: `
|
||||
<section class="page">
|
||||
<h1>{{ title() }}</h1>
|
||||
<p class="subtitle">Explora los indicadores de {{ title().toLowerCase() }}.</p>
|
||||
@if (measures.isLoading()) {
|
||||
<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) {
|
||||
<p class="muted empty">Este dominio todavía no tiene indicadores publicados.</p>
|
||||
} @else {
|
||||
<mat-tab-group mat-stretch-tabs="false" mat-align-tabs="center" animationDuration="0ms">
|
||||
<mat-tab [label]="domain() === 'tea' ? 'Resumen' : 'Indicadores'">
|
||||
<app-tab-indicadores [domain]="domain()" [measures]="measures.value()!" />
|
||||
</mat-tab>
|
||||
<mat-tab label="Trazabilidad">
|
||||
<ng-template matTabContent>
|
||||
<app-tab-trazabilidad [domain]="domain()" [measures]="measures.value()!" />
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
@if (domain() === 'cacu') {
|
||||
<mat-tab label="Análisis de riesgos">
|
||||
<ng-template matTabContent>
|
||||
<app-tab-riesgos [domain]="domain()" />
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
} @else if (domain() === 'tea') {
|
||||
<mat-tab label="Análisis de Riesgo">
|
||||
<ng-template matTabContent>
|
||||
<app-tab-riesgos-tea [domain]="domain()" />
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
} @else if (domain() === 'cama') {
|
||||
<mat-tab label="Análisis de riesgos">
|
||||
<ng-template matTabContent>
|
||||
<app-tab-seguimiento [domain]="domain()" />
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
}
|
||||
<mat-tab label="Datos y definiciones">
|
||||
<ng-template matTabContent>
|
||||
<app-tab-definiciones [domain]="domain()" [measures]="measures.value()!" />
|
||||
</ng-template>
|
||||
</mat-tab>
|
||||
</mat-tab-group>
|
||||
}
|
||||
</section>
|
||||
`,
|
||||
styles: `
|
||||
:host {
|
||||
display: block;
|
||||
}
|
||||
/* As the old page: the domain's name and a line under it, then a white tab bar under
|
||||
an olive rule. */
|
||||
h1 {
|
||||
font-size: 28px;
|
||||
font-weight: 500;
|
||||
margin: 16px 0 8px;
|
||||
}
|
||||
.subtitle {
|
||||
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;
|
||||
text-align: center;
|
||||
}
|
||||
::ng-deep .mdc-tab-indicator__content--underline {
|
||||
border-color: var(--color-primary) !important;
|
||||
}
|
||||
`,
|
||||
})
|
||||
export class Indicadores {
|
||||
private readonly fhir = inject(Fhir);
|
||||
readonly domain = input.required<string>();
|
||||
protected readonly title = computed(
|
||||
() => DOMAINS[this.domain() as keyof typeof DOMAINS] ?? this.domain(),
|
||||
);
|
||||
protected readonly measures = resource({
|
||||
params: () => this.domain(),
|
||||
loader: async ({ params }) =>
|
||||
resources<Measure>(await this.fhir.all(params, 'Measure'), 'Measure'),
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
export interface Layout {
|
||||
kpis: string[];
|
||||
route: {
|
||||
label: string;
|
||||
fromSample: string;
|
||||
fromStep: string;
|
||||
step: string;
|
||||
}[];
|
||||
anchor: string;
|
||||
}
|
||||
export const LAYOUTS: Record<string, Layout> = {
|
||||
cacu: {
|
||||
kpis: [
|
||||
'CACU_EU7',
|
||||
'CACU_EU_TIEMPO_REPORTE',
|
||||
'CACU_DIAS_TOMA_DIAGNOSTICO',
|
||||
'CACU_DIAS_TOMA_TRATAMIENTO',
|
||||
'CACU_DIAS_DIAGNOSTICO_TRATAMIENTO',
|
||||
],
|
||||
route: [
|
||||
{
|
||||
label: 'Resultado de citología',
|
||||
step: 'Toma a resultado de citología',
|
||||
fromSample: 'CACU_EU_TIEMPO_REPORTE',
|
||||
fromStep: 'CACU_EU_TIEMPO_REPORTE',
|
||||
},
|
||||
{
|
||||
label: 'Colposcopía',
|
||||
step: 'Del resultado de citología a la colposcopía',
|
||||
fromSample: 'CACU_DIAS_TOMA_COLPOSCOPIA',
|
||||
fromStep: 'CACU_DIAS_RESULTADO_COLPOSCOPIA',
|
||||
},
|
||||
{
|
||||
label: 'Resultado de biopsia',
|
||||
step: 'De la colposcopía al resultado de biopsia',
|
||||
fromSample: 'CACU_DIAS_TOMA_BIOPSIA',
|
||||
fromStep: 'CACU_DIAS_COLPOSCOPIA_BIOPSIA',
|
||||
},
|
||||
{
|
||||
label: 'Diagnóstico',
|
||||
step: 'Del resultado de biopsia al diagnóstico',
|
||||
fromSample: 'CACU_DIAS_TOMA_DIAGNOSTICO',
|
||||
fromStep: 'CACU_DIAS_BIOPSIA_DIAGNOSTICO',
|
||||
},
|
||||
],
|
||||
anchor: 'IND1',
|
||||
},
|
||||
cama: {
|
||||
kpis: [
|
||||
'CAMA_BIRADS',
|
||||
'CAMA_EU38A',
|
||||
'CAMA_DIAS_TOMA_DIAGNOSTICO',
|
||||
'CAMA_CONFIRMACION_BIRADS45',
|
||||
'CAMA_TASA_DETECCION_HISTOPATOLOGICA',
|
||||
],
|
||||
route: [
|
||||
{
|
||||
label: 'Resultado de mastografía',
|
||||
step: 'Toma a resultado de mastografía',
|
||||
fromSample: 'CAMA_EU38A',
|
||||
fromStep: 'CAMA_EU38A',
|
||||
},
|
||||
{
|
||||
label: 'Diagnóstico',
|
||||
step: 'Del resultado de mastografía al diagnóstico',
|
||||
fromSample: 'CAMA_DIAS_TOMA_DIAGNOSTICO',
|
||||
fromStep: 'CAMA_DIAS_RESULTADO_DIAGNOSTICO',
|
||||
},
|
||||
],
|
||||
anchor: 'CAMA_BIRADS',
|
||||
},
|
||||
tea: {
|
||||
kpis: [
|
||||
'M23_PACIENTES_EVALUADOS',
|
||||
'M24_CONFIRMACION_DIAGNOSTICO',
|
||||
'M25_DIAS_MCHAT_DIAGNOSTICO',
|
||||
'M21_DIAGNOSTICADOS_CON_EEG',
|
||||
'M29_CALIDAD_EEG',
|
||||
],
|
||||
route: [
|
||||
{
|
||||
label: 'ADOS-2',
|
||||
step: 'Del M-CHAT al ADOS-2',
|
||||
fromSample: 'M26_DIAS_MCHAT_ADOS2',
|
||||
fromStep: 'M26_DIAS_MCHAT_ADOS2',
|
||||
},
|
||||
{
|
||||
label: 'Valoración neuropediátrica',
|
||||
step: 'Del ADOS-2 a la valoración neuropediátrica',
|
||||
fromSample: 'M25_DIAS_MCHAT_DIAGNOSTICO',
|
||||
fromStep: 'M27_DIAS_ADOS2_DIAGNOSTICO',
|
||||
},
|
||||
],
|
||||
anchor: 'M23_PACIENTES_EVALUADOS',
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,299 @@
|
||||
import type { Measure, MeasureReport, MeasureReportGroup } from 'fhir/r4';
|
||||
import { code, ext } from '../fhir';
|
||||
import { Figure, PALETTE } from '../plot';
|
||||
export type PeriodType = 'semester' | 'month';
|
||||
export type Scoring = 'proportion' | 'continuous-variable' | 'cohort';
|
||||
export function periods(type: PeriodType, years = 6, today = new Date()): string[] {
|
||||
const found: string[] = [];
|
||||
const year = today.getFullYear();
|
||||
if (type === 'semester') {
|
||||
for (let y = year; y > year - years; y--) {
|
||||
if (y < year || today.getMonth() >= 6) found.push(`${y}-S2`);
|
||||
found.push(`${y}-S1`);
|
||||
}
|
||||
} else {
|
||||
for (let i = 0; i < years * 12; i++) {
|
||||
const d = new Date(year, today.getMonth() - i, 1);
|
||||
found.push(`${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}`);
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
export function periodLabel(period: string): string {
|
||||
const [year, part] = period.split('-');
|
||||
if (part.startsWith('S')) return `${part === 'S1' ? 'Ene–Jun' : 'Jul–Dic'} ${year}`;
|
||||
const month = new Date(Number(year), Number(part) - 1, 1).toLocaleString('es-MX', {
|
||||
month: 'short',
|
||||
});
|
||||
return `${month} ${year}`;
|
||||
}
|
||||
export function scoring(measure: Measure): Scoring {
|
||||
return code(measure.scoring) as Scoring;
|
||||
}
|
||||
export function periodTypes(measure: Measure): PeriodType[] {
|
||||
return (measure.extension ?? [])
|
||||
.filter((e) => e.url.endsWith('/period-type'))
|
||||
.map((e) => e.valueCode as PeriodType);
|
||||
}
|
||||
export interface Reading {
|
||||
populations: Record<string, number>;
|
||||
score?: number;
|
||||
low?: number;
|
||||
high?: number;
|
||||
unit?: string;
|
||||
strata: Record<string, Record<string, Record<string, number>>>;
|
||||
}
|
||||
function counts(group: {
|
||||
population?: {
|
||||
code?: {
|
||||
coding?: {
|
||||
code?: string;
|
||||
}[];
|
||||
};
|
||||
count?: number;
|
||||
}[];
|
||||
}) {
|
||||
return Object.fromEntries(
|
||||
(group.population ?? []).map((p) => [p.code?.coding?.[0]?.code ?? '', p.count ?? 0]),
|
||||
);
|
||||
}
|
||||
export function reading(report: MeasureReport | undefined): Reading | undefined {
|
||||
const group: MeasureReportGroup | undefined = report?.group?.[0];
|
||||
if (!group) return undefined;
|
||||
const score = group.measureScore;
|
||||
const strata: Reading['strata'] = {};
|
||||
for (const s of group.stratifier ?? []) {
|
||||
const name = (s.code ?? []).map((c) => code(c) ?? c.text ?? '').join('-');
|
||||
strata[name] = Object.fromEntries(
|
||||
(s.stratum ?? []).map((x) => [
|
||||
x.component?.length
|
||||
? x.component.map((c) => c.value?.text ?? '').join('|')
|
||||
: (x.value?.text ?? ''),
|
||||
counts(x),
|
||||
]),
|
||||
);
|
||||
}
|
||||
return {
|
||||
populations: counts(group),
|
||||
score: score?.value,
|
||||
low: (ext(score, 'ic-bajo') ?? ext(score, 'q1'))?.valueDecimal,
|
||||
high: (ext(score, 'ic-alto') ?? ext(score, 'q3'))?.valueDecimal,
|
||||
unit: score?.unit,
|
||||
strata,
|
||||
};
|
||||
}
|
||||
export const LABELS: Record<string, string> = {
|
||||
NILM: 'Normal (NILM)',
|
||||
LSIL: 'LIEBG',
|
||||
HSIL: 'LIEAG',
|
||||
normal: 'Normal',
|
||||
carcinoma: 'Carcinoma',
|
||||
no_data: 'Sin dato',
|
||||
no_biopsy: 'Sin biopsia',
|
||||
pre_colposcopy: 'Pre colposcopia',
|
||||
post_colposcopy: 'Post colposcopia',
|
||||
post_treatment: 'Post tratamiento',
|
||||
case: 'Caso (cáncer)',
|
||||
low: 'Bajo',
|
||||
intermediate: 'Intermedio',
|
||||
high: 'Alto',
|
||||
satisfactory: 'satisfactoria',
|
||||
unsatisfactory: 'insatisfactoria',
|
||||
benign: 'Benigno',
|
||||
in_situ: 'Carcinoma in situ',
|
||||
invasive: 'Carcinoma invasor',
|
||||
cancer: 'Diagnóstico confirmado',
|
||||
pending_biopsy: 'Pendiente de biopsia',
|
||||
biopsy_no_result: 'Biopsia sin resultado',
|
||||
benign_biopsy: 'Biopsia benigna',
|
||||
confirmed: 'Diagnóstico confirmado',
|
||||
in_process: 'En proceso',
|
||||
not_confirmed: 'Sin TEA',
|
||||
mchat_only: 'Solo M-CHAT',
|
||||
psychology: 'Psicología (ADOS-2)',
|
||||
neuropediatrics: 'Neuropediatría',
|
||||
eeg: 'EEG',
|
||||
good: 'Bueno',
|
||||
bad: 'Malo',
|
||||
not_analyzed: 'Sin analizar',
|
||||
...Object.fromEntries(
|
||||
['0', '1', '2', '3', '4', '4A', '4B', '4C', '5', '6'].map((c) => [c, `BI-RADS ${c}`]),
|
||||
),
|
||||
};
|
||||
export const PRIORITY: Record<string, string> = { high: 'Alta', medium: 'Media', low: 'Baja' };
|
||||
export const STRATA: Record<string, string> = {
|
||||
category: 'Categoría',
|
||||
age_group: 'Grupo de edad',
|
||||
follow_up_status: 'Estatus de seguimiento',
|
||||
result: 'Citología de alto grado',
|
||||
birads: 'BI-RADS de la mastografía',
|
||||
};
|
||||
export const name = (value: string) => LABELS[value] ?? value;
|
||||
export function formatScore(measure: Measure, r: Reading | undefined): string {
|
||||
if (!r || r.score === undefined) return 'Sin dato';
|
||||
switch (scoring(measure)) {
|
||||
case 'proportion':
|
||||
return `${(r.score * 100).toFixed(1)} %`;
|
||||
case 'continuous-variable':
|
||||
return `${Math.round(r.score * 10) / 10} días`;
|
||||
default:
|
||||
return `${r.score}`;
|
||||
}
|
||||
}
|
||||
export function detail(measure: Measure, r: Reading | undefined): string {
|
||||
if (!r) return '';
|
||||
const p = r.populations;
|
||||
switch (scoring(measure)) {
|
||||
case 'proportion':
|
||||
return r.score === undefined
|
||||
? 'Sin pacientes en el periodo.'
|
||||
: `${p['numerator']} de ${p['denominator']} pacientes. IC 95 %: ${pct(r.low)}–${pct(r.high)}.`;
|
||||
case 'continuous-variable':
|
||||
return r.score === undefined
|
||||
? `${p['initial-population'] ?? 0} sin medición en el periodo.`
|
||||
: `Mediana de ${p['measure-observation']} mediciones; cuartiles ${r.low}–${r.high} días.`;
|
||||
default:
|
||||
return `${p['initial-population'] ?? 0} pacientes.`;
|
||||
}
|
||||
}
|
||||
const pct = (v?: number) => (v === undefined ? '—' : `${(v * 100).toFixed(1)} %`);
|
||||
export function donut(measure: Measure, r: Reading, stratifier = 'category'): Figure {
|
||||
let labels: string[], values: number[];
|
||||
if (scoring(measure) === 'proportion') {
|
||||
const { numerator = 0, denominator = 0 } = r.populations;
|
||||
labels = ['Numerador', 'Resto'];
|
||||
values = [numerator, denominator - numerator];
|
||||
} else {
|
||||
const cells = Object.entries(r.strata[stratifier] ?? {});
|
||||
labels = cells.map(([v]) => name(v));
|
||||
values = cells.map(([, c]) => c['initial-population'] ?? 0);
|
||||
}
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
type: 'pie',
|
||||
hole: 0.62,
|
||||
labels,
|
||||
values,
|
||||
sort: false,
|
||||
textinfo: 'value+percent',
|
||||
marker: { colors: PALETTE },
|
||||
},
|
||||
],
|
||||
layout: { showlegend: true, margin: { t: 32, r: 8, b: 32, l: 8 } },
|
||||
};
|
||||
}
|
||||
export function strataBars(measure: Measure, r: Reading, stratifier: string): Figure {
|
||||
const cells = Object.entries(r.strata[stratifier] ?? {});
|
||||
const proportion = scoring(measure) === 'proportion';
|
||||
const values = cells.map(([, c]) =>
|
||||
proportion
|
||||
? c['denominator']
|
||||
? (100 * (c['numerator'] ?? 0)) / c['denominator']
|
||||
: 0
|
||||
: (c['initial-population'] ?? 0),
|
||||
);
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
type: 'bar',
|
||||
orientation: 'h',
|
||||
y: cells.map(([v]) => name(v)),
|
||||
x: values,
|
||||
marker: { color: PALETTE[0] },
|
||||
},
|
||||
],
|
||||
layout: {
|
||||
xaxis: { title: { text: proportion ? '%' : 'Pacientes' } },
|
||||
yaxis: { automargin: true },
|
||||
margin: { t: 8, r: 16, b: 48, l: 8 },
|
||||
},
|
||||
};
|
||||
}
|
||||
export function medians(
|
||||
rows: {
|
||||
label: string;
|
||||
r: Reading | undefined;
|
||||
}[],
|
||||
): Figure {
|
||||
const shown = rows.filter((x) => x.r?.score !== undefined);
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
type: 'bar',
|
||||
orientation: 'h',
|
||||
y: shown.map((x) => x.label),
|
||||
x: shown.map((x) => x.r!.score!),
|
||||
error_x: {
|
||||
type: 'data',
|
||||
symmetric: false,
|
||||
array: shown.map((x) => (x.r!.high ?? x.r!.score!) - x.r!.score!),
|
||||
arrayminus: shown.map((x) => x.r!.score! - (x.r!.low ?? x.r!.score!)),
|
||||
color: '#17324d',
|
||||
},
|
||||
marker: { color: PALETTE[0] },
|
||||
hovertemplate: '%{y}: %{x} días<extra></extra>',
|
||||
},
|
||||
],
|
||||
layout: {
|
||||
xaxis: { title: { text: 'Días (mediana, Q1–Q3)' } },
|
||||
yaxis: { automargin: true, autorange: 'reversed' },
|
||||
},
|
||||
};
|
||||
}
|
||||
export function history(
|
||||
measure: Measure,
|
||||
series: {
|
||||
period: string;
|
||||
r: Reading | undefined;
|
||||
}[],
|
||||
): Figure {
|
||||
const x = series.map((s) => periodLabel(s.period));
|
||||
const kind = scoring(measure);
|
||||
if (kind === 'cohort') {
|
||||
const categories = [
|
||||
...new Set(series.flatMap((s) => Object.keys(s.r?.strata['category'] ?? {}))),
|
||||
];
|
||||
return {
|
||||
data: categories.map((c, i) => ({
|
||||
type: 'bar',
|
||||
name: name(c),
|
||||
x,
|
||||
y: series.map((s) => s.r?.strata['category']?.[c]?.['initial-population'] ?? 0),
|
||||
marker: { color: PALETTE[i % PALETTE.length] },
|
||||
})),
|
||||
layout: { barmode: 'stack', yaxis: { title: { text: 'Pacientes' } } },
|
||||
};
|
||||
}
|
||||
const k = kind === 'proportion' ? 100 : 1;
|
||||
const value = (v?: number) => (v === undefined ? null : v * k);
|
||||
return {
|
||||
data: [
|
||||
{
|
||||
x,
|
||||
y: series.map((s) => value(s.r?.high)),
|
||||
mode: 'lines',
|
||||
line: { width: 0 },
|
||||
showlegend: false,
|
||||
hoverinfo: 'skip',
|
||||
},
|
||||
{
|
||||
x,
|
||||
y: series.map((s) => value(s.r?.low)),
|
||||
mode: 'lines',
|
||||
line: { width: 0 },
|
||||
fill: 'tonexty',
|
||||
fillcolor: 'rgba(168,194,67,0.25)',
|
||||
name: kind === 'proportion' ? 'IC 95 %' : 'Q1–Q3',
|
||||
},
|
||||
{
|
||||
x,
|
||||
y: series.map((s) => value(s.r?.score)),
|
||||
mode: 'lines+markers',
|
||||
name: kind === 'proportion' ? '%' : 'Mediana',
|
||||
line: { color: PALETTE[0] },
|
||||
},
|
||||
],
|
||||
layout: { yaxis: { title: { text: kind === 'proportion' ? '%' : 'Días' } } },
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,635 @@
|
||||
export interface Page {
|
||||
kpis: Kpi[];
|
||||
opportunity?: Section[];
|
||||
clinical: Section[];
|
||||
anchor: string;
|
||||
}
|
||||
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';
|
||||
title?: string;
|
||||
cards: {
|
||||
measure?: string;
|
||||
title: string;
|
||||
}[];
|
||||
subtitles?: boolean;
|
||||
}
|
||||
| {
|
||||
kind: 'grid';
|
||||
figures: FigureSpec[];
|
||||
}
|
||||
| {
|
||||
kind: 'tea-summary';
|
||||
}
|
||||
| ({
|
||||
kind: 'card';
|
||||
} & Kpi);
|
||||
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;
|
||||
names: [string, string];
|
||||
}
|
||||
| {
|
||||
kind: 'rates';
|
||||
title: string;
|
||||
measure: string;
|
||||
stratum: string;
|
||||
rows: Category[];
|
||||
colored?: boolean;
|
||||
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[];
|
||||
faded?: string[];
|
||||
}
|
||||
const OLIVE = '#A8C243';
|
||||
const ROSE = '#C24269';
|
||||
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' },
|
||||
],
|
||||
};
|
||||
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.';
|
||||
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',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
export interface HistoryPanel {
|
||||
title: string;
|
||||
measure: string;
|
||||
kind: 'stack' | 'percent' | 'median';
|
||||
series?: {
|
||||
code: string;
|
||||
label: string;
|
||||
color: string;
|
||||
}[];
|
||||
axis?: string;
|
||||
group?: string;
|
||||
}
|
||||
export interface History {
|
||||
panels: HistoryPanel[];
|
||||
line: string;
|
||||
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,75 @@
|
||||
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';
|
||||
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();
|
||||
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))));
|
||||
}
|
||||
@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 {
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
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';
|
||||
const SCORING: Record<string, string> = {
|
||||
proportion: 'Proporción',
|
||||
'continuous-variable': 'Variable continua (mediana)',
|
||||
cohort: 'Composición (conteo)',
|
||||
};
|
||||
const IMPROVEMENT: Record<string, string> = {
|
||||
increase: 'Mejor si sube',
|
||||
decrease: 'Mejor si baja',
|
||||
};
|
||||
const PERIODS: Record<string, string> = { semester: 'Semestral', month: 'Mensual' };
|
||||
@Component({
|
||||
selector: 'app-tab-definiciones',
|
||||
template: `
|
||||
<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>
|
||||
}
|
||||
@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;
|
||||
}
|
||||
`,
|
||||
})
|
||||
export class TabDefiniciones {
|
||||
readonly domain = input.required<string>();
|
||||
readonly measures = input.required<Measure[]>();
|
||||
protected readonly scoring = SCORING;
|
||||
protected readonly improvement = IMPROVEMENT;
|
||||
protected readonly code = code;
|
||||
protected readonly domainName = computed(
|
||||
() => DOMAINS[this.domain() as Domain]?.toLocaleLowerCase('es-MX') ?? this.domain(),
|
||||
);
|
||||
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));
|
||||
return names.map((n) => STRATA[n] ?? n).join(', ') || '—';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
<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
|
||||
[value]="type()"
|
||||
(change)="setType($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>
|
||||
</div>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<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">{{ p }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<button
|
||||
mat-flat-button
|
||||
(click)="applied.set(chosen())"
|
||||
[disabled]="!chosen() || chosen() === applied()"
|
||||
>
|
||||
Aplicar
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@if (reports.isLoading()) {
|
||||
<app-loading what="los indicadores" text="Calculando los indicadores…" />
|
||||
}
|
||||
|
||||
@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-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>
|
||||
</mat-card>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (layout().route.length) {
|
||||
<mat-card appearance="outlined" class="route">
|
||||
<mat-card-header>
|
||||
<mat-card-title>Ruta del tamizaje</mat-card-title>
|
||||
<mat-button-toggle-group
|
||||
[value]="routeView()"
|
||||
(change)="routeView.set($event.value)"
|
||||
class="route-toggle"
|
||||
>
|
||||
<mat-button-toggle value="sample">Acumulado desde la toma</mat-button-toggle>
|
||||
<mat-button-toggle value="step">Por pasos</mat-button-toggle>
|
||||
</mat-button-toggle-group>
|
||||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
<app-plot [figure]="route()" [height]="260" />
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
}
|
||||
|
||||
<h2>Indicadores clínicos</h2>
|
||||
<div class="clinical">
|
||||
@for (m of clinical(); track m.id) {
|
||||
<mat-card appearance="outlined" class="clinical-card" [attr.data-measure]="m.name">
|
||||
<mat-card-header>
|
||||
<mat-card-title>{{ m.title }}</mat-card-title>
|
||||
<mat-card-subtitle>{{ score(m) }} · {{ detail(m) }}</mat-card-subtitle>
|
||||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
@for (f of figureSets().get(m.name!) ?? []; track f.title) {
|
||||
<h3 class="figure-title">{{ f.title }}</h3>
|
||||
<app-plot [figure]="f.figure" [height]="260" />
|
||||
} @empty {
|
||||
<p class="muted">Sin datos en el periodo.</p>
|
||||
}
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
:host {
|
||||
display: block;
|
||||
padding-top: var(--space-4);
|
||||
}
|
||||
|
||||
.filters {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-4);
|
||||
margin-bottom: var(--space-4);
|
||||
}
|
||||
|
||||
.field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-1);
|
||||
}
|
||||
|
||||
.label {
|
||||
color: var(--color-text-secondary);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-size: 1.15rem;
|
||||
font-weight: 500;
|
||||
margin: var(--space-6) 0 var(--space-3);
|
||||
}
|
||||
|
||||
.kpis {
|
||||
display: grid;
|
||||
gap: var(--space-3);
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
@media (min-width: 600px) {
|
||||
.kpis {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1000px) {
|
||||
.kpis {
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1350px) {
|
||||
.kpis {
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
.kpi-title {
|
||||
font-weight: 500;
|
||||
min-height: 2.6em;
|
||||
}
|
||||
|
||||
.kpi-value {
|
||||
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 {
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.route {
|
||||
margin-top: var(--space-4);
|
||||
}
|
||||
|
||||
.route mat-card-header {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-3);
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.clinical {
|
||||
display: grid;
|
||||
gap: var(--space-4);
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
@media (min-width: 1304px) {
|
||||
.clinical {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
.figure-title {
|
||||
color: var(--color-text-secondary);
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
margin: var(--space-3) 0 0;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
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 { Fhir, resources } from '../fhir';
|
||||
import { Figure, Plot } from '../plot';
|
||||
import { LAYOUTS } from './layout';
|
||||
import {
|
||||
ageShare,
|
||||
ageStack,
|
||||
boxFigure,
|
||||
countBars,
|
||||
fill,
|
||||
nestedDonut,
|
||||
rateDots,
|
||||
routeFigure,
|
||||
scenarioBars,
|
||||
shareDonut,
|
||||
} from './figures';
|
||||
import { FigureSpec, Kpi, PAGES, Section } from './pages';
|
||||
import {
|
||||
detail,
|
||||
donut,
|
||||
formatScore,
|
||||
medians,
|
||||
name,
|
||||
periodLabel,
|
||||
periods,
|
||||
PeriodType,
|
||||
reading,
|
||||
Reading,
|
||||
scoring,
|
||||
STRATA,
|
||||
strataBars,
|
||||
} from './measures';
|
||||
import { Loading } from '../loading';
|
||||
@Component({
|
||||
selector: 'app-tab-indicadores',
|
||||
imports: [
|
||||
Loading,
|
||||
FormsModule,
|
||||
NgTemplateOutlet,
|
||||
MatButtonModule,
|
||||
MatButtonToggleModule,
|
||||
MatCardModule,
|
||||
MatSelectModule,
|
||||
Plot,
|
||||
],
|
||||
templateUrl: './tab-indicadores.html',
|
||||
styleUrl: './tab-indicadores.scss',
|
||||
})
|
||||
export class TabIndicadores {
|
||||
private readonly fhir = inject(Fhir);
|
||||
readonly domain = input.required<string>();
|
||||
readonly measures = input.required<Measure[]>();
|
||||
protected readonly type = signal<PeriodType>('semester');
|
||||
protected readonly options = computed(() => periods(this.type()));
|
||||
protected readonly chosen = signal<string | undefined>(undefined);
|
||||
protected readonly applied = signal<string | undefined>(undefined);
|
||||
protected readonly routeView = signal<'sample' | 'step'>('sample');
|
||||
protected readonly layout = computed(
|
||||
() => LAYOUTS[this.domain()] ?? { kpis: [], route: [], anchor: '' },
|
||||
);
|
||||
protected readonly pending = 'Indicador no publicado en el catálogo institucional.';
|
||||
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()
|
||||
.kpis.map((n) => this.byName().get(n))
|
||||
.filter((m) => !!m),
|
||||
);
|
||||
protected readonly clinical = computed(() => {
|
||||
const placed = new Set([
|
||||
...this.layout().kpis,
|
||||
...this.layout().route.flatMap((s) => [s.fromSample, s.fromStep]),
|
||||
]);
|
||||
return this.measures().filter((m) => !placed.has(m.name!));
|
||||
});
|
||||
private readonly latest = resource({
|
||||
params: () => ({
|
||||
domain: this.domain(),
|
||||
anchor: this.byName().get(this.page()?.anchor ?? this.layout().anchor) ?? this.measures()[0],
|
||||
all: this.options(),
|
||||
}),
|
||||
loader: async ({ params }) => {
|
||||
const pages = await this.fhir.all(params.domain, 'MeasureReport', {
|
||||
measure: params.anchor.id!,
|
||||
'reporting-period': params.all.join(','),
|
||||
});
|
||||
const found = resources<MeasureReport>(pages, 'MeasureReport');
|
||||
const index = found.findIndex(
|
||||
(r) => (reading(r)?.populations['initial-population'] ?? 0) > 0,
|
||||
);
|
||||
return params.all[Math.max(index, 0)];
|
||||
},
|
||||
});
|
||||
protected readonly reports = resource({
|
||||
params: () => ({ domain: this.domain(), period: this.applied(), measures: this.measures() }),
|
||||
loader: async ({ params }) => {
|
||||
if (!params.period) return new Map<string, Reading | undefined>();
|
||||
const found = await Promise.all(
|
||||
params.measures.map(async (m) => {
|
||||
const page = await this.fhir.search(params.domain, 'MeasureReport', {
|
||||
measure: m.id!,
|
||||
'reporting-period': params.period,
|
||||
});
|
||||
return [m.name!, reading(resources<MeasureReport>(page, 'MeasureReport')[0])] as const;
|
||||
}),
|
||||
);
|
||||
return new Map(found);
|
||||
},
|
||||
});
|
||||
protected loaded(): Map<string, Reading | undefined> | undefined {
|
||||
return this.reports.hasValue() ? this.reports.value() : undefined;
|
||||
}
|
||||
constructor() {
|
||||
effect(() => {
|
||||
const latest = this.latest.value();
|
||||
if (latest && !this.applied()) {
|
||||
this.chosen.set(latest);
|
||||
this.applied.set(latest);
|
||||
}
|
||||
});
|
||||
}
|
||||
protected readonly label = periodLabel;
|
||||
protected readonly strataNames = STRATA;
|
||||
protected r(m: Measure): Reading | undefined {
|
||||
return this.loaded()?.get(m.name!);
|
||||
}
|
||||
protected score(m: Measure): string {
|
||||
return formatScore(m, this.r(m));
|
||||
}
|
||||
protected detail(m: Measure): string {
|
||||
return detail(m, this.r(m));
|
||||
}
|
||||
protected setType(type: PeriodType): void {
|
||||
this.type.set(type);
|
||||
this.chosen.set(this.options()[0]);
|
||||
}
|
||||
protected readonly route = computed<Figure>(() => {
|
||||
const view = this.routeView();
|
||||
return medians(
|
||||
this.layout().route.map((s) => {
|
||||
const m = this.byName().get(view === 'sample' ? s.fromSample : s.fromStep);
|
||||
return { label: view === 'sample' ? s.label : s.step, r: m && this.r(m) };
|
||||
}),
|
||||
);
|
||||
});
|
||||
protected readonly figureSets = computed(
|
||||
() =>
|
||||
new Map(this.clinical().map((m) => [m.name!, this.build(m, this.loaded()?.get(m.name!))])),
|
||||
);
|
||||
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' && !s.includes('-') && Object.keys(r.strata[s]).length,
|
||||
);
|
||||
const kind = scoring(m);
|
||||
if (kind === 'continuous-variable')
|
||||
return [{ title: 'Mediana y cuartiles', figure: medians([{ label: m.title!, r }]) }];
|
||||
return [
|
||||
{ title: kind === 'proportion' ? 'Numerador y resto' : 'Por categoría', figure: donut(m, r) },
|
||||
...strata.map((s) => ({
|
||||
title: `Por ${STRATA[s]?.toLowerCase() ?? s}`,
|
||||
figure: strataBars(m, r, s),
|
||||
})),
|
||||
];
|
||||
}
|
||||
protected readonly name = name;
|
||||
protected rd(code: string): Reading | undefined {
|
||||
return this.loaded()?.get(code);
|
||||
}
|
||||
protected kpi(code: string): Measure | undefined {
|
||||
return this.byName().get(code);
|
||||
}
|
||||
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) : '';
|
||||
}
|
||||
protected titled(title: string): string {
|
||||
return title.replace('{p}', this.applied() ?? '');
|
||||
}
|
||||
protected boxOf(measure: string | undefined): Figure | undefined {
|
||||
const r = measure ? this.rd(measure) : undefined;
|
||||
return r && r.score !== undefined ? boxFigure(r, this.applied() ?? '') : undefined;
|
||||
}
|
||||
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) || '';
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
<section class="card risk-tea" aria-labelledby="tea-risk-title">
|
||||
<h2 id="tea-risk-title" class="risk-title">Alteraciones de EEG relacionadas al TEA</h2>
|
||||
<div class="filters">
|
||||
<app-patient-search [(value)]="search" (searched)="pageIndex.set(0)" />
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Fecha de corte</mat-label>
|
||||
<input matInput type="date" [ngModel]="cutoff()" (ngModelChange)="cutoff.set($event)" />
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<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>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Estatus de EEG</mat-label>
|
||||
<mat-select [value]="eeg()" (selectionChange)="setFilter(eeg.set.bind(eeg), $event.value)">
|
||||
<mat-option value="">Todos</mat-option>
|
||||
@for (s of eegStatuses | keyvalue; track s.key) {
|
||||
<mat-option [value]="s.key">{{ s.value }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Grupo de edad</mat-label>
|
||||
<mat-select [value]="age()" (selectionChange)="setFilter(age.set.bind(age), $event.value)">
|
||||
<mat-option value="">Todos</mat-option>
|
||||
@for (a of ages(); track a) {
|
||||
<mat-option [value]="a">{{ ageLabel(a) }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Puntaje M-CHAT</mat-label>
|
||||
<mat-select
|
||||
[value]="mchat()"
|
||||
(selectionChange)="setFilter(mchat.set.bind(mchat), $event.value)"
|
||||
>
|
||||
<mat-option value="">Todos</mat-option>
|
||||
@for (b of mchatBands; track b.id) {
|
||||
<mat-option [value]="b.id">{{ b.label }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>CSS ADOS-2</mat-label>
|
||||
<mat-select [value]="css()" (selectionChange)="setFilter(css.set.bind(css), $event.value)">
|
||||
<mat-option value="">Todos</mat-option>
|
||||
@for (l of cssLevels; track l.id) {
|
||||
<mat-option [value]="l.id">{{ l.label }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Estado del caso</mat-label>
|
||||
<mat-select
|
||||
[value]="caseState()"
|
||||
(selectionChange)="setFilter(caseState.set.bind(caseState), $event.value)"
|
||||
>
|
||||
<mat-option value="">Todos</mat-option>
|
||||
@for (c of cases | keyvalue; track c.key) {
|
||||
<mat-option [value]="c.key">{{ c.value }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<mat-label>Tipo de alteración</mat-label>
|
||||
<mat-select
|
||||
[value]="altered()"
|
||||
(selectionChange)="setFilter(altered.set.bind(altered), $event.value)"
|
||||
>
|
||||
<mat-option value="">Todas</mat-option>
|
||||
@for (a of alterations(); track a) {
|
||||
<mat-option [value]="a">{{ alteration(a) }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic" class="narrow">
|
||||
<mat-label>Registros por página</mat-label>
|
||||
<input
|
||||
matInput
|
||||
type="number"
|
||||
min="10"
|
||||
max="200"
|
||||
[ngModel]="size()"
|
||||
(ngModelChange)="size.set(+$event || 50); pageIndex.set(0)"
|
||||
/>
|
||||
</mat-form-field>
|
||||
<button mat-stroked-button (click)="consult()">Consultar</button>
|
||||
</div>
|
||||
|
||||
@if (loading()) {
|
||||
<app-loading what="el seguimiento" />
|
||||
} @else {
|
||||
@let s = summary();
|
||||
<div class="eeg-summary" aria-label="EEG de los pacientes filtrados">
|
||||
<h3>EEG de los pacientes filtrados</h3>
|
||||
<div class="counts">
|
||||
<span
|
||||
><strong>{{ s.normal }}</strong> Normales</span
|
||||
>
|
||||
<span
|
||||
><strong>{{ s.abnormal }}</strong> Anormales</span
|
||||
>
|
||||
<span
|
||||
><strong>{{ s.none }}</strong> Sin EEG válido</span
|
||||
>
|
||||
</div>
|
||||
@if (s.alterations.length) {
|
||||
<ul class="by-alteration">
|
||||
@for (a of s.alterations; track a[0]) {
|
||||
<li>
|
||||
{{ alteration(a[0]) }}: <strong>{{ a[1] }}</strong>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
</div>
|
||||
|
||||
<table class="worklist">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Paciente</th>
|
||||
<th>Grupo de edad</th>
|
||||
<th>Estado del caso</th>
|
||||
<th>Último EEG</th>
|
||||
<th class="num">Puntaje M-CHAT</th>
|
||||
<th class="num">CSS ADOS-2</th>
|
||||
<th>Estatus de EEG</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (r of shown(); track r.patient.id) {
|
||||
<tr>
|
||||
<td>
|
||||
<a [routerLink]="['/indicadores', domain(), 'pacientes', r.patient.id]">{{
|
||||
r.name
|
||||
}}</a>
|
||||
</td>
|
||||
<td>{{ r.ageGroup ? ageLabel(r.ageGroup) : 'Sin dato' }}</td>
|
||||
<td>{{ cases[r.case] ?? r.case }}</td>
|
||||
<td>{{ r.lastEeg ?? '—' }}</td>
|
||||
<td class="num">{{ r.mchat ?? '—' }}</td>
|
||||
<td class="num">{{ r.css ?? '—' }}</td>
|
||||
<td>{{ eegStatuses[r.eegStatus] ?? r.eegStatus }}</td>
|
||||
</tr>
|
||||
} @empty {
|
||||
<tr>
|
||||
<td colspan="7" class="muted">No hay registros para los filtros aplicados.</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="pager">
|
||||
<button mat-button [disabled]="pageIndex() === 0" (click)="pageIndex.set(pageIndex() - 1)">
|
||||
Anterior
|
||||
</button>
|
||||
<span>Página {{ pageIndex() + 1 }} de {{ pages() }} · {{ filtered().length }} pacientes</span>
|
||||
<button
|
||||
mat-button
|
||||
[disabled]="pageIndex() + 1 >= pages()"
|
||||
(click)="pageIndex.set(pageIndex() + 1)"
|
||||
>
|
||||
Siguiente
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</section>
|
||||
@@ -0,0 +1,80 @@
|
||||
.risk-tea {
|
||||
background: var(--color-surface);
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 8px;
|
||||
margin-top: 24px;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.risk-title {
|
||||
font-family: var(--font-heading);
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
margin: 0 0 16px;
|
||||
}
|
||||
|
||||
.filters {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
|
||||
.narrow {
|
||||
width: 160px;
|
||||
}
|
||||
}
|
||||
|
||||
.eeg-summary {
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 8px;
|
||||
margin-bottom: 16px;
|
||||
padding: 12px 16px;
|
||||
|
||||
h3 {
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
|
||||
.counts {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.by-alteration {
|
||||
columns: 2;
|
||||
margin: 8px 0 0;
|
||||
padding-left: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
.pager {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
justify-content: flex-end;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.worklist {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
|
||||
th,
|
||||
td {
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
padding: 8px 10px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
th {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.num {
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
import { METRIC_NAMES } from '../eeg-labels';
|
||||
import { KeyValuePipe } from '@angular/common';
|
||||
import { Component, computed, inject, input, resource, signal } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import type { Patient } from 'fhir/r4';
|
||||
import { EXT, Fhir, resources } from '../fhir';
|
||||
import { Loading } from '../loading';
|
||||
import { ageLabel } from './figures';
|
||||
import { name } from './measures';
|
||||
import { matchesSearch, PatientSearch } from './patient-search';
|
||||
export interface TeaRow {
|
||||
patient: Patient;
|
||||
name: string;
|
||||
ageGroup: string;
|
||||
case: string;
|
||||
status: string;
|
||||
eegStatus: string;
|
||||
alterations: string[];
|
||||
lastEeg?: string;
|
||||
mchat?: number;
|
||||
css?: number;
|
||||
}
|
||||
const has = (p: Patient, n: string) => (p.extension ?? []).filter((e) => e.url === EXT + n);
|
||||
export function teaRow(p: Patient): TeaRow {
|
||||
const coded = (n: string) => has(p, n)[0]?.valueCoding?.code ?? '';
|
||||
return {
|
||||
patient: p,
|
||||
name: p.name?.[0]?.text ?? (p.id ?? '').slice(0, 8),
|
||||
ageGroup: has(p, 'tea-age-group')[0]?.valueString ?? '',
|
||||
case: coded('tea-case'),
|
||||
status: coded('follow-up-status'),
|
||||
eegStatus: coded('tea-eeg-status'),
|
||||
alterations: has(p, 'tea-eeg-alteration').map((e) => e.valueCoding?.code ?? ''),
|
||||
lastEeg: has(p, 'tea-last-eeg')[0]?.valueDate,
|
||||
mchat: has(p, 'mchat-score')[0]?.valueInteger,
|
||||
css: has(p, 'ados2-css')[0]?.valueInteger,
|
||||
};
|
||||
}
|
||||
const MCHAT = [
|
||||
{ id: 'low', label: 'Bajo (0 a 2)', test: (v: number) => v <= 2 },
|
||||
{ id: 'medium', label: 'Medio (3 a 7)', test: (v: number) => v >= 3 && v <= 7 },
|
||||
{ id: 'high', label: 'Alto (8 a 20)', test: (v: number) => v >= 8 },
|
||||
];
|
||||
const CSS = [
|
||||
{ id: 'minimal', label: 'Mínimo (1 a 2)', test: (v: number) => v <= 2 },
|
||||
{ id: 'low', label: 'Bajo (3 a 4)', test: (v: number) => v >= 3 && v <= 4 },
|
||||
{ id: 'moderate', label: 'Moderado (5 a 7)', test: (v: number) => v >= 5 && v <= 7 },
|
||||
{ id: 'high', label: 'Alto (8 a 10)', test: (v: number) => v >= 8 },
|
||||
];
|
||||
const EEG_STATUS: Record<string, string> = {
|
||||
normal: 'Normal',
|
||||
abnormal: 'Anormal',
|
||||
no_valid_eeg: 'Sin EEG válido',
|
||||
};
|
||||
const CASE: Record<string, string> = {
|
||||
confirmed: 'Diagnóstico confirmado',
|
||||
in_process: 'En proceso',
|
||||
not_confirmed: 'Sin TEA',
|
||||
};
|
||||
export const alteration = (a: string) => {
|
||||
const [metric, side] = a.split(':');
|
||||
const shown = (METRIC_NAMES[metric] ?? metric).replace(/ \(.*\)$/, '');
|
||||
return side ? `${shown} (${side === 'above' ? 'aumentado' : 'disminuido'})` : shown;
|
||||
};
|
||||
@Component({
|
||||
selector: 'app-tab-riesgos-tea',
|
||||
imports: [
|
||||
PatientSearch,
|
||||
FormsModule,
|
||||
KeyValuePipe,
|
||||
Loading,
|
||||
MatButtonModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
MatSelectModule,
|
||||
RouterLink,
|
||||
],
|
||||
templateUrl: './tab-riesgos-tea.html',
|
||||
styleUrls: ['./tab-riesgos.scss', './tab-riesgos-tea.scss'],
|
||||
})
|
||||
export class TabRiesgosTea {
|
||||
private readonly fhir = inject(Fhir);
|
||||
readonly domain = input.required<string>();
|
||||
protected readonly cutoff = signal('');
|
||||
protected readonly window = signal(3);
|
||||
protected readonly eeg = signal('');
|
||||
protected readonly age = signal('');
|
||||
protected readonly mchat = signal('');
|
||||
protected readonly css = signal('');
|
||||
protected readonly caseState = signal('');
|
||||
protected readonly altered = signal('');
|
||||
protected readonly size = signal(50);
|
||||
protected readonly search = signal('');
|
||||
protected readonly pageIndex = signal(0);
|
||||
private readonly asked = signal({ cutoff: '', window: 3 });
|
||||
protected readonly mchatBands = MCHAT;
|
||||
protected readonly cssLevels = CSS;
|
||||
protected readonly eegStatuses = EEG_STATUS;
|
||||
protected readonly cases = CASE;
|
||||
protected readonly label = name;
|
||||
protected readonly ageLabel = ageLabel;
|
||||
protected readonly alteration = alteration;
|
||||
private readonly list = resource({
|
||||
params: () => ({ domain: this.domain(), ...this.asked() }),
|
||||
loader: async ({ params: { domain, cutoff, window } }) => {
|
||||
const pages = await this.fhir.all(domain, 'Patient', {
|
||||
'follow-up-window': window,
|
||||
...(cutoff ? { 'follow-up-cutoff': cutoff } : {}),
|
||||
_count: 200,
|
||||
});
|
||||
return resources<Patient>(pages, 'Patient').map(teaRow);
|
||||
},
|
||||
});
|
||||
protected readonly loading = computed(() => this.list.isLoading());
|
||||
protected readonly all = computed(() => this.list.value() ?? []);
|
||||
protected readonly ages = computed(() => [...new Set(this.all().map((r) => r.ageGroup))].sort());
|
||||
protected readonly alterations = computed(() =>
|
||||
[...new Set(this.all().flatMap((r) => r.alterations))].sort(),
|
||||
);
|
||||
protected readonly filtered = computed(() => {
|
||||
const band = MCHAT.find((b) => b.id === this.mchat());
|
||||
const level = CSS.find((l) => l.id === this.css());
|
||||
return this.all().filter(
|
||||
(r) =>
|
||||
(!this.eeg() || r.eegStatus === this.eeg()) &&
|
||||
(!this.age() || r.ageGroup === this.age()) &&
|
||||
(!band || (r.mchat !== undefined && band.test(r.mchat))) &&
|
||||
(!level || (r.css !== undefined && level.test(r.css))) &&
|
||||
(!this.caseState() || r.case === this.caseState()) &&
|
||||
(!this.altered() || r.alterations.includes(this.altered())) &&
|
||||
matchesSearch(this.search(), [
|
||||
r.name,
|
||||
r.patient.id,
|
||||
...(r.patient.name ?? []).map((n) => n.text),
|
||||
...(r.patient.identifier ?? []).map((i) => i.value),
|
||||
]),
|
||||
);
|
||||
});
|
||||
protected readonly shown = computed(() =>
|
||||
this.filtered().slice(this.pageIndex() * this.size(), (this.pageIndex() + 1) * this.size()),
|
||||
);
|
||||
protected readonly pages = computed(() =>
|
||||
Math.max(1, Math.ceil(this.filtered().length / this.size())),
|
||||
);
|
||||
protected readonly summary = computed(() => {
|
||||
const rows = this.filtered();
|
||||
const count = (s: string) => rows.filter((r) => r.eegStatus === s).length;
|
||||
const by = new Map<string, number>();
|
||||
for (const r of rows) for (const a of r.alterations) by.set(a, (by.get(a) ?? 0) + 1);
|
||||
return {
|
||||
normal: count('normal'),
|
||||
abnormal: count('abnormal'),
|
||||
none: count('no_valid_eeg'),
|
||||
alterations: [...by.entries()].sort((a, b) => b[1] - a[1]),
|
||||
};
|
||||
});
|
||||
protected consult(): void {
|
||||
this.pageIndex.set(0);
|
||||
this.asked.set({ cutoff: this.cutoff(), window: this.window() });
|
||||
}
|
||||
protected setFilter(set: (v: string) => void, value: string): void {
|
||||
set(value);
|
||||
this.pageIndex.set(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
<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
|
||||
matInput
|
||||
type="date"
|
||||
[ngModel]="cutoff() || applied()"
|
||||
(ngModelChange)="cutoff.set($event)"
|
||||
name="cutoff"
|
||||
/>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<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>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<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) {
|
||||
<mat-option [value]="s">{{ name(s) }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<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>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<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>
|
||||
<mat-option value="-risk-cancer">Mayor riesgo de cáncer</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<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>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</form>
|
||||
|
||||
@if (error()) {
|
||||
<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 de seguimiento</th>
|
||||
<th>Última citología</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>
|
||||
@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>
|
||||
@if (row.curp) {
|
||||
<div class="muted curp">{{ row.curp }}</div>
|
||||
}
|
||||
</td>
|
||||
<td>{{ row.ageGroup }}</td>
|
||||
<td>{{ name(row.status) }}</td>
|
||||
<td>
|
||||
@if (row.cytology; as c) {
|
||||
{{
|
||||
c.result
|
||||
? name(c.result)
|
||||
: c.adequacy === 'unsatisfactory'
|
||||
? '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' }}
|
||||
<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) {
|
||||
{{ name(b.histology ?? '') || 'Sin grado' }}
|
||||
<small>Fecha: {{ b.date }}</small>
|
||||
} @else {
|
||||
No disponible
|
||||
}
|
||||
</td>
|
||||
<td class="num">
|
||||
{{
|
||||
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>{{ latest(row) ?? 'No disponible' }}</td>
|
||||
<td class="num">{{ row.daysToDiagnosis ?? 'No disponible' }}</td>
|
||||
</tr>
|
||||
} @empty {
|
||||
@if (page() && !loading()) {
|
||||
<tr>
|
||||
<td colspan="10" class="muted">No hay registros para los filtros aplicados.</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="pager">
|
||||
<span class="muted">
|
||||
@if (page()?.total; as total) {
|
||||
Página {{ pageNumber() }} de {{ pageCount() }}, {{ total }} registros
|
||||
}
|
||||
</span>
|
||||
<button mat-stroked-button (click)="go('previous')" [disabled]="!has('previous') || loading()">
|
||||
Anterior
|
||||
</button>
|
||||
<button mat-stroked-button (click)="go('next')" [disabled]="!has('next') || loading()">
|
||||
Siguiente
|
||||
</button>
|
||||
</div>
|
||||
@@ -0,0 +1,60 @@
|
||||
:host {
|
||||
display: block;
|
||||
padding-top: var(--space-4);
|
||||
}
|
||||
|
||||
.filters {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-3);
|
||||
margin-bottom: var(--space-4);
|
||||
}
|
||||
.filters mat-form-field {
|
||||
min-width: 14.5rem;
|
||||
}
|
||||
|
||||
.table-wrap {
|
||||
overflow-x: auto;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.worklist .num {
|
||||
text-align: right;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--color-action);
|
||||
}
|
||||
|
||||
.curp {
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.pager {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
gap: var(--space-3);
|
||||
justify-content: flex-end;
|
||||
margin-top: var(--space-3);
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
import { DecimalPipe } from '@angular/common';
|
||||
import { Component, computed, inject, input, resource, signal } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import type { Bundle } from 'fhir/r4';
|
||||
import { Fhir } from '../fhir';
|
||||
import { Row, rows, windowStart } from './follow-up';
|
||||
import { PatientSearch, patientSearch } from './patient-search';
|
||||
import { Loading } from '../loading';
|
||||
import { name } from './measures';
|
||||
const STATUSES = ['case', 'pre_colposcopy', 'post_colposcopy', 'post_treatment'];
|
||||
@Component({
|
||||
selector: 'app-tab-riesgos',
|
||||
imports: [
|
||||
PatientSearch,
|
||||
DecimalPipe,
|
||||
FormsModule,
|
||||
Loading,
|
||||
MatButtonModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
MatSelectModule,
|
||||
RouterLink,
|
||||
],
|
||||
templateUrl: './tab-riesgos.html',
|
||||
styleUrl: './tab-riesgos.scss',
|
||||
})
|
||||
export class TabRiesgos {
|
||||
private readonly fhir = inject(Fhir);
|
||||
readonly domain = input.required<string>();
|
||||
protected readonly cutoff = signal<string>('');
|
||||
protected readonly window = signal(3);
|
||||
protected readonly status = signal<string>('');
|
||||
protected readonly horizon = signal(5);
|
||||
protected readonly sort = signal('-recent');
|
||||
protected readonly size = signal(20);
|
||||
protected readonly search = signal('');
|
||||
private readonly moved = signal<Bundle | undefined>(undefined);
|
||||
protected readonly statuses = STATUSES;
|
||||
protected readonly name = name;
|
||||
private readonly first = resource({
|
||||
params: () => ({
|
||||
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(),
|
||||
_sort: this.sort(),
|
||||
_count: this.size(),
|
||||
}),
|
||||
loader: ({ params: { domain, ...params } }) => {
|
||||
this.moved.set(undefined);
|
||||
return this.fhir.search(domain, 'Patient', {
|
||||
...params,
|
||||
_revinclude: ['DiagnosticReport:subject', 'RiskAssessment:subject'],
|
||||
'_include:iterate': 'DiagnosticReport:result',
|
||||
});
|
||||
},
|
||||
});
|
||||
protected readonly loading = signal(false);
|
||||
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') ?? '') : '';
|
||||
});
|
||||
protected readonly offset = computed(() => {
|
||||
const self = this.page()?.link?.find((l) => l.relation === 'self')?.url;
|
||||
return self ? Number(new URL(self).searchParams.get('_offset') ?? 0) : 0;
|
||||
});
|
||||
protected readonly rows = computed(() => {
|
||||
const page = this.page();
|
||||
const cutoff = this.applied();
|
||||
return page && cutoff
|
||||
? rows(page, windowStart(cutoff, this.window()), cutoff, this.horizon())
|
||||
: [];
|
||||
});
|
||||
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 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);
|
||||
}
|
||||
protected async go(relation: 'next' | 'previous'): Promise<void> {
|
||||
const page = this.page();
|
||||
const next = page && this.fhir.follow(this.domain(), page, relation);
|
||||
if (!next) return;
|
||||
this.loading.set(true);
|
||||
try {
|
||||
this.moved.set(await next);
|
||||
} finally {
|
||||
this.loading.set(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<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
|
||||
matInput
|
||||
type="date"
|
||||
[ngModel]="cutoff() || applied()"
|
||||
(ngModelChange)="cutoff.set($event)"
|
||||
name="cutoff"
|
||||
/>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<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>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<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) {
|
||||
<mat-option [value]="s">{{ name(s) }}</mat-option>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline" subscriptSizing="dynamic">
|
||||
<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>
|
||||
}
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</form>
|
||||
|
||||
@if (error()) {
|
||||
<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>Última mastografía</th>
|
||||
<th>Última biopsia</th>
|
||||
<th>Estatus de seguimiento</th>
|
||||
<th>Prioridad</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (row of rows(); track row.patient.id) {
|
||||
<tr>
|
||||
<td>
|
||||
<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>
|
||||
{{ name(row.mammogram.birads ?? '') || 'Sin dato' }}
|
||||
<small>Fecha: {{ row.mammogram.date }}</small>
|
||||
</td>
|
||||
<td>
|
||||
@if (row.biopsy; as b) {
|
||||
{{ 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 {
|
||||
@if (page() && !loading()) {
|
||||
<tr>
|
||||
<td colspan="6" class="muted">No hay registros para los filtros aplicados.</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="pager">
|
||||
<span class="muted">
|
||||
@if (page()?.total; as total) {
|
||||
Página {{ pageNumber() }} de {{ pageCount() }}, {{ total }} registros
|
||||
}
|
||||
</span>
|
||||
<button mat-stroked-button (click)="go('previous')" [disabled]="!has('previous') || loading()">
|
||||
Anterior
|
||||
</button>
|
||||
<button mat-stroked-button (click)="go('next')" [disabled]="!has('next') || loading()">
|
||||
Siguiente
|
||||
</button>
|
||||
</div>
|
||||
@@ -0,0 +1,102 @@
|
||||
import { Component, computed, inject, input, resource, signal } from '@angular/core';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { RouterLink } from '@angular/router';
|
||||
import type { Bundle } from 'fhir/r4';
|
||||
import { Fhir } from '../fhir';
|
||||
import { camaRows, windowStart } from './follow-up';
|
||||
import { PatientSearch, patientSearch } from './patient-search';
|
||||
import { Loading } from '../loading';
|
||||
import { name, PRIORITY } from './measures';
|
||||
const STATUSES = ['cancer', 'pending_biopsy', 'biopsy_no_result', 'benign_biopsy'];
|
||||
@Component({
|
||||
selector: 'app-tab-seguimiento',
|
||||
imports: [
|
||||
PatientSearch,
|
||||
FormsModule,
|
||||
Loading,
|
||||
MatButtonModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
MatSelectModule,
|
||||
RouterLink,
|
||||
],
|
||||
templateUrl: './tab-seguimiento.html',
|
||||
styleUrl: './tab-riesgos.scss',
|
||||
})
|
||||
export class TabSeguimiento {
|
||||
private readonly fhir = inject(Fhir);
|
||||
readonly domain = input.required<string>();
|
||||
protected readonly cutoff = signal<string>('');
|
||||
protected readonly window = signal(3);
|
||||
protected readonly status = signal<string>('');
|
||||
protected readonly size = signal(20);
|
||||
protected readonly search = signal('');
|
||||
private readonly moved = signal<Bundle | undefined>(undefined);
|
||||
protected readonly statuses = STATUSES;
|
||||
protected readonly name = name;
|
||||
protected readonly priority = (code: string) => PRIORITY[code] ?? code;
|
||||
private readonly first = resource({
|
||||
params: () => ({
|
||||
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(),
|
||||
}),
|
||||
loader: ({ params: { domain, ...params } }) => {
|
||||
this.moved.set(undefined);
|
||||
return this.fhir.search(domain, 'Patient', {
|
||||
...params,
|
||||
_revinclude: ['DiagnosticReport:subject'],
|
||||
'_include:iterate': 'DiagnosticReport:result',
|
||||
});
|
||||
},
|
||||
});
|
||||
protected readonly loading = signal(false);
|
||||
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') ?? '') : '';
|
||||
});
|
||||
protected readonly offset = computed(() => {
|
||||
const self = this.page()?.link?.find((l) => l.relation === 'self')?.url;
|
||||
return self ? Number(new URL(self).searchParams.get('_offset') ?? 0) : 0;
|
||||
});
|
||||
protected readonly rows = computed(() => {
|
||||
const page = this.page();
|
||||
const cutoff = this.applied();
|
||||
return page && cutoff ? camaRows(page, cutoff) : [];
|
||||
});
|
||||
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);
|
||||
}
|
||||
protected async go(relation: 'next' | 'previous'): Promise<void> {
|
||||
const page = this.page();
|
||||
const next = page && this.fhir.follow(this.domain(), page, relation);
|
||||
if (!next) return;
|
||||
this.loading.set(true);
|
||||
try {
|
||||
this.moved.set(await next);
|
||||
} finally {
|
||||
this.loading.set(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
import { Component, computed, inject, input, resource, signal } from '@angular/core';
|
||||
import { MatButtonToggleModule } from '@angular/material/button-toggle';
|
||||
import type { Measure, MeasureReport } from 'fhir/r4';
|
||||
import { Fhir, resources } from '../fhir';
|
||||
import { Loading } from '../loading';
|
||||
import { Figure, Plot } from '../plot';
|
||||
import { historyFigure } from './figures';
|
||||
import { periodLabel, periods, PeriodType, reading } from './measures';
|
||||
import { HISTORY, HistoryPanel } from './pages';
|
||||
interface Drawn {
|
||||
panel: HistoryPanel;
|
||||
heading?: string;
|
||||
figure?: Figure;
|
||||
}
|
||||
@Component({
|
||||
selector: 'app-tab-trazabilidad',
|
||||
imports: [Loading, MatButtonToggleModule, Plot],
|
||||
template: `
|
||||
<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 {
|
||||
@for (d of drawn(); track d.panel.measure) {
|
||||
@if (d.heading) {
|
||||
<h2 class="group-title">{{ d.heading }}</h2>
|
||||
}
|
||||
<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: `
|
||||
: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;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.filters-title {
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
.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;
|
||||
}
|
||||
`,
|
||||
})
|
||||
export class TabTrazabilidad {
|
||||
private readonly fhir = inject(Fhir);
|
||||
readonly domain = input.required<string>();
|
||||
readonly measures = input.required<Measure[]>();
|
||||
protected readonly type = signal<PeriodType>('month');
|
||||
protected readonly series = resource({
|
||||
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();
|
||||
return Promise.all(
|
||||
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(','),
|
||||
});
|
||||
const found = resources<MeasureReport>(pages, 'MeasureReport');
|
||||
return { panel, points: asked.map((period, i) => ({ period, r: reading(found[i]) })) };
|
||||
}),
|
||||
);
|
||||
},
|
||||
});
|
||||
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) };
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user