From 3aba7fe32960ce7777eb831b636d10487092be07 Mon Sep 17 00:00:00 2001 From: rockdrigo Date: Mon, 9 Nov 2026 19:52:53 -0600 Subject: [PATCH] feat(cama): histopathological confirmation drawn like CaCu's, by BI-RADS category How: CaCu's confirmation view (rates per row with their horizontal Wilson interval, and a donut of biopsy results whose buttons choose what the rates count) takes a VistaConfirmacion: indicator id, stratum, fixed rows (most severe on top), the grade whose group is the base view, the grade read as a false positive, and its words. CONFIRMACION_CACU reproduces the previous behaviour exactly; CONFIRMACION_CAMA reads cama_histopatologia_birads by BI-RADS 6, 5, 4C, 4B and 4A, with "Maligno" (the group of INVASOR) as the base, so the base rate is the cancer detection rate, and "Benigno" alone reads as false positives. The catalog card chooses the view with vistaConfirmacion(dominio, indicador). Implications: the backend must publish cama_histopatologia_birads stratified by `birads`, with exactly two groups of results (plus SIN_DATO/SIN_BIOPSIA kept apart), as cacu_confirmacion_citologia is. The EU7-style view stays available through the catalog's `escenario` field but no CaMa indicator uses it now. --- .../indicadores/indicador-catalog-card.ts | 4 +- .../indicador-confirmacion-citologia.html | 18 ++--- .../indicador-confirmacion-citologia.ts | 26 +++---- ...indicadores-confirmacion-citologia.spec.ts | 41 ++++++++++- .../indicadores-confirmacion-citologia.ts | 68 +++++++++++++------ 5 files changed, 111 insertions(+), 46 deletions(-) diff --git a/src/app/features/indicadores/indicador-catalog-card.ts b/src/app/features/indicadores/indicador-catalog-card.ts index 6e6f570..b059fa4 100644 --- a/src/app/features/indicadores/indicador-catalog-card.ts +++ b/src/app/features/indicadores/indicador-catalog-card.ts @@ -18,7 +18,7 @@ import { IndicadorEu7Escenario } from './indicador-eu7-escenario'; import { vistaEscenario } from './indicadores-eu7-escenario'; import { IndicadorTiemposPareados } from './indicador-tiempos-pareados'; import { IndicadorConfirmacionCitologia } from './indicador-confirmacion-citologia'; -import { ID_CONFIRMACION } from './indicadores-confirmacion-citologia'; +import { vistaConfirmacion } from './indicadores-confirmacion-citologia'; import { parTiempos } from './indicadores-tiempos-pareados'; @Component({ @@ -122,7 +122,7 @@ export class IndicadorCatalogCard implements OnChanges, OnDestroy { } get pair() { return dualFigures(this.indicador); } get isEu7() { return !!vistaEscenario(this.dominio, this.indicador); } - get isConfirmacion() { return this.dominio === 'cacu' && this.indicador.id === ID_CONFIRMACION; } + get isConfirmacion() { return !!vistaConfirmacion(this.dominio, this.indicador); } // Connected time pairs replace the diagnosis card with one coordinated box plot. get tiempos() { return parTiempos(this.dominio, this.indicador.id); } get isDual() { return this.pair.includes(this.selectedFigure ?? ''); } diff --git a/src/app/features/indicadores/indicador-confirmacion-citologia.html b/src/app/features/indicadores/indicador-confirmacion-citologia.html index a089cd1..380007c 100644 --- a/src/app/features/indicadores/indicador-confirmacion-citologia.html +++ b/src/app/features/indicadores/indicador-confirmacion-citologia.html @@ -1,4 +1,4 @@ -
+

Filtro general aplicado: {{ appliedSummary }}

@if (helpOpen) { @@ -16,7 +16,7 @@ } @switch (status()) { @case ('deferred') {

La vista se cargará al acercarse a esta región.

} - @case ('loading') {

Cargando el mismo periodo para tasas y dona…

} + @case ('loading') {

Cargando el mismo periodo para tasas y dona…

} @case ('error') {

{{ message }}

} @case ('incompatible') {

Respuesta incompatible: {{ message }}

} } @@ -30,7 +30,7 @@ } @if (model; as m) {

{{ m.periodo }}, selección: {{ selectionLabel }}. {{ reading }}

- @if (status() === 'empty') {

No hay citologías de alto grado publicadas para este periodo.

} + @if (status() === 'empty') {

{{ vista.textos.vacio }}

} @else {
@@ -46,9 +46,9 @@
-

Por resultado de la citología, {{ m.periodo }}

+

{{ vista.textos.filas }}, {{ m.periodo }}

@if (ratesFigure) { - + }
    @for (t of rates; track t.fila.id) { @if (t.k === null) {
  • {{ t.fila.etiqueta }}: {{ estadoTasa(t) }}
  • } } @@ -57,15 +57,15 @@

    Resultado de la biopsia, {{ m.periodo }}

    @if (m.conBiopsia !== null && m.conBiopsia > 0 && donutFigure) { - } @else {

    {{ m.conBiopsia === null ? 'Dona no disponible: hay celdas suprimidas o datos incompletos. No se calcula un total parcial.' : 'Sin mujeres con biopsia en el periodo.' }}

    } + } @else {

    {{ m.conBiopsia === null ? 'Dona no disponible: hay celdas suprimidas o datos incompletos. No se calcula un total parcial.' : 'Sin ' + vista.textos.sujetos + ' con biopsia en el periodo.' }}

    }
} @for (note of m.notas; track $index) {

{{ note }}

}
Valores publicados -
- - @for (g of m.grados; track g.id) { }@for (a of m.aparte; track a.id) { } +
+
Tabla de contingencia de mujeres, {{ m.periodo }}
Citología{{ g.etiqueta }}Con biopsia{{ a.etiqueta }}
+ @for (g of m.grados; track g.id) { }@for (a of m.aparte; track a.id) { }@for (fila of m.filas; track fila.id) { @for (g of m.grados; track g.id) { }@for (a of m.aparte; track a.id) { } } diff --git a/src/app/features/indicadores/indicador-confirmacion-citologia.ts b/src/app/features/indicadores/indicador-confirmacion-citologia.ts index 4a55021..ca333dc 100644 --- a/src/app/features/indicadores/indicador-confirmacion-citologia.ts +++ b/src/app/features/indicadores/indicador-confirmacion-citologia.ts @@ -8,12 +8,9 @@ import { Dominio, Indicador, IndicadorMetadatos, PlotlyFigure, Tema } from './in import { describePeriods, filterCompatibility, GlobalApplied } from './indicadores-memory'; import { IndicadoresSnapshots, snapshotKey } from './indicadores-snapshots'; import { httpMessage } from './indicadores-http'; -import { clicConfirmacion, ConfirmacionIncompatible, donaConfirmacion, ESTRATO_CITOLOGIA, estadoTasa, figuraTasas, ID_CONFIRMACION, +import { clicConfirmacion, ConfirmacionIncompatible, CONFIRMACION_CACU, donaConfirmacion, estadoTasa, figuraTasas, lectura, ModeloConfirmacion, modeloConfirmacion, periodosConfirmacion, SeleccionConfirmacion, seleccionBase, seleccionEtiqueta, - Celda, tasas } from './indicadores-confirmacion-citologia'; - -// Figures of the kit whose "Cómo leer" describes this coordinated view. -const FIGURAS = [['fig_c2_donas', 'Dona de grados de biopsia'], ['fig_c2_barras', 'Tasas por resultado de la citología']] as const; + Celda, Tasa, tasas, vistaConfirmacion } from './indicadores-confirmacion-citologia'; @Component({ selector: 'app-indicador-confirmacion-citologia', @@ -50,12 +47,16 @@ export class IndicadorConfirmacionCitologia implements OnChanges, OnDestroy { get reading() { return this.model && this.selection ? lectura(this.model, this.selection) : ''; } get isBase() { return !!this.model && !!this.selection && !this.selection.categoria && this.selection.grupo === this.model.base; } get rates() { return this.model && this.selection ? tasas(this.model, this.selection) : []; } - readonly estadoTasa = estadoTasa; + // CaCu's words when the catalog doesn't name this indicator, so the messages still read. + get vista() { return vistaConfirmacion(this.dominio, this.indicador) ?? CONFIRMACION_CACU; } + estadoTasa(t: Tasa) { return estadoTasa(t, this.vista.textos.sujetos); } cellText(cell: Celda) { return cell.n === null ? cell.estado : cell.n.toLocaleString('es-MX'); } denText(den: number | null, estado: string) { return den === null ? estado : den.toLocaleString('es-MX'); } get readingGuide() { const details = this.metadata?.figuras_detalle ?? []; - return FIGURAS.flatMap(([figura, nombre]) => { + // Figures of the kit whose "Cómo leer" describes this coordinated view. + const figuras = [['fig_c2_donas', 'Dona de resultados de biopsia'], ['fig_c2_barras', 'Tasas ' + this.vista.textos.filas.toLowerCase()]] as const; + return figuras.flatMap(([figura, nombre]) => { const detail = details.find(item => item.figura === figura); const descripcion = detail?.descripcion?.trim() ?? ''; const como_leer = (detail?.como_leer ?? []).filter(line => line.trim().length > 0); @@ -65,7 +66,7 @@ export class IndicadorConfirmacionCitologia implements OnChanges, OnDestroy { toggleHelp() { this.helpOpen = !this.helpOpen; if (this.helpOpen) this.metadataRequested.emit(); } ngOnChanges(changes: SimpleChanges) { - const key = snapshotKey(this.dominio, this.indicador, this.applied, { estrato: ESTRATO_CITOLOGIA }) + const key = snapshotKey(this.dominio, this.indicador, this.applied, { estrato: this.vista.estrato }) + JSON.stringify([this.indicador.contrato, this.indicador.tipos_periodo, this.indicador.figuras]); if (key !== this.key) { this.subscription?.unsubscribe(); this.key = key; this.loaded = false; @@ -84,7 +85,8 @@ export class IndicadorConfirmacionCitologia implements OnChanges, OnDestroy { this.subscription?.unsubscribe(); this.loaded = true; this.clear(); const compatibility = filterCompatibility(this.applied, this.indicador.tipos_periodo); - if (this.dominio !== 'cacu' || this.indicador.id !== ID_CONFIRMACION || this.indicador.contrato !== 'C2' || !compatibility.compatible) { + const vista = vistaConfirmacion(this.dominio, this.indicador); + if (!vista || this.indicador.contrato !== 'C2' || !compatibility.compatible) { this.message = !compatibility.compatible ? compatibility.reason : 'El catálogo no publica las capacidades necesarias para esta vista.'; this.status.set('incompatible'); return; } @@ -92,12 +94,12 @@ export class IndicadorConfirmacionCitologia implements OnChanges, OnDestroy { const periods = this.applied.selection.mode === 'explicit' ? [...this.applied.selection.periodos] : undefined; this.status.set('loading'); this.subscription = this.snapshots.datos(this.dominio, this.indicador.id, this.applied.tipo, periods, this.indicador.version, - { estrato: ESTRATO_CITOLOGIA }).pipe(timeout({ first: 40000 })).subscribe({ + { estrato: vista.estrato }).pipe(timeout({ first: 40000 })).subscribe({ next: datos => { if (key !== this.key) return; try { - this.periods = periodosConfirmacion(datos, this.applied.tipo, periods); - this.pages = this.periods.map(p => modeloConfirmacion(datos, p)); + this.periods = periodosConfirmacion(datos, this.applied.tipo, periods, vista); + this.pages = this.periods.map(p => modeloConfirmacion(datos, p, vista)); // The most recent period first, as the prototype; navigation goes back. this.periodIndex = Math.max(0, this.periods.length - 1); this.activatePeriod(); } catch (error) { this.failure(error); } diff --git a/src/app/features/indicadores/indicadores-confirmacion-citologia.spec.ts b/src/app/features/indicadores/indicadores-confirmacion-citologia.spec.ts index 53da8d4..b58de47 100644 --- a/src/app/features/indicadores/indicadores-confirmacion-citologia.spec.ts +++ b/src/app/features/indicadores/indicadores-confirmacion-citologia.spec.ts @@ -9,8 +9,8 @@ import { IndicadorFigurePanel } from './indicador-figure-panel'; import { PlotlyChart } from '../../shared/plotly/plotly-chart'; import { GlobalApplied } from './indicadores-memory'; import { Indicador, IndicadorDatos } from './indicadores.models'; -import { clicConfirmacion, ConfirmacionIncompatible, donaConfirmacion, estadoTasa, figuraTasas, lectura, modeloConfirmacion, - periodosConfirmacion, rangoTasas, seleccionBase, tasas, wilson } from './indicadores-confirmacion-citologia'; +import { clicConfirmacion, ConfirmacionIncompatible, CONFIRMACION_CAMA, donaConfirmacion, estadoTasa, figuraTasas, lectura, modeloConfirmacion, + periodosConfirmacion, rangoTasas, seleccionBase, tasas, vistaConfirmacion, wilson } from './indicadores-confirmacion-citologia'; @Component({ selector: 'app-plotly-chart', template: '' }) class ChartStub { figure = input(); label = input(); showNotes = input(); plotClick = output(); } @@ -62,7 +62,7 @@ describe('Confirmación histopatológica: modelo', () => { const d = respuesta(['2026-S2'], { LIEAG: CONTEOS['LIEAG'] }); const m = modeloConfirmacion(d, '2026-S2'); expect(m.filas.map(f => f.den)).toEqual([0, 58, 0]); - expect(tasas(m, seleccionBase(m)).map(estadoTasa)).toEqual(['Sin mujeres con biopsia', '', 'Sin mujeres con biopsia']); + expect(tasas(m, seleccionBase(m)).map(t => estadoTasa(t))).toEqual(['Sin mujeres con biopsia', '', 'Sin mujeres con biopsia']); expect(m.filas[0].etiqueta).toBe('Carcinoma in situ'); (d['totales_estrato'] as Record[])[0]['suprimido'] = 1; const s = modeloConfirmacion(d, '2026-S2'); @@ -223,3 +223,38 @@ describe('Confirmación histopatológica: componente', () => { card.destroy(); http.expectNone(() => true); }); }); + +// Cáncer de mama's configuration of the same view. Fixture: a one-period answer of cama_histopatologia_birads +// built below, with two BI-RADS categories published and biopsies without a result kept apart. +describe('Confirmación histopatológica de cáncer de mama', () => { + const categorias = { + BENIGNO: { etiqueta: 'Benigno', color: '#9DBFE3', grupo: 'NO_MALIGNO' }, RIESGO_B3: { etiqueta: 'Lesión de riesgo (B3)', color: '#2F6DB3', grupo: 'NO_MALIGNO' }, + IN_SITU: { etiqueta: 'Carcinoma in situ', color: '#D9822B', grupo: 'MALIGNO' }, INVASOR: { etiqueta: 'Carcinoma invasor', color: '#B5482E', grupo: 'MALIGNO' }, + SIN_DATO: { etiqueta: 'Sin resultado histopatológico', color: '#BDBDBD', grupo: 'SIN_DATO' }, + }; + const n: Record> = { + BIRADS_5: { BENIGNO: 3, RIESGO_B3: 0, IN_SITU: 11, INVASOR: 38, SIN_DATO: 3 }, + BIRADS_4A: { BENIGNO: 91, RIESGO_B3: 15, IN_SITU: 1, INVASOR: 7, SIN_DATO: 9 }, + }; + const datos = () => ({ id: 'cama_histopatologia_birads', contrato: 'C2', tipo_periodo: 'semestre', periodos: ['2025-S2'], estrato: 'birads', + valores_estrato: Object.keys(n), categorias, grupos_de_categoria: { NO_MALIGNO: 'No maligno', MALIGNO: 'Maligno', SIN_DATO: 'Sin dato' }, + filas: Object.entries(n).flatMap(([estrato, c]) => Object.entries(c).map(([categoria, v]) => + ({ periodo: '2025-S2', grupo: 'TOTAL', estrato, categoria, n: v, suprimido: 0 }))) }) as IndicadorDatos; + + it('la elige el dominio y el indicador', () => { + // Fails if the view stops being found for cáncer de mama, or leaks to another indicator. + expect(vistaConfirmacion('cama', { id: 'cama_histopatologia_birads' })).toBe(CONFIRMACION_CAMA); + expect(vistaConfirmacion('cama', { id: 'cacu_confirmacion_citologia' })).toBeUndefined(); + }); + it('filas BI-RADS de la más grave a la menor, base maligna y sin resultado aparte', () => { + // Fails if the rows don't follow the configuration, the base isn't malignancy or «Sin dato» enters the rate. + const m = modeloConfirmacion(datos(), '2025-S2', CONFIRMACION_CAMA), base = seleccionBase(m); + expect(m.filas.map(f => f.id)).toEqual(['BIRADS_6', 'BIRADS_5', 'BIRADS_4C', 'BIRADS_4B', 'BIRADS_4A']); + expect(base).toEqual({ grupo: 'MALIGNO' }); + expect(lectura(m, base)).toBe('Detección de cáncer (valor predictivo positivo)'); + const t = tasas(m, base); + expect(t[1].k).toBe(49); expect(t[1].fila.den).toBe(52); + expect(t[4].k).toBe(8); expect(t[4].fila.den).toBe(114); + expect(estadoTasa(t[0], m.vista.textos.sujetos)).toBe('Sin pacientes con biopsia'); + }); +}); diff --git a/src/app/features/indicadores/indicadores-confirmacion-citologia.ts b/src/app/features/indicadores/indicadores-confirmacion-citologia.ts index db80358..d97a389 100644 --- a/src/app/features/indicadores/indicadores-confirmacion-citologia.ts +++ b/src/app/features/indicadores/indicadores-confirmacion-citologia.ts @@ -1,4 +1,4 @@ -import { IndicadorDatos, PlotlyFigure, Tema } from './indicadores.models'; +import { DimensionEstrato, Dominio, Indicador, IndicadorDatos, PlotlyFigure, Tema } from './indicadores.models'; import { c2Theme } from './indicadores-c2-palette'; import { percentNumber, shareText } from './indicadores-format'; @@ -24,6 +24,34 @@ export const FILAS_CITOLOGIA = [ ] as const; export const Z95 = 1.959963984540054; +// One confirmation view: which indicator and stratum, its fixed rows (most severe on top), the grade whose group is +// the base view (the true positives), the grade read as a false positive, and the words the view uses. +export interface VistaConfirmacion { + id: string; estrato: DimensionEstrato; filas: readonly { id: string; etiqueta: string }[]; + base: string; falsoPositivo: string; + textos: { base: string; falsoPositivo: string; sinConfirmacion: string; filas: string; encabezado: string; sujetos: string; vacio: string }; +} +export const CONFIRMACION_CACU: VistaConfirmacion = { + id: ID_CONFIRMACION, estrato: ESTRATO_CITOLOGIA, filas: FILAS_CITOLOGIA, base: 'LIEAG', falsoPositivo: 'NORMAL', + textos: { base: 'Verdaderos positivos (valor predictivo positivo)', falsoPositivo: 'Falsos positivos: la biopsia no confirmó lesión', + sinConfirmacion: 'Sin confirmación de alto grado', filas: 'Por resultado de la citología', encabezado: 'Citología', sujetos: 'mujeres', + vacio: 'No hay citologías de alto grado publicadas para este periodo.' }, +}; +// Cáncer de mama: the biopsies by the BI-RADS of the mammogram that led to them; the base is malignancy. +export const CONFIRMACION_CAMA: VistaConfirmacion = { + id: 'cama_histopatologia_birads', estrato: 'birads', base: 'INVASOR', falsoPositivo: 'BENIGNO', + filas: [{ id: 'BIRADS_6', etiqueta: 'BI-RADS 6' }, { id: 'BIRADS_5', etiqueta: 'BI-RADS 5' }, { id: 'BIRADS_4C', etiqueta: 'BI-RADS 4C' }, + { id: 'BIRADS_4B', etiqueta: 'BI-RADS 4B' }, { id: 'BIRADS_4A', etiqueta: 'BI-RADS 4A' }], + textos: { base: 'Detección de cáncer (valor predictivo positivo)', falsoPositivo: 'Falsos positivos: la biopsia resultó benigna', + sinConfirmacion: 'Sin malignidad', filas: 'Por categoría BI-RADS', encabezado: 'BI-RADS', sujetos: 'pacientes', + vacio: 'No hay biopsias publicadas para este periodo.' }, +}; +const VISTAS_CONFIRMACION: Readonly>> = { cacu: CONFIRMACION_CACU, cama: CONFIRMACION_CAMA }; +export function vistaConfirmacion(dominio: Dominio, indicador: Pick): VistaConfirmacion | undefined { + const vista = VISTAS_CONFIRMACION[dominio]; + return vista?.id === indicador.id ? vista : undefined; +} + export interface Celda { n: number | null; estado: 'Publicado' | 'Suprimido' | 'No disponible'; } export interface Grado { id: string; etiqueta: string; color: string; grupo: string; } export interface GrupoGrados { id: string; etiqueta: string; color: string; grados: string[]; } @@ -37,7 +65,7 @@ export interface FilaCitologia { export interface ModeloConfirmacion { periodo: string; grados: Grado[]; grupos: GrupoGrados[]; base: string; filas: FilaCitologia[]; totales: Record; conBiopsia: number | null; - aparte: { id: string; etiqueta: string }[]; vacio: boolean; notas: string[]; + aparte: { id: string; etiqueta: string }[]; vacio: boolean; notas: string[]; vista: VistaConfirmacion; } export interface SeleccionConfirmacion { grupo: string; categoria?: string; } export interface Tasa { fila: FilaCitologia; k: number | null; valor: number | null; bajo: number | null; alto: number | null; } @@ -81,8 +109,8 @@ function rgba(hex: string, alfa: number): string { const etiquetaGrupo = (v: unknown) => texto(v) ? v : registro(v) && texto(v['etiqueta']) ? v['etiqueta'] : undefined; /** Validated periods of one stratified response, in request order or sorted. */ -export function periodosConfirmacion(datos: IndicadorDatos, tipo: string, solicitados?: readonly string[]): string[] { - if (datos.id !== ID_CONFIRMACION || datos.contrato !== 'C2' || datos.tipo_periodo !== tipo || datos['estrato'] !== ESTRATO_CITOLOGIA +export function periodosConfirmacion(datos: IndicadorDatos, tipo: string, solicitados?: readonly string[], vista = CONFIRMACION_CACU): string[] { + if (datos.id !== vista.id || datos.contrato !== 'C2' || datos.tipo_periodo !== tipo || datos['estrato'] !== vista.estrato || !Array.isArray(datos.periodos) || new Set(datos.periodos).size !== datos.periodos.length || datos.periodos.some(p => typeof p !== 'string' || !(tipo === 'semestre' ? /^[0-9]{4}-S[12]$/ : /^[0-9]{4}-(0[1-9]|1[0-2])$/).test(p)) || (solicitados && datos.periodos.some(p => !solicitados.includes(p))) @@ -93,8 +121,8 @@ export function periodosConfirmacion(datos: IndicadorDatos, tipo: string, solici } /** One /datos payload -> the contingency table of a single period. */ -export function modeloConfirmacion(datos: IndicadorDatos, periodo: string): ModeloConfirmacion { - periodosConfirmacion(datos, datos.tipo_periodo); +export function modeloConfirmacion(datos: IndicadorDatos, periodo: string, vista = CONFIRMACION_CACU): ModeloConfirmacion { + periodosConfirmacion(datos, datos.tipo_periodo, undefined, vista); const cats = datos['categorias'], nombres = datos['grupos_de_categoria']; if (!registro(cats) || !registro(nombres)) return fail('Catálogo de grados incompleto.'); const aparte = APARTE.filter(a => Object.hasOwn(cats, a.id)).map(a => { @@ -112,8 +140,8 @@ export function modeloConfirmacion(datos: IndicadorDatos, periodo: string): Mode return { id, etiqueta: etiquetaGrupo(nombres[id])!, color: promedio((publicados.length ? publicados : propios).map(g => g.color)), grados: propios.map(g => g.id) }; }); - // The base view is the group of LIEAG ("LIEAG o más"): the true positives. - const base = grados.find(g => g.id === 'LIEAG')?.grupo ?? fail('El catálogo no publica el grado LIEAG.'); + // The base view is the group of the view's base grade (CaCu: "LIEAG o más"): the true positives. + const base = grados.find(g => g.id === vista.base)?.grupo ?? fail(`El catálogo no publica el grado ${vista.base}.`); if (grupos.length !== 2) fail('Se esperaban dos grupos de grados.'); const index = new Map>(); for (const row of datos.filas.filter(f => f['periodo'] === periodo)) { @@ -128,11 +156,11 @@ export function modeloConfirmacion(datos: IndicadorDatos, periodo: string): Mode } // valores_estrato may list only the strata with data; a fixed row absent from it has no women. const publicados = Array.isArray(datos['valores_estrato']) ? (datos['valores_estrato'] as unknown[]) : undefined; - if (publicados && !publicados.every(v => typeof v === 'string')) fail('Estratos de citología inválidos.'); + if (publicados && !publicados.every(v => typeof v === 'string')) fail('Estratos inválidos.'); const etiquetas = registro(datos['etiquetas_estrato']) ? datos['etiquetas_estrato'] : {}; const totales = Array.isArray(datos['totales_estrato']) ? (datos['totales_estrato'] as unknown[]) : []; - if (!totales.every(registro)) fail('Totales de citología inválidos.'); - const filas = FILAS_CITOLOGIA.map(({ id, etiqueta }) => { + if (!totales.every(registro)) fail('Totales por estrato inválidos.'); + const filas = vista.filas.map(({ id, etiqueta }) => { const rotulo = texto(etiquetas[id]) ? etiquetas[id] : registro(cats[id]) && texto(cats[id]['etiqueta']) ? cats[id]['etiqueta'] : etiqueta; const tieneFilas = [...index.keys()].some(k => JSON.parse(k)[0] === id); const ausente = !tieneFilas && (!publicados || !publicados.includes(id)); @@ -148,7 +176,7 @@ export function modeloConfirmacion(datos: IndicadorDatos, periodo: string): Mode const porGrado = Object.fromEntries(grados.map(g => [g.id, filas.some(f => f.den === null) ? null : suma(filas.map(f => f.celdas[g.id]))])); return { periodo, grados, grupos, base, filas, totales: porGrado, conBiopsia: suma(grados.map(g => ({ n: porGrado[g.id], estado: 'Publicado' as const }))), - aparte, vacio: index.size === 0, notas: [...new Set(datos.notas ?? [])] }; + aparte, vacio: index.size === 0, notas: [...new Set(datos.notas ?? [])], vista }; } export function seleccionBase(m: ModeloConfirmacion): SeleccionConfirmacion { return { grupo: m.base }; } @@ -169,9 +197,9 @@ export function clicConfirmacion(m: ModeloConfirmacion, sel: SeleccionConfirmaci } /** The axis title says what the rate reads. */ export function lectura(m: ModeloConfirmacion, sel: SeleccionConfirmacion): string { - if (!sel.categoria && sel.grupo === m.base) return 'Verdaderos positivos (valor predictivo positivo)'; - if (sel.categoria === 'NORMAL') return 'Falsos positivos: la biopsia no confirmó lesión'; - if (!sel.categoria) return 'Sin confirmación de alto grado'; + if (!sel.categoria && sel.grupo === m.base) return m.vista.textos.base; + if (sel.categoria === m.vista.falsoPositivo) return m.vista.textos.falsoPositivo; + if (!sel.categoria) return m.vista.textos.sinConfirmacion; return 'Proporción con biopsia ' + seleccionEtiqueta(m, sel); } /** Per cytology: selected grades over women with a biopsy. "No biopsy yet" never enters. */ @@ -184,8 +212,8 @@ export function tasas(m: ModeloConfirmacion, sel: SeleccionConfirmacion): Tasa[] return { fila, k, valor: 100 * k / fila.den, bajo, alto }; }); } -export function estadoTasa(t: Tasa): string { - return t.fila.den === 0 ? 'Sin mujeres con biopsia' : t.fila.estado === 'Publicado' ? '' : t.fila.estado; +export function estadoTasa(t: Tasa, sujetos = 'mujeres'): string { + return t.fila.den === 0 ? `Sin ${sujetos} con biopsia` : t.fila.estado === 'Publicado' ? '' : t.fila.estado; } /** Axis bounded to what is shown: 5-point margin, multiples of 5, within 0-100. */ export function rangoTasas(valores: Tasa[]): [number, number] { @@ -206,7 +234,7 @@ export function figuraTasas(m: ModeloConfirmacion, sel: SeleccionConfirmacion, t marker: { size: 12, color }, cliponaxis: false, error_x: { type: 'data', symmetric: false, color, thickness: 2, width: 6, array: valores.map(t => t.valor === null ? 0 : t.alto! - t.valor), arrayminus: valores.map(t => t.valor === null ? 0 : t.valor - t.bajo!) }, - customdata: valores.map(t => t.k === null ? [estadoTasa(t), '', '', '', ''] : [shareText(t.k, t.fila.den!), t.k, t.fila.den, percentNumber(t.bajo!), percentNumber(t.alto!)]), + customdata: valores.map(t => t.k === null ? [estadoTasa(t, m.vista.textos.sujetos), '', '', '', ''] : [shareText(t.k, t.fila.den!), t.k, t.fila.den, percentNumber(t.bajo!), percentNumber(t.alto!)]), hovertemplate: '%{y}
%{customdata[0]} (%{customdata[1]}/%{customdata[2]})
IC 95 %: %{customdata[3]}–%{customdata[4]} %', }], layout: { autosize: true, height: 360, showlegend: false, paper_bgcolor: p.background, plot_bgcolor: p.background, font: { color: p.text }, @@ -215,7 +243,7 @@ export function figuraTasas(m: ModeloConfirmacion, sel: SeleccionConfirmacion, t xaxis: { range: rangoTasas(valores), ticksuffix: ' %', gridcolor: p.grid, zeroline: false, fixedrange: true, title: { text: lectura(m, sel) } }, annotations: valores.map(t => ({ x: 1, xref: 'paper', xanchor: 'left', xshift: 8, y: t.fila.etiqueta, yref: 'y', showarrow: false, align: 'left', font: { size: 12, color: p.text }, - text: t.k === null ? estadoTasa(t) : `${shareText(t.k, t.fila.den!)}
${t.k}/${t.fila.den}` })), + text: t.k === null ? estadoTasa(t, m.vista.textos.sujetos) : `${shareText(t.k, t.fila.den!)}
${t.k}/${t.fila.den}` })), }, config: { displayModeBar: false } }; } @@ -227,7 +255,7 @@ export function donaConfirmacion(m: ModeloConfirmacion, sel: SeleccionConfirmaci const interior = m.grupos.map(g => g.grados.reduce((s, c) => s + m.totales[c]!, 0)); const exterior = m.grados.map(g => m.totales[g.id]!); const comun = { type: 'pie', sort: false, direction: 'clockwise', rotation: 0, showlegend: false, textinfo: 'none' }; - const hover = { hovertemplate: '%{label}
%{customdata[0]} mujeres con biopsia, %{customdata[1]}' }; + const hover = { hovertemplate: `%{label}
%{customdata[0]} ${m.vista.textos.sujetos} con biopsia, %{customdata[1]}` }; const custom = (values: number[]) => values.map(n => [miles(n), shareText(n, total)]); return { data: [ { ...comun, name: 'centro', values: [1], labels: ['centro'], domain: { x: [.32, .68], y: [.32, .68] }, textinfo: 'text', textposition: 'inside',
Tabla de contingencia de {{ vista.textos.sujetos }}, {{ m.periodo }}
{{ vista.textos.encabezado }}{{ g.etiqueta }}Con biopsia{{ a.etiqueta }}
{{ fila.etiqueta }}{{ cellText(fila.celdas[g.id]) }}{{ denText(fila.den, fila.estado) }}{{ cellText(fila.aparte[a.id]) }}