diff --git a/src/app/features/indicadores/fixtures/cama_dias_resultado_suprimido.json b/src/app/features/indicadores/fixtures/cama_dias_resultado_suprimido.json new file mode 100644 index 0000000..2c30a24 --- /dev/null +++ b/src/app/features/indicadores/fixtures/cama_dias_resultado_suprimido.json @@ -0,0 +1,63 @@ +{ + "id": "cama_dias_resultado_diagnostico", + "titulo": "Tiempo de resultado a diagnóstico (demostración sintética)", + "version": "0.1.0", + "contrato": "C3r", + "unidad": "examen", + "tipo_periodo": "semestre", + "periodos": [ + "2025-S1" + ], + "estrato": null, + "valores_estrato": [], + "etiquetas_estrato": {}, + "grupos": { + "TOTAL": "Días de resultado a diagnóstico" + }, + "categorias": {}, + "grupos_de_categoria": {}, + "notas": [ + "Datos sintéticos fijos; sin nota hasta el corte no hay observación. Convención provisional." + ], + "reportes": [ + { + "periodo": "2025-S1", + "report_id": 71, + "periodo_inicio": "2025-01-01", + "periodo_fin": "2025-07-01", + "fecha_corte": "2026-11-12", + "generado_en": "2026-11-12T17:00:26.219496+00:00", + "kit_version": "0.8.0", + "toml_sha": "9349fdd093c85bfe9adc86b91ea5350a03be829825645b51ab87a35fccc5d42d", + "parametros_sha": "5e4badce17afe0141e8296c9edd88ff1ce50a21c8c278d1aad5327069830d251", + "parametros": { + "sql": { + "_catalogo": [], + "_grupos": [ + "TOTAL" + ], + "fecha_corte": "2026-11-12", + "periodo_fin": "2025-07-01", + "periodo_inicio": "2025-01-01" + }, + "umbral_supresion": 5 + } + } + ], + "filas": [ + { + "periodo": "2025-S1", + "grupo": "TOTAL", + "estrato": null, + "n": null, + "mediana": null, + "q1": null, + "q3": null, + "n_sin_evento": 0, + "n_excluido": 0, + "suprimido": 1, + "unidad": "dias" + } + ], + "totales_estrato": [] +} \ No newline at end of file diff --git a/src/app/features/indicadores/fixtures/cama_dias_resultado_visible.json b/src/app/features/indicadores/fixtures/cama_dias_resultado_visible.json new file mode 100644 index 0000000..0f2eb14 --- /dev/null +++ b/src/app/features/indicadores/fixtures/cama_dias_resultado_visible.json @@ -0,0 +1,63 @@ +{ + "id": "cama_dias_resultado_diagnostico", + "titulo": "Tiempo de resultado a diagnóstico (demostración sintética)", + "version": "0.1.0", + "contrato": "C3r", + "unidad": "examen", + "tipo_periodo": "semestre", + "periodos": [ + "2025-S1" + ], + "estrato": null, + "valores_estrato": [], + "etiquetas_estrato": {}, + "grupos": { + "TOTAL": "Días de resultado a diagnóstico" + }, + "categorias": {}, + "grupos_de_categoria": {}, + "notas": [ + "Datos sintéticos fijos; sin nota hasta el corte no hay observación. Convención provisional." + ], + "reportes": [ + { + "periodo": "2025-S1", + "report_id": 71, + "periodo_inicio": "2025-01-01", + "periodo_fin": "2025-07-01", + "fecha_corte": "2026-11-12", + "generado_en": "2026-11-12T17:00:38.264922+00:00", + "kit_version": "0.8.0", + "toml_sha": "38b2efac7d70f9c0bf37b03b7abd21d48bff4c6d8f6786fccbccfa31a7fcd7e7", + "parametros_sha": "f26ecdc2fcef0aa015f8997b7c1aa2053678cb86ca9cff9b1524efaf000971ad", + "parametros": { + "sql": { + "_catalogo": [], + "_grupos": [ + "TOTAL" + ], + "fecha_corte": "2026-11-12", + "periodo_fin": "2025-07-01", + "periodo_inicio": "2025-01-01" + }, + "umbral_supresion": 1 + } + } + ], + "filas": [ + { + "periodo": "2025-S1", + "grupo": "TOTAL", + "estrato": null, + "n": 4, + "mediana": 6.5, + "q1": 2.25, + "q3": 12.5, + "n_sin_evento": 0, + "n_excluido": 1, + "suprimido": 0, + "unidad": "dias" + } + ], + "totales_estrato": [] +} \ No newline at end of file diff --git a/src/app/features/indicadores/fixtures/cama_tasa_deteccion_suprimido.json b/src/app/features/indicadores/fixtures/cama_tasa_deteccion_suprimido.json new file mode 100644 index 0000000..ab86600 --- /dev/null +++ b/src/app/features/indicadores/fixtures/cama_tasa_deteccion_suprimido.json @@ -0,0 +1,59 @@ +{ + "id": "cama_tasa_deteccion_histopatologica", + "titulo": "Detección histopatológica (demostración sintética)", + "version": "0.1.0", + "contrato": "C1", + "unidad": "examen", + "tipo_periodo": "semestre", + "periodos": [ + "2025-S1" + ], + "estrato": null, + "valores_estrato": [], + "etiquetas_estrato": {}, + "grupos": { + "total": "Total" + }, + "categorias": {}, + "grupos_de_categoria": {}, + "notas": [ + "Detección histopatológica (demostración sintética)" + ], + "reportes": [ + { + "periodo": "2025-S1", + "report_id": 127, + "periodo_inicio": "2025-01-01", + "periodo_fin": "2025-07-01", + "fecha_corte": "2026-11-12", + "generado_en": "2026-11-12T17:00:31.282549+00:00", + "kit_version": "0.8.0", + "toml_sha": "9349fdd093c85bfe9adc86b91ea5350a03be829825645b51ab87a35fccc5d42d", + "parametros_sha": "d909bc4a153b244533acde1f26ce8c4cfaaedf0d277239dd9b1ce9e9f65b23a9", + "parametros": { + "sql": { + "fecha_corte": "2026-11-12", + "periodo_fin": "2025-07-01", + "periodo_inicio": "2025-01-01" + }, + "umbral_supresion": 5 + } + } + ], + "filas": [ + { + "periodo": "2025-S1", + "grupo": "total", + "estrato": null, + "numerador": null, + "denominador": null, + "valor": null, + "ic_bajo": null, + "ic_alto": null, + "suprimido": 1, + "n_sin_evento": 0, + "n_excluido": 0 + } + ], + "totales_estrato": [] +} \ No newline at end of file diff --git a/src/app/features/indicadores/fixtures/cama_tasa_deteccion_visible.json b/src/app/features/indicadores/fixtures/cama_tasa_deteccion_visible.json new file mode 100644 index 0000000..4950dac --- /dev/null +++ b/src/app/features/indicadores/fixtures/cama_tasa_deteccion_visible.json @@ -0,0 +1,59 @@ +{ + "id": "cama_tasa_deteccion_histopatologica", + "titulo": "Detección histopatológica (demostración sintética)", + "version": "0.1.0", + "contrato": "C1", + "unidad": "examen", + "tipo_periodo": "semestre", + "periodos": [ + "2025-S1" + ], + "estrato": null, + "valores_estrato": [], + "etiquetas_estrato": {}, + "grupos": { + "total": "Total" + }, + "categorias": {}, + "grupos_de_categoria": {}, + "notas": [ + "Detección histopatológica (demostración sintética)" + ], + "reportes": [ + { + "periodo": "2025-S1", + "report_id": 127, + "periodo_inicio": "2025-01-01", + "periodo_fin": "2025-07-01", + "fecha_corte": "2026-11-12", + "generado_en": "2026-11-12T17:00:42.857591+00:00", + "kit_version": "0.8.0", + "toml_sha": "38b2efac7d70f9c0bf37b03b7abd21d48bff4c6d8f6786fccbccfa31a7fcd7e7", + "parametros_sha": "7202a2779ae47c29a7659dd6fdfb77e8895d4d778a772ff13cc2ce93c5a6e871", + "parametros": { + "sql": { + "fecha_corte": "2026-11-12", + "periodo_fin": "2025-07-01", + "periodo_inicio": "2025-01-01" + }, + "umbral_supresion": 1 + } + } + ], + "filas": [ + { + "periodo": "2025-S1", + "grupo": "total", + "estrato": null, + "numerador": 0, + "denominador": 1, + "valor": 0.0, + "ic_bajo": 0.0, + "ic_alto": 79.3450688208, + "suprimido": 0, + "n_sin_evento": 1, + "n_excluido": 0 + } + ], + "totales_estrato": [] +} \ No newline at end of file diff --git a/src/app/features/indicadores/indicadores-cama-f4c.spec.ts b/src/app/features/indicadores/indicadores-cama-f4c.spec.ts new file mode 100644 index 0000000..fe9beab --- /dev/null +++ b/src/app/features/indicadores/indicadores-cama-f4c.spec.ts @@ -0,0 +1,223 @@ +// Covers the three CaMa indicators WebApi now publishes (CAM-01 tasa de detección, CAM-02 resultado a diagnóstico, +// CAM-03 histopatología por BI-RADS) as they reach the summary and the history. The payloads are what WebApi +// answered for an isolated synthetic base (fixtures/cama_*): `visible` with the suppression threshold lowered so +// the figures show, and `suprimido` with the normal threshold of 5, where the small synthetic counts are hidden. +import { Component } from '@angular/core'; +import { TestBed } from '@angular/core/testing'; +import { provideHttpClient } from '@angular/common/http'; +import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing'; +import { provideRouter } from '@angular/router'; +import { By } from '@angular/platform-browser'; +import { MatDialog } from '@angular/material/dialog'; +import { PlotlyChart } from '../../shared/plotly/plotly-chart'; +import tasaVisible from './fixtures/cama_tasa_deteccion_visible.json'; +import tasaSuprimida from './fixtures/cama_tasa_deteccion_suprimido.json'; +import diasVisible from './fixtures/cama_dias_resultado_visible.json'; +import diasSuprimido from './fixtures/cama_dias_resultado_suprimido.json'; +import generalFixture from './fixtures/cama_histopatologia_birads_general.json'; +import catalogoFixture from './fixtures/cama_catalogo_f4c.json'; +import { IndicadoresPage } from './indicadores-page'; +import { IndicadoresHistorico } from './indicadores-historico'; +import { historicoFigura } from './indicadores-historico-figures'; +import { CAMA_FUERA_DEL_RESUMEN, CAMA_RESULTADO_DIAGNOSTICO_KPI, CAMA_TASA_DETECCION_KPI, KPI_BY_DOMAIN, KpiDefinition, kpiResult } from './indicadores-kpi'; +import { GlobalApplied, IndicadoresMemory } from './indicadores-memory'; +import { Indicador, IndicadorDatos } from './indicadores.models'; + +const applied: GlobalApplied = { tipo: 'semestre', selection: { mode: 'explicit', periodos: ['2025-S1'] }, revision: 0 }; +const dato = (v: unknown) => structuredClone(v) as unknown as IndicadorDatos; +const REALES = catalogoFixture as unknown as Indicador[]; + +describe('CAM-01 y CAM-02: tarjetas con las respuestas reales de WebApi', () => { + it('CAM-01 con el umbral de prueba: un 0 de 1 es un cero válido, con su detalle', () => { + // Fails if a published 0/1 becomes "sin valor" or loses its numerator and denominator. + expect(kpiResult(dato(tasaVisible), CAMA_TASA_DETECCION_KPI, 'cama', applied)) + .toEqual({ state: 'Disponible', value: '0.0', info: '0 de 1 biopsias con resultado maligno.' }); + }); + it('CAM-01 con el umbral normal: el dato está suprimido y no muestra cifra', () => { + const r = kpiResult(dato(tasaSuprimida), CAMA_TASA_DETECCION_KPI, 'cama', applied); + expect(r.state).toBe('Dato oculto por tamaño'); expect(r.value).toBeUndefined(); + }); + it('CAM-02 con el umbral de prueba: mediana, Q1 y Q3 tal como las publica el C3r, sin recalcular', () => { + expect(kpiResult(dato(diasVisible), CAMA_RESULTADO_DIAGNOSTICO_KPI, 'cama', applied)) + .toEqual({ state: 'Disponible', value: 6.5, info: '4 mastografías; Q1 a Q3: 2.25 a 12.5 días.' }); + }); + it('CAM-02 con el umbral normal: suprimido, sin mediana ni cero', () => { + const r = kpiResult(dato(diasSuprimido), CAMA_RESULTADO_DIAGNOSTICO_KPI, 'cama', applied); + expect(r.state).toBe('Dato oculto por tamaño'); expect(r.value).toBeUndefined(); + }); + it('CAM-01 y CAM-02 sin valores (nulos, no suprimidos) no se vuelven cero', () => { + const c1 = dato(tasaVisible); Object.assign((c1.filas[0]), { valor: null, numerador: null, denominador: null }); + const c3 = dato(diasVisible); Object.assign((c3.filas[0]), { n: null, mediana: null, q1: null, q3: null }); + expect(kpiResult(c1, CAMA_TASA_DETECCION_KPI, 'cama', applied)).toMatchObject({ state: 'Sin valor disponible' }); + expect(kpiResult(c3, CAMA_RESULTADO_DIAGNOSTICO_KPI, 'cama', applied)).toMatchObject({ state: 'Sin valor disponible' }); + const sinFilas = { ...dato(tasaVisible), periodos: [], filas: [] }; + expect(kpiResult(sinFilas, CAMA_TASA_DETECCION_KPI, 'cama', applied).state).toBe('Sin filas utilizables'); + }); + it('la respuesta de una medida no pasa por la tarjeta de otra, ni de otro periodo', () => { + expect(kpiResult(dato(tasaVisible), CAMA_RESULTADO_DIAGNOSTICO_KPI, 'cama', applied).state).toBe('Error de contrato'); + expect(kpiResult(dato(diasVisible), CAMA_TASA_DETECCION_KPI, 'cama', applied).state).toBe('Error de contrato'); + expect(kpiResult(dato(tasaVisible), CAMA_TASA_DETECCION_KPI, 'cama', { ...applied, tipo: 'mes' }).state).toBe('Error de contrato'); + }); +}); + +describe('CAM-01, CAM-02 y CAM-03: histórico con las respuestas reales', () => { + it('CAM-01: la línea y su banda de confianza dibujan el cero válido y el cero no se confunde con «sin dato»', () => { + const f = historicoFigura(dato(tasaVisible), 'claro'); + expect(f.contrato).toBe('C1'); expect(f.suprimidos).toEqual([]); expect(f.sinDato).toEqual([]); + const linea = f.figure.data.find(t => t['name'] === 'Porcentaje')!; + expect(linea['y']).toEqual([0]); expect(linea['x']).toEqual(['2025 S1']); + expect(f.figure.data.find(t => t['name'] === 'Intervalo de confianza')!['y']).toEqual([79.3450688208, 0]); + }); + it('CAM-01 y CAM-02 suprimidos: el periodo se sombrea, se nombra y la línea queda sin valor', () => { + for (const d of [tasaSuprimida, diasSuprimido]) { + const f = historicoFigura(dato(d), 'claro'); + expect(f.suprimidos).toEqual(['2025 S1']); expect(f.sinDato).toEqual([]); + expect(f.figure.data.find(t => t['name'] === 'Porcentaje' || t['name'] === 'Mediana')!['y']).toEqual([null]); + expect(f.figure.layout['shapes']).toHaveLength(1); + } + }); + it('CAM-02: la mediana y la banda de cuartiles salen de lo publicado', () => { + const f = historicoFigura(dato(diasVisible), 'claro'); + expect(f.figure.data.find(t => t['name'] === 'Mediana')!['y']).toEqual([6.5]); + expect(f.figure.data.find(t => t['name'] === 'Primer a tercer cuartil')!['y']).toEqual([12.5, 2.25]); + }); + it('CAM-03: el C2 general se apila en las seis categorías del catálogo, con sus colores y en su orden', () => { + const f = historicoFigura(dato(generalFixture), 'claro'); + expect(f.contrato).toBe('C2'); expect(f.suprimidos).toEqual([]); expect(f.sinDato).toEqual([]); + expect(f.figure.data.map(t => [t['name'], (t['y'] as number[])[0]])).toEqual([ + ['Benigno', 7], ['Lesión de riesgo (B3)', 5], ['Carcinoma in situ', 6], ['Carcinoma invasor', 7], ['Sin biopsia reportada', 6], ['Sin dato', 6]]); + expect(f.figure.data.map(t => (t['marker'] as { color: string }).color)).toEqual(['#9DBFE3', '#2F6DB3', '#D9822B', '#B5482E', '#C9CDD2', '#C9CDD2']); + expect(f.figure.layout['barmode']).toBe('stack'); + expect(f.comoLeer).toContain('pacientes'); + }); + it('CAM-03: una celda suprimida o ausente en el periodo se avisa, y no se dibuja como cero', () => { + const suprimida = dato(generalFixture); Object.assign(suprimida.filas[2], { n: null, suprimido: 1 }); + expect(historicoFigura(suprimida, 'claro').suprimidos).toEqual(['2025 S1']); + const ausente = dato(generalFixture); ausente.filas.splice(3, 1); + const f = historicoFigura(ausente, 'claro'); + expect(f.sinDato).toEqual(['2025 S1']); + expect(f.figure.data.find(t => t['name'] === 'Carcinoma invasor')!['y']).toEqual([null]); + }); +}); + +@Component({ selector: 'app-plotly-chart', inputs: ['figure', 'label', 'showNotes'], template: '' }) +class ChartStub { figure?: { data: { name?: string }[] }; label?: string; } + +describe('CAM-01, CAM-02 y CAM-03 en el panel histórico', () => { + let fixture: ReturnType>, http: HttpTestingController; + function montar(visibles: boolean) { + TestBed.configureTestingModule({ imports: [IndicadoresHistorico], providers: [provideHttpClient(), provideHttpClientTesting(), { provide: MatDialog, useValue: { open: vi.fn() } }] }); + TestBed.overrideComponent(IndicadoresHistorico, { remove: { imports: [PlotlyChart] }, add: { imports: [ChartStub] } }); + fixture = TestBed.createComponent(IndicadoresHistorico); http = TestBed.inject(HttpTestingController); + fixture.componentRef.setInput('dominio', 'cama'); fixture.componentRef.setInput('catalog', REALES); + fixture.componentRef.setInput('tema', 'claro'); fixture.componentRef.setInput('active', true); + fixture.componentInstance.elegido.set('semestre'); fixture.detectChanges(); + const respuestas: Record = visibles + ? { cama_tasa_deteccion_histopatologica: tasaVisible, cama_dias_resultado_diagnostico: diasVisible, cama_histopatologia_birads: generalFixture } + : { cama_tasa_deteccion_histopatologica: tasaSuprimida, cama_dias_resultado_diagnostico: diasSuprimido, cama_histopatologia_birads: generalFixture }; + const pedidos: string[] = []; + for (let ola = http.match(() => true); ola.length; ola = http.match(() => true)) { + for (const r of ola) { + const id = r.request.url.split('/').at(-2)!; + pedidos.push(r.request.url + (r.request.params.get('periodos') ? '?periodos=' + r.request.params.get('periodos') : '')); + if (r.request.url.endsWith('/periodos')) r.flush({ id, periodos: [{ periodo: '2025-S1', tipo: 'semestre' }] }); + else r.flush(respuestas[id] as Record); + } + fixture.detectChanges(); + } + return pedidos; + } + afterEach(() => { fixture?.destroy(); http.verify(); }); + const paneles = () => [...(fixture.nativeElement as HTMLElement).querySelectorAll('article.panel')] as HTMLElement[]; + const graficas = () => fixture.debugElement.queryAll(By.directive(ChartStub)).map(d => d.componentInstance as ChartStub); + + it('los tres indicadores publicados se piden y se dibujan; los cinco restantes de la lista siguen pendientes', () => { + const pedidos = montar(true); + expect(pedidos.filter(p => p.includes('/datos'))).toEqual([ + '/cama/indicadores/cama_histopatologia_birads/datos?periodos=2025-S1', + '/cama/indicadores/cama_dias_resultado_diagnostico/datos?periodos=2025-S1', + '/cama/indicadores/cama_tasa_deteccion_histopatologica/datos?periodos=2025-S1'].sort((a, b) => pedidos.indexOf(a) - pedidos.indexOf(b))); + const titulos = paneles().map(p => [p.querySelector('h2')!.textContent, p.textContent!.includes('Integración pendiente') ? 'pendiente' : 'dibujado']); + expect(titulos.filter(([t]) => ['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'].includes(t!))) + .toEqual([['Resultado histopatológico por categoría BI-RADS', 'dibujado'], ['Días del resultado de la mastografía al diagnóstico', 'dibujado'], ['Tasa de detección histopatológica', 'dibujado']]); + expect(graficas()).toHaveLength(3); + expect(graficas().map(g => g.figure!.data.length)).toEqual([6, 2, 2]); + }); + it('con el umbral normal los dos paneles C1 y C3r avisan el periodo suprimido, y la matriz CAM-03 sigue visible', () => { + montar(false); + const texto = paneles().map(p => p.textContent!); + expect(texto.filter(t => t.includes('Datos suprimidos, sombreados en la figura: 2025 S1.'))).toHaveLength(2); + expect(graficas()).toHaveLength(3); + }); +}); + +describe('CaMa Resumen con CAM-01, CAM-02 y CAM-03 publicados', () => { + let fixture: ReturnType>, http: HttpTestingController; + beforeEach(() => { + vi.stubGlobal('IntersectionObserver', class { observe() {} unobserve() {} disconnect() {} }); + TestBed.configureTestingModule({ imports: [IndicadoresPage], providers: [provideRouter([]), provideHttpClient(), provideHttpClientTesting()] }); + TestBed.inject(IndicadoresMemory).finishInitialKpiPresentation('cama'); + fixture = TestBed.createComponent(IndicadoresPage); http = TestBed.inject(HttpTestingController); + http.expectOne('/tea/indicadores').flush([]); fixture.detectChanges(); + }); + afterEach(() => { fixture.destroy(); http.verify(); vi.unstubAllGlobals(); }); + const propios = (d: KpiDefinition): Indicador => ({ id: d.id, titulo: d.title, contrato: d.contrato, figuras: [], tipos_periodo: ['semestre', 'mes'] }) as Indicador; + const row = { periodo: '2025-S1', estrato: null, suprimido: 0 }; + function cargar(catalogo: Indicador[]) { + fixture.componentInstance.changeDominio('cama'); fixture.detectChanges(); + http.expectOne('/cama/indicadores').flush(catalogo); + for (let ola = http.match(r => r.url.endsWith('/periodos')); ola.length; ola = http.match(r => r.url.endsWith('/periodos'))) { + ola.forEach(r => r.flush({ id: r.request.url.split('/').at(-2), periodos: [{ tipo: 'semestre', periodo: '2025-S1' }] })); + } + fixture.detectChanges(); + const pedidos: string[] = []; + for (let ola = http.match(r => r.url.endsWith('/datos')); ola.length; ola = http.match(r => r.url.endsWith('/datos'))) { + ola.forEach(r => { + const id = r.request.url.split('/').at(-2)!; + pedidos.push(id); + r.flush(id === 'cama_tasa_deteccion_histopatologica' ? tasaVisible : id === 'cama_dias_resultado_diagnostico' ? diasVisible + : id === 'cama_birads_456_paciente' ? { id, contrato: 'C2', tipo_periodo: 'semestre', periodos: ['2025-S1'], categorias: { A: {} }, filas: [{ ...row, grupo: 'TOTAL', categoria: 'A', n: 5 }] } + : { id, contrato: 'C3r', tipo_periodo: 'semestre', periodos: ['2025-S1'], categorias: {}, filas: [{ ...row, grupo: 'TOTAL', unidad: 'dias', mediana: 7, n: 5, q1: 3, q3: 9 }] }); + }); + fixture.detectChanges(); + } + return pedidos; + } + const root = () => fixture.nativeElement as HTMLElement; + const kpis = () => [...root().querySelectorAll('.kpi-grid app-indicador-kpi-card')] as HTMLElement[]; + const tarjetas = () => [...root().querySelectorAll('.catalog-grid > *')] as HTMLElement[]; + const completo = () => [...KPI_BY_DOMAIN.cama.map(propios), ...REALES]; + + it('las cuatro tarjetas de oportunidad tienen datos, ninguna pendiente, con los valores publicados', () => { + cargar(completo()); + expect(kpis()).toHaveLength(4); + expect(root().querySelector('.kpi-grid')!.textContent).not.toContain('Integración pendiente'); + expect(kpis()[1].textContent).toContain('0 de 1 biopsias con resultado maligno.'); + expect(kpis()[3].textContent).toContain('6.5'); expect(kpis()[3].textContent).toContain('Q1 a Q3: 2.25 a 12.5 días.'); + }); + it('CAM-03 ocupa el lugar de la tarjeta pendiente, primero y con su vista especializada; no se consulta mientras no es visible', () => { + const pedidos = cargar(completo()); + expect(root().querySelector('app-indicador-histopatologia-pendiente')).toBeNull(); + const primera = tarjetas()[0]; + expect(primera.tagName).toBe('APP-INDICADOR-CATALOG-CARD'); + expect(primera.querySelector('app-indicador-histopatologia-cama')).not.toBeNull(); + expect(primera.querySelector('h2')!.textContent).toBe('Histopatología por BI-RADS (demostración sintética)'); + expect(pedidos).not.toContain('cama_histopatologia_birads'); + }); + it('CAM-01 y CAM-02 son solo tarjetas de oportunidad: no dibujan una figura propia en el Resumen', () => { + cargar(completo()); + const titulos = tarjetas().map(t => t.querySelector('h2')?.textContent ?? ''); + expect(titulos.some(t => t.includes('Detección histopatológica') || t.includes('resultado a diagnóstico'))).toBe(false); + expect(CAMA_FUERA_DEL_RESUMEN).toContain('cama_tasa_deteccion_histopatologica'); + expect(CAMA_FUERA_DEL_RESUMEN).toContain('cama_dias_resultado_diagnostico'); + }); + it('sin CAM-03 en el catálogo la tarjeta sigue pendiente, como antes', () => { + cargar([...KPI_BY_DOMAIN.cama.map(propios), ...REALES.filter(i => i.id !== 'cama_histopatologia_birads')]); + expect(root().querySelector('app-indicador-histopatologia-pendiente')).not.toBeNull(); + expect(root().querySelector('app-indicador-histopatologia-cama')).toBeNull(); + }); + it('solo CAM-01 y CAM-02 sin CAM-03: dos tarjetas con datos y la de histopatología pendiente', () => { + cargar([...KPI_BY_DOMAIN.cama.map(propios), ...REALES.filter(i => i.id !== 'cama_histopatologia_birads')]); + expect(kpis()).toHaveLength(4); expect(root().querySelector('app-indicador-histopatologia-pendiente')!.textContent).toContain('Integración pendiente'); + }); +}); diff --git a/src/app/features/indicadores/indicadores-historico-figures.ts b/src/app/features/indicadores/indicadores-historico-figures.ts index 84d9705..1ee9fab 100644 --- a/src/app/features/indicadores/indicadores-historico-figures.ts +++ b/src/app/features/indicadores/indicadores-historico-figures.ts @@ -119,7 +119,9 @@ function conteo(data: IndicadorDatos, tema: Tema): Trazo { celdas.set(key, row); categorias.set(id, row['orden']); } - const orden = [...categorias].sort(([, a], [, b]) => a - b).map(([id]) => id); + // A category the catalog announces but no row carries is still a category: its absence is shown as a gap and + // named under the figure, not dropped as if it did not exist, nor drawn as zero. + const orden = [...[...categorias].sort(([, a], [, b]) => a - b).map(([id]) => id), ...Object.keys(catalogo).filter(id => !categorias.has(id))]; const estadoDe = (periodo: string) => orden.map(id => celdas.get(JSON.stringify([id, periodo]))); const suprimidos = periodos.filter(p => estadoDe(p).some(row => row?.['suprimido'] === 1)); const sinDato = periodos.filter(p => !suprimidos.includes(p) && estadoDe(p).some(row => !numero(row?.['n']))); diff --git a/src/app/features/indicadores/indicadores-kpi.ts b/src/app/features/indicadores/indicadores-kpi.ts index 7e95a06..50ba801 100644 --- a/src/app/features/indicadores/indicadores-kpi.ts +++ b/src/app/features/indicadores/indicadores-kpi.ts @@ -69,7 +69,9 @@ export function camaKpiCards(published: (id: string) => boolean): KpiCardSlot[] // Published CaMa indicators whose card the summary does not draw. // The summary draws the paired card and the histopathology card; the rest of CaMa's indicators are in Histórico // and in Datos y definiciones, which still list the whole catalog. -export const CAMA_FUERA_DEL_RESUMEN: readonly string[] = ['cama_biopsias', 'cama_confirmacion_birads45', 'cama_dias_toma_diagnostico', 'cama_eu38a']; +// The two published opportunity indicators draw their KPI card only; their evolution is in Histórico. +export const CAMA_FUERA_DEL_RESUMEN: readonly string[] = ['cama_biopsias', 'cama_confirmacion_birads45', 'cama_dias_toma_diagnostico', 'cama_eu38a', + 'cama_tasa_deteccion_histopatologica', 'cama_dias_resultado_diagnostico']; export const ID_HISTOPATOLOGIA_CAMA = 'cama_histopatologia_birads'; // C1 rows of CaCu/CaMa carry the linkId `total`; TEA's ficha names its single group `TOTAL`. const C1_GROUP: Record = { tea: 'TOTAL', cacu: 'total', cama: 'total' };