From 72aa91af0416a0845a915bc27948d684e6a0dc24 Mon Sep 17 00:00:00 2001 From: edgar Date: Thu, 3 Dec 2026 23:47:37 -0600 Subject: [PATCH] =?UTF-8?q?CaMa:=20tipo=20histol=C3=B3gico,=20BI-RADS=204-?= =?UTF-8?q?6=20primero=20y=20detecci=C3=B3n=20en=20el=20hist=C3=B3rico?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- e2e/pages.spec.ts | 8 ++--- src/app/indicadores/bars.spec.ts | 58 ++++++++++++++++++++++++++++++++ src/app/indicadores/bars.ts | 47 +++++++++++++++++++------- src/app/indicadores/pages.ts | 42 ++++++++++++----------- 4 files changed, 119 insertions(+), 36 deletions(-) diff --git a/e2e/pages.spec.ts b/e2e/pages.spec.ts index 13d31e5..ea749c9 100644 --- a/e2e/pages.spec.ts +++ b/e2e/pages.spec.ts @@ -228,10 +228,10 @@ for (const domain of ['cama', 'tea']) { const clinical = all.findIndex((i) => i.text === 'Indicadores clínicos'); // The histopathology figures are two cards: the result by BI-RADS and the confirmation. const results = all.findIndex( - (i) => i.text === 'Resultado histopatológico por categoría BI-RADS', + (i) => i.text === 'Tipo histológico por categoría BI-RADS', ); const cards = [ - { kind: 'h3', text: 'Resultado histopatológico por categoría BI-RADS' }, + { kind: 'h3', text: 'Tipo histológico por categoría BI-RADS' }, { kind: 'h3', text: 'Confirmación histopatológica' }, // one card: title, tabs and reading ]; const old = @@ -248,14 +248,14 @@ for (const domain of ['cama', 'tea']) { const from = headings.indexOf('Indicadores de oportunidad'); if (domain === 'cama') { const ordered = [ + 'Pacientes evaluadas con BI-RADS 4, 5 o 6', 'Tiempo de toma de mastografía a interpretación radiológica', 'Tiempo de interpretación radiológica a diagnóstico', 'Tiempo de interpretación radiológica a resultado de biopsia', 'Tiempo de diagnóstico a tratamiento', 'Tiempo de tamizaje a diagnóstico', - 'Pacientes evaluadas con BI-RADS 4, 5 o 6', 'Porcentaje de mastografías con resultado BI-RADS 4, 5 ó 6', - 'Resultado histopatológico por categoría BI-RADS', + 'Tipo histológico por categoría BI-RADS', 'Confirmación histopatológica', ]; let last = -1; diff --git a/src/app/indicadores/bars.spec.ts b/src/app/indicadores/bars.spec.ts index 2b20952..d81128d 100644 --- a/src/app/indicadores/bars.spec.ts +++ b/src/app/indicadores/bars.spec.ts @@ -3,6 +3,64 @@ import { scenarioBars } from './figures'; import { Reading } from './measures'; describe('bars', () => { + it('shows histologic types by BI-RADS while deriving malignancy from biopsy classification', () => { + const type: Reading = { + populations: {}, + strata: { + category: { '8500/3': { 'initial-population': 1 }, no_data: { 'initial-population': 1 } }, + birads: { '4A': { 'initial-population': 2 } }, + 'birads-category': { + '4A|8500/3': { 'initial-population': 1 }, + '4A|no_data': { 'initial-population': 1 }, + }, + }, + }; + const classification: Reading = { + populations: {}, + strata: { + 'birads-category': { + '4A|benign': { 'initial-population': 1 }, + '4A|invasive': { 'initial-population': 1 }, + }, + }, + }; + const mode: Mode = { + kind: 'outcomes', + label: 'Por categoría BI-RADS', + measure: 'types', + stratum: 'birads', + rows: [{ code: '4A', label: '4A', color: '#000' }], + results: [ + { code: 'no_biopsy', label: 'Sin biopsia', color: '#aaa' }, + { code: 'no_data', label: 'Sin dato', color: '#bbb' }, + ], + malignant: ['in_situ', 'invasive'], + dynamicResults: true, + malignancyMeasure: 'grades', + }; + const table = bars(mode, (key) => (key === 'types' ? type : classification))!; + expect(table.head).toEqual(['Pacientes', '8500/3', 'Sin biopsia', 'Sin dato', '% maligno']); + expect(table.rows[0].cells).toEqual(['2', '1', '0', '1', '1/2 (50.0 %)']); + expect(bars(mode, (key) => (key === 'types' ? type : undefined))!.rows[0].cells.at(-1)).toBe( + 'No disponible', + ); + }); + it('lists histologic codes from gold and preserves missing types in the denominator', () => { + const r: Reading = { + populations: { 'initial-population': 4 }, + strata: { + category: { '8500/3': { 'initial-population': 1 }, no_data: { 'initial-population': 3 } }, + }, + }; + const table = bars( + { kind: 'counts', label: 'Tipos histológicos', measure: 'M', catalog: [], unit: 'Biopsias' }, + () => r, + )!; + expect(table.rows.map((row) => [row.label, ...row.cells])).toEqual([ + ['8500/3', '1', '25.0 %'], + ['Sin dato', '3', '75.0 %'], + ]); + }); it('list every category, so the shares add up', () => { const r: Reading = { populations: {}, diff --git a/src/app/indicadores/bars.ts b/src/app/indicadores/bars.ts index 9742f1c..6386a3c 100644 --- a/src/app/indicadores/bars.ts +++ b/src/app/indicadores/bars.ts @@ -92,6 +92,8 @@ export type Mode = { rows: Category[]; results: Category[]; malignant: string[]; + dynamicResults?: boolean; + malignancyMeasure?: string; } | { kind: 'figure'; @@ -404,16 +406,33 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined): 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); + const colors = ['#5C42C2', '#C24269', '#9C42C2', '#A8C243', '#2778B8', '#B19525']; + const actual = Object.keys(r?.strata['category'] ?? {}) + .filter((code) => !['no_biopsy', 'no_data'].includes(code)) + .sort(); + const results = mode.dynamicResults + ? [ + ...actual.map((code, i) => ({ + code, + label: name(code), + color: colors[i % colors.length], + })), + ...mode.results, + ] + : mode.results; + const malignancy = mode.malignancyMeasure ? of(mode.malignancyMeasure) : r; + const hasMalignancy = !!malignancy?.strata[`${mode.stratum}-category`]; + const malignancyCells = malignancy?.strata[`${mode.stratum}-category`] ?? {}; + const grades = ['benign', 'in_situ', 'invasive']; return { - head: ['Pacientes', ...mode.results.map((x) => x.label), '% maligno'], - legend: mode.results.map(({ label, color }) => ({ label, color })), + head: ['Pacientes', ...results.map((x) => x.label), '% maligno'], + legend: 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), + const by = results.map((x) => size(cells[`${code}|${x.code}`])); + const den = grades.reduce((t, grade) => t + size(malignancyCells[`${code}|${grade}`]), 0); + const bad = mode.malignant.reduce( + (t, grade) => t + size(malignancyCells[`${code}|${grade}`]), 0, ); return { @@ -421,7 +440,7 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined): width: 100, marks: [], none: n ? undefined : 'Sin pacientes en el periodo', - segments: mode.results.map((x, i) => ({ + segments: 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)})`, @@ -430,11 +449,13 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined): `${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' + ? !hasMalignancy + ? 'No disponible' + : den + ? `${bad}/${den} (${pct(bad, den)})` + : size(malignancyCells[`${code}|no_data`]) + ? 'Sin biopsias clasificables' + : 'Sin biopsias' : '—', ], }; diff --git a/src/app/indicadores/pages.ts b/src/app/indicadores/pages.ts index 6e36997..a7bd96d 100644 --- a/src/app/indicadores/pages.ts +++ b/src/app/indicadores/pages.ts @@ -251,6 +251,12 @@ export const PAGES: Record = { anchor: 'CAMA_BIRADS456_PACIENTE', // every single-number card, together at the start, in the order asked for 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_EU38A', title: 'Tiempo de toma de mastografía a interpretación radiológica', @@ -276,12 +282,6 @@ export const PAGES: Record = { title: 'Tiempo de tamizaje a diagnóstico', ...CAMA_DAYS, }, - { - 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.', - }, ], opportunity: [ { @@ -330,26 +330,28 @@ export const PAGES: Record = { }, { kind: 'readings', - title: 'Resultado histopatológico por categoría BI-RADS', - 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.', + title: 'Tipo histológico por categoría BI-RADS', + 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. Los tipos se muestran como códigos CIE-O-3; «Sin dato» incluye tipos ausentes o con vínculo ambiguo. El porcentaje maligno conserva la clasificación de la biopsia y su denominador de pacientes con clasificación conocida.', modes: [ { kind: 'outcomes', label: 'Por categoría BI-RADS', heading: 'Resultados por paciente', caption: NO_BIOPSY_MEANS, - measure: 'CAMA_HISTOPATOLOGIA_BIRADS', + measure: 'CAMA_TIPO_HISTOLOGICO_BIRADS', stratum: 'birads', rows: BIRADS.categories, - results: [...BIOPSY_GRADES, ...NO_RESULT], + results: NO_RESULT, malignant: ['in_situ', 'invasive'], + dynamicResults: true, + malignancyMeasure: 'CAMA_HISTOPATOLOGIA_BIRADS', }, { kind: 'counts', label: 'Todas las categorías', heading: 'Resultados por paciente', - measure: 'CAMA_HISTOPATOLOGIA_BIRADS', - catalog: [...BIOPSY_GRADES, ...NO_RESULT], + measure: 'CAMA_TIPO_HISTOLOGICO_BIRADS', + catalog: [], unit: 'Pacientes', percent: true, percentLabel: 'Porcentaje de pacientes', @@ -362,18 +364,19 @@ export const PAGES: Record = { card: true, choices: [ { - label: 'Resultado de biopsias', + label: 'Tipos histológicos', section: { kind: 'readings', - title: 'Resultado de biopsias', - note: 'Biopsias con resultado reportado, por fecha del reporte (no son pacientes ni mastografías). Los porcentajes incluyen todas las biopsias reportadas, también «Sin dato» (sin grado).', + title: 'Tipos histológicos', + unit: 'biopsias', + note: 'Biopsias por fecha de reporte, agrupadas por código de tipo histológico CIE-O-3. «Sin dato» incluye los tipos ausentes y los que no pueden vincularse de forma inequívoca. La tasa de detección conserva su cálculo de carcinomas entre biopsias con clasificación conocida; su denominador puede ser distinto.', modes: [ { kind: 'counts', - label: 'Biopsias reportadas', - heading: 'Biopsias reportadas', - measure: 'CAMA_BIOPSIAS', - catalog: [...BIOPSY_GRADES, NO_RESULT[1]], + label: 'Tipos histológicos', + heading: 'Tipos histológicos (CIE-O-3)', + measure: 'CAMA_TIPO_HISTOLOGICO', + catalog: [], unit: 'Biopsias', percent: true, percentLabel: 'Porcentaje de reportes de biopsia', @@ -534,6 +537,7 @@ export const HISTORY: Record = { measure: 'CAMA_DIAS_TOMA_DIAGNOSTICO', kind: 'median', }, + { title: 'Tasa de detección histopatológica', measure: 'CAMA_TASA_DETECCION_HISTOPATOLOGICA', kind: 'percent' }, stack( 'Porcentaje de mastografías con resultado BI-RADS 4, 5 ó 6', 'CAMA_BIRADS456_MASTOGRAFIA',