diff --git a/e2e/pages.spec.ts b/e2e/pages.spec.ts index 21b5010..9db7863 100644 --- a/e2e/pages.spec.ts +++ b/e2e/pages.spec.ts @@ -87,7 +87,7 @@ test("indicators: the KPIs are the API's MeasureReports, every tab and the patie const camaRows = page.locator('table.worklist tbody tr'); await expect(camaRows.first()).toContainText('BI-RADS'); await page.goto('/indicadores/tea'); - await expect(page.getByRole('tab', { name: 'Indicadores' })).toBeVisible(); + await expect(page.getByRole('tab', { name: 'Resumen' })).toBeVisible(); expect(problems).toEqual([]); }); @@ -184,7 +184,8 @@ test('conectar: someone who knows nothing of databases connects the SQL Server w * opportunity section on, in order, and the kind of each plot (its traces' types). */ function captured(domain: string) { const path = `../tests/fixtures/reference/${domain}/ui/pages.json`; - const items = JSON.parse(readFileSync(path, 'utf8')).tabs['Indicadores'] as any[]; + const tabs = JSON.parse(readFileSync(path, 'utf8')).tabs; + const items = (tabs['Indicadores'] ?? tabs['Resumen']) as any[]; // TEA's first tab is its summary const from = items.findIndex((i) => i.text === 'Indicadores de oportunidad'); return items .slice(from) @@ -194,7 +195,7 @@ function captured(domain: string) { const period = (text: string) => text.replace(/, \d{4}-(S[12]|\d{2})$/, ', '); const kindOf = (types: string[]) => [...new Set(types)].sort().join('+'); -for (const domain of ['cacu', 'cama']) { +for (const domain of ['cacu', 'cama', 'tea']) { test(`indicadores ${domain}: the old page's headings, in order, and the same kinds of plots`, async ({ page, }) => { diff --git a/src/app/indicadores/figures.ts b/src/app/indicadores/figures.ts index de4690b..068bd04 100644 --- a/src/app/indicadores/figures.ts +++ b/src/app/indicadores/figures.ts @@ -326,3 +326,92 @@ export function shareDonut(r: Reading, catalog: Catalog, center: string): Figure }, }; } + +/** A category's count per bar, one bar each, in the period. */ +export function countBars(r: Reading, catalog: Catalog, axis: string, period: string): Figure { + const y = catalog.categories.map((c) => c.label); + return { + data: [ + { + type: 'bar', + orientation: 'h', + name: period, + y, + x: catalog.categories.map((c) => counted(r, c.code)), + marker: { color: catalog.categories.map((c) => c.color) }, + texttemplate: '%{x}', + textposition: 'outside', + hovertemplate: '%{y}: %{x}', + } as Partial, + ], + layout: { + showlegend: false, + xaxis: { title: { text: axis }, rangemode: 'tozero' }, + yaxis: { type: 'category', autorange: 'reversed', automargin: true }, + }, + }; +} + +const AGE_COLORS = ['#A8C243', '#42C29C', '#9C42C2', '#4269C2']; +/** "16-23" as the screens say it: "16 a 23 meses". */ +export const ageLabel = (band: string) => band.replace(/^(\d+)-(\d+)$/, '$1 a $2 meses'); + +function ages(r: Reading): [string, Record][] { + return Object.entries(r.strata['age_group'] ?? {}).sort( + ([a], [b]) => parseInt(a, 10) - parseInt(b, 10), + ); +} + +/** By age group: the numerator and the rest of the denominator, stacked. */ +export function ageStack(r: Reading, names: [string, string]): Figure { + const rows = ages(r); + const x = rows.map(([a]) => ageLabel(a)); + return { + data: [ + { + type: 'bar', + name: names[0], + x, + y: rows.map(([, c]) => c['numerator'] ?? 0), + marker: { color: AGE_COLORS[0] }, + }, + { + type: 'bar', + name: names[1], + x, + y: rows.map(([, c]) => (c['denominator'] ?? 0) - (c['numerator'] ?? 0)), + marker: { color: AGE_COLORS[1] }, + }, + ] as Partial[], + layout: { + barmode: 'stack', + xaxis: { title: { text: 'Grupo de edad' }, type: 'category' }, + yaxis: { title: { text: 'Pacientes' }, rangemode: 'tozero' }, + }, + }; +} + +/** By age group: the numerator's share of the denominator, one bar each. */ +export function ageShare(r: Reading, axis: string): Figure { + const rows = ages(r); + return { + data: [ + { + type: 'bar', + x: rows.map(([a]) => ageLabel(a)), + y: rows.map(([, c]) => + c['denominator'] ? (100 * (c['numerator'] ?? 0)) / c['denominator'] : 0, + ), + marker: { color: rows.map((_, i) => AGE_COLORS[i % AGE_COLORS.length]) }, + texttemplate: '%{y:.1f} %', + textposition: 'outside', + hovertemplate: '%{x}: %{y:.1f} %', + } as Partial, + ], + layout: { + showlegend: false, + xaxis: { title: { text: 'Grupo de edad' }, type: 'category' }, + yaxis: { title: { text: axis }, range: [0, 100], ticksuffix: ' %' }, + }, + }; +} diff --git a/src/app/indicadores/indicadores.ts b/src/app/indicadores/indicadores.ts index 58ce1ad..beec0a6 100644 --- a/src/app/indicadores/indicadores.ts +++ b/src/app/indicadores/indicadores.ts @@ -34,7 +34,7 @@ import { Loading } from '../loading';

Este dominio todavía no tiene indicadores publicados.

} @else { - + diff --git a/src/app/indicadores/pages.ts b/src/app/indicadores/pages.ts index 9e75e3e..cf7636f 100644 --- a/src/app/indicadores/pages.ts +++ b/src/app/indicadores/pages.ts @@ -20,7 +20,18 @@ export interface Kpi { 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 }[] } + | { + kind: 'boxes'; + /** none: the boxes stand alone (TEA) */ + title?: string; + cards: { measure?: string; title: string }[]; + /** the measure's own title under each card's (CaMa) */ + subtitles?: boolean; + } + /** Each figure in its own card, titled, two to a row (TEA). */ + | { kind: 'grid'; figures: FigureSpec[] } + /** TEA's period summary in words, its numbers from the measures. */ + | { kind: 'tea-summary' } | ({ kind: 'card' } & Kpi); /** Figure titles may carry `{p}`, the applied period. */ export type FigureSpec = @@ -32,6 +43,14 @@ export type FigureSpec = center: string; } | { kind: 'scenario-bars'; title: string; measure: string; catalog: Catalog; stratum: string } + | { kind: 'counts'; title: string; measure: string; catalog: Catalog; axis: string } + | { + kind: 'age-stack' | 'age-share'; + title: string; + measure: string; + /** the numerator's and the rest's names (stack), or the axis (share) */ + names: [string, string]; + } | { kind: 'rates'; title: string; @@ -128,6 +147,98 @@ const BREAST_BIOPSY: Catalog = { }; export const PAGES: Record = { + 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: [ @@ -163,6 +274,7 @@ export const PAGES: Record = { { kind: 'boxes', title: 'Tiempo de tamizaje a diagnóstico', + subtitles: true, cards: [ { measure: 'CAMA_EU38A', diff --git a/src/app/indicadores/tab-indicadores.html b/src/app/indicadores/tab-indicadores.html index f52e2a9..b75f5e4 100644 --- a/src/app/indicadores/tab-indicadores.html +++ b/src/app/indicadores/tab-indicadores.html @@ -83,9 +83,60 @@

Sin tiempos publicados en el periodo.

} } + @case ('tea-summary') { + @if (teaSummary(); as t) { + + +

Resumen

+

+ Al cierre del periodo {{ period }}, se evaluaron + {{ t.evaluated }} niños entre 16 y 36 meses; + {{ t.mchatOnly }} únicamente tienen M-CHAT, + {{ t.psychology }} hasta la evaluación psicológica y + {{ t.neuropediatrics }} presentan evaluación neuropediátrica. En este + periodo el {{ t.confirmed }} de los pacientes tiene diagnóstico + confirmado de TEA (CIE-10 F84.0). Las ventanas de tiempo* de tamizaje + son: {{ t.toAdos }} de M-CHAT (psicología) a ADOS-2, + {{ t.toDiagnosis }} de ADOS-2 a diagnóstico. El tiempo* de + tamizaje completo de M-CHAT a diagnóstico fue de {{ t.whole }}. +

+

+ De los {{ t.diagnosed }} niños con diagnóstico confirmado en este + periodo, {{ t.eeg }} presentan estudio de EEG y faltan + {{ t.missing }} por realizarlo. {{ t.unusable }} estudios + de EEG no son aceptables para un análisis. +

+

*tomando la mediana de los tiempos

+
+
+ } @else if (reports.isLoading()) { + + } + } + @case ('grid') { +
+ @for (f of section.figures; track f.title) { + + +

{{ f.title }}

+

Filtro general aplicado: {{ period }}

+ @if (reports.isLoading()) { + + } @else if (figureOf(f); as fig) { + + } @else { +
Sin datos publicados
+ } +
+
+ } +
+ } @case ('boxes') { -

{{ section.title }}

-
+ @if (section.title) { +

{{ section.title }}

+ } +
@for (b of section.cards; track b.title) { Sin datos publicados
} @else {

Filtro general aplicado: {{ period }}

-

{{ measureTitle(b.measure) }}

-

Figura: Caja de cuartiles

+ @if (section.subtitles) { +

{{ measureTitle(b.measure) }}

+

Figura: Caja de cuartiles

+ } @if (reports.isLoading()) { } @else if (boxOf(b.measure); as fig) { diff --git a/src/app/indicadores/tab-indicadores.scss b/src/app/indicadores/tab-indicadores.scss index dc3d8b7..31bbd11 100644 --- a/src/app/indicadores/tab-indicadores.scss +++ b/src/app/indicadores/tab-indicadores.scss @@ -241,3 +241,45 @@ h2.box-subtitle { .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)); + } +} diff --git a/src/app/indicadores/tab-indicadores.ts b/src/app/indicadores/tab-indicadores.ts index f2aacd9..62b1042 100644 --- a/src/app/indicadores/tab-indicadores.ts +++ b/src/app/indicadores/tab-indicadores.ts @@ -10,7 +10,10 @@ import { Fhir, resources } from '../fhir'; import { Figure, Plot } from '../plot'; import { LAYOUTS } from './layout'; import { + ageShare, + ageStack, boxFigure, + countBars, fill, nestedDonut, rateDots, @@ -215,6 +218,40 @@ export class TabIndicadores { const r = measure ? this.rd(measure) : undefined; return r && r.score !== undefined ? boxFigure(r, this.applied() ?? '') : undefined; } + /** TEA's summary of the period: its numbers from the measures (none: no summary). */ + protected readonly teaSummary = computed(() => { + const rd = (c: string) => this.reports.value()?.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) || ''; } @@ -232,6 +269,12 @@ export class TabIndicadores { 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':