diff --git a/src/app/features/indicadores/export/tracking-export-bar.spec.ts b/src/app/features/indicadores/export/tracking-export-bar.spec.ts index feaee74..adf8632 100644 --- a/src/app/features/indicadores/export/tracking-export-bar.spec.ts +++ b/src/app/features/indicadores/export/tracking-export-bar.spec.ts @@ -39,6 +39,13 @@ describe('Exportación: botones', () => { const boton = (root: HTMLElement, texto: string) => [...root.querySelectorAll('button')].find(b => b.textContent!.includes(texto)) as HTMLButtonElement | undefined; const esperar = async () => { for (let i = 0; i < 20; i++) { await fixture.whenStable(); await new Promise(r => setTimeout(r, 10)); fixture.detectChanges(); } }; + // Fails if the buttons stop being a bare group (the title row of the table holds them) or bring back their own block. + it('has no block of its own: only the buttons, and messages after them', () => { + const root = montar(); + expect(root.querySelector('h3, section')).toBeNull(); + expect(root.firstElementChild!.classList.contains('actions')).toBe(true); + }); + // Fails if the button stops being available for a query that fits the limit. it('enables the spreadsheet export for a query within the limit', () => { expect(boton(montar(), 'Excel')!.disabled).toBe(false); diff --git a/src/app/features/indicadores/export/tracking-export-bar.ts b/src/app/features/indicadores/export/tracking-export-bar.ts index 990a531..d5be694 100644 --- a/src/app/features/indicadores/export/tracking-export-bar.ts +++ b/src/app/features/indicadores/export/tracking-export-bar.ts @@ -19,30 +19,29 @@ const FORMAT_LABEL: Record = { xlsx: 'Excel (.xlsx)', pdf: selector: 'app-seguimiento-exportar', imports: [DecimalPipe], template: ` -
-

Exportar resultados

-

Se exportan los {{ total() | number }} registros de la consulta mostrada, no solo la página visible.

-
- @for (formato of formatos; track formato) { - - } - @if (estado() === 'working') { } -
+
@for (formato of formatos; track formato) { - @if (total() > limits[formato]) { -

{{ label[formato] }} admite hasta {{ limits[formato] | number }} registros; la consulta tiene {{ total() | number }}. Acota los filtros para exportar.

- } + } - @if (estado() === 'working') {

{{ progressText() }}

} - @if (estado() === 'error') {

{{ mensaje() }}

} - @if (listo()) {

{{ listo() }}

} -
+ @if (estado() === 'working') { } + + @for (formato of formatos; track formato) { + @if (total() > limits[formato]) { +

{{ label[formato] }} admite hasta {{ limits[formato] | number }} registros; la consulta tiene {{ total() | number }}. Acota los filtros para exportar.

+ } + } + @if (estado() === 'working') {

{{ progressText() }}

} + @if (estado() === 'error') { } + @if (listo()) {

{{ listo() }}

} `, + // The host takes no box of its own: the buttons sit in the title row that holds it, and each message + // takes a full line below that row. styles: ` - :host { display: block; margin-top: 1.5rem; } - h3 { margin: 0 0 .5rem; font-size: 1rem; } - .hint { color: var(--issste-text-secondary); margin: .25rem 0; } - .actions { display: flex; flex-wrap: wrap; gap: 1rem; margin: .5rem 0; } + :host { display: contents; } + .message { flex: 0 0 100%; margin: 0; } + .hint { color: var(--issste-text-secondary); } + .actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .75rem; margin-inline-start: auto; } button { color: inherit; background: var(--issste-surface); border: 1px solid var(--issste-border); border-radius: 4px; padding: .6rem 1rem; min-height: 44px; box-sizing: border-box; font: inherit; cursor: pointer; } button:disabled { opacity: .5; cursor: default; } diff --git a/src/app/features/indicadores/indicador-conteos-pareados.ts b/src/app/features/indicadores/indicador-conteos-pareados.ts index 3ae0ebf..b91c0c9 100644 --- a/src/app/features/indicadores/indicador-conteos-pareados.ts +++ b/src/app/features/indicadores/indicador-conteos-pareados.ts @@ -38,6 +38,10 @@ 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; } @@ -107,9 +111,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.donutFigure = donaConteos(m, this.par, this.tema, this.estrecha?.matches ?? false); this.barsFigure = barrasConteos(m, this.par, this.tema); this.changeDetector.markForCheck(); } - ngOnDestroy() { this.subscription?.unsubscribe(); } + ngOnDestroy() { this.subscription?.unsubscribe(); this.estrecha?.removeEventListener('change', this.alCambiarAncho); } } diff --git a/src/app/features/indicadores/indicadores-conteos-pareados.spec.ts b/src/app/features/indicadores/indicadores-conteos-pareados.spec.ts index 714f5f2..72236e3 100644 --- a/src/app/features/indicadores/indicadores-conteos-pareados.spec.ts +++ b/src/app/features/indicadores/indicadores-conteos-pareados.spec.ts @@ -91,6 +91,49 @@ 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; + + // Fails if the long label of the 4 without subcategory goes back inside the ring (where it is cut), loses its + // percentage or its guide line, or if the short labels or the centre total change. + it('2025-S2: la etiqueta larga sale del anillo, horizontal y con línea guía; las cortas y el total se conservan', () => { + const f = dona(), t = f.data[0], llamada = f.layout.annotations[1]; + expect(t['text'][0]).toBe(''); + 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.annotations[0]['text']).toBe('33
mastografías'); + expect(f.layout.annotations).toHaveLength(2); + expect(llamada['text']).toBe('BI-RADS 4
(sin subcategoría)
45.5 %'); + // A guide line: an arrow without head from the label to a point inside the slice, and no text rotation. + expect(llamada['showarrow']).toBe(true); + expect(llamada['arrowhead']).toBe(0); + expect(llamada['textangle']).toBeUndefined(); + }); + + // Fails if the label can reach the neighbouring chart: its side must keep a margin, and it sits on the side of its slice. + it('reserva espacio del lado de la etiqueta y la coloca del lado de su segmento', () => { + const f = dona(), llamada = f.layout.annotations[1]; + // The slice is 45 % of a clockwise ring: its middle points right, so label and margin are on the right. + expect(llamada['xanchor']).toBe('left'); + expect(llamada['ax']).toBeGreaterThan(0); + expect(f.layout.margin['r']).toBeGreaterThanOrEqual(110); + expect(f.layout.margin['l']).toBeLessThan(20); + expect(f.layout.showlegend).toBe(false); + }); + + // Fails if a narrow screen keeps a label that needs side room instead of moving to a legend under the donut. + it('en pantalla estrecha no hay llamada: la dona usa una leyenda debajo', () => { + const f = dona(true); + expect(f.layout.annotations).toHaveLength(1); + expect(f.layout.showlegend).toBe(true); + expect((f.layout as Record)['legend']['orientation']).toBe('h'); + expect(f.layout.margin['r']).toBeLessThan(20); + expect(f.data[0]['values']).toEqual([15, 0, 0, 0, 18, 0]); + }); +}); + describe('Conteos pareados de CaMa: lo que no se calcula', () => { it('no hay razón de mastografías por paciente en la figura ni en el modelo', () => { // Fails if a "≈ x por paciente" annotation comes back: exams of a category include those of patients whose diff --git a/src/app/features/indicadores/indicadores-conteos-pareados.ts b/src/app/features/indicadores/indicadores-conteos-pareados.ts index c531203..ce01023 100644 --- a/src/app/features/indicadores/indicadores-conteos-pareados.ts +++ b/src/app/features/indicadores/indicadores-conteos-pareados.ts @@ -44,6 +44,8 @@ export const esSocioConteos = (dominio: Dominio, id: string, ids: readonly strin const ETIQUETA_RESPALDO: Readonly> = { B4: 'BI-RADS 4 (sin subcategoría)' }; const COLOR_RESPALDO: Readonly> = { B4: '#E9C08C' }; const COLOR_NEUTRO = '#8A9199'; +// Labels longer than «BI-RADS 4A» do not fit inside the ring. +const LARGO_ETIQUETA_INTERIOR = 12; 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; } @@ -102,19 +104,49 @@ export function modelosConteos(par: ParConteos, examenes: IndicadorDatos, pacien } export const totalExamenes = (m: ModeloConteos) => sumar(m.examenes.map(c => c.n)); -/** Exams by category around their total; nothing is drawn when a cell is unknown. */ -export function donaConteos(m: ModeloConteos, par: ParConteos, tema: Tema): PlotlyFigure { +// Geometry the callouts rely on. The ring is height-bound (a 400 px figure with a 10 px margin above and below and +// the pie over 90 % of that height), so its radius does not depend on the width of the card. +const ALTO_DONA = 400, MARGEN_VERTICAL = 10, RADIO_DONA = Math.round((ALTO_DONA - 2 * MARGEN_VERTICAL) * .9 / 2); +const MARGEN_ROTULO = 120, SALIDA_ROTULO = 28; + +/** + * Exams by category around their total; nothing is drawn when a cell is unknown. A long label does not fit in the + * ring: it is drawn outside, horizontal and on two lines, joined to its slice by a guide line, on the side of the + * slice with room reserved for it so it never reaches the neighbouring chart. On a narrow card (`compacta`) the + * callouts give way to a legend under the donut. + */ +export function donaConteos(m: ModeloConteos, par: ParConteos, tema: Tema, compacta = false): PlotlyFigure { const total = totalExamenes(m); if (!total) return { data: [], layout: {} }; const p = c2Theme(tema), n = m.examenes.map(c => c.n!); + const larga = (i: number) => m.examenes[i].etiqueta.length > LARGO_ETIQUETA_INTERIOR && n[i] > 0; + const porcentaje = (i: number) => percentNumber(100 * n[i] / total) + ' %'; + const dibujadas = (i: number) => !larga(i) && n[i] / total >= .05; + // Each long label is a callout whose guide line ends inside its slice. + let antes = 0; + const llamadas = n.flatMap((v, i) => { + const angulo = 2 * Math.PI * (antes + v / 2) / total; + antes += v; + if (compacta || !larga(i)) return []; + const seno = Math.sin(angulo), coseno = Math.cos(angulo), dentro = Math.round(RADIO_DONA * .8), fuera = RADIO_DONA + SALIDA_ROTULO - dentro; + const etiqueta = escapar(m.examenes[i].etiqueta), corte = etiqueta.indexOf(' ('); + return [{ x: .5, y: .5, xref: 'paper', yref: 'paper', xshift: Math.round(dentro * seno), yshift: Math.round(dentro * coseno), + ax: Math.round(fuera * seno), ay: Math.round(-fuera * coseno), axref: 'pixel', ayref: 'pixel', showarrow: true, arrowhead: 0, arrowwidth: 1, arrowcolor: p.text, + text: (corte > 0 ? etiqueta.slice(0, corte) + '
' + etiqueta.slice(corte + 1) : etiqueta) + '
' + porcentaje(i), + align: seno >= 0 ? 'left' : 'right', xanchor: seno >= 0 ? 'left' : 'right', yanchor: 'middle', font: { size: 12, color: p.text }, lado: seno >= 0 ? 'r' : 'l' }]; + }); + const lado = (l: string) => llamadas.some(a => a.lado === l) ? MARGEN_ROTULO : 10; 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: 'inside', - text: n.map((v, i) => v / total < .05 ? '' : escapar(m.examenes[i].etiqueta) + '
' + percentNumber(100 * v / total) + ' %'), + text: n.map((_, i) => dibujadas(i) ? escapar(m.examenes[i].etiqueta) + '
' + porcentaje(i) : ''), + domain: { x: [0, 1], y: [.05, .95] }, customdata: n.map(v => [miles(v), percentNumber(100 * v / total)]), hovertemplate: `%{label}
%{customdata[0]} ${par.unidades.examenes}, %{customdata[1]} %` }], - layout: { autosize: true, height: 400, showlegend: false, margin: { t: 10, l: 10, r: 10, b: 10 }, paper_bgcolor: p.background, font: { color: p.text }, + layout: { autosize: true, height: compacta ? ALTO_DONA + 40 : ALTO_DONA, showlegend: compacta, paper_bgcolor: p.background, font: { color: p.text }, + margin: { t: MARGEN_VERTICAL, b: compacta ? 70 : MARGEN_VERTICAL, l: lado('l'), r: lado('r') }, + ...(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 } }; + text: `${miles(total)}
${par.unidades.examenes}` }, ...llamadas.map(({ lado: _lado, ...a }) => a)] }, 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-page.html b/src/app/features/indicadores/indicadores-page.html index 0c09d9e..356d594 100644 --- a/src/app/features/indicadores/indicadores-page.html +++ b/src/app/features/indicadores/indicadores-page.html @@ -5,7 +5,7 @@

Consulta individual de seguimiento de {{ dominio === 'cama' ? domainLabels.cama : 'cáncer cervicouterino' }}

} @else { @if (dominio !== 'cama') { {{ domainTitles[dominio] }}, investigación } -

{{ dominio === 'cama' ? 'Cáncer de mama' : 'Indicadores' }}

+

{{ dominio === 'cama' ? 'Sistema TNM de clasificación tumoral' : 'Indicadores' }}

Explora los indicadores de {{ domainLabels[dominio] }}.

} diff --git a/src/app/features/indicadores/indicadores-seguimiento-ficha.spec.ts b/src/app/features/indicadores/indicadores-seguimiento-ficha.spec.ts index 34119a4..f6ab443 100644 --- a/src/app/features/indicadores/indicadores-seguimiento-ficha.spec.ts +++ b/src/app/features/indicadores/indicadores-seguimiento-ficha.spec.ts @@ -33,6 +33,15 @@ describe('Seguimiento de CaMa: ficha del paciente', () => { const enlace = (n = 0) => root().querySelectorAll('.patient-link')[n]; const ficha = () => root().querySelector('app-cama-patient-card'); + // Fails if the export buttons leave the title row or come back under the table. + it('has the export buttons in the row of the section title, and nothing after the pagination', () => { + const row = root().querySelector('.title-row')!; + expect(row.querySelector('h2')!.textContent).toContain('Seguimiento de'); + expect([...row.querySelectorAll('button')].map(b => b.textContent!.trim())).toEqual(['Exportar Excel (.xlsx)', 'Exportar PDF']); + expect(root().querySelector('nav')!.nextElementSibling).toBeNull(); + expect(root().textContent).not.toContain('Exportar resultados'); + }); + // Fails if the identifier stops being a control, which leaves the record reachable only by mouse. it('draws each identifier as a button named after the patient', () => { expect(root().querySelectorAll('.patient-link')).toHaveLength(5); @@ -104,7 +113,7 @@ describe('Seguimiento: ficha de CaMa y cambio de dominio', () => { (fixture.nativeElement as HTMLElement).querySelector('.patient-link')!.click(); await fixture.whenStable(); fixture.detectChanges(); expect(abierta).toEqual([true]); - expect((fixture.nativeElement as HTMLElement).querySelector('h2')!.hidden).toBe(true); + expect((fixture.nativeElement as HTMLElement).querySelector('.title-row')!.closest('[hidden]')).not.toBeNull(); fixture.componentRef.setInput('dominio', 'tea'); fixture.detectChanges(); expect(abierta).toEqual([true, false]); http.verify(); fixture.destroy(); diff --git a/src/app/features/indicadores/indicadores-seguimiento-tabla.ts b/src/app/features/indicadores/indicadores-seguimiento-tabla.ts index c6331ce..43695ca 100644 --- a/src/app/features/indicadores/indicadores-seguimiento-tabla.ts +++ b/src/app/features/indicadores/indicadores-seguimiento-tabla.ts @@ -28,6 +28,12 @@ interface Borrador { corte?: string; meses: 1 | 3 | 6 | 12; page_size: number; f }
+
+

Seguimiento de {{ domainLabel }}

+ @if (data(); as respuesta) { + + } +