CaMa: tipo histológico, BI-RADS 4-6 primero y detección en el histórico

This commit is contained in:
2026-12-03 23:47:37 -06:00
parent 2a84eb56ca
commit 72aa91af04
4 changed files with 119 additions and 36 deletions
+4 -4
View File
@@ -228,10 +228,10 @@ for (const domain of ['cama', 'tea']) {
const clinical = all.findIndex((i) => i.text === 'Indicadores clínicos'); const clinical = all.findIndex((i) => i.text === 'Indicadores clínicos');
// The histopathology figures are two cards: the result by BI-RADS and the confirmation. // The histopathology figures are two cards: the result by BI-RADS and the confirmation.
const results = all.findIndex( 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 = [ 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 { kind: 'h3', text: 'Confirmación histopatológica' }, // one card: title, tabs and reading
]; ];
const old = const old =
@@ -248,14 +248,14 @@ for (const domain of ['cama', 'tea']) {
const from = headings.indexOf('Indicadores de oportunidad'); const from = headings.indexOf('Indicadores de oportunidad');
if (domain === 'cama') { if (domain === 'cama') {
const ordered = [ const ordered = [
'Pacientes evaluadas con BI-RADS 4, 5 o 6',
'Tiempo de toma de mastografía a interpretación radiológica', '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 diagnóstico',
'Tiempo de interpretación radiológica a resultado de biopsia', 'Tiempo de interpretación radiológica a resultado de biopsia',
'Tiempo de diagnóstico a tratamiento', 'Tiempo de diagnóstico a tratamiento',
'Tiempo de tamizaje a diagnóstico', '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', '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', 'Confirmación histopatológica',
]; ];
let last = -1; let last = -1;
+58
View File
@@ -3,6 +3,64 @@ import { scenarioBars } from './figures';
import { Reading } from './measures'; import { Reading } from './measures';
describe('bars', () => { 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', () => { it('list every category, so the shares add up', () => {
const r: Reading = { const r: Reading = {
populations: {}, populations: {},
+31 -10
View File
@@ -92,6 +92,8 @@ export type Mode = {
rows: Category[]; rows: Category[];
results: Category[]; results: Category[];
malignant: string[]; malignant: string[];
dynamicResults?: boolean;
malignancyMeasure?: string;
} }
| { | {
kind: 'figure'; kind: 'figure';
@@ -404,16 +406,33 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
const units = r?.strata[mode.stratum] ?? {}; const units = r?.strata[mode.stratum] ?? {};
const cells = r?.strata[`${mode.stratum}-category`] ?? {}; const cells = r?.strata[`${mode.stratum}-category`] ?? {};
if (!Object.keys(units).length) return undefined; 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 { return {
head: ['Pacientes', ...mode.results.map((x) => x.label), '% maligno'], head: ['Pacientes', ...results.map((x) => x.label), '% maligno'],
legend: mode.results.map(({ label, color }) => ({ label, color })), legend: results.map(({ label, color }) => ({ label, color })),
rows: mode.rows.map(({ code, label }) => { rows: mode.rows.map(({ code, label }) => {
const n = size(units[code]); const n = size(units[code]);
const by = mode.results.map((x) => size(cells[`${code}|${x.code}`])); const by = results.map((x) => size(cells[`${code}|${x.code}`]));
const den = by.reduce((t, k, i) => t + (graded(i) ? k : 0), 0); const den = grades.reduce((t, grade) => t + size(malignancyCells[`${code}|${grade}`]), 0);
const bad = by.reduce( const bad = mode.malignant.reduce(
(t, k, i) => t + (mode.malignant.includes(mode.results[i].code) ? k : 0), (t, grade) => t + size(malignancyCells[`${code}|${grade}`]),
0, 0,
); );
return { return {
@@ -421,7 +440,7 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
width: 100, width: 100,
marks: [], marks: [],
none: n ? undefined : 'Sin pacientes en el periodo', 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, width: n ? (100 * by[i]) / n : 0,
color: x.color, color: x.color,
title: `${x.label}: ${by[i]} de ${n} (${pct(by[i], n)})`, title: `${x.label}: ${by[i]} de ${n} (${pct(by[i], n)})`,
@@ -430,9 +449,11 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
`${n}`, `${n}`,
...by.map((k) => (n ? `${k}` : '—')), ...by.map((k) => (n ? `${k}` : '—')),
n n
? den ? !hasMalignancy
? 'No disponible'
: den
? `${bad}/${den} (${pct(bad, den)})` ? `${bad}/${den} (${pct(bad, den)})`
: by[mode.results.findIndex((x) => x.code === 'no_data')] : size(malignancyCells[`${code}|no_data`])
? 'Sin biopsias clasificables' ? 'Sin biopsias clasificables'
: 'Sin biopsias' : 'Sin biopsias'
: '—', : '—',
+23 -19
View File
@@ -251,6 +251,12 @@ export const PAGES: Record<string, Page> = {
anchor: 'CAMA_BIRADS456_PACIENTE', anchor: 'CAMA_BIRADS456_PACIENTE',
// every single-number card, together at the start, in the order asked for // every single-number card, together at the start, in the order asked for
kpis: [ 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', measure: 'CAMA_EU38A',
title: 'Tiempo de toma de mastografía a interpretación radiológica', title: 'Tiempo de toma de mastografía a interpretación radiológica',
@@ -276,12 +282,6 @@ export const PAGES: Record<string, Page> = {
title: 'Tiempo de tamizaje a diagnóstico', title: 'Tiempo de tamizaje a diagnóstico',
...CAMA_DAYS, ...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: [ opportunity: [
{ {
@@ -330,26 +330,28 @@ export const PAGES: Record<string, Page> = {
}, },
{ {
kind: 'readings', kind: 'readings',
title: 'Resultado histopatológico por categoría BI-RADS', 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. El porcentaje maligno se calcula solo sobre las pacientes con biopsia con grado.', 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: [ modes: [
{ {
kind: 'outcomes', kind: 'outcomes',
label: 'Por categoría BI-RADS', label: 'Por categoría BI-RADS',
heading: 'Resultados por paciente', heading: 'Resultados por paciente',
caption: NO_BIOPSY_MEANS, caption: NO_BIOPSY_MEANS,
measure: 'CAMA_HISTOPATOLOGIA_BIRADS', measure: 'CAMA_TIPO_HISTOLOGICO_BIRADS',
stratum: 'birads', stratum: 'birads',
rows: BIRADS.categories, rows: BIRADS.categories,
results: [...BIOPSY_GRADES, ...NO_RESULT], results: NO_RESULT,
malignant: ['in_situ', 'invasive'], malignant: ['in_situ', 'invasive'],
dynamicResults: true,
malignancyMeasure: 'CAMA_HISTOPATOLOGIA_BIRADS',
}, },
{ {
kind: 'counts', kind: 'counts',
label: 'Todas las categorías', label: 'Todas las categorías',
heading: 'Resultados por paciente', heading: 'Resultados por paciente',
measure: 'CAMA_HISTOPATOLOGIA_BIRADS', measure: 'CAMA_TIPO_HISTOLOGICO_BIRADS',
catalog: [...BIOPSY_GRADES, ...NO_RESULT], catalog: [],
unit: 'Pacientes', unit: 'Pacientes',
percent: true, percent: true,
percentLabel: 'Porcentaje de pacientes', percentLabel: 'Porcentaje de pacientes',
@@ -362,18 +364,19 @@ export const PAGES: Record<string, Page> = {
card: true, card: true,
choices: [ choices: [
{ {
label: 'Resultado de biopsias', label: 'Tipos histológicos',
section: { section: {
kind: 'readings', kind: 'readings',
title: 'Resultado de biopsias', title: 'Tipos histológicos',
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).', 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: [ modes: [
{ {
kind: 'counts', kind: 'counts',
label: 'Biopsias reportadas', label: 'Tipos histológicos',
heading: 'Biopsias reportadas', heading: 'Tipos histológicos (CIE-O-3)',
measure: 'CAMA_BIOPSIAS', measure: 'CAMA_TIPO_HISTOLOGICO',
catalog: [...BIOPSY_GRADES, NO_RESULT[1]], catalog: [],
unit: 'Biopsias', unit: 'Biopsias',
percent: true, percent: true,
percentLabel: 'Porcentaje de reportes de biopsia', percentLabel: 'Porcentaje de reportes de biopsia',
@@ -534,6 +537,7 @@ export const HISTORY: Record<string, History> = {
measure: 'CAMA_DIAS_TOMA_DIAGNOSTICO', measure: 'CAMA_DIAS_TOMA_DIAGNOSTICO',
kind: 'median', kind: 'median',
}, },
{ title: 'Tasa de detección histopatológica', measure: 'CAMA_TASA_DETECCION_HISTOPATOLOGICA', kind: 'percent' },
stack( stack(
'Porcentaje de mastografías con resultado BI-RADS 4, 5 ó 6', 'Porcentaje de mastografías con resultado BI-RADS 4, 5 ó 6',
'CAMA_BIRADS456_MASTOGRAFIA', 'CAMA_BIRADS456_MASTOGRAFIA',