From 2a84eb56ca295105ac49cb76b104f5f928b66898 Mon Sep 17 00:00:00 2001 From: edgar Date: Thu, 3 Dec 2026 22:21:59 -0600 Subject: [PATCH] Agrupar las tarjetas de CaMa y elegir el periodo en Trazabilidad --- e2e/pages.spec.ts | 14 ++--- src/app/indicadores/bars.spec.ts | 23 +-------- src/app/indicadores/bars.ts | 32 ++---------- src/app/indicadores/follow-up.spec.ts | 12 ++++- src/app/indicadores/layout.ts | 1 - src/app/indicadores/measures.ts | 7 +++ src/app/indicadores/pages-cacu.ts | 2 +- src/app/indicadores/pages.ts | 32 +++++++----- src/app/indicadores/readings.ts | 22 +------- src/app/indicadores/tab-indicadores.html | 12 +---- src/app/indicadores/tab-trazabilidad.spec.ts | 51 ++++++++++++++++++ src/app/indicadores/tab-trazabilidad.ts | 54 ++++++++++++++------ 12 files changed, 142 insertions(+), 120 deletions(-) create mode 100644 src/app/indicadores/tab-trazabilidad.spec.ts diff --git a/e2e/pages.spec.ts b/e2e/pages.spec.ts index 3388d2f..13d31e5 100644 --- a/e2e/pages.spec.ts +++ b/e2e/pages.spec.ts @@ -226,12 +226,7 @@ for (const domain of ['cama', 'tea']) { (i) => i.kind === 'h3' && i.text === 'Tiempo de tamizaje a diagnóstico', ); const clinical = all.findIndex((i) => i.text === 'Indicadores clínicos'); - // Lote 2: the detection rate has its own title, and the histopathology figures are two - // cards (the result by BI-RADS; the confirmation in two readings). - const detection = (i: { text?: string }) => - i.text === 'Tasa de confirmación histopatológica' - ? { ...i, text: 'Tasa de detección histopatológica' } - : i; + // The histopathology figures are two cards: the result by BI-RADS and the confirmation. const results = all.findIndex( (i) => i.text === 'Resultado histopatológico por categoría BI-RADS', ); @@ -241,7 +236,7 @@ for (const domain of ['cama', 'tea']) { ]; const old = domain === 'cama' - ? [...all.slice(0, route + 1).map(detection), ...all.slice(clinical, results), ...cards] + ? [...all.slice(0, route + 1), ...all.slice(clinical, results), ...cards] : all; await page.goto(`/indicadores/${domain}`); const tab = page.locator('app-tab-indicadores'); @@ -255,12 +250,13 @@ for (const domain of ['cama', 'tea']) { const ordered = [ 'Tiempo de toma de mastografía a interpretación radiológica', 'Tiempo de interpretación radiológica a diagnóstico', + 'Tiempo de interpretación radiológica a resultado de biopsia', + 'Tiempo de diagnóstico a tratamiento', 'Tiempo de tamizaje a diagnóstico', - 'Porcentaje de mastografías con resultado BI-RADS 4, 5 ó 6', 'Pacientes evaluadas con BI-RADS 4, 5 o 6', + 'Porcentaje de mastografías con resultado BI-RADS 4, 5 ó 6', 'Resultado histopatológico por categoría BI-RADS', 'Confirmación histopatológica', - 'Tasa de detección histopatológica', ]; let last = -1; for (const title of ordered) { diff --git a/src/app/indicadores/bars.spec.ts b/src/app/indicadores/bars.spec.ts index 9bbb388..2b20952 100644 --- a/src/app/indicadores/bars.spec.ts +++ b/src/app/indicadores/bars.spec.ts @@ -1,4 +1,4 @@ -import { bars, grouped, hiddenNote, Mode, subsequentHistory, unavailable } from './bars'; +import { bars, grouped, hiddenNote, Mode, unavailable } from './bars'; import { scenarioBars } from './figures'; import { Reading } from './measures'; @@ -51,25 +51,6 @@ describe('bars', () => { )!; expect(g.groups[0].rows[1].text).toBe('3/10 · 30.0 %'); }); - it('shows the form history within subsequent screening without treating missing answers as a category', () => { - const r: Reading = { - populations: {}, - strata: { - round: { subsequent: { 'initial-population': 5 } }, - subsequent_history: { - within_1_year: { 'initial-population': 1 }, - '3_or_more_years': { 'initial-population': 2 }, - no_data: { 'initial-population': 2 }, - }, - }, - }; - expect(subsequentHistory(r)).toEqual([ - { label: 'Un año o menos', text: '1/5 · 20.0 %' }, - { label: 'Dos años', text: '0/5 · 0.0 %' }, - { label: 'Tres o más años', text: '2/5 · 40.0 %' }, - ]); - expect(subsequentHistory({ populations: {}, strata: {} })).toBeUndefined(); - }); it('a group with no patients has no rate', () => { const r: Reading = { populations: {}, @@ -353,7 +334,7 @@ describe('independent bars by group', () => { ['0/0 · —', undefined], ['0/0 · —', undefined], ]); - expect(empty.note).toContain('una categoría en cero significa'); + expect(empty.note).toBeUndefined(); const unreconciled = grouped(mode({ complete: true }), () => reading({ 'subsequent|NILM': 2 }, 5), )!; diff --git a/src/app/indicadores/bars.ts b/src/app/indicadores/bars.ts index 8ade4a1..9742f1c 100644 --- a/src/app/indicadores/bars.ts +++ b/src/app/indicadores/bars.ts @@ -172,8 +172,6 @@ export interface Bars { export const NOT_AVAILABLE = 'No disponible'; export const NO_PATIENTS = 'Sin pacientes en el periodo'; -const EMPTY_ROUND = - 'Hay pacientes sin clasificación de ronda («Sin dato»): una categoría en cero significa que no hay pacientes clasificadas en esa ronda según la información disponible.'; const NO_ROUND = 'Ninguna paciente del periodo tiene clasificación de detección inicial o subsecuente: los grupos en cero reflejan información no registrada, no ausencia de pacientes.'; @@ -448,24 +446,6 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined): } } -/** Reported form answers within the subsequent round, over that round's own total. */ -export function subsequentHistory(reading?: Reading) { - const values = reading?.strata['subsequent_history']; - const den = reading?.strata['round']?.['subsequent']?.['initial-population'] ?? 0; - if (!values) return undefined; - return [ - ['within_1_year', 'Un año o menos'], - ['2_years', 'Dos años'], - ['3_or_more_years', 'Tres o más años'], - ].map(([code, label]) => { - const count = values[code]?.['initial-population'] ?? 0; - return { - label, - text: `${count}/${den} · ${den ? ((100 * count) / den).toFixed(1) + ' %' : '—'}`, - }; - }); -} - /** The groups of a grouped mode: each group (an age group, a follow-up status, a screening round) with * one independent bar per category over the group's own records. A group the report leaves out is * drawn empty only when the listed ones add up to every record of the period (`complete`). */ @@ -501,7 +481,7 @@ export function grouped( mode.stratum === 'age_group' && code === '<25' && ['CACU_EU7', 'CACU_VPH_GENOTIPO'].includes(mode.measure) - ? '14 años y 10 meses a menos de 25 años' + ? '15-24' : name(code), total: den, hint: den ? undefined : `Sin ${mode.unit} en el grupo`, @@ -543,9 +523,7 @@ export function grouped( ? 'Los conteos del informe no concilian con el total: los grupos ausentes no se muestran como cero.' : none && unclassified ? NO_ROUND - : unclassified && classified.some((g) => !g.total) - ? EMPTY_ROUND - : undefined; + : undefined; note = [sentence, note].filter(Boolean).join(' ') || undefined; } return { groups, note }; @@ -586,7 +564,6 @@ function complete( const classified = order.filter((c) => c !== 'no_data' && listed.includes(c)); const empty = classified.filter((c) => !(counts(c)?.[1] ?? 0)); const none = empty.length === classified.length; - const unclassified = counts('no_data')?.[1] ?? 0; return { head: ['n/N', percentLabel], rows, @@ -594,10 +571,7 @@ function complete( ? 'Los conteos del informe no concilian con el total de pacientes: los grupos ausentes no se muestran como cero.' : none && listed.includes('no_data') ? NO_ROUND - : unclassified && - (empty.length || order.some((c) => !listed.includes(c) && c !== 'no_data')) - ? EMPTY_ROUND - : undefined, + : undefined, }; } diff --git a/src/app/indicadores/follow-up.spec.ts b/src/app/indicadores/follow-up.spec.ts index 1bd53dd..89376d6 100644 --- a/src/app/indicadores/follow-up.spec.ts +++ b/src/app/indicadores/follow-up.spec.ts @@ -1,6 +1,6 @@ import type { RiskAssessment } from 'fhir/r4'; import { ageGroup, currentRisk, windowStart, ageAt, bornFor } from './follow-up'; -import { periods } from './measures'; +import { historyPeriods, periods } from './measures'; describe('follow-up list', () => { it('starts the window the day after the same day months before (core.follow_up)', () => { @@ -36,6 +36,16 @@ describe('follow-up list', () => { expect(currentRisk(risks, 'cin2', 3)).toBeUndefined(); }); + it('ends history at the selected complete period for months and semesters', () => { + const monthly = historyPeriods('month', '2025-03'); + expect(monthly.slice(-3)).toEqual(['2025-01', '2025-02', '2025-03']); + expect(monthly).toHaveLength(72); + const firstSemester = historyPeriods('semester', '2025-S1'); + expect(firstSemester.slice(-3)).toEqual(['2024-S1', '2024-S2', '2025-S1']); + const secondSemester = historyPeriods('semester', '2025-S2'); + expect(secondSemester.slice(-2)).toEqual(['2025-S1', '2025-S2']); + }); + it('lists periods most recent first', () => { expect(periods('semester', 1, new Date(2026, 10, 25))).toEqual(['2026-S2', '2026-S1']); expect(periods('month', 1, new Date(2026, 1, 3)).slice(0, 3)).toEqual([ diff --git a/src/app/indicadores/layout.ts b/src/app/indicadores/layout.ts index dfcd6b3..ff8380f 100644 --- a/src/app/indicadores/layout.ts +++ b/src/app/indicadores/layout.ts @@ -51,7 +51,6 @@ export const LAYOUTS: Record = { 'CAMA_EU38A', 'CAMA_DIAS_TOMA_DIAGNOSTICO', 'CAMA_CONFIRMACION_BIRADS45', - 'CAMA_TASA_DETECCION_HISTOPATOLOGICA', ], route: [ { diff --git a/src/app/indicadores/measures.ts b/src/app/indicadores/measures.ts index 2aa6816..3d3285a 100644 --- a/src/app/indicadores/measures.ts +++ b/src/app/indicadores/measures.ts @@ -23,6 +23,13 @@ export function periods(type: PeriodType, years = 6, today = new Date()): string return found; } +/** Historical periods ending in the selected month or semester, oldest first. */ +export function historyPeriods(type: PeriodType, selected: string): string[] { + const [year, part] = selected.split('-'); + const month = type === 'semester' ? (part === 'S1' ? 0 : 6) : Number(part) - 1; + return periods(type, 6, new Date(Number(year), month, 1)).reverse(); +} + export function periodLabel(period: string): string { const [year, part] = period.split('-'); if (part.startsWith('S')) return `${part === 'S1' ? 'Ene–Jun' : 'Jul–Dic'} ${year}`; diff --git a/src/app/indicadores/pages-cacu.ts b/src/app/indicadores/pages-cacu.ts index e18c86f..c02e594 100644 --- a/src/app/indicadores/pages-cacu.ts +++ b/src/app/indicadores/pages-cacu.ts @@ -199,7 +199,7 @@ export const CACU: Page = { }, { measure: 'CACU_DIAS_DIAGNOSTICO_TRATAMIENTO', - title: 'Tiempo de diagnóstico a tratamiento', + title: 'Tiempo de diagnóstico tras biopsia a tratamiento', ...CACU_DAYS, }, ], diff --git a/src/app/indicadores/pages.ts b/src/app/indicadores/pages.ts index 42eb4ce..6e36997 100644 --- a/src/app/indicadores/pages.ts +++ b/src/app/indicadores/pages.ts @@ -249,6 +249,7 @@ export const PAGES: Record = { }, cama: { anchor: 'CAMA_BIRADS456_PACIENTE', + // every single-number card, together at the start, in the order asked for kpis: [ { measure: 'CAMA_EU38A', @@ -260,18 +261,27 @@ export const PAGES: Record = { title: 'Tiempo de interpretación radiológica a diagnóstico', ...CAMA_DAYS, }, + { + measure: 'CAMA_DIAS_RESULTADO_BIOPSIA', + title: 'Tiempo de interpretación radiológica a resultado de biopsia', + ...CAMA_DAYS, + }, + { + title: 'Tiempo de diagnóstico a tratamiento', + value: 'Indicador no disponible', + note: 'Indicador no publicado en el catálogo institucional.', + }, + { + measure: 'CAMA_DIAS_TOMA_DIAGNOSTICO', + title: 'Tiempo de tamizaje a diagnóstico', + ...CAMA_DAYS, + }, { measure: 'CAMA_BIRADS456_PACIENTE', title: 'Pacientes evaluadas con BI-RADS 4, 5 o 6', value: '{n} pacientes', note: 'Pacientes con mastografía BI-RADS 4, 5 o 6 en el periodo.', }, - { - measure: 'CAMA_TASA_DETECCION_HISTOPATOLOGICA', - title: 'Tasa de detección histopatológica', - value: '{pct} %', - note: '{num} de {den} biopsias con grado conocido presentan carcinoma (in situ o invasor).', - }, ], opportunity: [ { @@ -356,9 +366,7 @@ export const PAGES: Record = { section: { kind: 'readings', title: 'Resultado de biopsias', - headline: 'CAMA_TASA_DETECCION_HISTOPATOLOGICA', - unit: 'biopsias', - note: 'Biopsias con resultado reportado, por fecha del reporte (no son pacientes ni mastografías). La tasa divide los carcinomas (in situ o invasor) entre biopsias con grado conocido. Los porcentajes de la distribución incluyen todas las biopsias reportadas, también «Sin dato» (sin grado), por lo que sus denominadores pueden ser distintos.', + note: 'Biopsias con resultado reportado, por fecha del reporte (no son pacientes ni mastografías). Los porcentajes incluyen todas las biopsias reportadas, también «Sin dato» (sin grado).', modes: [ { kind: 'counts', @@ -380,7 +388,7 @@ export const PAGES: Record = { title: 'Mastografías con biopsia', headline: 'CAMA_CONFIRMACION_BIRADS45', unit: 'mastografías', - note: 'Mastografías BI-RADS 4, 4A, 4B, 4C o 5 con reporte, por fecha del examen: cuántas tienen un reporte de biopsia. Mide el seguimiento, no el resultado de la biopsia; no es equivalente a la tasa de detección.', + note: 'Mastografías BI-RADS 4, 4A, 4B, 4C o 5 con reporte, por fecha del examen: cuántas tienen un reporte de biopsia. Mide el seguimiento, no el resultado de la biopsia.', modes: [ { kind: 'split', @@ -496,7 +504,7 @@ export const HISTORY: Record = { kind: 'median', }, { - title: 'Tiempo de diagnóstico a tratamiento', + title: 'Tiempo de diagnóstico tras biopsia a tratamiento', measure: 'CACU_DIAS_DIAGNOSTICO_TRATAMIENTO', kind: 'median', }, @@ -546,7 +554,7 @@ export const HISTORY: Record = { ['no_data', 'Sin dato', GREY], ]), { - title: 'Tasa de confirmación histopatológica', + title: 'Confirmación histopatológica', measure: 'CAMA_CONFIRMACION_BIRADS45', kind: 'percent', }, diff --git a/src/app/indicadores/readings.ts b/src/app/indicadores/readings.ts index c73942e..36dcb28 100644 --- a/src/app/indicadores/readings.ts +++ b/src/app/indicadores/readings.ts @@ -2,7 +2,7 @@ import { Component, computed, input, signal } from '@angular/core'; import { MatButtonToggleModule } from '@angular/material/button-toggle'; import { Loading } from '../loading'; import { Figure, Plot } from '../plot'; -import { bars, grouped, hiddenNote, Mode, subsequentHistory, unavailable } from './bars'; +import { bars, grouped, hiddenNote, Mode, unavailable } from './bars'; import { Reading } from './measures'; /** A card read one mode at a time: its title, its headline, the toggle and the bars. */ @@ -77,21 +77,6 @@ import { Reading } from './measures'; @if (g.note) {

{{ g.note }}

} - @if (historyBreakdown(); as history) { -
-

Dentro de detección subsecuente: antecedente declarado

-

- Las categorías son respuestas del formulario; el denominador es el total de la ronda - subsecuente. La diferencia incluye valores no registrados o primera vez declarada con - procedimientos previos. -

-
    - @for (item of history; track item.label) { -
  • {{ item.label }}: {{ item.text }}
  • - } -
-
- } } @else if (figure(); as f) { @if (hidden(); as why) { @@ -388,11 +373,6 @@ export class Readings { () => this.modes().find((m) => m.label === (this.view() || this.chosen())) ?? this.modes()[0], ); protected readonly groups = computed(() => grouped(this.mode(), this.read())); - protected readonly historyBreakdown = computed(() => { - const mode = this.mode(); - if (mode.kind !== 'grouped' || mode.stratum !== 'round') return undefined; - return subsequentHistory(this.read()(mode.measure)); - }); protected readonly table = computed(() => bars(this.mode(), this.read())); /** The bars of a scenarios figure need more room than a donut. */ protected readonly height = computed(() => { diff --git a/src/app/indicadores/tab-indicadores.html b/src/app/indicadores/tab-indicadores.html index 5637b5e..a6113ae 100644 --- a/src/app/indicadores/tab-indicadores.html +++ b/src/app/indicadores/tab-indicadores.html @@ -46,8 +46,8 @@

Indicadores de oportunidad

Periodo {{ period }} -
- @for (k of pg.kpis.slice(0, 2); track k.title) { +
+ @for (k of pg.kpis; track k.title) { }
@@ -63,15 +63,7 @@ - @if ($index === 0) { -
- -
- } } -
- -
} @else { @if (domain() === 'cacu') { diff --git a/src/app/indicadores/tab-trazabilidad.spec.ts b/src/app/indicadores/tab-trazabilidad.spec.ts new file mode 100644 index 0000000..b38f21a --- /dev/null +++ b/src/app/indicadores/tab-trazabilidad.spec.ts @@ -0,0 +1,51 @@ +import { TestBed } from '@angular/core/testing'; +import type { Measure } from 'fhir/r4'; +import { Fhir } from '../fhir'; +import { HISTORY } from './pages'; +import { TabTrazabilidad } from './tab-trazabilidad'; + +describe('Trazabilidad: periodo seleccionado', () => { + for (const domain of ['cama', 'cacu']) { + it(`applies a monthly and semester period to the ${domain} queries`, async () => { + const requests: Record[] = []; + await TestBed.configureTestingModule({ + imports: [TabTrazabilidad], + providers: [ + { + provide: Fhir, + useValue: { + all: async (_domain: string, _resource: string, params: Record) => { + requests.push(params); + return [{ resourceType: 'Bundle', type: 'searchset', entry: [] }]; + }, + }, + }, + ], + }).compileComponents(); + const fixture = TestBed.createComponent(TabTrazabilidad); + fixture.componentRef.setInput('domain', domain); + fixture.componentRef.setInput('measures', [ + { resourceType: 'Measure', id: 'test', name: HISTORY[domain].panels[0].measure }, + ] as Measure[]); + fixture.detectChanges(); + await fixture.whenStable(); + const component = fixture.componentInstance as any; + component.chosen.set('2025-03'); + fixture.detectChanges(); + (fixture.nativeElement.querySelector('button[mat-flat-button]') as HTMLButtonElement).click(); + fixture.detectChanges(); + await fixture.whenStable(); + expect(requests.at(-1)?.['reporting-period'].split(',').at(-1)).toBe('2025-03'); + expect(requests.at(-1)?.['as-of']).toBeUndefined(); + component.setType('semester'); + fixture.detectChanges(); + await fixture.whenStable(); + component.chosen.set('2024-S1'); + fixture.detectChanges(); + (fixture.nativeElement.querySelector('button[mat-flat-button]') as HTMLButtonElement).click(); + fixture.detectChanges(); + await fixture.whenStable(); + expect(requests.at(-1)?.['reporting-period'].split(',').at(-1)).toBe('2024-S1'); + }); + } +}); diff --git a/src/app/indicadores/tab-trazabilidad.ts b/src/app/indicadores/tab-trazabilidad.ts index f58ba55..17366ef 100644 --- a/src/app/indicadores/tab-trazabilidad.ts +++ b/src/app/indicadores/tab-trazabilidad.ts @@ -1,11 +1,13 @@ import { Component, computed, inject, input, resource, signal } from '@angular/core'; +import { MatButtonModule } from '@angular/material/button'; import { MatButtonToggleModule } from '@angular/material/button-toggle'; +import { MatSelectModule } from '@angular/material/select'; import type { Measure, MeasureReport } from 'fhir/r4'; import { Fhir, resources } from '../fhir'; import { Loading } from '../loading'; import { Figure, Plot } from '../plot'; import { historyFigure } from './figures'; -import { periodLabel, periods, PeriodType, reading } from './measures'; +import { historyPeriods, periodLabel, periods, PeriodType, reading } from './measures'; import { HISTORY, HistoryPanel } from './pages'; interface Drawn { @@ -19,21 +21,30 @@ interface Drawn { * each measure period by period. */ @Component({ selector: 'app-tab-trazabilidad', - imports: [Loading, MatButtonToggleModule, Plot], + imports: [Loading, MatButtonModule, MatButtonToggleModule, MatSelectModule, Plot], template: `

Filtros

Mensual Semestral @if (domain() === 'cama' || domain() === 'cacu') { - - + + Periodo seleccionado + + @for (p of options(); track p) { + {{ p }} + } + + + }
@if (series.isLoading()) { @@ -75,6 +86,12 @@ interface Drawn { padding: 16px 20px; margin-bottom: 16px; } + .filters { + display: flex; + align-items: center; + flex-wrap: wrap; + gap: 16px; + } .filters-title { font-size: 16px; font-weight: 500; @@ -99,16 +116,28 @@ export class TabTrazabilidad { readonly domain = input.required(); readonly measures = input.required(); protected readonly type = signal('month'); - protected readonly chosenCutoff = signal(''); - protected readonly cutoff = signal(''); + protected readonly options = computed(() => periods(this.type())); + protected readonly chosen = signal(periods('month')[0]); + protected readonly applied = signal(periods('month')[0]); + + protected setType(type: PeriodType): void { + this.type.set(type); + const latest = this.options()[0]; + this.chosen.set(latest); + this.applied.set(latest); + } protected readonly series = resource({ - params: () => ({ domain: this.domain(), type: this.type(), measures: this.measures(), cutoff: this.cutoff() }), + params: () => ({ + domain: this.domain(), + type: this.type(), + measures: this.measures(), + period: this.applied(), + }), loader: async ({ params }) => { const history = HISTORY[params.domain]; if (!history) return []; - const day = params.cutoff ? new Date(`${params.cutoff}T12:00:00`) : new Date(); - const asked = periods(params.type, 6, day).reverse(); + const asked = historyPeriods(params.type, params.period); return Promise.all( history.panels.map(async (panel) => { const measure = params.measures.find((m) => m.name === panel.measure); @@ -116,11 +145,6 @@ export class TabTrazabilidad { const pages = await this.fhir.all(params.domain, 'MeasureReport', { measure: measure.id!, 'reporting-period': asked.join(','), - ...(params.cutoff ? { - 'as-of': `${params.cutoff}T23:59:59.999999Z`, - 'event-cutoff': params.cutoff, - 'period-cutoff': params.cutoff, - } : {}), }); // One report per period asked, in the order asked. const found = resources(pages, 'MeasureReport');