561a5dde36
dev already names the history tab «Trazabilidad» for the three domains, so its version of those files stays. CaCu's diagnosis-to-treatment time keeps one presentation, its card: it has no figure of its own next to the screening route chart.
92 lines
5.2 KiB
TypeScript
92 lines
5.2 KiB
TypeScript
import { provideHttpClient } from '@angular/common/http';
|
|
import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing';
|
|
import { TestBed } from '@angular/core/testing';
|
|
import { ActivatedRoute, provideRouter } from '@angular/router';
|
|
import { datosDeReportes, indicadorDeMeasure, Measure, Report } from './indicadores-fhir';
|
|
import { CACU_TRATAMIENTO_KPIS, kpiResult } from './indicadores-kpi';
|
|
import { GlobalApplied, IndicadoresMemory } from './indicadores-memory';
|
|
import { IndicadoresPage } from './indicadores-page';
|
|
|
|
const PERIOD = '2025-S2';
|
|
const applied: GlobalApplied = { tipo: 'semestre', selection: { mode: 'explicit', periodos: [PERIOD] }, revision: 1 };
|
|
const measure = (id: string): Measure => ({
|
|
resourceType: 'Measure', id, title: id, extension: [
|
|
{ url: 'contrato', valueCode: 'C3r' },
|
|
{ url: 'tipos-periodo', valueCode: 'semestre' },
|
|
{ url: 'figuras', valueString: 'fig_c3r_caja' },
|
|
],
|
|
});
|
|
const report = (median: number, q1: number, q3: number, n: number): Report => ({
|
|
resourceType: 'MeasureReport', period: { start: '2025-07-01', end: '2025-12-31' },
|
|
group: [{
|
|
code: { coding: [{ code: 'TOTAL' }] },
|
|
population: [{ code: { coding: [{ code: 'measure-observation' }] }, count: n }],
|
|
measureScore: { value: median, unit: 'd', extension: [
|
|
{ url: 'q1', valueDecimal: q1 },
|
|
{ url: 'q3', valueDecimal: q3 },
|
|
] },
|
|
}],
|
|
});
|
|
|
|
describe('KPI de tratamiento de CaCu', () => {
|
|
it.each([
|
|
['CACU-DIAS-TOMA-TRATAMIENTO', 'cacu_dias_toma_tratamiento', 21.5, 8.25, 33.75, 12],
|
|
['CACU-DIAS-DIAGNOSTICO-TRATAMIENTO', 'cacu_dias_diagnostico_tratamiento', 7.75, 2.5, 14, 9],
|
|
] as const)('mapea %s y conserva los valores C3r publicados', (fhirId, id, median, q1, q3, n) => {
|
|
const fhirMeasure = measure(fhirId);
|
|
const definition = CACU_TRATAMIENTO_KPIS.find(kpi => kpi.id === id)!;
|
|
expect(indicadorDeMeasure(fhirMeasure)).toMatchObject({ id, contrato: 'C3r' });
|
|
const data = datosDeReportes(fhirMeasure, [report(median, q1, q3, n)], 'semestre');
|
|
expect(kpiResult(data, definition, 'cacu', applied)).toEqual({
|
|
state: 'Disponible', value: median,
|
|
info: `${n} observaciones. Primer cuartil de ${q1} días y tercer cuartil de ${q3} días.`,
|
|
});
|
|
});
|
|
|
|
it('distingue una mediana publicada de cero días de la ausencia de observaciones o la supresión', () => {
|
|
const fhirMeasure = measure('CACU-DIAS-TOMA-TRATAMIENTO');
|
|
const definition = CACU_TRATAMIENTO_KPIS[0];
|
|
const empty = datosDeReportes(fhirMeasure, [report(0, 0, 0, 0)], 'semestre');
|
|
expect(kpiResult(empty, definition, 'cacu', applied)).toEqual({ state: 'Sin valor disponible' });
|
|
const published = datosDeReportes(fhirMeasure, [report(0, 0, 0, 1)], 'semestre');
|
|
expect(kpiResult(published, definition, 'cacu', applied).value).toBe(0);
|
|
const suppressed = { ...published, filas: [{ ...published.filas[0], suprimido: 1 }] };
|
|
expect(kpiResult(suppressed, definition, 'cacu', applied)).toEqual({ state: 'Dato oculto por tamaño' });
|
|
});
|
|
|
|
it('presenta una sola tarjeta por medida con publicación parcial y conserva el periodo del dato', () => {
|
|
TestBed.configureTestingModule({ providers: [provideHttpClient(), provideHttpClientTesting(), provideRouter([]),
|
|
{ provide: ActivatedRoute, useValue: { snapshot: { data: { dominio: 'cacu' } } } }] });
|
|
TestBed.inject(IndicadoresMemory).finishInitialKpiPresentation('cacu');
|
|
const fixture = TestBed.createComponent(IndicadoresPage), http = TestBed.inject(HttpTestingController);
|
|
const fhirMeasure = measure('CACU-DIAS-DIAGNOSTICO-TRATAMIENTO');
|
|
const { id } = indicadorDeMeasure(fhirMeasure);
|
|
try {
|
|
http.expectOne('/cacu/indicadores').flush([indicadorDeMeasure(fhirMeasure)]);
|
|
http.expectOne(`/cacu/indicadores/${id}/periodos`).flush({ id, periodos: [{ periodo: PERIOD, tipo: 'semestre' }] });
|
|
fixture.detectChanges();
|
|
const request = http.expectOne(r => r.url === `/cacu/indicadores/${id}/datos`);
|
|
expect(request.request.params.get('periodos')).toBe(PERIOD);
|
|
request.flush(datosDeReportes(fhirMeasure, [report(7.75, 2.5, 14, 9)], 'semestre'));
|
|
fixture.detectChanges();
|
|
const root = fixture.nativeElement as HTMLElement;
|
|
const cards = [...root.querySelectorAll('.kpi-grid app-indicador-kpi-card')];
|
|
expect(cards.map(card => card.querySelector('h3')?.textContent)).toEqual([
|
|
'Tiempo de tamizaje a tratamiento', 'Tiempo de diagnóstico a tratamiento',
|
|
]);
|
|
expect(cards[0].querySelector('.kpi-state')?.textContent).toBe('Integración pendiente');
|
|
expect(cards[0].querySelector('.value')).toBeNull();
|
|
expect(cards[1].querySelector('.value')?.firstChild?.textContent).toBe('7.75');
|
|
expect(cards[1].querySelector('.period')?.textContent).toContain(PERIOD);
|
|
// the cards carry no provisional notice: what the measure is lives in its technical sheet
|
|
expect(cards[1].textContent).not.toContain('Indicador provisional');
|
|
expect(root.querySelector('.kpi-section .catalog-grid')).toBeNull();
|
|
expect(root.querySelector('.graphic-section app-indicador-catalog-card')).toBeNull();
|
|
http.expectNone(() => true);
|
|
} finally {
|
|
fixture.destroy();
|
|
http.verify();
|
|
}
|
|
});
|
|
});
|