diff --git a/src/app/features/indicadores/indicador-histopatologia-cama.html b/src/app/features/indicadores/indicador-histopatologia-cama.html index 0b7b077..e4024ab 100644 --- a/src/app/features/indicadores/indicador-histopatologia-cama.html +++ b/src/app/features/indicadores/indicador-histopatologia-cama.html @@ -33,19 +33,6 @@

{{ 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 { -
- -
- @for (g of m.grupos; track g.id; let i = $index) { - - } -
-
- @for (c of m.categorias; track c.id; let i = $index) { - - } -
-

Por categoría BI-RADS, {{ m.periodo }}

@if (ratesFigure) { @@ -61,6 +48,19 @@ } @else {

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

}
+
+ +
+ @for (g of m.grupos; track g.id; let i = $index) { + + } +
+
+ @for (c of m.categorias; track c.id; let i = $index) { + + } +
+
} @for (note of m.notas; track $index) {

{{ note }}

}
Valores publicados diff --git a/src/app/features/indicadores/indicadores-cama-fhir.ts b/src/app/features/indicadores/indicadores-cama-fhir.ts index 1d8277d..812c3fe 100644 --- a/src/app/features/indicadores/indicadores-cama-fhir.ts +++ b/src/app/features/indicadores/indicadores-cama-fhir.ts @@ -44,4 +44,4 @@ export const CATEGORIA_HISTOPATOLOGIA_PAGINA: Readonly> = { NO_MALIGNO: 'No metástasis', MALIGNO: 'Metástasis', SIN_DATO: 'Sin dato' }; +export const GRUPOS_HISTOPATOLOGIA_PAGINA: Readonly> = { NO_MALIGNO: 'No maligno', MALIGNO: 'Maligno', SIN_DATO: 'Sin dato' }; diff --git a/src/app/features/indicadores/indicadores-conteos-pareados.spec.ts b/src/app/features/indicadores/indicadores-conteos-pareados.spec.ts index bd02a1d..a7da565 100644 --- a/src/app/features/indicadores/indicadores-conteos-pareados.spec.ts +++ b/src/app/features/indicadores/indicadores-conteos-pareados.spec.ts @@ -95,35 +95,17 @@ 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 4 without subcategory goes back outside the ring with a guide line instead of inside its slice on two - // lines like BI-RADS 5, loses its percentage, or if the short labels or the centre total change. - it('2025-S2: la etiqueta del 4 sin subcategoría va dentro de su segmento, en dos líneas; las cortas y el total se conservan', () => { - const f = dona(), t = f.data[0]; - 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['textposition']).toBe('inside'); - expect(t['values']).toEqual([15, 0, 0, 0, 18, 0]); - expect(f.layout.annotations).toHaveLength(1); - expect(f.layout.annotations[0]['text']).toBe('33
mastografías'); - }); - - // Fails if an inside label still reserves side margins, as a callout would. - it('sin llamada exterior no se reservan márgenes laterales', () => { - const f = dona(); - expect(f.layout.margin['r']).toBeLessThan(20); - 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]); + 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'); + } }); }); diff --git a/src/app/features/indicadores/indicadores-conteos-pareados.ts b/src/app/features/indicadores/indicadores-conteos-pareados.ts index 94a7ef0..0c697e9 100644 --- a/src/app/features/indicadores/indicadores-conteos-pareados.ts +++ b/src/app/features/indicadores/indicadores-conteos-pareados.ts @@ -47,7 +47,6 @@ 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. -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; } @@ -109,51 +108,24 @@ export function modelosConteos(par: ParConteos, examenes: IndicadorDatos, pacien } export const totalExamenes = (m: ModeloConteos) => sumar(m.examenes.map(c => c.n)); -// 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; +const ALTO_DONA = 400, MARGEN_VERTICAL = 30, MARGEN_ROTULO = 120; -/** - * 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!); - // «BI-RADS 4 (sin subcategoría)» is long but is drawn inside its slice on two lines, like the short labels. - const sinSubcategoria = (i: number) => m.examenes[i].etiqueta.endsWith(' (sin subcategoría)'); - const larga = (i: number) => m.examenes[i].etiqueta.length > LARGO_ETIQUETA_INTERIOR && n[i] > 0 && !sinSubcategoria(i); 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((_, i) => dibujadas(i) ? (sinSubcategoria(i) ? escapar(m.examenes[i].etiqueta).replace(' (', '
(') : escapar(m.examenes[i].etiqueta)) + '
' + porcentaje(i) : ''), + 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)]), hovertemplate: `%{label}
%{customdata[0]} ${par.unidades.examenes}, %{customdata[1]} %` }], - 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') }, + 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}` }, ...llamadas.map(({ lado: _lado, ...a }) => a)] }, config: { displayModeBar: false } }; + text: `${miles(total)}
${par.unidades.examenes}` }] }, 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 68336c0..c767e64 100644 --- a/src/app/features/indicadores/indicadores-histopatologia-cama.spec.ts +++ b/src/app/features/indicadores/indicadores-histopatologia-cama.spec.ts @@ -138,14 +138,14 @@ describe('Histopatología por BI-RADS: tasas, selección y figuras', () => { expect(tasas(m, sel).map(t => [t.k, t.fila.den])).toEqual([[2, 4], [3, 5], [2, 4], [2, 4], [2, 4], [2, 4]]); const [bajo, alto] = wilson(3, 5); expect(tasas(m, sel)[1]).toMatchObject({ valor: 60, bajo, alto }); - expect(lectura(m, sel)).toBe('Pacientes con resultado metástasis entre las que tienen resultado de biopsia'); + expect(lectura(m, sel)).toBe('Pacientes con resultado maligno entre las que tienen resultado de biopsia'); }); it('grupo, categoría, segundo clic al grupo y centro a la base', () => { const m = base(), sel = seleccionBase(m); const noMaligno = clicHistopatologia(m, sel, 'grupos', 0); expect(noMaligno).toEqual({ grupo: 'NO_MALIGNO' }); expect(tasas(m, noMaligno).map(t => t.k)).toEqual([2, 2, 2, 2, 2, 2]); - expect(lectura(m, noMaligno)).toBe('Pacientes con resultado no metástasis entre las que tienen resultado de biopsia'); + expect(lectura(m, noMaligno)).toBe('Pacientes con resultado no maligno entre las que tienen resultado de biopsia'); const b3 = clicHistopatologia(m, noMaligno, 'categorias', 1); expect(b3).toEqual({ grupo: 'NO_MALIGNO', categoria: 'RIESGO_B3' }); expect(tasas(m, b3).map(t => t.k)).toEqual([0, 1, 1, 1, 1, 1]); diff --git a/src/app/features/indicadores/indicadores-histopatologia-cama.ts b/src/app/features/indicadores/indicadores-histopatologia-cama.ts index af02b4d..e79a3b9 100644 --- a/src/app/features/indicadores/indicadores-histopatologia-cama.ts +++ b/src/app/features/indicadores/indicadores-histopatologia-cama.ts @@ -113,7 +113,7 @@ export function modeloHistopatologia(datos: IndicadorDatos, periodo: string): Mo }); const grupos: GrupoCategorias[] = [...new Set(categorias.map(c => c.grupo))].map(id => { const propias = categorias.filter(c => c.grupo === id); - return { id, etiqueta: etiquetaGrupo(nombres[id])!, color: promedio(propias.map(c => c.color)), categorias: propias.map(c => c.id) }; + return { id, etiqueta: id === 'MALIGNO' ? 'Maligno' : id === 'NO_MALIGNO' ? 'No maligno' : etiquetaGrupo(nombres[id])!, color: promedio(propias.map(c => c.color)), categorias: propias.map(c => c.id) }; }); if (grupos.length !== 2) return fail('Se esperaban dos grupos de resultados.'); const base = categorias.find(c => c.id === CATEGORIA_BASE)!.grupo; @@ -181,8 +181,8 @@ export function clicHistopatologia(m: ModeloHistopatologia, sel: SeleccionHistop } /** The axis title says what the rate reads. */ export function lectura(m: ModeloHistopatologia, sel: SeleccionHistopatologia): string { - if (!sel.categoria && sel.grupo === m.base) return 'Pacientes con resultado metástasis entre las que tienen resultado de biopsia'; - if (!sel.categoria) return 'Pacientes con resultado no metástasis entre las que tienen resultado de biopsia'; + if (!sel.categoria && sel.grupo === m.base) return 'Pacientes con resultado maligno entre las que tienen resultado de biopsia'; + if (!sel.categoria) return 'Pacientes con resultado no maligno entre las que tienen resultado de biopsia'; return 'Proporción con resultado ' + enFrase(seleccionEtiqueta(m, sel)); } /** Per BI-RADS stratum: the selected categories over the patients with a biopsy result. No biopsy and no data never enter. */ diff --git a/src/app/features/indicadores/indicadores-historico-pestana.spec.ts b/src/app/features/indicadores/indicadores-historico-pestana.spec.ts index bc75e1d..ae6fd5d 100644 --- a/src/app/features/indicadores/indicadores-historico-pestana.spec.ts +++ b/src/app/features/indicadores/indicadores-historico-pestana.spec.ts @@ -30,7 +30,7 @@ describe('Pestaña Histórico', () => { it('CaMa: Resumen, Histórico, Análisis epidemiológico, Seguimiento y Datos y definiciones, en ese orden', () => { abrir('cama', [item('cama_eu38a', 'C3r')]); - expect(tabs()).toEqual(['Resumen', 'Histórico', 'Análisis epidemiológico', 'Seguimiento', 'Datos y definiciones']); + expect(tabs()).toEqual(['Resumen', 'Histórico', 'Análisis', 'Seguimiento', 'Datos y definiciones']); expect(root().querySelector('#panel-historico')).not.toBeNull(); }); it('cacu no tiene la pestaña Histórico', () => { diff --git a/src/app/features/indicadores/indicadores-page.html b/src/app/features/indicadores/indicadores-page.html index a889eea..7eda76a 100644 --- a/src/app/features/indicadores/indicadores-page.html +++ b/src/app/features/indicadores/indicadores-page.html @@ -135,7 +135,7 @@ @if (conAnalisis) {
- +

En desarrollo

} diff --git a/src/app/features/indicadores/indicadores-page.ts b/src/app/features/indicadores/indicadores-page.ts index c3347c6..f8826bd 100644 --- a/src/app/features/indicadores/indicadores-page.ts +++ b/src/app/features/indicadores/indicadores-page.ts @@ -43,11 +43,11 @@ 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 epidemiológico' }, SECTIONS_WITH_HISTORY[2], SECTIONS_WITH_HISTORY[3]]; + SECTIONS_WITH_HISTORY[0], SECTIONS_WITH_HISTORY[1], { id: 'analisis', label: 'Análisis' }, SECTIONS_WITH_HISTORY[2], SECTIONS_WITH_HISTORY[3]]; @Component({ selector: 'app-indicadores-page', - imports: [FormsModule, MatButtonModule, MatCardModule, MatFormFieldModule, MatInputModule, MatIconModule, MatSelectModule, MatProgressBarModule, IndicadorCatalogCard, IndicadorKpiPanel, IndicadorKpiCard, IndicadorHistopatologiaPendiente, IndicadorPeriodFilters, IndicadoresDefinitions, IndicadoresTracking, IndicadoresHistorico, IndicadoresAnalisis, TeaResumenPeriodo], + imports: [FormsModule, MatButtonModule, MatCardModule, MatFormFieldModule, MatInputModule, MatIconModule, MatSelectModule, MatProgressBarModule, IndicadorCatalogCard, IndicadorKpiPanel, IndicadorKpiCard, IndicadorHistopatologiaPendiente, IndicadorPeriodFilters, IndicadoresDefinitions, IndicadoresTracking, IndicadoresHistorico, TeaResumenPeriodo], templateUrl: './indicadores-page.html', styleUrl: './indicadores-page.scss', }) diff --git a/src/app/features/indicadores/indicadores-sections.spec.ts b/src/app/features/indicadores/indicadores-sections.spec.ts index 06532bb..19d0fd0 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 epidemiológico', 'Seguimiento', 'Datos y definiciones'] + const esperadas = domain === 'cama' ? ['Resumen', 'Histórico', 'Análisis', 'Seguimiento', '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)));