From 8e85c91f1511be6013b31b544ee7d61760bccd34 Mon Sep 17 00:00:00 2001 From: Angel Capetillo Zavala Date: Wed, 18 Nov 2026 12:23:17 -0600 Subject: [PATCH] fix(cama): completar ajustes visuales de indicadores --- .../indicador-conteos-pareados.html | 2 +- .../indicador-conteos-pareados.scss | 2 + .../indicadores/indicador-conteos-pareados.ts | 8 +-- .../indicador-histopatologia-cama.html | 2 +- .../indicadores-conteos-pareados.spec.ts | 22 ++++---- .../indicadores-conteos-pareados.ts | 54 ++++++++++++++----- .../indicadores-histopatologia-cama.spec.ts | 6 ++- .../indicadores-historico-cama.spec.ts | 2 +- .../indicadores-historico-pestana.spec.ts | 10 +++- .../indicadores/indicadores-historico.ts | 2 +- .../features/indicadores/indicadores-page.ts | 2 +- .../indicadores/indicadores-sections.spec.ts | 2 +- 12 files changed, 73 insertions(+), 41 deletions(-) diff --git a/src/app/features/indicadores/indicador-conteos-pareados.html b/src/app/features/indicadores/indicador-conteos-pareados.html index 22e0deb..18eb9ea 100644 --- a/src/app/features/indicadores/indicador-conteos-pareados.html +++ b/src/app/features/indicadores/indicador-conteos-pareados.html @@ -34,7 +34,7 @@

{{ par.unidades.examenes | titlecase }} por categoría, {{ m.periodo }}

@if (total) { - + } @else {

{{ total === null ? 'Dona no disponible: hay celdas suprimidas o sin dato.' : 'Sin ' + par.unidades.examenes + ' en el periodo.' }}

} @if (m.sinDato) {

Fuera de la dona: {{ texto(m.sinDato) }} {{ par.unidades.examenes }} sin categoría.

}
diff --git a/src/app/features/indicadores/indicador-conteos-pareados.scss b/src/app/features/indicadores/indicador-conteos-pareados.scss index 632a2a3..4f3a5e0 100644 --- a/src/app/features/indicadores/indicador-conteos-pareados.scss +++ b/src/app/features/indicadores/indicador-conteos-pareados.scss @@ -14,6 +14,8 @@ h3 { font-size: 1rem; font-weight: 500; line-height: 1.5; } .figures { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--issste-space-6); } @media (min-width: 1100px) { .figures { grid-template-columns: repeat(2, minmax(0, 1fr)); } } app-plotly-chart { --plot-height: 400px; } +// Keep space for the outside labels and let the existing plot viewport scroll on very narrow cards. +.donut-chart { --plot-min-width: 390px; } summary { cursor: pointer; padding-block: .75rem; } summary:focus-visible, .table-scroll:focus-visible { outline: 2px solid var(--issste-text); outline-offset: 3px; } .table-scroll { overflow: auto; } diff --git a/src/app/features/indicadores/indicador-conteos-pareados.ts b/src/app/features/indicadores/indicador-conteos-pareados.ts index b91c0c9..3ae0ebf 100644 --- a/src/app/features/indicadores/indicador-conteos-pareados.ts +++ b/src/app/features/indicadores/indicador-conteos-pareados.ts @@ -38,10 +38,6 @@ export class IndicadorConteosPareados implements OnChanges, OnDestroy { private subscription?: Subscription; private key = ''; private loaded = false; - // On a narrow screen the donut's long label gives way to a legend under it. - private readonly estrecha = typeof matchMedia === 'function' ? matchMedia('(max-width: 520px)') : undefined; - private readonly alCambiarAncho = () => { if (this.model) this.draw(); }; - constructor() { this.estrecha?.addEventListener('change', this.alCambiarAncho); } get model(): ModeloConteos | undefined { return this.pages[this.periodIndex]; } get total() { return this.model ? totalExamenes(this.model) : null; } @@ -111,9 +107,9 @@ export class IndicadorConteosPareados implements OnChanges, OnDestroy { private draw() { const m = this.model; if (!m) return; - this.donutFigure = donaConteos(m, this.par, this.tema, this.estrecha?.matches ?? false); + this.donutFigure = donaConteos(m, this.par, this.tema); this.barsFigure = barrasConteos(m, this.par, this.tema); this.changeDetector.markForCheck(); } - ngOnDestroy() { this.subscription?.unsubscribe(); this.estrecha?.removeEventListener('change', this.alCambiarAncho); } + ngOnDestroy() { this.subscription?.unsubscribe(); } } diff --git a/src/app/features/indicadores/indicador-histopatologia-cama.html b/src/app/features/indicadores/indicador-histopatologia-cama.html index e4024ab..cc12406 100644 --- a/src/app/features/indicadores/indicador-histopatologia-cama.html +++ b/src/app/features/indicadores/indicador-histopatologia-cama.html @@ -30,7 +30,6 @@ } @if (model; as m) { -

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

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

No hay pacientes con resultado de mastografía BI-RADS 4, 5 o 6 publicadas para este periodo.

} @else {
@@ -62,6 +61,7 @@
} +

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

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

{{ note }}

}
Valores publicados
diff --git a/src/app/features/indicadores/indicadores-conteos-pareados.spec.ts b/src/app/features/indicadores/indicadores-conteos-pareados.spec.ts index a7da565..c4bd04f 100644 --- a/src/app/features/indicadores/indicadores-conteos-pareados.spec.ts +++ b/src/app/features/indicadores/indicadores-conteos-pareados.spec.ts @@ -93,19 +93,17 @@ describe('Conteos pareados de CaMa: lo que se puede sumar', () => { describe('Conteos pareados de CaMa: etiquetas de la dona', () => { type Figura = { data: Record[]; layout: { annotations: Record[]; margin: Record; showlegend: boolean } }; - const dona = (compacta = false) => donaConteos(modelo(examenes(LAB_E), pacientes(LAB_P)), PAR, 'claro', compacta) as unknown as Figura; + const dona = () => donaConteos(modelo(examenes(LAB_E), pacientes(LAB_P)), PAR, 'claro') as unknown as Figura; - it('mantiene las etiquetas con porcentaje fuera del sector en ambos tamaños', () => { - for (const compacta of [false, true]) { - const f = dona(compacta), t = f.data[0]; - expect(t['textposition']).toBe('outside'); - expect(t['text'][0]).toBe('BI-RADS 4
(sin subcategoría)
45.5 %'); - expect(t['text'][1]).toBe(''); - expect(t['text'][4]).toMatch(/^BI-RADS 5
54[.,]5 %$/); - expect(t['values']).toEqual([15, 0, 0, 0, 18, 0]); - expect(f.layout.showlegend).toBe(false); - expect(f.layout.annotations[0]['text']).toBe('33
mastografías'); - } + it('mantiene las etiquetas con porcentaje fuera del sector', () => { + const f = dona(), t = f.data[0]; + expect(t['textinfo']).toBe('none'); + expect(f.layout.annotations.slice(1).map(a => a['text']).sort()).toEqual([ + 'BI-RADS 4
(sin
subcategoría)
45.5 %', 'BI-RADS 5
54.5 %', + ]); + expect(t['values']).toEqual([15, 0, 0, 0, 18, 0]); + expect(f.layout.showlegend).toBe(false); + expect(f.layout.annotations[0]['text']).toBe('33
mastografías'); }); }); diff --git a/src/app/features/indicadores/indicadores-conteos-pareados.ts b/src/app/features/indicadores/indicadores-conteos-pareados.ts index 0c697e9..4a6484a 100644 --- a/src/app/features/indicadores/indicadores-conteos-pareados.ts +++ b/src/app/features/indicadores/indicadores-conteos-pareados.ts @@ -46,7 +46,6 @@ const ETIQUETA_RESPALDO: Readonly> = { B4: 'BI-RADS 4 (si const OPCIONALES: ReadonlySet = new Set(Object.keys(ETIQUETA_RESPALDO)); const COLOR_RESPALDO: Readonly> = { B4: '#E9C08C' }; const COLOR_NEUTRO = '#8A9199'; -// Labels longer than «BI-RADS 4A» do not fit inside the ring. export interface CategoriaConteo { id: string; etiqueta: string; color: string; n: number | null; } export interface FilaConteo { id: string; etiqueta: string; pacientes: number | null; examenes: number | null; } @@ -108,24 +107,51 @@ export function modelosConteos(par: ParConteos, examenes: IndicadorDatos, pacien } export const totalExamenes = (m: ModeloConteos) => sumar(m.examenes.map(c => c.n)); -const ALTO_DONA = 400, MARGEN_VERTICAL = 30, MARGEN_ROTULO = 120; +const ALTO_DONA = 400, MARGEN_DONA = 8; +const RADIO_DONA = (ALTO_DONA - 2 * MARGEN_DONA) * .2; -export function donaConteos(m: ModeloConteos, par: ParConteos, tema: Tema, compacta = false): PlotlyFigure { +export function donaConteos(m: ModeloConteos, par: ParConteos, tema: Tema): PlotlyFigure { const total = totalExamenes(m); if (!total) return { data: [], layout: {} }; const p = c2Theme(tema), n = m.examenes.map(c => c.n!); - const porcentaje = (i: number) => percentNumber(100 * n[i] / total) + ' %'; - return { data: [{ type: 'pie', hole: .6, sort: false, direction: 'clockwise', values: n, labels: m.examenes.map(c => escapar(c.etiqueta)), - marker: { colors: m.examenes.map(c => c.color), line: { color: p.background, width: 2 } }, textinfo: 'text', textposition: 'outside', - text: n.map((v, i) => v > 0 ? escapar(m.examenes[i].etiqueta).replace(' (', '
(') + '
' + porcentaje(i) : ''), - domain: { x: [0, 1], y: [.05, .95] }, - customdata: n.map(v => [miles(v), percentNumber(100 * v / total)]), + const etiquetas = m.examenes.map(c => escapar(c.etiqueta)); + const porcentajes = n.map(v => percentNumber(100 * v / total)); + const centro = { x: .5, y: .5, xref: 'paper', yref: 'paper', showarrow: false }; + // The pie starts at noon. Keep each callout on its slice's side and order the rows vertically, + // so even several adjacent slivers get separate labels and their guide lines keep the same order. + let acumulado = 0; + const puntos = n.flatMap((valor, i) => { + const angulo = 2 * Math.PI * (acumulado + valor / 2) / total; + acumulado += valor; + if (!valor) return []; + const x = RADIO_DONA * Math.sin(angulo), y = RADIO_DONA * Math.cos(angulo); + return [{ i, x, y }]; + }); + const llamadas = [-1, 1].flatMap(lado => { + const columna = puntos.filter(punto => (punto.x < 0 ? -1 : 1) === lado).sort((a, b) => b.y - a.y); + return columna.map(({ i, x, y }, fila) => { + const altura = (columna.length - 1 - 2 * fila) * 24; + const texto = etiquetas[i].replace(' (sin subcategoría)', '
(sin
subcategoría)'); + return { + annotation: { ...centro, xshift: lado * 105, yshift: altura, + xanchor: lado < 0 ? 'right' : 'left', align: lado < 0 ? 'right' : 'left', + font: { size: 11, color: p.text }, text: texto + '
' + porcentajes[i] + ' %' }, + shape: { type: 'path', xref: 'paper', yref: 'paper', xsizemode: 'pixel', ysizemode: 'pixel', + xanchor: .5, yanchor: .5, line: { color: p.text, width: 1 }, + path: 'M ' + Math.round(x) + ',' + Math.round(y) + ' L ' + lado * 86 + ',' + y + ' L ' + lado * 101 + ',' + altura }, + }; + }); + }); + return { data: [{ type: 'pie', hole: .6, sort: false, direction: 'clockwise', values: n, labels: etiquetas, + marker: { colors: m.examenes.map(c => c.color), line: { color: p.background, width: 2 } }, textinfo: 'none', + domain: { x: [0, 1], y: [.3, .7] }, + customdata: n.map((v, i) => [miles(v), porcentajes[i]]), hovertemplate: `%{label}
%{customdata[0]} ${par.unidades.examenes}, %{customdata[1]} %` }], - layout: { autosize: true, height: compacta ? ALTO_DONA + 40 : ALTO_DONA, showlegend: false, paper_bgcolor: p.background, font: { color: p.text }, - margin: { t: MARGEN_VERTICAL, b: MARGEN_VERTICAL, l: MARGEN_ROTULO, r: MARGEN_ROTULO }, - ...(compacta ? { legend: { orientation: 'h', x: .5, xanchor: 'center', y: -.02, yanchor: 'top', font: { size: 12 } } } : {}), - annotations: [{ x: .5, y: .5, xref: 'paper', yref: 'paper', showarrow: false, font: { size: 18, color: p.text }, - text: `${miles(total)}
${par.unidades.examenes}` }] }, config: { displayModeBar: false } }; + layout: { autosize: true, height: ALTO_DONA, showlegend: false, paper_bgcolor: p.background, font: { color: p.text }, + margin: { t: MARGEN_DONA, b: MARGEN_DONA, l: MARGEN_DONA, r: MARGEN_DONA }, + shapes: llamadas.map(({ shape }) => shape), + annotations: [{ ...centro, font: { size: 16, color: p.text }, + text: `${miles(total)}
${par.unidades.examenes}` }, ...llamadas.map(({ annotation }) => annotation)] }, config: { displayModeBar: false } }; } /** Per BI-RADS family: patients (in their most severe category) next to exams. No ratio between them is drawn. */ diff --git a/src/app/features/indicadores/indicadores-histopatologia-cama.spec.ts b/src/app/features/indicadores/indicadores-histopatologia-cama.spec.ts index c767e64..268a5a3 100644 --- a/src/app/features/indicadores/indicadores-histopatologia-cama.spec.ts +++ b/src/app/features/indicadores/indicadores-histopatologia-cama.spec.ts @@ -242,7 +242,11 @@ describe('Histopatología por BI-RADS: componente', () => { expect(figures.map(s => s.classList.contains('rates') ? 'tasas' : 'dona')).toEqual(['tasas', 'dona']); expect([...f.nativeElement.querySelectorAll('.keys button')].map((b: Element) => b.textContent!.trim())) .toEqual(['No maligno', 'Maligno', 'Benigno', 'Lesión de riesgo (B3)', 'Carcinoma in situ', 'Carcinoma invasor']); - expect(f.nativeElement.querySelector('.selection-status').textContent).toContain('selección: Maligno'); + const grafica = f.nativeElement.querySelector('.figures') as HTMLElement; + const seleccion = f.nativeElement.querySelector('.selection-status') as HTMLElement; + expect(grafica.nextElementSibling?.classList.contains('legend')).toBe(true); + expect(grafica.nextElementSibling?.nextElementSibling).toBe(seleccion); + expect(seleccion.textContent).toContain('selección: Maligno'); const table = f.nativeElement.querySelector('table') as HTMLTableElement; expect([...table.querySelectorAll('thead th')].map(th => th.textContent)).toEqual( ['Categoría BI-RADS', 'Benigno', 'Lesión de riesgo (B3)', 'Carcinoma in situ', 'Carcinoma invasor', 'Con resultado', 'Sin biopsia reportada', 'Sin dato', 'Total de pacientes']); diff --git a/src/app/features/indicadores/indicadores-historico-cama.spec.ts b/src/app/features/indicadores/indicadores-historico-cama.spec.ts index f8b051c..15219fc 100644 --- a/src/app/features/indicadores/indicadores-historico-cama.spec.ts +++ b/src/app/features/indicadores/indicadores-historico-cama.spec.ts @@ -83,7 +83,7 @@ describe('Histórico de CaMa', () => { montar(CATALOGO, true); responder(); expect(paneles().map(p => p.querySelector('h2')?.textContent)).toEqual(HISTORICO_CAMA.map(e => e.titulo)); const pendientes = paneles().filter(p => p.textContent!.includes('Integración pendiente')).map(p => p.querySelector('h2')!.textContent); - expect(pendientes).toEqual(['Resultado histopatológico por categoría BI-RADS', 'Días del resultado de la mastografía al diagnóstico', 'Tasa de detección histopatológica']); + expect(pendientes).toEqual(['Resultado histopatológico', 'Días del resultado de la mastografía al diagnóstico', 'Tasa de detección histopatológica']); expect(graficas()).toHaveLength(5); expect(paneles().filter(p => p.textContent!.includes('Integración pendiente') && p.querySelector('app-plotly-chart')).length).toBe(0); }); diff --git a/src/app/features/indicadores/indicadores-historico-pestana.spec.ts b/src/app/features/indicadores/indicadores-historico-pestana.spec.ts index ae6fd5d..444c173 100644 --- a/src/app/features/indicadores/indicadores-historico-pestana.spec.ts +++ b/src/app/features/indicadores/indicadores-historico-pestana.spec.ts @@ -28,10 +28,16 @@ describe('Pestaña Histórico', () => { http.match(() => true); } - it('CaMa: Resumen, Histórico, Análisis epidemiológico, Seguimiento y Datos y definiciones, en ese orden', () => { + it('CaMa: Resumen, Histórico, Análisis, Análisis de Riesgos y Datos y definiciones, en ese orden', () => { abrir('cama', [item('cama_eu38a', 'C3r')]); - expect(tabs()).toEqual(['Resumen', 'Histórico', 'Análisis', 'Seguimiento', 'Datos y definiciones']); + expect(tabs()).toEqual(['Resumen', 'Histórico', 'Análisis', 'Análisis de Riesgos', 'Datos y definiciones']); expect(root().querySelector('#panel-historico')).not.toBeNull(); + root().querySelector('#tab-analisis')!.click(); + fixture.detectChanges(); + const panel = root().querySelector('#panel-analisis')!; + expect(panel.hidden).toBe(false); + expect(panel.textContent?.trim()).toBe('En desarrollo'); + http.expectNone(request => request.url.startsWith('/cama/analisis')); }); it('cacu no tiene la pestaña Histórico', () => { // Fails if the history tab of TEA or CaMa leaks into CaCu. diff --git a/src/app/features/indicadores/indicadores-historico.ts b/src/app/features/indicadores/indicadores-historico.ts index a84dbc7..ad494d2 100644 --- a/src/app/features/indicadores/indicadores-historico.ts +++ b/src/app/features/indicadores/indicadores-historico.ts @@ -26,7 +26,7 @@ const PERSONALIZADO = -1; // CaMa's history, in the order of the mockup. The titles are the mockup's; an indicator the catalog does not // publish is drawn as a pending panel instead of being left out, so what is missing stays visible. export const HISTORICO_CAMA: readonly { id: string; titulo: string }[] = [ - { id: 'cama_histopatologia_birads', titulo: 'Resultado histopatológico por categoría BI-RADS' }, + { id: 'cama_histopatologia_birads', titulo: 'Resultado histopatológico' }, { id: 'cama_birads_456_paciente', titulo: 'Pacientes evaluadas con BI-RADS 4, 5 y 6' }, { id: 'cama_birads_456_mastografia', titulo: 'Porcentaje individual de mastografías con resultado en la clasificación de BI-RADS 4, 5 y 6' }, { id: 'cama_confirmacion_birads45', titulo: 'Tasa de confirmación histopatológica' }, diff --git a/src/app/features/indicadores/indicadores-page.ts b/src/app/features/indicadores/indicadores-page.ts index f8826bd..8cb772a 100644 --- a/src/app/features/indicadores/indicadores-page.ts +++ b/src/app/features/indicadores/indicadores-page.ts @@ -43,7 +43,7 @@ const SECTIONS: readonly { id: DashboardSection; label: string }[] = [ // between its history and its follow-up list. const SECTIONS_WITH_HISTORY: readonly { id: DashboardSection; label: string }[] = [SECTIONS[0], { id: 'historico', label: 'Histórico' }, SECTIONS[1], SECTIONS[2]]; const SECTIONS_WITH_ANALYSIS: readonly { id: DashboardSection; label: string }[] = [ - SECTIONS_WITH_HISTORY[0], SECTIONS_WITH_HISTORY[1], { id: 'analisis', label: 'Análisis' }, SECTIONS_WITH_HISTORY[2], SECTIONS_WITH_HISTORY[3]]; + SECTIONS_WITH_HISTORY[0], SECTIONS_WITH_HISTORY[1], { id: 'analisis', label: 'Análisis' }, { id: 'seguimiento', label: 'Análisis de Riesgos' }, SECTIONS_WITH_HISTORY[3]]; @Component({ selector: 'app-indicadores-page', diff --git a/src/app/features/indicadores/indicadores-sections.spec.ts b/src/app/features/indicadores/indicadores-sections.spec.ts index 19d0fd0..1f3c97f 100644 --- a/src/app/features/indicadores/indicadores-sections.spec.ts +++ b/src/app/features/indicadores/indicadores-sections.spec.ts @@ -38,7 +38,7 @@ describe('Secciones compartidas por dominio', () => { const root = harness.routeNativeElement!; const tabs = Array.from(root.querySelectorAll('[role="tab"]')); // TEA and CaMa also have Histórico; CaMa adds Análisis epidemiológico before Seguimiento; CaCu keeps its three. - const esperadas = domain === 'cama' ? ['Resumen', 'Histórico', 'Análisis', 'Seguimiento', 'Datos y definiciones'] + const esperadas = domain === 'cama' ? ['Resumen', 'Histórico', 'Análisis', 'Análisis de Riesgos', 'Datos y definiciones'] : domain === 'tea' ? ['Resumen', 'Histórico', 'Seguimiento', 'Datos y definiciones'] : ['Resumen', 'Seguimiento', 'Datos y definiciones']; expect(tabs.map(t => t.textContent?.trim())).toEqual(esperadas); expect(tabs.map(t => t.getAttribute('aria-selected'))).toEqual(esperadas.map((_, i) => String(i === 0)));