CaCu: show screening rounds and restore category palettes
This commit is contained in:
+162
-1
@@ -1,4 +1,6 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
import { expect, type Page, test } from '@playwright/test';
|
||||
import { layoutProblems } from './layout';
|
||||
import { type Simulation, simulateRounds } from './simulated-rounds';
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
const form = { username: 'admin@isssteleon.mx', password: 'solo-para-pruebas' };
|
||||
@@ -34,7 +36,41 @@ test('indicadores cacu: its sections in order, each card read one mode at a time
|
||||
route.getByRole('table', { name: mode }).or(route.getByText('Sin datos en el periodo.')),
|
||||
).toBeVisible();
|
||||
}
|
||||
// the screening round replaces the clinical scenario: the same tab, label and order on four cards
|
||||
const round = { name: 'Por detección inicial y subsecuente' };
|
||||
await expect(tab.getByRole('radio', { name: 'Por escenario clínico' })).toHaveCount(0);
|
||||
for (const card of [
|
||||
'Distribución de resultados citológicos',
|
||||
'Pacientes evaluadas por resultado de VPH',
|
||||
'Valor predictivo positivo de la colposcopía',
|
||||
]) {
|
||||
const readings = tab.locator('app-readings', {
|
||||
has: page.getByRole('heading', { name: card }),
|
||||
});
|
||||
await readings.getByRole('radio', round).click();
|
||||
// rows in the order of the contract, "no disponible", or no patients in the period
|
||||
await expect(
|
||||
readings
|
||||
.getByRole('table', round)
|
||||
.or(readings.locator('app-plot'))
|
||||
.or(readings.getByText(/No disponible|Sin datos en el periodo/)),
|
||||
).toBeVisible();
|
||||
if (await readings.getByRole('table', round).count()) {
|
||||
const labels = await readings.getByRole('rowheader').allInnerTexts();
|
||||
expect(labels.map((l) => l.trim().split(/\s{2,}|\n/)[0])).toEqual([
|
||||
'Detección inicial',
|
||||
'Detección subsecuente',
|
||||
'Sin dato',
|
||||
]);
|
||||
}
|
||||
}
|
||||
await tab.getByRole('radio', { name: 'Biopsia', exact: true }).click();
|
||||
await tab
|
||||
.locator('app-readings', {
|
||||
has: page.getByRole('heading', { name: 'Valor predictivo positivo de la biopsia' }),
|
||||
})
|
||||
.getByRole('radio', round)
|
||||
.click();
|
||||
await expect(
|
||||
tab.getByRole('heading', { name: 'Valor predictivo positivo de la biopsia' }),
|
||||
).toBeVisible();
|
||||
@@ -67,3 +103,128 @@ test('riesgos cacu: ages filter the whole list and a row opens its stages', asyn
|
||||
await page.getByRole('button', { name: 'Exportar PDF' }).click();
|
||||
expect((await record).suggestedFilename()).toBe('expediente-cacu.pdf');
|
||||
});
|
||||
|
||||
// ---- Screening rounds on SIMULATED answers (see simulated-rounds.ts): the groups the contract of
|
||||
// `rebuild` allows, tried without loading data. They show how the page draws them, not the backend.
|
||||
const ROUND = { name: 'Por detección inicial y subsecuente' };
|
||||
const TITLES = {
|
||||
cytology: 'Distribución de resultados citológicos',
|
||||
vph: 'Pacientes evaluadas por resultado de VPH',
|
||||
colposcopy: 'Valor predictivo positivo de la colposcopía',
|
||||
biopsy: 'Valor predictivo positivo de la biopsia',
|
||||
};
|
||||
const BAR = {
|
||||
initial: 'rgb(95, 127, 154)',
|
||||
subsequent: 'rgb(143, 167, 187)',
|
||||
no_data: 'rgb(201, 205, 210)',
|
||||
};
|
||||
|
||||
async function withRounds(page: Page, how: Simulation) {
|
||||
await simulateRounds(page, how);
|
||||
await page.goto('/indicadores/cacu');
|
||||
const tab = page.locator('app-tab-indicadores');
|
||||
await expect(tab.getByRole('heading', { name: 'Indicadores clínicos' })).toBeVisible({
|
||||
timeout: 3 * 60_000,
|
||||
});
|
||||
await expect(tab.locator('app-loading')).toHaveCount(0, { timeout: 5 * 60_000 });
|
||||
const card = (title: string) =>
|
||||
tab.locator('app-readings', { has: page.getByRole('heading', { name: title }) }).first();
|
||||
const open = async (key: keyof typeof TITLES) => {
|
||||
if (key === 'biopsy') await tab.getByRole('radio', { name: 'Biopsia', exact: true }).click();
|
||||
if (key === 'colposcopy')
|
||||
await tab.getByRole('radio', { name: 'Colposcopía', exact: true }).click();
|
||||
const readings = card(TITLES[key]);
|
||||
await readings.getByRole('radio', ROUND).click();
|
||||
return readings;
|
||||
};
|
||||
return { tab, open };
|
||||
}
|
||||
|
||||
for (const key of ['vph', 'colposcopy', 'biopsy'] as const) {
|
||||
test(`rondas (simulado) ${key}: three groups in order, each with its own colour`, async ({
|
||||
page,
|
||||
}) => {
|
||||
const { open } = await withRounds(page, 'as-is');
|
||||
const readings = await open(key);
|
||||
const rows = readings.getByRole('row').filter({ has: page.getByRole('rowheader') });
|
||||
await expect(rows).toHaveCount(3);
|
||||
const names = await readings.getByRole('rowheader').allInnerTexts();
|
||||
expect(names.map((n) => n.trim().split(/\s*\n\s*/)[0])).toEqual([
|
||||
'Detección inicial',
|
||||
'Detección subsecuente',
|
||||
'Sin dato',
|
||||
]);
|
||||
const colours = await readings
|
||||
.locator('tbody .bar')
|
||||
.evaluateAll((els) => els.map((e) => getComputedStyle(e).backgroundColor));
|
||||
expect(colours).toEqual([BAR.initial, BAR.subsequent, BAR.no_data]);
|
||||
});
|
||||
|
||||
test(`rondas (simulado) ${key}: an empty initial group is zero patients, not hidden`, async ({
|
||||
page,
|
||||
}) => {
|
||||
const { open } = await withRounds(page, 'no-initial');
|
||||
const readings = await open(key);
|
||||
const initial = readings.getByRole('row').filter({ hasText: 'Detección inicial' });
|
||||
await expect(initial).toContainText('Sin pacientes en el periodo');
|
||||
await expect(initial).toContainText('0/0');
|
||||
});
|
||||
|
||||
test(`rondas (simulado) ${key}: without the stratum the card says it is not available`, async ({
|
||||
page,
|
||||
}) => {
|
||||
const { open } = await withRounds(page, 'unpublished');
|
||||
const readings = await open(key);
|
||||
await expect(readings).toContainText('No disponible');
|
||||
await expect(readings.getByRole('table', ROUND)).toHaveCount(0);
|
||||
});
|
||||
}
|
||||
|
||||
test('rondas (simulado) cytology: the bars follow the round and the cytology colours', async ({
|
||||
page,
|
||||
}) => {
|
||||
const { open } = await withRounds(page, 'as-is');
|
||||
const readings = await open('cytology');
|
||||
const plot = readings.locator('.js-plotly-plot');
|
||||
await expect(plot).toBeVisible();
|
||||
const { y, colours } = await plot.evaluate((e: any) => ({
|
||||
y: e.data[0].y as string[],
|
||||
colours: Object.fromEntries(e.data.map((t: any) => [t.name, t.marker.color])),
|
||||
}));
|
||||
expect(y.map((s) => s.split('<br>')[0])).toEqual([
|
||||
'Detección inicial',
|
||||
'Detección subsecuente',
|
||||
'Sin dato',
|
||||
]);
|
||||
expect(colours).toMatchObject({
|
||||
Normal: '#408651',
|
||||
'ASC-US': '#2778B8',
|
||||
LIEBG: '#B19525',
|
||||
'ASC-H': '#7955B1',
|
||||
LIEAG: '#CE4778',
|
||||
'Carcinoma in situ': '#AA394D',
|
||||
});
|
||||
});
|
||||
|
||||
test('rondas (simulado): an initial group folded into "Sin dato" keeps its counts there', async ({
|
||||
page,
|
||||
}) => {
|
||||
const { open } = await withRounds(page, 'unclassified');
|
||||
const readings = await open('vph');
|
||||
const rows = readings.getByRole('row').filter({ has: page.getByRole('rowheader') });
|
||||
await expect(rows.filter({ hasText: 'Detección inicial' })).toContainText('0/0');
|
||||
await expect(rows.filter({ hasText: 'Sin dato' })).not.toContainText('0/0');
|
||||
await expect(readings).toContainText('una categoría en cero significa');
|
||||
});
|
||||
|
||||
for (const width of [1440, 480]) {
|
||||
test(`rondas (simulado) at ${width} px: the four cards open on their rounds lay out cleanly`, async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.setViewportSize({ width, height: 1000 });
|
||||
const { open } = await withRounds(page, 'as-is');
|
||||
for (const key of ['cytology', 'vph', 'colposcopy', 'biopsy'] as const) await open(key);
|
||||
await page.waitForTimeout(1500);
|
||||
expect(await layoutProblems(page)).toEqual([]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import type { Page } from '@playwright/test';
|
||||
|
||||
/** SIMULATED answers. The pages read the API's aggregated MeasureReports; these helpers pass them
|
||||
* through the browser and rewrite the screening-round strata, so the cards can be tried with the
|
||||
* groups the contract of `rebuild` allows (stratum `round`, crossed `round-category`) without
|
||||
* loading data. They prove how the page draws such answers, not what the backend computes.
|
||||
*
|
||||
* - `as-is`: the answers untouched, but the old candidate's `screening_round` is named `round`.
|
||||
* - `no-initial`: nobody is in the initial group (the group is absent and the totals drop).
|
||||
* - `unclassified`: the initial group folds into "Sin dato" (what 5740's answers look like).
|
||||
* - `unpublished`: the round strata are not in the answers. */
|
||||
export type Simulation = 'as-is' | 'no-initial' | 'unclassified' | 'unpublished';
|
||||
|
||||
type Stratum = {
|
||||
value?: { text?: string };
|
||||
component?: { value?: { text?: string } }[];
|
||||
population?: { code?: { coding?: { code?: string }[] }; count: number }[];
|
||||
};
|
||||
type Stratifier = { code?: { coding?: { code?: string }[] }[]; stratum?: Stratum[] };
|
||||
|
||||
const named = (s: Stratifier) => (s.code ?? []).map((c) => c.coding?.[0]?.code).join('-');
|
||||
const label = (x: Stratum) => x.component?.[0]?.value?.text ?? x.value?.text;
|
||||
const pop = (o: { population?: Stratum['population'] }, code: string) =>
|
||||
o.population?.find((p) => p.code?.coding?.[0]?.code === code);
|
||||
|
||||
function fold(into: Stratum, from: Stratum) {
|
||||
for (const p of from.population ?? []) {
|
||||
const q = pop(into, p.code!.coding![0].code!);
|
||||
if (q) q.count += p.count;
|
||||
else (into.population ??= []).push(structuredClone(p));
|
||||
}
|
||||
}
|
||||
|
||||
export function simulate(report: any, how: Simulation) {
|
||||
const group = report?.group?.[0];
|
||||
if (!group) return report;
|
||||
for (const s of group.stratifier ?? ([] as Stratifier[]))
|
||||
for (const c of s.code ?? []) {
|
||||
const k = c.coding?.[0];
|
||||
if (k?.code === 'screening_round') k.code = 'round';
|
||||
}
|
||||
const rounds: Stratifier[] = (group.stratifier ?? []).filter((s: Stratifier) =>
|
||||
['round', 'round-category'].includes(named(s)),
|
||||
);
|
||||
if (how === 'unpublished')
|
||||
group.stratifier = (group.stratifier ?? []).filter((s: Stratifier) => !rounds.includes(s));
|
||||
if (how === 'no-initial' || how === 'unclassified')
|
||||
for (const s of rounds) {
|
||||
const initial = (s.stratum ?? []).filter((x) => label(x) === 'initial');
|
||||
const rest = (s.stratum ?? []).filter((x) => label(x) !== 'initial');
|
||||
for (const x of initial) {
|
||||
if (how === 'unclassified') {
|
||||
const other = x.component?.[1]?.value?.text;
|
||||
const target = rest.find(
|
||||
(y) => label(y) === 'no_data' && (!other || y.component?.[1]?.value?.text === other),
|
||||
);
|
||||
if (target) fold(target, x);
|
||||
else {
|
||||
(x.component ? x.component[0].value! : x.value!).text = 'no_data';
|
||||
rest.push(x);
|
||||
}
|
||||
} else if (named(s) === 'round') {
|
||||
// the group vanishes and the period's total drops by its patients: a real zero
|
||||
for (const p of x.population ?? []) {
|
||||
const total = pop(group, p.code!.coding![0].code!);
|
||||
if (total && p.code!.coding![0].code !== 'numerator')
|
||||
total.count = Math.max(0, total.count - p.count);
|
||||
}
|
||||
}
|
||||
}
|
||||
s.stratum = rest;
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
/** Answers every CaCu MeasureReport search through `simulate`. */
|
||||
export async function simulateRounds(page: Page, how: Simulation) {
|
||||
await page.route('**/api/cacu/fhir/MeasureReport**', async (route) => {
|
||||
const response = await route.fetch();
|
||||
const body = await response.json();
|
||||
for (const entry of body.entry ?? []) simulate(entry.resource, how);
|
||||
await route.fulfill({
|
||||
response,
|
||||
body: JSON.stringify(body),
|
||||
contentType: 'application/fhir+json',
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user