6de193f44e
The WebApi names the group of a proportion `principal`; the page read it as `total` only for CaMa, so the EU13 and IND1 trends of CaCu came out empty. The rename now applies to every domain.
168 lines
12 KiB
TypeScript
168 lines
12 KiB
TypeScript
// What this module covers: how CaCu's FHIR measures reach the indicator page: the page's id of each measure, and what the
|
|
// initial-period anchor (`cacu_eu7`) makes of a C2 Measure that publishes, or does not publish, its category labels.
|
|
// The Measure and the report are synthetic and minimal: the shape of `GET /cacu/fhir/Measure` and `/MeasureReport`.
|
|
import { Bundle, resources } from './fhir';
|
|
import { Measure, Report, datosDeReportes, indicadorDeMeasure, indicadorId } from './indicadores-fhir';
|
|
import { c2Figure } from './indicadores-c2-adapter';
|
|
import { FigureSelection } from './indicadores.models';
|
|
import measuresData from './fixtures/cacu_fhir_measures.json';
|
|
import { CACU_MEASURE_IDS } from './indicadores-cacu-fhir';
|
|
import { ID_CONFIRMACION } from './indicadores-confirmacion-citologia';
|
|
import { CACU_RESULTADO_KPI, KPI_BY_DOMAIN, kpiResult } from './indicadores-kpi';
|
|
import { GlobalApplied } from './indicadores-memory';
|
|
import { historicoFigura } from './indicadores-historico-figures';
|
|
|
|
const STRUCTURE = 'https://isssteleon.org/fhir/StructureDefinition';
|
|
const ENDPOINT = ['CACU-CONFIRMACION-CITOLOGIA', 'CACU-DIAS-TOMA-DIAGNOSTICO', 'CACU-EU-TIEMPO-REPORTE', 'CACU-EU13', 'CACU-EU7',
|
|
'CACU-RIESGO-BANDA', 'IND1'];
|
|
const etiqueta = (codigo: string, texto: string, color: string) => ({ url: `${STRUCTURE}/categoria`, extension: [
|
|
{ url: 'codigo', valueCode: codigo }, { url: 'etiqueta', valueString: texto }, { url: 'color', valueString: color }] });
|
|
const eu7 = (extra: object[]): Measure => ({
|
|
resourceType: 'Measure', id: 'CACU-EU7', version: '0.3.3', title: 'Distribución de resultados citológicos',
|
|
subjectCodeableConcept: { coding: [{ code: 'paciente' }] },
|
|
extension: [{ url: `${STRUCTURE}/contrato`, valueCode: 'C2' }, { url: `${STRUCTURE}/tipos-periodo`, valueCode: 'semestre' }, ...extra],
|
|
group: [{ code: { coding: [{ code: 'TOTAL' }] }, population: [], stratifier: [{ code: [{ coding: [{ code: 'resultado' }] }], stratum: [] }] }],
|
|
} as unknown as Measure);
|
|
const reporte = (): Report => ({
|
|
resourceType: 'MeasureReport', id: 'CACU-EU7-1', period: { start: '2025-07-01', end: '2025-12-31' },
|
|
group: [{ code: { coding: [{ code: 'TOTAL' }] }, population: [{ code: { coding: [{ code: 'initial-population' }] }, count: 12 }],
|
|
stratifier: [{ code: [{ coding: [{ code: 'resultado' }] }], stratum: [
|
|
{ value: { coding: [{ code: 'NORMAL' }] }, population: [{ code: { coding: [{ code: 'initial-population' }] }, count: 8 }] },
|
|
{ value: { coding: [{ code: 'ASC-US' }] }, population: [{ code: { coding: [{ code: 'initial-population' }] }, count: 3 }] },
|
|
{ value: { coding: [{ code: 'SIN_DATO' }] }, population: [{ code: { coding: [{ code: 'initial-population' }] }, count: 1 }] },
|
|
] }] }],
|
|
} as unknown as Report);
|
|
const aplicado: GlobalApplied = { tipo: 'semestre', selection: { mode: 'explicit', periodos: ['2025-S2'] }, revision: 0 };
|
|
const ancla = KPI_BY_DOMAIN.cacu[0];
|
|
|
|
describe('Identificadores de CaCu entre FHIR y la página', () => {
|
|
it('cada medida que publica el WebApi tiene el id de minúsculas que usa la página y ninguno se repite', () => {
|
|
// Pins down: the table covers the seven measures `GET /cacu/fhir/Measure` lists and the ids are unique. Fails if a
|
|
// measure is published without a correspondence (it would come back as `CACU_X`, which no card matches) or two
|
|
// measures collapse into one page id.
|
|
const ids = ENDPOINT.map(indicadorId);
|
|
expect(ids.sort()).toEqual(['cacu_confirmacion_citologia', 'cacu_dias_toma_diagnostico', 'cacu_eu13', 'cacu_eu7',
|
|
'cacu_eu_tiempo_reporte', 'cacu_riesgo_banda', 'ind1']);
|
|
expect(ENDPOINT.every(id => Object.hasOwn(CACU_MEASURE_IDS, id))).toBe(true);
|
|
});
|
|
|
|
it('los ids que la página busca (ancla, tiempos, confirmación) existen entre los publicados', () => {
|
|
// Pins down: the page's own constants (the KPI definitions of CaCu, the confirmation card's id and the result-time KPI)
|
|
// are values of the table. Fails if the page renames one of them without the table: the catalog would keep `CACU_EU7`
|
|
// while the page looks for `cacu_eu7`, and no initial period would be searched.
|
|
const publicados = Object.values(CACU_MEASURE_IDS);
|
|
for (const id of [...KPI_BY_DOMAIN.cacu.map(k => k.id), CACU_RESULTADO_KPI.id, ID_CONFIRMACION, 'cacu_eu7']) {
|
|
expect(publicados).toContain(id);
|
|
}
|
|
});
|
|
|
|
it('el catálogo de una medida de CaCu lleva el id de la página y sus figuras', () => {
|
|
// Pins down: the catalog entry takes the page id and the `figuras` the Measure publishes. Fails if the mapper stops
|
|
// using the CaCu table or drops the figures.
|
|
const item = indicadorDeMeasure(eu7([{ url: `${STRUCTURE}/figuras`, valueString: 'fig_c2_donas' },
|
|
{ url: `${STRUCTURE}/figuras`, valueString: 'fig_c2_barras' }]));
|
|
expect(item.id).toBe('cacu_eu7');
|
|
expect(item.figuras).toEqual(['fig_c2_donas', 'fig_c2_barras']);
|
|
});
|
|
});
|
|
|
|
describe('El ancla de CaCu con y sin etiquetas de categoría publicadas', () => {
|
|
it('con etiquetas, los conteos del periodo son filas y el ancla muestra el total', () => {
|
|
// Pins down: a C2 Measure that publishes its categories gives one row per category and the anchor KPI the sum
|
|
// (12 patients), so the initial-period search can stop on the period. Fails if the rows stop following the Measure's
|
|
// categories or the anchor no longer accepts a CaCu partition.
|
|
const measure = eu7([etiqueta('NORMAL', 'Normal', '#9DBFE3'), etiqueta('ASC-US', 'ASC-US', '#2F6DB3'),
|
|
etiqueta('SIN_DATO', 'Sin dato', '#C9CDD2')]);
|
|
const datos = datosDeReportes(measure, [reporte()], 'semestre');
|
|
expect(datos.filas.map(f => [f['categoria'], f['n']])).toEqual([['NORMAL', 8], ['ASC-US', 3], ['SIN_DATO', 1]]);
|
|
const resultado = kpiResult(datos, ancla, 'cacu', aplicado);
|
|
expect(resultado.state).toBe('Disponible');
|
|
expect(resultado.value).toBe(12);
|
|
});
|
|
|
|
it('sin etiquetas, el mismo reporte no deja filas y el ancla no encuentra periodo', () => {
|
|
// Pins down the failure the Measure without `categoria` causes: the report counts 12 patients, but with no declared
|
|
// category there is no row, so the anchor reads «Sin filas utilizables» and the initial period stays empty. Fails
|
|
// if the page starts inventing categories from the report (it must keep asking the Measure).
|
|
const datos = datosDeReportes(eu7([]), [reporte()], 'semestre');
|
|
expect(datos.filas).toEqual([]);
|
|
expect(kpiResult(datos, ancla, 'cacu', aplicado).state).toBe('Sin filas utilizables');
|
|
});
|
|
});
|
|
|
|
// `fixtures/cacu_fhir_measures.json` is the Measure bundle `GET /cacu/fhir/Measure` returns from the dbt definitions once
|
|
// CaCu declares its figures and category labels (WebApi with the figures and labels declared in Transformation); the reports are built
|
|
// from the categories each Measure declares, as the WebApi would count them.
|
|
const publicadas = resources(measuresData as unknown as Bundle, 'Measure') as Measure[];
|
|
const medida = (id: string) => publicadas.find(m => m.id === id)!;
|
|
const declaradas = (m: Measure) => (m.extension ?? []).filter(e => e.url.endsWith('/categoria'))
|
|
.map(e => e.extension!.find(x => x.url === 'codigo')!.valueCode!);
|
|
const codigo = (c: string) => ({ coding: [{ code: c }] });
|
|
const reporteDe = (m: Measure, conteos: number[]): Report => ({
|
|
resourceType: 'MeasureReport', id: `${m.id}-1`, period: { start: '2025-07-01', end: '2025-12-31' },
|
|
group: [{ code: codigo('TOTAL'), population: [{ code: codigo('initial-population'), count: conteos.reduce((a, b) => a + b, 0) }],
|
|
stratifier: [{ code: [codigo('categoria')], stratum: declaradas(m).map((c, i) => ({
|
|
value: codigo(c), population: [{ code: codigo('initial-population'), count: conteos[i] }] })) }] }],
|
|
} as unknown as Report);
|
|
|
|
describe('Las medidas de CaCu como las publica el WebApi con figuras y etiquetas declaradas', () => {
|
|
it('el catálogo ofrece las figuras que cada contrato sabe dibujar y deja sin ellas las que aún no', () => {
|
|
// Pins down: C2 measures offer the donut and the bars, the two C3r the box plot, and the C1 and the risk bands none
|
|
// yet (no declared figure the renderer supports). Fails if a CaCu measure loses its figures or gains one that was not
|
|
// checked against the renderer.
|
|
const figuras = Object.fromEntries(publicadas.map(m => [indicadorDeMeasure(m).id, indicadorDeMeasure(m).figuras]));
|
|
expect(figuras).toEqual({
|
|
cacu_confirmacion_citologia: ['fig_c2_donas', 'fig_c2_barras'], cacu_dias_toma_diagnostico: ['fig_c3r_caja'],
|
|
cacu_eu_tiempo_reporte: ['fig_c3r_caja'], cacu_eu13: [], cacu_eu7: ['fig_c2_donas', 'fig_c2_barras'],
|
|
cacu_riesgo_banda: [], ind1: [],
|
|
});
|
|
});
|
|
|
|
it('con las etiquetas publicadas, el ancla muestra el total y el donut y las barras se dibujan', () => {
|
|
// Pins down the whole chain for the anchor: published categories -> rows -> «Pacientes evaluadas» total (16) ->
|
|
// supported C2 donut and bars. Fails if the page cannot read what the WebApi publishes for CaCu's distribution.
|
|
const eu7 = medida('CACU-EU7');
|
|
const datos = datosDeReportes(eu7, [reporteDe(eu7, [8, 3, 2, 1, 1, 0, 1])], 'semestre');
|
|
const resultado = kpiResult(datos, ancla, 'cacu', aplicado);
|
|
expect(resultado).toMatchObject({ state: 'Disponible', value: 16 });
|
|
for (const figura of ['fig_c2_donas', 'fig_c2_barras']) {
|
|
const dibujo = c2Figure(datos, { dominio: 'cacu', indicador: 'cacu_eu7', figura, tipoPeriodo: 'semestre', tema: 'claro',
|
|
periodos: ['2025-S2'] } as unknown as FigureSelection);
|
|
expect(dibujo.status).toBe('supported');
|
|
}
|
|
});
|
|
|
|
it('un C1 publicado con su intervalo de Wilson llena la banda del histórico, en porcentaje', () => {
|
|
// Pins down: the `ic-bajo` and `ic-alto` of a proportion's score (proportions) reach the rows as percentages and
|
|
// the history trend draws them as its band. Fails if the bounds are read unconverted or dropped.
|
|
const eu13 = medida('CACU-EU13');
|
|
const cuenta = (code: string, count: number) => ({ code: { coding: [{ code }] }, count });
|
|
const reporte13 = { resourceType: 'MeasureReport', id: 'CACU-EU13-1', period: { start: '2025-01-01', end: '2025-06-30' },
|
|
group: [{ code: { coding: [{ code: 'principal' }] }, population: [cuenta('initial-population', 4), cuenta('denominator', 4), cuenta('numerator', 1)],
|
|
measureScore: { value: 0.25, extension: [{ url: `${STRUCTURE}/ic-bajo`, valueDecimal: 0.0456 }, { url: `${STRUCTURE}/ic-alto`, valueDecimal: 0.6994 }] } }] } as unknown as Report;
|
|
const datos = datosDeReportes(eu13, [reporte13], 'semestre');
|
|
expect(datos.filas[0]).toMatchObject({ valor: 25, ic_bajo: 4.6, ic_alto: 69.9 });
|
|
const banda = (historicoFigura(datos, 'claro').figure as unknown as { data: { name: string; y: number[] }[] }).data[0];
|
|
expect(banda.name).toBe('Intervalo de confianza');
|
|
expect(banda.y).toEqual([69.9, 4.6]);
|
|
});
|
|
|
|
it('un C1 de CaCu cuyo grupo se llama principal dibuja su tendencia en el histórico', () => {
|
|
// Pins down: the WebApi names the group of a proportion `principal`; the page reads it as `total`, the group the
|
|
// history trend draws, for CaCu as for CaMa. Fails if the rows keep the group `principal` and the trend comes out
|
|
// empty, with its period listed as having no data.
|
|
const cuenta = (code: string, count: number) => ({ code: { coding: [{ code }] }, count });
|
|
for (const id of ['CACU-EU13', 'IND1']) {
|
|
const medida13 = medida(id);
|
|
const reporte = { resourceType: 'MeasureReport', id: id + '-1', period: { start: '2025-01-01', end: '2025-06-30' },
|
|
group: [{ code: { coding: [{ code: 'principal' }] }, population: [cuenta('initial-population', 4), cuenta('denominator', 4), cuenta('numerator', 1)],
|
|
measureScore: { value: 0.25 } }] } as unknown as Report;
|
|
const datos = datosDeReportes(medida13, [reporte], 'semestre');
|
|
expect(datos.filas[0]['grupo']).toBe('total');
|
|
const figura = historicoFigura(datos, 'claro');
|
|
expect((figura.figure as unknown as { data: { y: number[] }[] }).data[1].y).toEqual([25]);
|
|
expect(figura.sinDato).toEqual([]);
|
|
}
|
|
});
|
|
});
|