diff --git a/e2e/pages.spec.ts b/e2e/pages.spec.ts index ad8c6db..04e226a 100644 --- a/e2e/pages.spec.ts +++ b/e2e/pages.spec.ts @@ -210,7 +210,29 @@ for (const domain of ['cama', 'tea']) { test(`indicadores ${domain}: the old page's headings, in order, and the same kinds of plots`, async ({ page, }) => { - const old = captured(domain); + const all = captured(domain); + // CaMa's five timeliness boxes are one route card now: its heading stands for them. + const route = all.findIndex( + (i) => i.kind === 'h3' && i.text === 'Tiempo de tamizaje a diagnóstico', + ); + const clinical = all.findIndex((i) => i.text === 'Indicadores clínicos'); + // Lote 2: the detection rate has its own title, and the histopathology figures are two + // cards (the result by BI-RADS; the confirmation in two readings). + const detection = (i: { text?: string }) => + i.text === 'Tasa de confirmación histopatológica' + ? { ...i, text: 'Tasa de detección histopatológica' } + : i; + const results = all.findIndex( + (i) => i.text === 'Resultado histopatológico por categoría BI-RADS', + ); + const cards = [ + { kind: 'h3', text: 'Resultado histopatológico por categoría BI-RADS' }, + { kind: 'h3', text: 'Confirmación histopatológica' }, // one card: title, tabs and reading + ]; + const old = + domain === 'cama' + ? [...all.slice(0, route + 1).map(detection), ...all.slice(clinical, results), ...cards] + : all; await page.goto(`/indicadores/${domain}`); const tab = page.locator('app-tab-indicadores'); await expect(tab.getByRole('heading', { name: 'Indicadores clínicos' })).toBeVisible(); diff --git a/src/app/indicadores/bars.spec.ts b/src/app/indicadores/bars.spec.ts index 79b264d..6f05219 100644 --- a/src/app/indicadores/bars.spec.ts +++ b/src/app/indicadores/bars.spec.ts @@ -24,4 +24,91 @@ describe('bars', () => { const mode = { kind: 'shares', label: 'x', measure: 'M', stratum: 's', order: ['initial'] }; expect(bars(mode as any, () => r)!.rows[0].cells).toEqual(['0/0', '—']); }); + it('a proportion split into its parts shows both in units and shares', () => { + const r: Reading = { populations: { numerator: 1, denominator: 4 }, strata: {} }; + const t = bars({ kind: 'split', label: 'x', measure: 'M', yes: 'Con', no: 'Sin' }, () => r)!; + expect(t.rows.map((x) => [x.label, ...x.cells])).toEqual([ + ['Con', '1', '25.0 %'], + ['Sin', '3', '75.0 %'], + ]); + }); + it('rows with patients and no biopsy are not rows with no patients; malignant counts only graded', () => { + const r: Reading = { + populations: {}, + strata: { + birads: { + '4A': { 'initial-population': 3 }, + '5': { 'initial-population': 4 }, + '6': { 'initial-population': 2 }, + }, + 'birads-category': { + '4A|no_biopsy': { 'initial-population': 3 }, + '5|benign': { 'initial-population': 1 }, + '5|invasive': { 'initial-population': 1 }, + '5|no_data': { 'initial-population': 2 }, + '6|no_data': { 'initial-population': 2 }, + }, + }, + }; + const results = [ + { code: 'benign', label: 'Benigno', color: '#1' }, + { code: 'invasive', label: 'Invasor', color: '#2' }, + { code: 'no_biopsy', label: 'Sin biopsia', color: '#3' }, + { code: 'no_data', label: 'Sin dato', color: '#4' }, + ]; + const rows = ['4A', '5', '6', '4B'].map((code) => ({ code, label: code, color: '#0' })); + const mode = { + kind: 'outcomes', + label: 'x', + measure: 'M', + stratum: 'birads', + rows, + results, + malignant: ['invasive'], + }; + const t = bars(mode as any, () => r)!; + expect(t.rows.map((x) => x.cells)).toEqual([ + ['3', '0', '0', '3', '0', 'Sin biopsias'], + ['4', '1', '1', '0', '2', '1/2 (50.0 %)'], + ['2', '0', '0', '0', '2', 'Sin biopsias clasificables'], + ['0', '—', '—', '—', '—', '—'], + ]); + expect(t.rows.map((x) => x.none)).toEqual([ + undefined, + undefined, + undefined, + 'Sin pacientes en el periodo', + ]); + expect(t.rows[1].segments!.map((x) => x.width)).toEqual([25, 25, 0, 50]); + }); + it('bars on a percent scale are as long as the shares shown', () => { + const r: Reading = { + populations: {}, + strata: { category: { a: { 'initial-population': 1 }, b: { 'initial-population': 3 } } }, + }; + const catalog = [ + { code: 'a', label: 'A', color: '#0' }, + { code: 'b', label: 'B', color: '#1' }, + { code: 'c', label: 'C', color: '#2' }, + ]; + const t = bars({ kind: 'counts', label: 'x', measure: 'M', catalog, percent: true }, () => r)!; + expect(t.rows.map((x) => x.width)).toEqual([25, 75, 0]); + expect(t.rows.map((x) => x.cells)).toEqual([ + ['1', '25.0 %'], + ['3', '75.0 %'], + ['0', '0.0 %'], + ]); + }); + it('a split takes the colours it is given', () => { + const r: Reading = { populations: { numerator: 1, denominator: 4 }, strata: {} }; + const mode = { + kind: 'split', + label: 'x', + measure: 'M', + yes: 'Con', + no: 'Sin', + colors: ['#a', '#b'], + }; + expect(bars(mode as any, () => r)!.rows.map((x) => x.color)).toEqual(['#a', '#b']); + }); }); diff --git a/src/app/indicadores/bars.ts b/src/app/indicadores/bars.ts index 5bfba09..afde68d 100644 --- a/src/app/indicadores/bars.ts +++ b/src/app/indicadores/bars.ts @@ -5,15 +5,34 @@ import { name, Reading } from './measures'; export type Category = { code: string; label: string; color: string }; /** One way of reading a card, as bars from the reports, or a figure. */ -export type Mode = { label: string; caption?: string } & ( - | { kind: 'counts'; measure: string; catalog: Category[] } - | { kind: 'shares'; measure: string; stratum: string; order: string[] } - | { kind: 'positives'; measure: string; stratum: string; order: string[] } - | { kind: 'signs'; measure: string; strata: string[] } - | { kind: 'days'; steps: { label: string; measure: string }[] } - | { kind: 'days-by'; measure: string; stratum: string } - | { kind: 'figure'; measure: string; figure: 'donut' | 'scenarios'; catalog?: Category[] } -); +export type Mode = { + label: string; + caption?: string; + /** said above the table: what its rows count (patients, reported biopsies…) */ + heading?: string; +} & + /** `percent`: every bar on a fixed scale of 0 to 100 %, so its length is the share shown */ + ( + | { kind: 'counts'; measure: string; catalog: Category[]; percent?: boolean } + | { kind: 'shares'; measure: string; stratum: string; order: string[] } + | { kind: 'positives'; measure: string; stratum: string; order: string[] } + | { kind: 'signs'; measure: string; strata: string[] } + | { kind: 'days'; steps: { label: string; measure: string }[] } + | { kind: 'days-by'; measure: string; stratum: string } + /** A proportion as its two parts (what counted and what did not), in units, with the shares */ + | { kind: 'split'; measure: string; yes: string; no: string; colors?: [string, string] } + /** Each row's units by result (a bar in segments), and the share of the row's units with a + * result that are `malignant`; a row with units and no result is not a row with none */ + | { + kind: 'outcomes'; + measure: string; + stratum: string; + rows: Category[]; + results: Category[]; + malignant: string[]; + } + | { kind: 'figure'; measure: string; figure: 'donut' | 'scenarios'; catalog?: Category[] } + ); /** One bar: its length and quartile marks in % of the scale, and its cells of text. */ export interface Bar { @@ -22,10 +41,16 @@ export interface Bar { width: number; marks: number[]; cells: string[]; + /** the bar in parts (in % of the bar), each with what it says when hovered */ + segments?: { width: number; color: string; title: string }[]; + /** said in place of the bar (a row with nothing to draw) */ + none?: string; } export interface Bars { head: string[]; rows: Bar[]; + /** the colours of the segments */ + legend?: { label: string; color: string }[]; } const pct = (n: number, of: number) => (of ? `${((100 * n) / of).toFixed(1)} %` : '—'); @@ -46,7 +71,7 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined): ...mode.catalog, ...rest.map((code) => ({ code, label: name(code), color: '#9AA3AB' })), ]; - const most = Math.max(...Object.values(cells).map(size)); + const most = mode.percent ? total : Math.max(...Object.values(cells).map(size)); return { head: ['n', '%'], rows: all.map(({ code, label, color }) => { @@ -107,6 +132,66 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined): .sort((a, b) => b.n - a.n), ); } + case 'split': { + const { numerator = 0, denominator = 0 } = of(mode.measure)?.populations ?? {}; + if (!denominator) return undefined; + const parts: [string, number][] = [ + [mode.yes, numerator], + [mode.no, denominator - numerator], + ]; + return { + head: ['n', '%'], + rows: parts.map(([label, n], i) => ({ + label, + color: mode.colors?.[i], + width: (100 * n) / denominator, + marks: [], + cells: [`${n}`, pct(n, denominator)], + })), + }; + } + case 'outcomes': { + const r = of(mode.measure); + const units = r?.strata[mode.stratum] ?? {}; + const cells = r?.strata[`${mode.stratum}-category`] ?? {}; + if (!Object.keys(units).length) return undefined; + const graded = (i: number) => !['no_biopsy', 'no_data'].includes(mode.results[i].code); + return { + head: ['Pacientes', ...mode.results.map((x) => x.label), '% maligno'], + legend: mode.results.map(({ label, color }) => ({ label, color })), + rows: mode.rows.map(({ code, label }) => { + const n = size(units[code]); + const by = mode.results.map((x) => size(cells[`${code}|${x.code}`])); + const den = by.reduce((t, k, i) => t + (graded(i) ? k : 0), 0); + const bad = by.reduce( + (t, k, i) => t + (mode.malignant.includes(mode.results[i].code) ? k : 0), + 0, + ); + return { + label, + width: 100, + marks: [], + none: n ? undefined : 'Sin pacientes en el periodo', + segments: mode.results.map((x, i) => ({ + width: n ? (100 * by[i]) / n : 0, + color: x.color, + title: `${x.label}: ${by[i]} de ${n} (${pct(by[i], n)})`, + })), + cells: [ + `${n}`, + ...by.map((k) => (n ? `${k}` : '—')), + n + ? den + ? `${bad}/${den} (${pct(bad, den)})` + : by[mode.results.findIndex((x) => x.code === 'no_data')] + ? 'Sin biopsias clasificables' + : 'Sin biopsias' + : '—', + ], + }; + }), + }; + } default: return undefined; } diff --git a/src/app/indicadores/durations.spec.ts b/src/app/indicadores/durations.spec.ts new file mode 100644 index 0000000..78e8a58 --- /dev/null +++ b/src/app/indicadores/durations.spec.ts @@ -0,0 +1,55 @@ +import { durationMax, durationRows } from './durations'; +import { Reading } from './measures'; + +const reading = (score?: number, n = 0, low?: number, high?: number): Reading => ({ + populations: { 'measure-observation': n }, + score, + low, + high, + strata: {}, +}); + +describe('durationRows', () => { + const reads: Record = { + A: reading(0, 3, 0, 1), + B: reading(6, 20, 4, 8), + C: reading(undefined, 0), + }; + const rows = durationRows( + [ + { label: 'zero', measure: 'A' }, + { label: 'value', measure: 'B' }, + { label: 'nothing measured', measure: 'C' }, + { label: 'no report', measure: 'D' }, + { label: 'not in the catalog', measure: 'E' }, + { label: 'no measure' }, + ], + (m) => reads[m], + (m) => m !== 'E', + ); + + it('keeps a real zero as a value', () => { + expect(rows[0]).toEqual({ + label: 'zero', + status: 'value', + median: 0, + observations: 3, + low: 0, + high: 1, + }); + }); + it('tells no measurements from an unpublished measure', () => { + expect(rows.map((r) => r.status)).toEqual([ + 'value', + 'value', + 'empty', + 'empty', + 'unpublished', + 'unpublished', + ]); + }); + it('scales from zero to the largest median or third quartile', () => { + expect(durationMax(rows)).toBe(8); + expect(durationMax([])).toBe(0); + }); +}); diff --git a/src/app/indicadores/durations.ts b/src/app/indicadores/durations.ts new file mode 100644 index 0000000..df24851 --- /dev/null +++ b/src/app/indicadores/durations.ts @@ -0,0 +1,46 @@ +import { Reading } from './measures'; + +/** One step of a route: its name and the measure that times it. A step with no measure is + * not published yet. */ +export interface RouteStep { + label: string; + measure?: string; +} + +/** One row of a duration table: the median days, how many measurements and the quartiles. + * `empty` (published, nothing measured in the period) is not `unpublished` (no measure), and + * neither is a zero: a median of 0 days is a value. */ +export interface DurationRow { + label: string; + status: 'value' | 'empty' | 'unpublished'; + median?: number; + observations?: number; + low?: number; + high?: number; +} + +/** The rows of a route in one reading; every step keeps its row. `published` says which + * measures the catalog has. */ +export function durationRows( + steps: RouteStep[], + read: (measure: string) => Reading | undefined, + published: (measure: string) => boolean, +): DurationRow[] { + return steps.map(({ label, measure }) => { + if (!measure || !published(measure)) return { label, status: 'unpublished' }; + const r = read(measure); + if (r?.score === undefined) return { label, status: 'empty' }; + return { + label, + status: 'value', + median: r.score, + observations: r.populations['measure-observation'], + low: r.low, + high: r.high, + }; + }); +} + +/** The scale of a table of durations, from zero: the largest median or third quartile shown. */ +export const durationMax = (rows: DurationRow[]): number => + Math.max(0, ...rows.map((r) => Math.max(r.median ?? 0, r.high ?? 0))); diff --git a/src/app/indicadores/measures.ts b/src/app/indicadores/measures.ts index 7d9e304..c779353 100644 --- a/src/app/indicadores/measures.ts +++ b/src/app/indicadores/measures.ts @@ -182,14 +182,14 @@ export function formatScore(measure: Measure, r: Reading | undefined): string { } } -export function detail(measure: Measure, r: Reading | undefined): string { +export function detail(measure: Measure, r: Reading | undefined, unit = 'pacientes'): 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)}.`; + ? `Sin ${unit} en el periodo.` + : `${p['numerator']} de ${p['denominator']} ${unit}. 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.` diff --git a/src/app/indicadores/pages.ts b/src/app/indicadores/pages.ts index 7380911..af9e313 100644 --- a/src/app/indicadores/pages.ts +++ b/src/app/indicadores/pages.ts @@ -1,5 +1,6 @@ import type { Mode } from './bars'; import { CACU } from './pages-cacu'; +import type { RouteStep } from './durations'; /** A domain's Indicadores page as the old app showed it (tests/fixtures/reference//ui): * the timeliness cards with their own words, then the clinical sections and their figures. @@ -25,15 +26,28 @@ export interface ReadingsCard { kind: 'readings'; title: string; headline?: string; + /** what the headline proportion counts, in the plural (default: pacientes) */ + unit?: string; note?: string; modes: Mode[]; } export type Section = | ReadingsCard + /** A screening route as one compact card: a bar per step with its median, observations and + * quartiles. `sample` reads each step from the sample (its own measure, never a sum of + * medians); `step` reads each from the previous step. A reading with no steps is not offered. */ + | { kind: 'route'; title: string; sample: RouteStep[]; step: RouteStep[] } /** Cards side by side; the last one alone when odd. */ | { kind: 'columns'; title: string; sections: ReadingsCard[] } /** One section at a time. */ - | { kind: 'choice'; title: string; choices: { label: string; section: ReadingsCard }[] } + /** `card`: the title, the tabs and the chosen reading in one card (the reading's own title is + * left out: its tab names it) */ + | { + kind: 'choice'; + title: string; + choices: { label: string; section: ReadingsCard }[]; + card?: boolean; + } | { kind: 'figures'; title?: string; figures: FigureSpec[] } | { kind: 'boxes'; @@ -113,17 +127,22 @@ const BIRADS: Catalog = { { 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' }, - ], -}; + +/** A breast biopsy's grades, and what stands in their place when there is none. */ +const BIOPSY_GRADES = [ + { code: 'benign', label: 'Benigno', color: '#A8C243' }, + { code: 'in_situ', label: 'Carcinoma in situ', color: '#9C42C2' }, + { code: 'invasive', label: 'Carcinoma invasor', color: '#5C42C2' }, +]; +/** What «Sin biopsia» says, whatever the contract's category is called. */ +const NO_BIOPSY_MEANS = + '«Sin biopsia»: no existe una biopsia vinculada según los datos disponibles.'; +const INSTITUTIONAL = '#A8C243'; +const NEUTRAL = '#C9CDD2'; +const NO_RESULT = [ + { code: 'no_biopsy', label: 'Sin biopsia', color: '#C9CDD2' }, + { code: 'no_data', label: 'Sin dato', color: '#8C949C' }, +]; export const PAGES: Record = { tea: { @@ -229,9 +248,9 @@ export const PAGES: Record = { }, { measure: 'CAMA_TASA_DETECCION_HISTOPATOLOGICA', - title: 'Tasa de confirmación histopatológica', + title: 'Tasa de detección histopatológica', value: '{pct} %', - note: '{num} de {den} biopsias con riesgo a carcinoma.', + note: '{num} de {den} biopsias con grado conocido presentan carcinoma (in situ o invasor).', }, { measure: 'CAMA_EU38A', @@ -251,21 +270,27 @@ export const PAGES: Record = { ], opportunity: [ { - kind: 'boxes', + kind: 'route', title: 'Tiempo de tamizaje a diagnóstico', - subtitles: true, - cards: [ + // from the mammography: only the two measures that start at it + sample: [ + { label: 'Interpretación radiológica', measure: 'CAMA_EU38A' }, { - measure: 'CAMA_EU38A', - title: 'Tiempo de toma de mastografía a interpretación radiológica', + label: 'Diagnóstico (tiempo total de tamizaje a diagnóstico)', + measure: 'CAMA_DIAS_TOMA_DIAGNOSTICO', }, + ], + step: [ + { label: 'Toma de mastografía a interpretación radiológica', measure: 'CAMA_EU38A' }, { + label: 'Interpretación radiológica a diagnóstico', 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' }, + { + label: 'Interpretación radiológica a resultado de biopsia', + measure: 'CAMA_DIAS_RESULTADO_BIOPSIA', + }, + { label: 'Diagnóstico a tratamiento' }, ], }, ], @@ -290,34 +315,78 @@ export const PAGES: Record = { ], }, { - kind: 'figures', + kind: 'readings', title: 'Resultado histopatológico por categoría BI-RADS', - figures: [ + note: 'Pacientes: su mastografía BI-RADS 4, 5 o 6 más grave y su biopsia más grave reportada, por fecha del examen. El porcentaje maligno se calcula solo sobre las pacientes con biopsia con grado.', + modes: [ { - kind: 'rates', - title: 'Por categoría BI-RADS, {p}', + kind: 'outcomes', + label: 'Por categoría BI-RADS', + heading: 'Resultados por paciente', + caption: NO_BIOPSY_MEANS, measure: 'CAMA_HISTOPATOLOGIA_BIRADS', stratum: 'birads', rows: BIRADS.categories, - colored: true, - positive: ['in_situ', 'invasive'], - axis: 'Porcentaje con resultado maligno', + results: [...BIOPSY_GRADES, ...NO_RESULT], + malignant: ['in_situ', 'invasive'], }, { - kind: 'donut', - title: 'Resultado de la biopsia, {p}', + kind: 'counts', + label: 'Todas las categorías', + heading: 'Resultados por paciente', + caption: `Todas las categorías BI-RADS juntas. ${NO_BIOPSY_MEANS}`, measure: 'CAMA_HISTOPATOLOGIA_BIRADS', - catalog: BREAST_BIOPSY, - center: 'con resultado', + catalog: [...BIOPSY_GRADES, ...NO_RESULT], + percent: true, }, ], }, { - 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.', + kind: 'choice', + title: 'Confirmación histopatológica', + card: true, + choices: [ + { + label: 'Resultado de biopsias', + section: { + kind: 'readings', + title: 'Resultado de biopsias', + headline: 'CAMA_TASA_DETECCION_HISTOPATOLOGICA', + unit: 'biopsias', + note: 'Biopsias con resultado reportado, por fecha del reporte (no son pacientes ni mastografías). La tasa divide los carcinomas (in situ o invasor) entre biopsias con grado conocido. Los porcentajes de la distribución incluyen todas las biopsias reportadas, también «Sin dato» (sin grado), por lo que sus denominadores pueden ser distintos.', + modes: [ + { + kind: 'counts', + label: 'Biopsias reportadas', + heading: 'Biopsias reportadas', + measure: 'CAMA_BIOPSIAS', + catalog: [...BIOPSY_GRADES, NO_RESULT[1]], + percent: true, + }, + ], + }, + }, + { + label: 'Mastografías con biopsia', + section: { + kind: 'readings', + title: 'Mastografías con biopsia', + headline: 'CAMA_CONFIRMACION_BIRADS45', + unit: 'mastografías', + note: 'Mastografías BI-RADS 4, 4A, 4B, 4C o 5 con reporte, por fecha del examen: cuántas tienen un reporte de biopsia. Mide el seguimiento, no el resultado de la biopsia; no es equivalente a la tasa de detección.', + modes: [ + { + kind: 'split', + label: 'Con y sin biopsia', + measure: 'CAMA_CONFIRMACION_BIRADS45', + yes: 'Con reporte de biopsia', + no: 'Sin reporte de biopsia', + colors: [INSTITUTIONAL, NEUTRAL], + }, + ], + }, + }, + ], }, ], }, diff --git a/src/app/indicadores/readings.ts b/src/app/indicadores/readings.ts index 8a5985e..bbf51bd 100644 --- a/src/app/indicadores/readings.ts +++ b/src/app/indicadores/readings.ts @@ -8,9 +8,12 @@ import { Reading } from './measures'; /** A card read one mode at a time: its title, its headline, the toggle and the bars. */ @Component({ selector: 'app-readings', + host: { '[class.cama]': 'camaStyle()' }, imports: [Loading, MatButtonToggleModule, Plot], template: ` -

{{ title() }}

+ @if (!hideTitle()) { +

{{ title() }}

+ } @if (headline()) {

{{ headline() }}

} @@ -28,6 +31,9 @@ import { Reading } from './measures'; } } + @if (mode().heading) { +

{{ mode().heading }}

+ } @if (mode().caption) {

{{ mode().caption }}

} @@ -50,16 +56,31 @@ import { Reading } from './measures'; {{ row.label }} - + @if (row.none) { + {{ row.none }} + } @else { + + } @for (c of row.cells; track $index) { {{ c }} @@ -68,6 +89,13 @@ import { Reading } from './measures'; } + @if (t.legend; as legend) { +

+ @for (l of legend; track l.label) { + {{ l.label }} + } +

+ } } @else {

Sin datos en el periodo.

} @@ -77,12 +105,32 @@ import { Reading } from './measures'; display: block; min-width: 0; } + :host(.cama) { + overflow-x: auto; + } .title { margin: 0 0 8px; } + :host(.cama) .title { + font-size: 18px; + font-weight: 500; + } + .heading { + font-size: 14px; + font-weight: 500; + margin: 12px 0 4px; + } .headline { font-weight: 500; } + :host(.cama) .headline { + margin: 8px 0; + } + :host(.cama) .state { + color: var(--color-text-secondary); + font-size: 13px; + margin: 8px 0; + } mat-button-toggle-group { flex-wrap: wrap; margin: 4px 0; @@ -91,6 +139,12 @@ import { Reading } from './measures'; border-collapse: collapse; width: 100%; } + :host(.cama) table { + font-size: 13px; + } + :host(.cama) thead th { + font-weight: 500; + } th, td { font-weight: 400; @@ -114,6 +168,28 @@ import { Reading } from './measures'; display: block; height: 100%; } + .parts { + display: flex; + } + .none { + color: rgba(0, 0, 0, 0.6); + display: block; + font-size: 12px; + font-weight: 400; + } + .legend { + display: flex; + flex-wrap: wrap; + font-size: 12px; + gap: 4px 16px; + margin: 8px 0 0; + } + .legend i { + display: inline-block; + height: 10px; + margin-right: 6px; + width: 10px; + } .mark { background: #333; height: 12px; @@ -127,6 +203,9 @@ export class Readings { readonly title = input.required(); readonly headline = input(''); readonly note = input(''); + /** the card around it names it already (tabs inside one card) */ + readonly hideTitle = input(false); + readonly camaStyle = input(false); readonly modes = input.required(); readonly loading = input(false); /** A measure's reading in the applied period, and the figure of a mode that has one. */ diff --git a/src/app/indicadores/route-card.ts b/src/app/indicadores/route-card.ts new file mode 100644 index 0000000..6e5f19c --- /dev/null +++ b/src/app/indicadores/route-card.ts @@ -0,0 +1,183 @@ +import { Component, input, signal } from '@angular/core'; +import { MatButtonToggleModule } from '@angular/material/button-toggle'; +import { MatCardModule } from '@angular/material/card'; +import { Loading } from '../loading'; +import { DurationRow, durationMax } from './durations'; + +/** A screening route as one compact card: a bar per step with its median, its observations + * and its quartiles, read step by step or cumulatively from the sample. A step that is not + * published, or has no measurements in the period, keeps its row and says so. */ +@Component({ + selector: 'app-route-card', + imports: [Loading, MatButtonToggleModule, MatCardModule], + template: ` + + +
+

{{ title() }}

+ @if (sample().length && step().length) { + + Por pasos + Acumulado desde la toma + + } +
+ @if (loading()) { + + } @else { + @let rows = mode() === 'sample' ? sample() : step(); + @let max = scale(rows); +

+ @if (mode() === 'sample') { + Mediana de días desde la toma de la mastografía hasta cada etapa; cada medida se + calcula por separado. + } @else { + Cada barra es la mediana de su paso, desde cero y por separado; los pasos pueden + corresponder a poblaciones diferentes, por lo que las medianas no se suman. + } + Las marcas indican el primer y tercer cuartil. + @if (max) { + Escala: 0 a {{ max }} días. + } +

+ + + + + + + + + + + @for (row of rows; track row.label) { + + + + + + + } + +
{{ mode() === 'sample' ? 'Etapa' : 'Paso' }}MedianaObservacionesQ1–Q3
+ {{ row.label }} + @if (row.status === 'value') { + + } @else { + + {{ + row.status === 'empty' + ? 'Sin mediciones en el periodo' + : 'Indicador no publicado' + }} + + } + {{ row.status === 'value' ? row.median + ' días' : '—' }}{{ row.observations ?? '—' }} + {{ + row.low === undefined || row.high === undefined + ? '—' + : row.low + '–' + row.high + }} +
+ } +
+
+ `, + styles: ` + :host { + display: block; + margin-top: 24px; + } + .head { + align-items: center; + display: flex; + flex-wrap: wrap; + gap: var(--space-3); + justify-content: space-between; + } + h3 { + font-size: 18px; + font-weight: 500; + margin: 0; + } + .state { + color: var(--color-text-secondary); + font-size: 13px; + margin: 8px 0; + } + table { + border-collapse: collapse; + font-size: 13px; + width: 100%; + } + th { + font-weight: 500; + text-align: left; + } + th[scope='row'] { + padding: 5px 0; + } + td, + thead th:not(:first-child) { + font-variant-numeric: tabular-nums; + padding-left: 12px; + text-align: right; + white-space: nowrap; + } + .track { + background: #eef1f3; + display: block; + height: 8px; + margin-top: 3px; + position: relative; + } + .bar { + background: #42a77e; + display: block; + height: 100%; + } + .mark { + background: #17324d; + height: 14px; + position: absolute; + top: -3px; + width: 2px; + } + .none { + color: var(--color-text-secondary); + display: block; + font-size: 12px; + font-weight: 400; + margin-top: 3px; + } + `, +}) +export class RouteCard { + readonly title = input.required(); + /** The rows from the sample, and the rows step by step. */ + readonly sample = input.required(); + readonly step = input.required(); + readonly loading = input(false); + + protected readonly mode = signal<'sample' | 'step'>('step'); + protected readonly scale = durationMax; +} diff --git a/src/app/indicadores/section.ts b/src/app/indicadores/section.ts index 305a507..ec09cd2 100644 --- a/src/app/indicadores/section.ts +++ b/src/app/indicadores/section.ts @@ -5,7 +5,7 @@ import type { Measure } from 'fhir/r4'; import { Mode } from './bars'; import { scenarioBars } from './figures'; import { detail, donut, formatScore, name, Reading, scoring } from './measures'; -import type { Section } from './pages'; +import type { ReadingsCard, Section } from './pages'; import { Readings } from './readings'; /** The applied period's readings and the measures they are of. */ @@ -27,7 +27,8 @@ type Shown = Extract; ; /> + } @else if (s.kind === 'choice' && s.card) { + @let open = chosen() || s.choices[0].label; + + +

{{ s.title }}

+ + @for (c of s.choices; track c.label) { + {{ c.label }} + } + + @for (c of s.choices; track c.label) { + @if (c.label === open) { + + } + } +
+
} @else {

{{ s.title }}

@if (s.kind === 'columns') { @@ -66,9 +98,17 @@ type Shown = Extract; styles: ` :host { display: block; - margin-top: 16px; + margin-top: 24px; min-width: 0; } + .title { + font-size: 18px; + font-weight: 500; + margin: 0 0 8px; + } + .choice-card app-readings { + margin-top: 8px; + } .columns { display: grid; column-gap: 16px; @@ -84,15 +124,19 @@ export class ReadingsSection { readonly of = input.required(); protected readonly chosen = signal(''); - protected readonly headline = computed(() => { - const s = this.section(); - const code = s.kind === 'readings' ? s.headline : undefined; + protected hasCamaHeading(s: ReadingsCard): boolean { + return s.modes.some((mode) => !!mode.heading); + } + + /** A reading card's headline: its measure's score and its counts, in its own units. */ + protected headlineOf(s: ReadingsCard): string { + const code = s.headline; const measure = code && this.of().measure(code); const r = code && this.of().reading(code); if (!measure || !r) return ''; - const words = detail(measure, r); + const words = detail(measure, r, s.unit); return scoring(measure) === 'cohort' ? words : `${formatScore(measure, r)} · ${words}`; - }); + } protected readonly draw = computed(() => (mode: Mode) => { if (mode.kind !== 'figure') return undefined; const r = this.of().reading(mode.measure); diff --git a/src/app/indicadores/tab-indicadores.html b/src/app/indicadores/tab-indicadores.html index 831afcd..4880d44 100644 --- a/src/app/indicadores/tab-indicadores.html +++ b/src/app/indicadores/tab-indicadores.html @@ -90,6 +90,14 @@ @case ('choice') { } + @case ('route') { + + } @case ('tea-summary') { @if (teaSummary(); as t) { diff --git a/src/app/indicadores/tab-indicadores.ts b/src/app/indicadores/tab-indicadores.ts index e6f4127..486fcce 100644 --- a/src/app/indicadores/tab-indicadores.ts +++ b/src/app/indicadores/tab-indicadores.ts @@ -8,6 +8,7 @@ import { MatSelectModule } from '@angular/material/select'; import type { Measure, MeasureReport } from 'fhir/r4'; import { Fhir, resources } from '../fhir'; import { Figure, Plot } from '../plot'; +import { DurationRow, durationRows } from './durations'; import { LAYOUTS } from './layout'; import { ageShare, @@ -37,6 +38,7 @@ import { strataBars, } from './measures'; import { Loading } from '../loading'; +import { RouteCard } from './route-card'; import { ReadingsSection, Source } from './section'; /** The period's indicators: the timeliness KPIs, the screening route, and a card per @@ -53,6 +55,7 @@ import { ReadingsSection, Source } from './section'; MatSelectModule, Plot, ReadingsSection, + RouteCard, ], templateUrl: './tab-indicadores.html', styleUrl: './tab-indicadores.scss', @@ -194,6 +197,15 @@ export class TabIndicadores { } protected readonly name = name; + protected stepRows(section: Section, mode: 'sample' | 'step'): DurationRow[] { + if (section.kind !== 'route') return []; + return durationRows( + section[mode], + (code) => this.rd(code), + (code) => this.byName().has(code), + ); + } + /** A measure's reading in the applied period, by code. */ protected rd(code: string): Reading | undefined { return this.loaded()?.get(code);