CaCu indicators: one selector for the cytology and HPV genotype views, grouped bars and genotype labels
This commit is contained in:
+179
-71
@@ -1,4 +1,4 @@
|
|||||||
import { expect, type Page, test } from '@playwright/test';
|
import { expect, type Locator, type Page, test } from '@playwright/test';
|
||||||
import { layoutProblems } from './layout';
|
import { layoutProblems } from './layout';
|
||||||
import { type Simulation, simulateRounds } from './simulated-rounds';
|
import { type Simulation, simulateRounds } from './simulated-rounds';
|
||||||
|
|
||||||
@@ -7,6 +7,17 @@ test.beforeEach(async ({ page }) => {
|
|||||||
expect((await page.request.post('/api/auth/login', { form })).status()).toBe(204);
|
expect((await page.request.post('/api/auth/login', { form })).status()).toBe(204);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const ROUND = { name: 'Por detección inicial y subsecuente' };
|
||||||
|
const VIEWS_LABEL = 'Lectura de la distribución citológica y del VPH por genotipo';
|
||||||
|
const VIEWS = ['General', 'Por grupo de edad', 'Por estatus de seguimiento', ROUND.name];
|
||||||
|
const TITLES = {
|
||||||
|
cytology: 'Distribución de resultados citológicos',
|
||||||
|
genotype: 'Resultados de VPH por genotipo',
|
||||||
|
biopsy: 'Resultados de biopsia cervical',
|
||||||
|
colposcopy: 'Valor predictivo positivo de la colposcopía',
|
||||||
|
ppvBiopsy: 'Valor predictivo positivo de la biopsia',
|
||||||
|
};
|
||||||
|
|
||||||
test('indicadores cacu: its sections in order, each card read one mode at a time', async ({
|
test('indicadores cacu: its sections in order, each card read one mode at a time', async ({
|
||||||
page,
|
page,
|
||||||
}) => {
|
}) => {
|
||||||
@@ -25,7 +36,6 @@ test('indicadores cacu: its sections in order, each card read one mode at a time
|
|||||||
'Distribución de resultados citológicos',
|
'Distribución de resultados citológicos',
|
||||||
'Resultados de VPH por genotipo',
|
'Resultados de VPH por genotipo',
|
||||||
'Resultados de biopsia cervical',
|
'Resultados de biopsia cervical',
|
||||||
'Pacientes evaluadas por resultado de VPH',
|
|
||||||
'Tasa de confirmación histopatológica',
|
'Tasa de confirmación histopatológica',
|
||||||
'Valor predictivo positivo de la colposcopía',
|
'Valor predictivo positivo de la colposcopía',
|
||||||
]);
|
]);
|
||||||
@@ -36,40 +46,59 @@ 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.')),
|
route.getByRole('table', { name: mode }).or(route.getByText('Sin datos en el periodo.')),
|
||||||
).toBeVisible();
|
).toBeVisible();
|
||||||
}
|
}
|
||||||
// the screening round replaces the clinical scenario: the same tab, label and order on four cards
|
// one selector for the cytology distribution and the HPV by genotype; the biopsy card is apart
|
||||||
const round = { name: 'Por detección inicial y subsecuente' };
|
await expect(
|
||||||
|
tab.locator('app-readings', {
|
||||||
|
has: page.getByRole('heading', { name: 'Pacientes evaluadas por resultado de VPH' }),
|
||||||
|
}),
|
||||||
|
).toHaveCount(0);
|
||||||
|
const views = tab.getByRole('radiogroup', { name: VIEWS_LABEL });
|
||||||
|
await expect(views.getByRole('radio')).toHaveText(VIEWS);
|
||||||
|
await expect(views.getByRole('radio', { name: 'General' })).toBeChecked();
|
||||||
await expect(tab.getByRole('radio', { name: 'Por escenario clínico' })).toHaveCount(0);
|
await expect(tab.getByRole('radio', { name: 'Por escenario clínico' })).toHaveCount(0);
|
||||||
for (const card of [
|
for (const view of VIEWS.slice(1)) {
|
||||||
'Distribución de resultados citológicos',
|
await views.getByRole('radio', { name: view }).click();
|
||||||
'Pacientes evaluadas por resultado de VPH',
|
for (const card of [TITLES.cytology, TITLES.genotype]) {
|
||||||
'Valor predictivo positivo de la colposcopía',
|
|
||||||
]) {
|
|
||||||
const readings = tab.locator('app-readings', {
|
const readings = tab.locator('app-readings', {
|
||||||
has: page.getByRole('heading', { name: card }),
|
has: page.getByRole('heading', { name: card }),
|
||||||
});
|
});
|
||||||
await readings.getByRole('radio', round).click();
|
// each card has no toggle of its own: the selector drives both
|
||||||
// rows in the order of the contract, "no disponible", or no patients in the period
|
await expect(readings.getByRole('radio')).toHaveCount(0);
|
||||||
await expect(
|
await expect(
|
||||||
readings
|
readings
|
||||||
.getByRole('table', round)
|
.locator('.group')
|
||||||
.or(readings.locator('app-plot'))
|
.first()
|
||||||
.or(readings.getByText(/No disponible|Sin datos en el periodo/)),
|
.or(readings.getByText(/No disponible|Sin datos en el periodo/)),
|
||||||
).toBeVisible();
|
).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',
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const biopsyCard = tab.locator('app-readings', {
|
||||||
|
has: page.getByRole('heading', { name: TITLES.biopsy }),
|
||||||
|
});
|
||||||
|
await expect(biopsyCard.getByRole('radio')).toHaveCount(0);
|
||||||
|
await views.getByRole('radio', { name: 'General' }).click();
|
||||||
|
await expect(
|
||||||
|
tab
|
||||||
|
.locator('app-readings', { has: page.getByRole('heading', { name: TITLES.cytology }) })
|
||||||
|
.getByRole('table'),
|
||||||
|
).toBeVisible();
|
||||||
|
// the PPV cards keep their round tab, in the same words and order
|
||||||
|
await tab.getByRole('radio', { name: 'Colposcopía', exact: true }).click();
|
||||||
|
const colposcopy = tab.locator('app-readings', {
|
||||||
|
has: page.getByRole('heading', { name: TITLES.colposcopy }),
|
||||||
|
});
|
||||||
|
await colposcopy.getByRole('radio', ROUND).click();
|
||||||
|
await expect(
|
||||||
|
colposcopy
|
||||||
|
.getByRole('table', ROUND)
|
||||||
|
.or(colposcopy.getByText(/No disponible|Sin datos en el periodo/)),
|
||||||
|
).toBeVisible();
|
||||||
await tab.getByRole('radio', { name: 'Biopsia', exact: true }).click();
|
await tab.getByRole('radio', { name: 'Biopsia', exact: true }).click();
|
||||||
await tab
|
await tab
|
||||||
.locator('app-readings', {
|
.locator('app-readings', {
|
||||||
has: page.getByRole('heading', { name: 'Valor predictivo positivo de la biopsia' }),
|
has: page.getByRole('heading', { name: TITLES.ppvBiopsy }),
|
||||||
})
|
})
|
||||||
.getByRole('radio', round)
|
.getByRole('radio', ROUND)
|
||||||
.click();
|
.click();
|
||||||
await expect(
|
await expect(
|
||||||
tab.getByRole('heading', { name: 'Valor predictivo positivo de la biopsia' }),
|
tab.getByRole('heading', { name: 'Valor predictivo positivo de la biopsia' }),
|
||||||
@@ -105,19 +134,28 @@ test('riesgos cacu: ages filter the whole list and a row opens its stages', asyn
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ---- Screening rounds on SIMULATED answers (see simulated-rounds.ts): the groups the contract of
|
// ---- 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.
|
// `rebuild` allows, tried on top of the API's own answers. They show how the page draws them, not the
|
||||||
const ROUND = { name: 'Por detección inicial y subsecuente' };
|
// backend. The shared selector drives the cytology and the HPV-by-genotype cards; the PPV cards keep a tab.
|
||||||
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 = {
|
const BAR = {
|
||||||
initial: 'rgb(95, 127, 154)',
|
initial: 'rgb(95, 127, 154)',
|
||||||
subsequent: 'rgb(143, 167, 187)',
|
subsequent: 'rgb(143, 167, 187)',
|
||||||
no_data: 'rgb(201, 205, 210)',
|
no_data: 'rgb(201, 205, 210)',
|
||||||
};
|
};
|
||||||
|
const GENOTYPE_COLOURS = {
|
||||||
|
Negativo: '#42A77E',
|
||||||
|
'VPH 16': '#DF8640',
|
||||||
|
'VPH 18': '#C29C42',
|
||||||
|
'VPH 16 y 18': '#C24269',
|
||||||
|
Positivo: '#A8C243',
|
||||||
|
};
|
||||||
|
const CYTOLOGY_COLOURS = {
|
||||||
|
Normal: '#408651',
|
||||||
|
'ASC-US': '#2778B8',
|
||||||
|
LIEBG: '#B19525',
|
||||||
|
'ASC-H': '#7955B1',
|
||||||
|
LIEAG: '#CE4778',
|
||||||
|
'Carcinoma in situ': '#AA394D',
|
||||||
|
};
|
||||||
|
|
||||||
async function withRounds(page: Page, how: Simulation) {
|
async function withRounds(page: Page, how: Simulation) {
|
||||||
await simulateRounds(page, how);
|
await simulateRounds(page, how);
|
||||||
@@ -129,23 +167,55 @@ async function withRounds(page: Page, how: Simulation) {
|
|||||||
await expect(tab.locator('app-loading')).toHaveCount(0, { timeout: 5 * 60_000 });
|
await expect(tab.locator('app-loading')).toHaveCount(0, { timeout: 5 * 60_000 });
|
||||||
const card = (title: string) =>
|
const card = (title: string) =>
|
||||||
tab.locator('app-readings', { has: page.getByRole('heading', { name: title }) }).first();
|
tab.locator('app-readings', { has: page.getByRole('heading', { name: title }) }).first();
|
||||||
const open = async (key: keyof typeof TITLES) => {
|
const view = async (name: string) => {
|
||||||
if (key === 'biopsy') await tab.getByRole('radio', { name: 'Biopsia', exact: true }).click();
|
await tab.getByRole('radiogroup', { name: VIEWS_LABEL }).getByRole('radio', { name }).click();
|
||||||
if (key === 'colposcopy')
|
};
|
||||||
await tab.getByRole('radio', { name: 'Colposcopía', exact: true }).click();
|
/** A PPV card on its round tab. */
|
||||||
|
const ppv = async (key: 'colposcopy' | 'ppvBiopsy') => {
|
||||||
|
await tab
|
||||||
|
.getByRole('radio', { name: key === 'colposcopy' ? 'Colposcopía' : 'Biopsia', exact: true })
|
||||||
|
.click();
|
||||||
const readings = card(TITLES[key]);
|
const readings = card(TITLES[key]);
|
||||||
await readings.getByRole('radio', ROUND).click();
|
await readings.getByRole('radio', ROUND).click();
|
||||||
return readings;
|
return readings;
|
||||||
};
|
};
|
||||||
return { tab, open };
|
return { tab, card, view, ppv };
|
||||||
}
|
}
|
||||||
|
/** The first group of independent bars of a card (the cytology and genotype breakdowns). */
|
||||||
|
const plotOf = (readings: Locator) => readings.locator('.group').first();
|
||||||
|
/** The groups of a card as the page draws them: "label<br>n = N", the width of the first bar and the colour of
|
||||||
|
* each category (the first group's rows), in hex. */
|
||||||
|
const traces = (readings: Locator) =>
|
||||||
|
readings.evaluate((el) => {
|
||||||
|
const hex = (rgb: string) =>
|
||||||
|
'#' +
|
||||||
|
(rgb.match(/\d+/g) ?? [])
|
||||||
|
.slice(0, 3)
|
||||||
|
.map((n) => Number(n).toString(16).padStart(2, '0'))
|
||||||
|
.join('')
|
||||||
|
.toUpperCase();
|
||||||
|
const groups = [...el.querySelectorAll('.group')];
|
||||||
|
return {
|
||||||
|
y: groups.map(
|
||||||
|
(g) =>
|
||||||
|
`${g.querySelector('h4')!.childNodes[0].textContent!.trim()}<br>n = ${g.querySelector('.n')!.textContent!.replace('n = ', '').trim()}`,
|
||||||
|
),
|
||||||
|
x: groups.map((g) => parseFloat((g.querySelector('.fill') as HTMLElement).style.width)),
|
||||||
|
colours: Object.fromEntries(
|
||||||
|
[...groups[0].querySelectorAll('.row')].map((r) => [
|
||||||
|
r.querySelector('.name')!.textContent!.trim(),
|
||||||
|
hex(getComputedStyle(r.querySelector('.fill')!).backgroundColor),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
for (const key of ['vph', 'colposcopy', 'biopsy'] as const) {
|
for (const key of ['colposcopy', 'ppvBiopsy'] as const) {
|
||||||
test(`rondas (simulado) ${key}: three groups in order, each with its own colour`, async ({
|
test(`rondas (simulado) ${key}: three groups in order, each with its own colour`, async ({
|
||||||
page,
|
page,
|
||||||
}) => {
|
}) => {
|
||||||
const { open } = await withRounds(page, 'as-is');
|
const { ppv } = await withRounds(page, 'as-is');
|
||||||
const readings = await open(key);
|
const readings = await ppv(key);
|
||||||
const rows = readings.getByRole('row').filter({ has: page.getByRole('rowheader') });
|
const rows = readings.getByRole('row').filter({ has: page.getByRole('rowheader') });
|
||||||
await expect(rows).toHaveCount(3);
|
await expect(rows).toHaveCount(3);
|
||||||
const names = await readings.getByRole('rowheader').allInnerTexts();
|
const names = await readings.getByRole('rowheader').allInnerTexts();
|
||||||
@@ -163,8 +233,8 @@ for (const key of ['vph', 'colposcopy', 'biopsy'] as const) {
|
|||||||
test(`rondas (simulado) ${key}: an empty initial group is zero patients, not hidden`, async ({
|
test(`rondas (simulado) ${key}: an empty initial group is zero patients, not hidden`, async ({
|
||||||
page,
|
page,
|
||||||
}) => {
|
}) => {
|
||||||
const { open } = await withRounds(page, 'no-initial');
|
const { ppv } = await withRounds(page, 'no-initial');
|
||||||
const readings = await open(key);
|
const readings = await ppv(key);
|
||||||
const initial = readings.getByRole('row').filter({ hasText: 'Detección inicial' });
|
const initial = readings.getByRole('row').filter({ hasText: 'Detección inicial' });
|
||||||
await expect(initial).toContainText('Sin pacientes en el periodo');
|
await expect(initial).toContainText('Sin pacientes en el periodo');
|
||||||
await expect(initial).toContainText('0/0');
|
await expect(initial).toContainText('0/0');
|
||||||
@@ -173,58 +243,96 @@ for (const key of ['vph', 'colposcopy', 'biopsy'] as const) {
|
|||||||
test(`rondas (simulado) ${key}: without the stratum the card says it is not available`, async ({
|
test(`rondas (simulado) ${key}: without the stratum the card says it is not available`, async ({
|
||||||
page,
|
page,
|
||||||
}) => {
|
}) => {
|
||||||
const { open } = await withRounds(page, 'unpublished');
|
const { ppv } = await withRounds(page, 'unpublished');
|
||||||
const readings = await open(key);
|
const readings = await ppv(key);
|
||||||
await expect(readings).toContainText('No disponible');
|
await expect(readings).toContainText('No disponible');
|
||||||
await expect(readings.getByRole('table', ROUND)).toHaveCount(0);
|
await expect(readings.getByRole('table', ROUND)).toHaveCount(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
test('rondas (simulado) cytology: the bars follow the round and the cytology colours', async ({
|
for (const card of ['cytology', 'genotype'] as const) {
|
||||||
|
test(`rondas (simulado) ${card}: the selector draws the rounds in order, with the category colours`, async ({
|
||||||
page,
|
page,
|
||||||
}) => {
|
}) => {
|
||||||
const { open } = await withRounds(page, 'as-is');
|
const { card: of, view } = await withRounds(page, 'as-is');
|
||||||
const readings = await open('cytology');
|
await view(ROUND.name);
|
||||||
const plot = readings.locator('.js-plotly-plot');
|
const readings = of(TITLES[card]);
|
||||||
await expect(plot).toBeVisible();
|
await expect(plotOf(readings)).toBeVisible();
|
||||||
const { y, colours } = await plot.evaluate((e: any) => ({
|
const found = await traces(readings);
|
||||||
y: e.data[0].y as string[],
|
expect(found.y.map((l) => l.split('<br>')[0])).toEqual([
|
||||||
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 inicial',
|
||||||
'Detección subsecuente',
|
'Detección subsecuente',
|
||||||
'Sin dato',
|
'Sin dato',
|
||||||
]);
|
]);
|
||||||
expect(colours).toMatchObject({
|
expect(found.colours).toMatchObject(card === 'cytology' ? CYTOLOGY_COLOURS : GENOTYPE_COLOURS);
|
||||||
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 ({
|
test(`rondas (simulado) ${card}: an empty initial group is an empty bar with its zero`, async ({
|
||||||
page,
|
page,
|
||||||
}) => {
|
}) => {
|
||||||
const { open } = await withRounds(page, 'unclassified');
|
const { card: of, view } = await withRounds(page, 'no-initial');
|
||||||
const readings = await open('vph');
|
await view(ROUND.name);
|
||||||
const rows = readings.getByRole('row').filter({ has: page.getByRole('rowheader') });
|
const found = await traces(of(TITLES[card]));
|
||||||
await expect(rows.filter({ hasText: 'Detección inicial' })).toContainText('0/0');
|
expect(found.y[0]).toBe('Detección inicial<br>n = 0');
|
||||||
await expect(rows.filter({ hasText: 'Sin dato' })).not.toContainText('0/0');
|
expect(found.x[0]).toBe(0);
|
||||||
await expect(readings).toContainText('una categoría en cero significa');
|
});
|
||||||
|
|
||||||
|
test(`rondas (simulado) ${card}: without the stratum the selector says it is not available`, async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
const { card: of, view } = await withRounds(page, 'unpublished');
|
||||||
|
await view(ROUND.name);
|
||||||
|
await expect(of(TITLES[card])).toContainText('No disponible');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
test('rondas (simulado): the genotype card never shows the incomplete positives, and says where they went', async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
const { card, view } = await withRounds(page, 'as-is');
|
||||||
|
const readings = card(TITLES.genotype);
|
||||||
|
await expect(readings).toContainText('«Positivo»');
|
||||||
|
await expect(readings.getByRole('rowheader')).not.toContainText([
|
||||||
|
'Otro de alto riesgo',
|
||||||
|
'incompleto',
|
||||||
|
]);
|
||||||
|
const labels = await readings.getByRole('rowheader').allInnerTexts();
|
||||||
|
expect(labels.map((l) => l.trim())).toEqual([
|
||||||
|
'Negativo',
|
||||||
|
'VPH 16',
|
||||||
|
'VPH 18',
|
||||||
|
'VPH 16 y 18',
|
||||||
|
'Positivo',
|
||||||
|
]);
|
||||||
|
for (const name of VIEWS.slice(1)) {
|
||||||
|
await view(name);
|
||||||
|
const found = await traces(readings);
|
||||||
|
expect(Object.keys(found.colours)).toEqual(Object.keys(GENOTYPE_COLOURS));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const width of [1440, 480]) {
|
for (const width of [1440, 480]) {
|
||||||
test(`rondas (simulado) at ${width} px: the four cards open on their rounds lay out cleanly`, async ({
|
test(`rondas (simulado) at ${width} px: the shared selector on each view lays out cleanly`, async ({
|
||||||
page,
|
page,
|
||||||
}) => {
|
}) => {
|
||||||
await page.setViewportSize({ width, height: 1000 });
|
await page.setViewportSize({ width, height: 1000 });
|
||||||
const { open } = await withRounds(page, 'as-is');
|
const { view, ppv } = await withRounds(page, 'as-is');
|
||||||
for (const key of ['cytology', 'vph', 'colposcopy', 'biopsy'] as const) await open(key);
|
for (const name of VIEWS) {
|
||||||
await page.waitForTimeout(1500);
|
await view(name);
|
||||||
|
await page.waitForTimeout(1200);
|
||||||
|
// every option of the selector is inside the window (it wraps on a narrow screen)
|
||||||
|
for (const box of await page
|
||||||
|
.getByRole('radiogroup', { name: VIEWS_LABEL })
|
||||||
|
.getByRole('radio')
|
||||||
|
.evaluateAll((els) =>
|
||||||
|
els.map((e) => e.closest('mat-button-toggle')!.getBoundingClientRect().right),
|
||||||
|
))
|
||||||
|
expect(box).toBeLessThanOrEqual(width);
|
||||||
|
expect(await layoutProblems(page), name).toEqual([]);
|
||||||
|
}
|
||||||
|
await ppv('colposcopy');
|
||||||
|
await ppv('ppvBiopsy');
|
||||||
|
await page.waitForTimeout(1200);
|
||||||
expect(await layoutProblems(page)).toEqual([]);
|
expect(await layoutProblems(page)).toEqual([]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import type { Page } from '@playwright/test';
|
|||||||
* groups the contract of `rebuild` allows (stratum `round`, crossed `round-category`) without
|
* 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.
|
* 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`.
|
* - `as-is`: the answers untouched, with a stratum named `screening_round` renamed `round`.
|
||||||
* - `no-initial`: nobody is in the initial group (the group is absent and the totals drop).
|
* - `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).
|
* - `unclassified`: the initial group folds into "Sin dato" (what 5740's answers look like).
|
||||||
* - `unpublished`: the round strata are not in the answers. */
|
* - `unpublished`: the round strata are not in the answers. */
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { bars, unavailable } from './bars';
|
import { bars, grouped, hiddenNote, Mode, unavailable } from './bars';
|
||||||
import { scenarioBars } from './figures';
|
import { scenarioBars } from './figures';
|
||||||
import { Reading } from './measures';
|
import { Reading } from './measures';
|
||||||
|
|
||||||
@@ -148,6 +148,7 @@ describe('bars', () => {
|
|||||||
? 'Detección subsecuente'
|
? 'Detección subsecuente'
|
||||||
: 'Sin dato',
|
: 'Sin dato',
|
||||||
['initial', 'subsequent', 'no_data'],
|
['initial', 'subsequent', 'no_data'],
|
||||||
|
{ fill: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
it('keeps the order and shows each bar with its n, an empty one included', () => {
|
it('keeps the order and shows each bar with its n, an empty one included', () => {
|
||||||
@@ -168,3 +169,162 @@ describe('bars', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('shared views of cytology and HPV by genotype', () => {
|
||||||
|
const HPV = [
|
||||||
|
{ code: 'negative', label: 'Negativo', color: '#42A77E', group: '' },
|
||||||
|
{ code: 'positive_other', label: 'Positivo', color: '#A8C243', group: '' },
|
||||||
|
];
|
||||||
|
const reading = (cells: Record<string, number>): Reading => ({
|
||||||
|
populations: { 'initial-population': Object.values(cells).reduce((a, b) => a + b, 0) },
|
||||||
|
strata: {
|
||||||
|
category: {
|
||||||
|
negative: { 'initial-population': 5 },
|
||||||
|
positive_other: { 'initial-population': 2 },
|
||||||
|
positive_incomplete: { 'initial-population': 3 },
|
||||||
|
},
|
||||||
|
'age_group-category': Object.fromEntries(
|
||||||
|
Object.entries(cells).map(([k, n]) => [k, { 'initial-population': n }]),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const counts: Mode = {
|
||||||
|
kind: 'counts',
|
||||||
|
label: 'General',
|
||||||
|
measure: 'M',
|
||||||
|
catalog: HPV,
|
||||||
|
hidden: { codes: ['positive_incomplete', 'inconsistent'], unit: 'reportes' },
|
||||||
|
};
|
||||||
|
|
||||||
|
it('does not list a hidden category but keeps it in the total and the percentages', () => {
|
||||||
|
const t = bars(counts, () => reading({}))!;
|
||||||
|
expect(t.rows.map((x) => x.label)).toEqual(['Negativo', 'Positivo']);
|
||||||
|
expect(t.rows.map((x) => x.cells)).toEqual([
|
||||||
|
['5', '50.0 %'],
|
||||||
|
['2', '20.0 %'],
|
||||||
|
]); // of 10 reports
|
||||||
|
expect(t.note).toBe(
|
||||||
|
'3 reportes (Positivo con genotipificación incompleta) no se muestran desglosados; están incluidos en el total y en los porcentajes.',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('says nothing when no report is hidden', () => {
|
||||||
|
const r: Reading = {
|
||||||
|
populations: {},
|
||||||
|
strata: { category: { negative: { 'initial-population': 1 } } },
|
||||||
|
};
|
||||||
|
expect(hiddenNote(counts, () => r)).toBeUndefined();
|
||||||
|
});
|
||||||
|
it('a figure by groups is not available without its breakdown, and counts every record of the group on request', () => {
|
||||||
|
const mode = {
|
||||||
|
kind: 'figure',
|
||||||
|
label: 'Por grupo de edad',
|
||||||
|
measure: 'M',
|
||||||
|
figure: 'scenarios',
|
||||||
|
stratum: 'age_group',
|
||||||
|
catalog: HPV,
|
||||||
|
} as const;
|
||||||
|
const noBreakdown: Reading = {
|
||||||
|
populations: { 'initial-population': 4 },
|
||||||
|
strata: { category: {} },
|
||||||
|
};
|
||||||
|
expect(unavailable(mode, () => noBreakdown)).toBe(
|
||||||
|
'No disponible: el informe de este periodo no publica el desglose «Por grupo de edad».',
|
||||||
|
);
|
||||||
|
const r: Reading = {
|
||||||
|
populations: { 'initial-population': 10 },
|
||||||
|
strata: {
|
||||||
|
'age_group-category': {
|
||||||
|
'25-34|negative': { 'initial-population': 4 },
|
||||||
|
'25-34|positive_other': { 'initial-population': 1 },
|
||||||
|
'25-34|positive_incomplete': { 'initial-population': 5 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const label = (c: string) => c;
|
||||||
|
const own = scenarioBars(r, { groups: [], categories: HPV }, 'age_group', label, ['25-34']);
|
||||||
|
const all = scenarioBars(r, { groups: [], categories: HPV }, 'age_group', label, ['25-34'], {
|
||||||
|
ofAll: true,
|
||||||
|
});
|
||||||
|
expect((own.data[0] as any).x).toEqual([80]); // 4 of the 5 the catalog draws
|
||||||
|
expect((all.data[0] as any).x).toEqual([40]); // 4 of the group's 10 reports
|
||||||
|
expect((all.data[0] as any).y).toEqual(['25-34<br>n = 10']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('independent bars by group', () => {
|
||||||
|
const cats = [
|
||||||
|
{ code: 'NILM', label: 'Normal', color: '#408651' },
|
||||||
|
{ code: 'HSIL', label: 'LIEAG', color: '#CE4778' },
|
||||||
|
];
|
||||||
|
const mode = (more: object = {}): Mode =>
|
||||||
|
({
|
||||||
|
kind: 'grouped',
|
||||||
|
label: 'x',
|
||||||
|
measure: 'M',
|
||||||
|
catalog: cats,
|
||||||
|
stratum: 'round',
|
||||||
|
order: ['initial', 'subsequent', 'no_data'],
|
||||||
|
unit: 'pacientes',
|
||||||
|
...more,
|
||||||
|
}) as Mode;
|
||||||
|
const reading = (cells: Record<string, number>, total?: number): Reading => ({
|
||||||
|
populations: { 'initial-population': total ?? Object.values(cells).reduce((a, b) => a + b, 0) },
|
||||||
|
strata: {
|
||||||
|
'round-category': Object.fromEntries(
|
||||||
|
Object.entries(cells).map(([k, n]) => [k, { 'initial-population': n }]),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
it('draws one bar per category in each group: count, denominator and percent over its own records', () => {
|
||||||
|
const g = grouped(mode(), () =>
|
||||||
|
reading({ 'initial|NILM': 3, 'initial|HSIL': 1, 'subsequent|NILM': 6 }),
|
||||||
|
)!;
|
||||||
|
expect(g.groups.map((x) => [x.label, x.total])).toEqual([
|
||||||
|
['Detección inicial', 4],
|
||||||
|
['Detección subsecuente', 6],
|
||||||
|
]);
|
||||||
|
expect(g.groups[0].rows.map((r) => [r.label, r.text, r.percent, r.color])).toEqual([
|
||||||
|
['Normal', '3/4 · 75.0 %', 75, '#408651'],
|
||||||
|
['LIEAG', '1/4 · 25.0 %', 25, '#CE4778'],
|
||||||
|
]);
|
||||||
|
expect(g.groups[1].rows.map((r) => r.text)).toEqual(['6/6 · 100.0 %', '0/6 · 0.0 %']); // a zero numerator is 0 %
|
||||||
|
});
|
||||||
|
it('an empty group has no percent; with complete it is drawn only when the counts reconcile', () => {
|
||||||
|
const empty = grouped(mode({ complete: true }), () =>
|
||||||
|
reading({ 'subsequent|NILM': 2, 'no_data|HSIL': 1 }),
|
||||||
|
)!;
|
||||||
|
expect(empty.groups.map((x) => x.code)).toEqual(['initial', 'subsequent', 'no_data']);
|
||||||
|
expect(empty.groups[0]).toMatchObject({ total: 0, hint: 'Sin pacientes en el grupo' });
|
||||||
|
expect(empty.groups[0].rows.map((r) => [r.text, r.percent])).toEqual([
|
||||||
|
['0/0 · —', undefined],
|
||||||
|
['0/0 · —', undefined],
|
||||||
|
]);
|
||||||
|
expect(empty.note).toContain('una categoría en cero significa');
|
||||||
|
const unreconciled = grouped(mode({ complete: true }), () =>
|
||||||
|
reading({ 'subsequent|NILM': 2 }, 5),
|
||||||
|
)!;
|
||||||
|
expect(unreconciled.groups.map((x) => x.code)).toEqual(['subsequent']);
|
||||||
|
expect(unreconciled.note).toContain('no concilian');
|
||||||
|
const open = grouped(mode(), () => reading({ 'subsequent|NILM': 2 }))!;
|
||||||
|
expect(open.groups.map((x) => x.code)).toEqual(['subsequent']); // without complete: only the listed groups
|
||||||
|
});
|
||||||
|
it('each group may count all its records, hidden categories included', () => {
|
||||||
|
const r = reading({ 'initial|NILM': 2, 'initial|positive_incomplete': 2 });
|
||||||
|
const own = grouped(mode(), () => r)!;
|
||||||
|
const all = grouped(mode({ ofAll: true }), () => r)!;
|
||||||
|
expect(own.groups[0].total).toBe(2);
|
||||||
|
expect(all.groups[0].total).toBe(4);
|
||||||
|
expect(all.groups[0].rows[0].text).toBe('2/4 · 50.0 %');
|
||||||
|
});
|
||||||
|
it('is not available without the breakdown, and draws nothing without records', () => {
|
||||||
|
const none: Reading = { populations: { 'initial-population': 4 }, strata: {} };
|
||||||
|
expect(grouped(mode(), () => none)).toBeUndefined();
|
||||||
|
expect(unavailable(mode(), () => none)).toContain('No disponible');
|
||||||
|
expect(grouped(mode(), () => reading({}, 0))).toBeUndefined();
|
||||||
|
});
|
||||||
|
it('says that unclassified records leave a classified group empty, and warns when none is classified', () => {
|
||||||
|
const lone = grouped(mode({ complete: true }), () => reading({ 'no_data|NILM': 3 }))!;
|
||||||
|
expect(lone.note).toContain('información no registrada');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
+142
-8
@@ -7,7 +7,7 @@ export type Category = { code: string; label: string; color: string };
|
|||||||
|
|
||||||
/** One way of reading a card, as bars from the reports, or a figure. */
|
/** One way of reading a card, as bars from the reports, or a figure. */
|
||||||
export type Mode = { label: string; caption?: string } & (
|
export type Mode = { label: string; caption?: string } & (
|
||||||
| { kind: 'counts'; measure: string; catalog: Category[] }
|
| { kind: 'counts'; measure: string; catalog: Category[]; hidden?: Hidden }
|
||||||
| {
|
| {
|
||||||
kind: 'shares';
|
kind: 'shares';
|
||||||
measure: string;
|
measure: string;
|
||||||
@@ -25,6 +25,22 @@ export type Mode = { label: string; caption?: string } & (
|
|||||||
colors?: Colors;
|
colors?: Colors;
|
||||||
}
|
}
|
||||||
| { kind: 'signs'; measure: string; strata: string[]; colors?: Colors }
|
| { kind: 'signs'; measure: string; strata: string[]; colors?: Colors }
|
||||||
|
| {
|
||||||
|
kind: 'grouped';
|
||||||
|
measure: string;
|
||||||
|
/** the categories drawn in each group, in this order (each in its own colour) */
|
||||||
|
catalog: Category[];
|
||||||
|
/** the groups' stratifier (its crossed cells `<stratum>-category`) and their order */
|
||||||
|
stratum: string;
|
||||||
|
order: string[];
|
||||||
|
/** what the records are called ("pacientes", "reportes") */
|
||||||
|
unit: string;
|
||||||
|
/** draw an empty group of `order` when the counts reconcile (see `reconciles`) */
|
||||||
|
complete?: boolean;
|
||||||
|
/** each group's denominator is all its records, not only those of the catalog's categories */
|
||||||
|
ofAll?: boolean;
|
||||||
|
hidden?: Hidden;
|
||||||
|
}
|
||||||
| { kind: 'days'; steps: { label: string; measure: string }[]; tint?: Tint }
|
| { kind: 'days'; steps: { label: string; measure: string }[]; tint?: Tint }
|
||||||
| { kind: 'days-by'; measure: string; stratum: string; tint?: Tint }
|
| { kind: 'days-by'; measure: string; stratum: string; tint?: Tint }
|
||||||
| {
|
| {
|
||||||
@@ -37,15 +53,48 @@ export type Mode = { label: string; caption?: string } & (
|
|||||||
/** the stratifier a scenarios figure crosses with the category (default: the follow-up status) */
|
/** the stratifier a scenarios figure crosses with the category (default: the follow-up status) */
|
||||||
stratum?: string;
|
stratum?: string;
|
||||||
order?: string[];
|
order?: string[];
|
||||||
|
/** draw the groups of `order` the report leaves out as zero (see `reconciles`) */
|
||||||
complete?: boolean;
|
complete?: boolean;
|
||||||
|
/** each bar is the share of all the group's records, not only of those the catalog draws */
|
||||||
|
ofAll?: boolean;
|
||||||
|
hidden?: Hidden;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** Categories a card does not draw: their records stay in the total and in the percentages. */
|
||||||
|
export type Hidden = { codes: string[]; unit: string };
|
||||||
|
|
||||||
/** A colour by category code (the category decides it, not its place in the report). */
|
/** A colour by category code (the category decides it, not its place in the report). */
|
||||||
export type Colors = Record<string, string>;
|
export type Colors = Record<string, string>;
|
||||||
/** The colours of a median bar and of the marks of its quartiles. */
|
/** The colours of a median bar and of the marks of its quartiles. */
|
||||||
export type Tint = { bar: string; mark: string };
|
export type Tint = { bar: string; mark: string };
|
||||||
|
|
||||||
|
/** One category of a group as an independent bar of 0 to 100 %: its records over the group's. */
|
||||||
|
export interface GroupRow {
|
||||||
|
label: string;
|
||||||
|
color: string;
|
||||||
|
count: number;
|
||||||
|
/** the group's records (the denominator) */
|
||||||
|
of: number;
|
||||||
|
/** none when the group has no records: a rate over nothing is not drawn */
|
||||||
|
percent?: number;
|
||||||
|
/** "2/5 · 40.0 %"; "0/0 · —" for an empty group */
|
||||||
|
text: string;
|
||||||
|
}
|
||||||
|
export interface Group {
|
||||||
|
code: string;
|
||||||
|
label: string;
|
||||||
|
/** the group's records */
|
||||||
|
total: number;
|
||||||
|
/** why the group has no figures */
|
||||||
|
hint?: string;
|
||||||
|
rows: GroupRow[];
|
||||||
|
}
|
||||||
|
export interface Groups {
|
||||||
|
groups: Group[];
|
||||||
|
note?: string;
|
||||||
|
}
|
||||||
|
|
||||||
/** One bar: its length and quartile marks in % of the scale, and its cells of text. */
|
/** One bar: its length and quartile marks in % of the scale, and its cells of text. */
|
||||||
export interface Bar {
|
export interface Bar {
|
||||||
label: string;
|
label: string;
|
||||||
@@ -84,20 +133,38 @@ export function reconciles(listed: number[], total: number): boolean {
|
|||||||
export const patients = (r?: Reading) =>
|
export const patients = (r?: Reading) =>
|
||||||
r?.populations['initial-population'] ?? r?.populations['denominator'] ?? 0;
|
r?.populations['initial-population'] ?? r?.populations['denominator'] ?? 0;
|
||||||
|
|
||||||
/** Why a card of a "complete" mode has nothing to draw though its period has patients: the report
|
/** Why a card of a "complete" mode, or a figure by groups, has nothing to draw though its period
|
||||||
* does not publish the stratifier. Undefined when there is nothing to say. */
|
* has records: the report does not publish the breakdown. Undefined when there is nothing to say. */
|
||||||
export function unavailable(
|
export function unavailable(
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
of: (measure: string) => Reading | undefined,
|
of: (measure: string) => Reading | undefined,
|
||||||
): string | undefined {
|
): string | undefined {
|
||||||
if (!('complete' in mode) || !mode.complete || !('stratum' in mode) || !mode.stratum)
|
const groups = mode.kind === 'grouped' || (mode.kind === 'figure' && mode.figure === 'scenarios');
|
||||||
return undefined;
|
const complete = 'complete' in mode && mode.complete;
|
||||||
|
if (!(groups || complete) || !('stratum' in mode) || !mode.stratum) return undefined;
|
||||||
const r = of(mode.measure);
|
const r = of(mode.measure);
|
||||||
if (!patients(r)) return undefined;
|
if (!patients(r)) return undefined;
|
||||||
const key = mode.kind === 'shares' ? mode.stratum : `${mode.stratum}-category`;
|
const key = mode.kind === 'shares' ? mode.stratum : `${mode.stratum}-category`;
|
||||||
return Object.keys(r?.strata[key] ?? {}).length
|
return Object.keys(r?.strata[key] ?? {}).length
|
||||||
? undefined
|
? undefined
|
||||||
: `${NOT_AVAILABLE}: el informe de este periodo no publica la clasificación por detección inicial o subsecuente.`;
|
: `${NOT_AVAILABLE}: el informe de este periodo no publica el desglose «${mode.label}».`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** What a card says about the categories it does not draw: how many records they hold and that
|
||||||
|
* they stay in the total and the percentages. Undefined when none is in the period. */
|
||||||
|
export function hiddenNote(
|
||||||
|
mode: Mode,
|
||||||
|
of: (measure: string) => Reading | undefined,
|
||||||
|
): string | undefined {
|
||||||
|
if (!('hidden' in mode) || !mode.hidden) return undefined;
|
||||||
|
const { codes, unit } = mode.hidden;
|
||||||
|
const cells = of(mode.measure)?.strata['category'] ?? {};
|
||||||
|
const found = codes.filter((c) => size(cells[c]));
|
||||||
|
if (!found.length) return undefined;
|
||||||
|
const n = found.reduce((t, c) => t + size(cells[c]), 0);
|
||||||
|
const names = found.map((c) => name(c)).join(', ');
|
||||||
|
const one = n === 1;
|
||||||
|
return `${n} ${one ? unit.replace(/s$/, '') : unit} (${names}) ${one ? 'no se muestra desglosado; está incluido' : 'no se muestran desglosados; están incluidos'} en el total y en los porcentajes.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pct = (n: number, of: number) => (of ? `${((100 * n) / of).toFixed(1)} %` : '—');
|
const pct = (n: number, of: number) => (of ? `${((100 * n) / of).toFixed(1)} %` : '—');
|
||||||
@@ -112,10 +179,11 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
|
|||||||
const total = Object.values(cells).reduce((n, c) => n + size(c), 0);
|
const total = Object.values(cells).reduce((n, c) => n + size(c), 0);
|
||||||
if (!total) return undefined;
|
if (!total) return undefined;
|
||||||
// a category outside the catalog is listed after it, so the shares add up
|
// a category outside the catalog is listed after it, so the shares add up
|
||||||
|
const hidden = mode.hidden?.codes ?? [];
|
||||||
const named = mode.catalog.map((c) => c.code);
|
const named = mode.catalog.map((c) => c.code);
|
||||||
const rest = Object.keys(cells).filter((c) => !named.includes(c));
|
const rest = Object.keys(cells).filter((c) => !named.includes(c) && !hidden.includes(c));
|
||||||
const all = [
|
const all = [
|
||||||
...mode.catalog,
|
...mode.catalog.filter((c) => !hidden.includes(c.code)),
|
||||||
...rest.map((code) => ({ code, label: name(code), color: NEUTRAL_DARK })),
|
...rest.map((code) => ({ code, label: name(code), color: NEUTRAL_DARK })),
|
||||||
];
|
];
|
||||||
const most = Math.max(...Object.values(cells).map(size));
|
const most = Math.max(...Object.values(cells).map(size));
|
||||||
@@ -126,6 +194,7 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
|
|||||||
const cols = [`${n}`, pct(n, total)];
|
const cols = [`${n}`, pct(n, total)];
|
||||||
return { label, color, width: (100 * n) / most, marks: [], cells: cols };
|
return { label, color, width: (100 * n) / most, marks: [], cells: cols };
|
||||||
}),
|
}),
|
||||||
|
note: hiddenNote(mode, of),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case 'shares': {
|
case 'shares': {
|
||||||
@@ -226,6 +295,71 @@ export function bars(mode: Mode, of: (measure: string) => Reading | undefined):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 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`). */
|
||||||
|
export function grouped(
|
||||||
|
mode: Mode,
|
||||||
|
of: (measure: string) => Reading | undefined,
|
||||||
|
): Groups | undefined {
|
||||||
|
if (mode.kind !== 'grouped') return undefined;
|
||||||
|
const r = of(mode.measure);
|
||||||
|
const cells = r?.strata[`${mode.stratum}-category`] ?? {};
|
||||||
|
const found = [...new Set(Object.keys(cells).map((k) => k.split('|')[0]))];
|
||||||
|
if (!patients(r) || !found.length) return undefined;
|
||||||
|
const n = (g: string, c: string) => size(cells[`${g}|${c}`]);
|
||||||
|
const reconciled = reconciles(
|
||||||
|
Object.values(cells).map((c) => c['initial-population']),
|
||||||
|
patients(r),
|
||||||
|
);
|
||||||
|
const codes = [
|
||||||
|
...mode.order.filter((g) => found.includes(g) || (mode.complete && reconciled)),
|
||||||
|
...found.filter((g) => !mode.order.includes(g)),
|
||||||
|
];
|
||||||
|
const total = (g: string) =>
|
||||||
|
mode.ofAll
|
||||||
|
? Object.entries(cells)
|
||||||
|
.filter(([k]) => k.split('|')[0] === g)
|
||||||
|
.reduce((t, [, c]) => t + size(c), 0)
|
||||||
|
: mode.catalog.reduce((t, c) => t + n(g, c.code), 0);
|
||||||
|
const groups: Group[] = codes.map((code) => {
|
||||||
|
const den = total(code);
|
||||||
|
return {
|
||||||
|
code,
|
||||||
|
label: name(code),
|
||||||
|
total: den,
|
||||||
|
hint: den ? undefined : `Sin ${mode.unit} en el grupo`,
|
||||||
|
rows: mode.catalog.map((c) => {
|
||||||
|
const count = n(code, c.code);
|
||||||
|
const percent = den ? (100 * count) / den : undefined;
|
||||||
|
return {
|
||||||
|
label: c.label,
|
||||||
|
color: c.color,
|
||||||
|
count,
|
||||||
|
of: den,
|
||||||
|
percent,
|
||||||
|
text: `${count}/${den} · ${percent === undefined ? '—' : percent.toFixed(1) + ' %'}`,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
let note = hiddenNote(mode, of);
|
||||||
|
if (mode.complete) {
|
||||||
|
const unclassified = total('no_data');
|
||||||
|
const classified = groups.filter((g) => g.code !== 'no_data');
|
||||||
|
const none = classified.every((g) => !g.total);
|
||||||
|
const sentence = !reconciled
|
||||||
|
? '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;
|
||||||
|
note = [sentence, note].filter(Boolean).join(' ') || undefined;
|
||||||
|
}
|
||||||
|
return { groups, note };
|
||||||
|
}
|
||||||
|
|
||||||
/** Every group of a stratifier the card names, in its order: those the report lists with their
|
/** Every group of a stratifier the card names, in its order: those the report lists with their
|
||||||
* counts; those it leaves out as no patients when the counts add up to the period's patients,
|
* counts; those it leaves out as no patients when the counts add up to the period's patients,
|
||||||
* else as not available. "Sin dato" keeps its own counts. */
|
* else as not available. "Sin dato" keeps its own counts. */
|
||||||
|
|||||||
@@ -10,11 +10,12 @@ import {
|
|||||||
REQUEST_COLORS,
|
REQUEST_COLORS,
|
||||||
ROUND_COLORS,
|
ROUND_COLORS,
|
||||||
STEEL,
|
STEEL,
|
||||||
VPH_DONUT,
|
|
||||||
} from './cacu-palette';
|
} from './cacu-palette';
|
||||||
import type { Measure } from 'fhir/r4';
|
import type { Measure } from 'fhir/r4';
|
||||||
import { donut, Reading } from './measures';
|
import { donut, Reading } from './measures';
|
||||||
|
|
||||||
|
const VPH = { negative: HPV_COLORS['negative'], positive: HPV_COLORS['positive_other'] };
|
||||||
|
|
||||||
describe('CaCu palette', () => {
|
describe('CaCu palette', () => {
|
||||||
it('a PPV group has the colour of its category elsewhere on the page', () => {
|
it('a PPV group has the colour of its category elsewhere on the page', () => {
|
||||||
expect(PPV_CYTOLOGY_COLORS['ascus_plus']).toBe(CYTOLOGY_COLORS['ASC-US']);
|
expect(PPV_CYTOLOGY_COLORS['ascus_plus']).toBe(CYTOLOGY_COLORS['ASC-US']);
|
||||||
@@ -48,15 +49,9 @@ describe('CaCu palette', () => {
|
|||||||
strata: { category: Object.fromEntries(order.map((c) => [c, { 'initial-population': 1 }])) },
|
strata: { category: Object.fromEntries(order.map((c) => [c, { 'initial-population': 1 }])) },
|
||||||
});
|
});
|
||||||
const colours = (order: string[]) =>
|
const colours = (order: string[]) =>
|
||||||
(donut(measure, cells(order), 'category', VPH_DONUT).data[0] as any).marker.colors;
|
(donut(measure, cells(order), 'category', VPH).data[0] as any).marker.colors;
|
||||||
expect(colours(['negative', 'positive'])).toEqual([
|
expect(colours(['negative', 'positive'])).toEqual([VPH['negative'], VPH['positive']]);
|
||||||
VPH_DONUT['negative'],
|
expect(colours(['positive', 'negative'])).toEqual([VPH['positive'], VPH['negative']]);
|
||||||
VPH_DONUT['positive'],
|
|
||||||
]);
|
|
||||||
expect(colours(['positive', 'negative'])).toEqual([
|
|
||||||
VPH_DONUT['positive'],
|
|
||||||
VPH_DONUT['negative'],
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
it('bars take their colour from the mode by group, absent groups included', () => {
|
it('bars take their colour from the mode by group, absent groups included', () => {
|
||||||
const r: Reading = {
|
const r: Reading = {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/** The colours of CaCu's charts, by category. A colour names a category (never a position in a
|
/** The colours of CaCu's charts, by category. A colour names a category (never a position in a
|
||||||
* report, never a threshold), so the same category looks the same on every card; neutral greys
|
* report, never a threshold), so the same category looks the same on every card; neutral greys
|
||||||
* are for what is absent or not classified. They are the ones CaCu's page had before the
|
* are for what is absent or not classified. They live here, not in the shared palette, so that no
|
||||||
* rebuild, kept here so that no other domain (CaMa, TEA) changes with them. */
|
* other domain (CaMa, TEA) takes them. */
|
||||||
|
|
||||||
/** Not classified, or no data. */
|
/** Not classified, or no data. */
|
||||||
export const NEUTRAL = '#C9CDD2';
|
export const NEUTRAL = '#C9CDD2';
|
||||||
@@ -66,17 +66,6 @@ export const ROUND_COLORS: Record<string, string> = {
|
|||||||
no_data: NEUTRAL,
|
no_data: NEUTRAL,
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Follow-up status and age groups, as the HPV card drew them. */
|
|
||||||
export const STATUS_COLORS: Record<string, string> = {
|
|
||||||
pre_colposcopy: STEEL,
|
|
||||||
post_colposcopy: STEEL_MID,
|
|
||||||
post_treatment: STEEL_LIGHT,
|
|
||||||
case: NEUTRAL_DARK,
|
|
||||||
};
|
|
||||||
export const AGE_COLORS: Record<string, string> = Object.fromEntries(
|
|
||||||
['<25', '25-34', '35-44', '45-54', '55-64', '65+'].map((c) => [c, STEEL]),
|
|
||||||
);
|
|
||||||
|
|
||||||
/** Referral PPV groups: cytology and histology levels by the colour of their category, HPV by
|
/** Referral PPV groups: cytology and histology levels by the colour of their category, HPV by
|
||||||
* genotype. */
|
* genotype. */
|
||||||
export const PPV_CYTOLOGY_COLORS: Record<string, string> = {
|
export const PPV_CYTOLOGY_COLORS: Record<string, string> = {
|
||||||
@@ -91,11 +80,7 @@ export const PPV_LEVEL_COLORS: Record<string, string> = {
|
|||||||
carcinoma: BIOPSY_COLORS['carcinoma'],
|
carcinoma: BIOPSY_COLORS['carcinoma'],
|
||||||
};
|
};
|
||||||
|
|
||||||
/** The whole of a CaCu card as a donut: the colours of its two parts. */
|
/** The whole of a PPV card as a donut: the colours of its two parts. */
|
||||||
export const VPH_DONUT: Record<string, string> = {
|
|
||||||
negative: HPV_COLORS['negative'],
|
|
||||||
positive: HPV_COLORS['positive_other'],
|
|
||||||
};
|
|
||||||
export const PPV_DONUT: Record<string, string> = { numerator: '#6A8000', rest: NEUTRAL };
|
export const PPV_DONUT: Record<string, string> = { numerator: '#6A8000', rest: NEUTRAL };
|
||||||
|
|
||||||
/** Median bars of the screening route, and the marks of their quartiles. */
|
/** Median bars of the screening route, and the marks of their quartiles. */
|
||||||
|
|||||||
@@ -97,22 +97,33 @@ export function scenarioBars(
|
|||||||
catalog: Catalog,
|
catalog: Catalog,
|
||||||
stratum: string,
|
stratum: string,
|
||||||
label: (code: string) => string,
|
label: (code: string) => string,
|
||||||
/** the groups in this order; an empty one is drawn when the counts reconcile (see `reconciles`) */
|
/** the groups in this order (the ones the report lists, then any other) */
|
||||||
order?: string[],
|
order?: string[],
|
||||||
|
options: {
|
||||||
|
/** draw an empty group of `order` when the counts reconcile (see `reconciles`) */
|
||||||
|
fill?: boolean;
|
||||||
|
/** a bar is the share of all the group's records, not only of those the catalog draws */
|
||||||
|
ofAll?: boolean;
|
||||||
|
} = {},
|
||||||
): Figure {
|
): Figure {
|
||||||
const cells = r.strata[`${stratum}-category`] ?? {};
|
const cells = r.strata[`${stratum}-category`] ?? {};
|
||||||
const found = [...new Set(Object.keys(cells).map((k) => k.split('|')[0]))];
|
const found = [...new Set(Object.keys(cells).map((k) => k.split('|')[0]))];
|
||||||
const listed = Object.values(cells).map((c) => c['initial-population']);
|
const listed = Object.values(cells).map((c) => c['initial-population']);
|
||||||
|
const empty = reconciles(listed, r.populations['initial-population'] ?? 0);
|
||||||
const scenarios = order
|
const scenarios = order
|
||||||
? [
|
? [
|
||||||
...order.filter(
|
...order.filter((s) => found.includes(s) || (options.fill && empty)),
|
||||||
(s) => found.includes(s) || reconciles(listed, r.populations['initial-population'] ?? 0),
|
|
||||||
),
|
|
||||||
...found.filter((s) => !order.includes(s)),
|
...found.filter((s) => !order.includes(s)),
|
||||||
]
|
]
|
||||||
: found.sort((a, b) => label(a).localeCompare(label(b), 'es'));
|
: found.sort((a, b) => label(a).localeCompare(label(b), 'es'));
|
||||||
const n = (s: string, c: string) => cells[`${s}|${c}`]?.['initial-population'] ?? 0;
|
const n = (s: string, c: string) => cells[`${s}|${c}`]?.['initial-population'] ?? 0;
|
||||||
const totals = scenarios.map((s) => catalog.categories.reduce((t, c) => t + n(s, c.code), 0));
|
const totals = scenarios.map((s) =>
|
||||||
|
options.ofAll
|
||||||
|
? Object.entries(cells)
|
||||||
|
.filter(([k]) => k.split('|')[0] === s)
|
||||||
|
.reduce((t, [, c]) => t + (c['initial-population'] ?? 0), 0)
|
||||||
|
: catalog.categories.reduce((t, c) => t + n(s, c.code), 0),
|
||||||
|
);
|
||||||
const y = order
|
const y = order
|
||||||
? scenarios.map((s, i) => `${label(s)}<br>n = ${totals[i]}`)
|
? scenarios.map((s, i) => `${label(s)}<br>n = ${totals[i]}`)
|
||||||
: scenarios.map(label);
|
: scenarios.map(label);
|
||||||
@@ -132,7 +143,9 @@ export function scenarioBars(
|
|||||||
xaxis: {
|
xaxis: {
|
||||||
title: {
|
title: {
|
||||||
text: order
|
text: order
|
||||||
? '% de pacientes con resultado'
|
? options.ofAll
|
||||||
|
? '% de los reportes del grupo'
|
||||||
|
: '% de pacientes con resultado'
|
||||||
: '% de pacientes del escenario con resultado',
|
: '% de pacientes del escenario con resultado',
|
||||||
},
|
},
|
||||||
ticksuffix: ' %',
|
ticksuffix: ' %',
|
||||||
|
|||||||
@@ -146,6 +146,7 @@ export const LABELS: Record<string, string> = {
|
|||||||
cin2_plus: 'Histología LIEAG o mayor',
|
cin2_plus: 'Histología LIEAG o mayor',
|
||||||
several: 'Varios códigos',
|
several: 'Varios códigos',
|
||||||
no_result: 'Sin resultado de VPH',
|
no_result: 'Sin resultado de VPH',
|
||||||
|
positive_incomplete: 'Positivo con genotipificación incompleta',
|
||||||
inconsistent: 'Inconsistente',
|
inconsistent: 'Inconsistente',
|
||||||
no_grade: 'Sin grado',
|
no_grade: 'Sin grado',
|
||||||
...Object.fromEntries(
|
...Object.fromEntries(
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import type { Mode } from './bars';
|
import type { Mode } from './bars';
|
||||||
import {
|
import {
|
||||||
AGE_COLORS,
|
|
||||||
BIOPSY_COLORS,
|
BIOPSY_COLORS,
|
||||||
CYTOLOGY_COLORS,
|
CYTOLOGY_COLORS,
|
||||||
DURATION,
|
DURATION,
|
||||||
@@ -11,8 +10,6 @@ import {
|
|||||||
QUARTILE,
|
QUARTILE,
|
||||||
REQUEST_COLORS,
|
REQUEST_COLORS,
|
||||||
ROUND_COLORS,
|
ROUND_COLORS,
|
||||||
STATUS_COLORS,
|
|
||||||
VPH_DONUT,
|
|
||||||
} from './cacu-palette';
|
} from './cacu-palette';
|
||||||
import type { Catalog, Page, ReadingsCard } from './pages';
|
import type { Catalog, Page, ReadingsCard } from './pages';
|
||||||
|
|
||||||
@@ -62,12 +59,7 @@ const HPV = [
|
|||||||
{ code: 'positive_16', label: 'VPH 16', color: HPV_COLORS['positive_16'] },
|
{ code: 'positive_16', label: 'VPH 16', color: HPV_COLORS['positive_16'] },
|
||||||
{ code: 'positive_18', label: 'VPH 18', color: HPV_COLORS['positive_18'] },
|
{ code: 'positive_18', label: 'VPH 18', color: HPV_COLORS['positive_18'] },
|
||||||
{ code: 'positive_16_18', label: 'VPH 16 y 18', color: HPV_COLORS['positive_16_18'] },
|
{ code: 'positive_16_18', label: 'VPH 16 y 18', color: HPV_COLORS['positive_16_18'] },
|
||||||
{ code: 'positive_other', label: 'Otro de alto riesgo', color: HPV_COLORS['positive_other'] },
|
{ code: 'positive_other', label: 'Positivo', color: HPV_COLORS['positive_other'] },
|
||||||
{
|
|
||||||
code: 'positive_incomplete',
|
|
||||||
label: 'Positivo, genotipo incompleto',
|
|
||||||
color: HPV_COLORS['positive_incomplete'],
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
const REQUESTS = [
|
const REQUESTS = [
|
||||||
{ code: 'high_grade', label: 'LIEAG o más', color: REQUEST_COLORS['high_grade'] },
|
{ code: 'high_grade', label: 'LIEAG o más', color: REQUEST_COLORS['high_grade'] },
|
||||||
@@ -86,6 +78,48 @@ const ROUND_CAPTION =
|
|||||||
'subsecuente (detección previa registrada, o ya con colposcopía o tratamiento) o «Sin dato». ' +
|
'subsecuente (detección previa registrada, o ya con colposcopía o tratamiento) o «Sin dato». ' +
|
||||||
'Un grupo sin pacientes se muestra en cero; sin porcentaje.';
|
'Un grupo sin pacientes se muestra en cero; sin porcentaje.';
|
||||||
|
|
||||||
|
/** The views the cytology and HPV-by-genotype cards share (one selector for both). */
|
||||||
|
const GENERAL = 'General';
|
||||||
|
const BY_AGE = 'Por grupo de edad';
|
||||||
|
const BY_STATUS = 'Por estatus de seguimiento';
|
||||||
|
const BY_ROUND = 'Por detección inicial y subsecuente';
|
||||||
|
const AGE_GROUPS = ['<25', '25-34', '35-44', '45-54', '55-64', '65+', 'no_data'];
|
||||||
|
const STATUSES = ['pre_colposcopy', 'post_colposcopy', 'post_treatment', 'case', 'no_data'];
|
||||||
|
const ROUND_MEANING =
|
||||||
|
'«Detección inicial»: primera vez en la vida y sin colposcopía ni tratamiento a la toma. ' +
|
||||||
|
'«Detección subsecuente»: con detección previa registrada, o ya con colposcopía o tratamiento a la toma. ' +
|
||||||
|
'«Sin dato»: sin detección previa registrada y sin colposcopía ni tratamiento. ';
|
||||||
|
const CYTOLOGY_BARS =
|
||||||
|
'Cada barra suma 100 % de las pacientes del grupo con resultado citológico (n indica cuántas son).';
|
||||||
|
const POSITIVE_MEANING =
|
||||||
|
'«Positivo»: VPH de alto riesgo positivo con los genotipos 16 y 18 reportados negativos; los positivos para 16, 18 o ambos se muestran aparte.';
|
||||||
|
/** HPV categories the cards do not draw (their reports stay in the total and the percentages). */
|
||||||
|
const HPV_HIDDEN = {
|
||||||
|
codes: ['positive_incomplete', 'inconsistent', 'no_result'],
|
||||||
|
unit: 'reportes',
|
||||||
|
};
|
||||||
|
|
||||||
|
/** One measure's breakdowns by group, each as stacked bars of the categories of `catalog`. */
|
||||||
|
const groupViews = (
|
||||||
|
measure: string,
|
||||||
|
catalog: { code: string; label: string; color: string }[],
|
||||||
|
unit: string,
|
||||||
|
caption: { age: string; status: string; round: string },
|
||||||
|
more: { ofAll?: boolean; hidden?: { codes: string[]; unit: string } } = {},
|
||||||
|
): Mode[] =>
|
||||||
|
[
|
||||||
|
{ label: BY_AGE, stratum: 'age_group', order: AGE_GROUPS, caption: caption.age },
|
||||||
|
{ label: BY_STATUS, stratum: 'follow_up_status', order: STATUSES, caption: caption.status },
|
||||||
|
{ label: BY_ROUND, stratum: 'round', order: ROUNDS, caption: caption.round, complete: true },
|
||||||
|
].map((v) => ({
|
||||||
|
kind: 'grouped' as const,
|
||||||
|
measure,
|
||||||
|
catalog,
|
||||||
|
unit,
|
||||||
|
...v,
|
||||||
|
...more,
|
||||||
|
}));
|
||||||
|
|
||||||
/** A PPV's card: the whole, and by each of its stratifiers. */
|
/** A PPV's card: the whole, and by each of its stratifiers. */
|
||||||
const ppv = (measure: string, title: string, note: string, ...more: Mode[]): ReadingsCard => ({
|
const ppv = (measure: string, title: string, note: string, ...more: Mode[]): ReadingsCard => ({
|
||||||
kind: 'readings',
|
kind: 'readings',
|
||||||
@@ -212,42 +246,57 @@ export const CACU: Page = {
|
|||||||
{
|
{
|
||||||
kind: 'columns',
|
kind: 'columns',
|
||||||
title: 'Resultados de citología, VPH y biopsia',
|
title: 'Resultados de citología, VPH y biopsia',
|
||||||
|
viewsLabel: 'Lectura de la distribución citológica y del VPH por genotipo',
|
||||||
|
views: [GENERAL, BY_AGE, BY_STATUS, BY_ROUND],
|
||||||
sections: [
|
sections: [
|
||||||
{
|
{
|
||||||
kind: 'readings',
|
kind: 'readings',
|
||||||
|
follows: true,
|
||||||
title: 'Distribución de resultados citológicos',
|
title: 'Distribución de resultados citológicos',
|
||||||
note: 'Pacientes, por su última muestra válida del periodo.',
|
note: 'Pacientes, por su última muestra válida del periodo.',
|
||||||
modes: [
|
modes: [
|
||||||
{
|
{ kind: 'counts', label: GENERAL, measure: 'CACU_EU7', catalog: CYTOLOGY.categories },
|
||||||
kind: 'counts',
|
...groupViews('CACU_EU7', CYTOLOGY.categories, 'pacientes', {
|
||||||
label: 'General',
|
age:
|
||||||
measure: 'CACU_EU7',
|
'Cada paciente cuenta una vez, con su última muestra válida del periodo; la edad es la de la paciente al inicio del periodo. ' +
|
||||||
catalog: CYTOLOGY.categories,
|
CYTOLOGY_BARS,
|
||||||
},
|
status:
|
||||||
{
|
'Cada paciente cuenta una vez, con su última muestra válida del periodo; el estatus es el de la paciente al inicio del periodo. ' +
|
||||||
kind: 'figure',
|
CYTOLOGY_BARS,
|
||||||
label: 'Por detección inicial y subsecuente',
|
round:
|
||||||
caption:
|
|
||||||
'Cada paciente cuenta una vez, con su última muestra válida del periodo; la detección es la de esa muestra (fecha de toma). ' +
|
'Cada paciente cuenta una vez, con su última muestra válida del periodo; la detección es la de esa muestra (fecha de toma). ' +
|
||||||
'«Detección inicial»: primera vez en la vida y sin colposcopía ni tratamiento a la toma. ' +
|
ROUND_MEANING +
|
||||||
'«Detección subsecuente»: con detección previa registrada, o ya con colposcopía o tratamiento a la toma. ' +
|
CYTOLOGY_BARS +
|
||||||
'«Sin dato»: sin detección previa registrada y sin colposcopía ni tratamiento. ' +
|
|
||||||
'Cada barra suma 100 % de las pacientes del grupo con resultado citológico (n indica cuántas son). ' +
|
|
||||||
' Si hay pacientes en «Sin dato», una barra vacía significa que no hay pacientes clasificadas en esa detección según la información disponible.',
|
' Si hay pacientes en «Sin dato», una barra vacía significa que no hay pacientes clasificadas en esa detección según la información disponible.',
|
||||||
measure: 'CACU_EU7',
|
}),
|
||||||
figure: 'scenarios',
|
|
||||||
catalog: CYTOLOGY.categories,
|
|
||||||
stratum: 'round',
|
|
||||||
order: ROUNDS,
|
|
||||||
complete: true,
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
kind: 'readings',
|
kind: 'readings',
|
||||||
|
follows: true,
|
||||||
title: 'Resultados de VPH por genotipo',
|
title: 'Resultados de VPH por genotipo',
|
||||||
note: 'Reportes, por fecha de toma.',
|
note: 'Reportes, por fecha de toma.',
|
||||||
modes: [{ kind: 'counts', label: 'General', measure: 'CACU_VPH_GENOTIPO', catalog: HPV }],
|
modes: [
|
||||||
|
{
|
||||||
|
kind: 'counts',
|
||||||
|
label: GENERAL,
|
||||||
|
measure: 'CACU_VPH_GENOTIPO',
|
||||||
|
catalog: HPV,
|
||||||
|
hidden: HPV_HIDDEN,
|
||||||
|
caption: POSITIVE_MEANING,
|
||||||
|
},
|
||||||
|
...groupViews(
|
||||||
|
'CACU_VPH_GENOTIPO',
|
||||||
|
HPV,
|
||||||
|
'reportes',
|
||||||
|
{
|
||||||
|
age: `Cada barra son los reportes de VPH del grupo de edad de la paciente al inicio del periodo. ${POSITIVE_MEANING}`,
|
||||||
|
status: `Cada barra son los reportes de VPH del estatus de la paciente al inicio del periodo. ${POSITIVE_MEANING}`,
|
||||||
|
round: `Cada barra son los reportes de VPH de las muestras de esa detección (fecha de toma). ${ROUND_MEANING}Si hay reportes en «Sin dato», una barra vacía significa que no hay reportes de muestras clasificadas en esa detección según la información disponible. ${POSITIVE_MEANING}`,
|
||||||
|
},
|
||||||
|
{ ofAll: true, hidden: HPV_HIDDEN },
|
||||||
|
),
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
kind: 'readings',
|
kind: 'readings',
|
||||||
@@ -264,54 +313,6 @@ export const CACU: Page = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
kind: 'readings',
|
|
||||||
title: 'Pacientes evaluadas por resultado de VPH',
|
|
||||||
headline: 'CACU_VPH',
|
|
||||||
note: 'Una vez cada paciente, por su última muestra con resultado.',
|
|
||||||
modes: [
|
|
||||||
{
|
|
||||||
kind: 'figure',
|
|
||||||
label: 'Total',
|
|
||||||
measure: 'CACU_VPH',
|
|
||||||
figure: 'donut',
|
|
||||||
colors: VPH_DONUT,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
kind: 'positives',
|
|
||||||
label: 'Por grupo de edad',
|
|
||||||
measure: 'CACU_VPH',
|
|
||||||
stratum: 'age_group',
|
|
||||||
colors: AGE_COLORS,
|
|
||||||
order: ['<25', '25-34', '35-44', '45-54', '55-64', '65+', 'no_data'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
kind: 'positives',
|
|
||||||
label: 'Por estatus de seguimiento',
|
|
||||||
measure: 'CACU_VPH',
|
|
||||||
stratum: 'follow_up_status',
|
|
||||||
colors: STATUS_COLORS,
|
|
||||||
order: ['pre_colposcopy', 'post_colposcopy', 'post_treatment', 'case'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
kind: 'signs',
|
|
||||||
label: 'Por genotipo',
|
|
||||||
measure: 'CACU_VPH',
|
|
||||||
strata: ['hpv_16', 'hpv_18'],
|
|
||||||
colors: HPV_COLORS,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
kind: 'positives',
|
|
||||||
label: 'Por detección inicial y subsecuente',
|
|
||||||
caption: `${ROUND_CAPTION} Positivas sobre las pacientes con resultado de VPH del grupo.`,
|
|
||||||
measure: 'CACU_VPH',
|
|
||||||
stratum: 'round',
|
|
||||||
colors: ROUND_COLORS,
|
|
||||||
order: ROUNDS,
|
|
||||||
complete: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
kind: 'choice',
|
kind: 'choice',
|
||||||
title: 'Tasa de confirmación histopatológica',
|
title: 'Tasa de confirmación histopatológica',
|
||||||
|
|||||||
@@ -27,11 +27,20 @@ export interface ReadingsCard {
|
|||||||
headline?: string;
|
headline?: string;
|
||||||
note?: string;
|
note?: string;
|
||||||
modes: Mode[];
|
modes: Mode[];
|
||||||
|
/** in a `columns` section with `views`: takes the mode whose label the section's selector chose */
|
||||||
|
follows?: boolean;
|
||||||
}
|
}
|
||||||
export type Section =
|
export type Section =
|
||||||
| ReadingsCard
|
| ReadingsCard
|
||||||
/** Cards side by side; the last one alone when odd. */
|
/** Cards side by side; the last one alone when odd. */
|
||||||
| { kind: 'columns'; title: string; sections: ReadingsCard[] }
|
| {
|
||||||
|
kind: 'columns';
|
||||||
|
title: string;
|
||||||
|
sections: ReadingsCard[];
|
||||||
|
/** one selector for the cards that `follow` it: the labels of their modes, the first by default */
|
||||||
|
views?: string[];
|
||||||
|
viewsLabel?: string;
|
||||||
|
}
|
||||||
/** One section at a time. */
|
/** One section at a time. */
|
||||||
| { kind: 'choice'; title: string; choices: { label: string; section: ReadingsCard }[] }
|
| { kind: 'choice'; title: string; choices: { label: string; section: ReadingsCard }[] }
|
||||||
| { kind: 'figures'; title?: string; figures: FigureSpec[] }
|
| { kind: 'figures'; title?: string; figures: FigureSpec[] }
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Component, computed, input, signal } from '@angular/core';
|
|||||||
import { MatButtonToggleModule } from '@angular/material/button-toggle';
|
import { MatButtonToggleModule } from '@angular/material/button-toggle';
|
||||||
import { Loading } from '../loading';
|
import { Loading } from '../loading';
|
||||||
import { Figure, Plot } from '../plot';
|
import { Figure, Plot } from '../plot';
|
||||||
import { bars, Mode, unavailable } from './bars';
|
import { bars, grouped, hiddenNote, Mode, unavailable } from './bars';
|
||||||
import { Reading } from './measures';
|
import { Reading } from './measures';
|
||||||
|
|
||||||
/** A card read one mode at a time: its title, its headline, the toggle and the bars. */
|
/** A card read one mode at a time: its title, its headline, the toggle and the bars. */
|
||||||
@@ -17,7 +17,7 @@ import { Reading } from './measures';
|
|||||||
@if (note()) {
|
@if (note()) {
|
||||||
<p class="state">{{ note() }}</p>
|
<p class="state">{{ note() }}</p>
|
||||||
}
|
}
|
||||||
@if (modes().length > 1) {
|
@if (modes().length > 1 && !view()) {
|
||||||
<mat-button-toggle-group
|
<mat-button-toggle-group
|
||||||
[attr.aria-label]="title()"
|
[attr.aria-label]="title()"
|
||||||
[value]="mode().label"
|
[value]="mode().label"
|
||||||
@@ -35,8 +35,47 @@ import { Reading } from './measures';
|
|||||||
<app-loading what="la figura" [figure]="true" />
|
<app-loading what="la figura" [figure]="true" />
|
||||||
} @else if (missing(); as why) {
|
} @else if (missing(); as why) {
|
||||||
<p class="state" role="status">{{ why }}</p>
|
<p class="state" role="status">{{ why }}</p>
|
||||||
|
} @else if (groups(); as g) {
|
||||||
|
<div class="axis" aria-hidden="true">
|
||||||
|
<span></span>
|
||||||
|
<span class="ticks">
|
||||||
|
<span style="left: 0">0 %</span><span style="left: 25%">25 %</span
|
||||||
|
><span style="left: 50%">50 %</span><span style="left: 75%">75 %</span
|
||||||
|
><span style="left: 100%">100 %</span>
|
||||||
|
</span>
|
||||||
|
<span></span>
|
||||||
|
</div>
|
||||||
|
@for (group of g.groups; track group.code) {
|
||||||
|
<section class="group" [attr.data-group]="group.code" [attr.aria-label]="group.label">
|
||||||
|
<h4>
|
||||||
|
{{ group.label }} <span class="n">n = {{ group.total }}</span>
|
||||||
|
@if (group.hint) {
|
||||||
|
<span class="hint">{{ group.hint }}</span>
|
||||||
|
}
|
||||||
|
</h4>
|
||||||
|
@for (row of group.rows; track row.label) {
|
||||||
|
<div class="row" [attr.data-category]="row.label">
|
||||||
|
<span class="name">{{ row.label }}</span>
|
||||||
|
<span class="track" aria-hidden="true">
|
||||||
|
<span
|
||||||
|
class="fill"
|
||||||
|
[style.width.%]="row.percent ?? 0"
|
||||||
|
[style.background]="row.color"
|
||||||
|
></span>
|
||||||
|
</span>
|
||||||
|
<span class="value">{{ row.text }}</span>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</section>
|
||||||
|
}
|
||||||
|
@if (g.note) {
|
||||||
|
<p class="state">{{ g.note }}</p>
|
||||||
|
}
|
||||||
} @else if (figure(); as f) {
|
} @else if (figure(); as f) {
|
||||||
<app-plot [figure]="f" [height]="height()" />
|
<app-plot [figure]="f" [height]="height()" />
|
||||||
|
@if (hidden(); as why) {
|
||||||
|
<p class="state">{{ why }}</p>
|
||||||
|
}
|
||||||
} @else if (table(); as t) {
|
} @else if (table(); as t) {
|
||||||
<table [attr.aria-label]="mode().label">
|
<table [attr.aria-label]="mode().label">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -111,6 +150,98 @@ import { Reading } from './measures';
|
|||||||
white-space: normal;
|
white-space: normal;
|
||||||
width: 60%;
|
width: 60%;
|
||||||
}
|
}
|
||||||
|
.axis {
|
||||||
|
column-gap: 8px;
|
||||||
|
display: grid;
|
||||||
|
font-size: 12px;
|
||||||
|
grid-template-columns: var(--name-width) 1fr var(--value-width);
|
||||||
|
margin: 12px 0 2px;
|
||||||
|
}
|
||||||
|
.ticks {
|
||||||
|
height: 1.2em;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
.ticks span {
|
||||||
|
white-space: nowrap;
|
||||||
|
position: absolute;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
}
|
||||||
|
.ticks span:first-child {
|
||||||
|
transform: none;
|
||||||
|
}
|
||||||
|
.ticks span:last-child {
|
||||||
|
transform: translateX(-100%);
|
||||||
|
}
|
||||||
|
.group {
|
||||||
|
margin: 6px 0 14px;
|
||||||
|
}
|
||||||
|
.group h4 {
|
||||||
|
font-size: 0.95rem;
|
||||||
|
margin: 0 0 4px;
|
||||||
|
}
|
||||||
|
.group .n,
|
||||||
|
.group .hint {
|
||||||
|
color: var(--mat-sys-on-surface-variant, #5f6368);
|
||||||
|
font-size: 0.8em;
|
||||||
|
font-weight: 400;
|
||||||
|
margin-left: 8px;
|
||||||
|
}
|
||||||
|
.row {
|
||||||
|
align-items: center;
|
||||||
|
column-gap: 8px;
|
||||||
|
display: grid;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
grid-template-columns: var(--name-width) 1fr var(--value-width);
|
||||||
|
min-height: 22px;
|
||||||
|
}
|
||||||
|
.row .track {
|
||||||
|
background:
|
||||||
|
linear-gradient(to right, #d8dde1 1px, transparent 1px) 25% 0 / 1px 100% no-repeat,
|
||||||
|
linear-gradient(to right, #d8dde1 1px, transparent 1px) 50% 0 / 1px 100% no-repeat,
|
||||||
|
linear-gradient(to right, #d8dde1 1px, transparent 1px) 75% 0 / 1px 100% no-repeat,
|
||||||
|
rgba(0, 0, 0, 0.06);
|
||||||
|
display: block;
|
||||||
|
height: 10px;
|
||||||
|
}
|
||||||
|
.row .fill {
|
||||||
|
display: block;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
.row .value {
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
text-align: right;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
:host {
|
||||||
|
--name-width: 8.5rem;
|
||||||
|
--value-width: 8.5rem;
|
||||||
|
}
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
:host {
|
||||||
|
--name-width: 0px;
|
||||||
|
--value-width: 0px;
|
||||||
|
}
|
||||||
|
.axis {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
.axis > span:not(.ticks) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.row {
|
||||||
|
grid-template-areas: 'name value' 'track track';
|
||||||
|
grid-template-columns: 1fr auto;
|
||||||
|
padding-bottom: 4px;
|
||||||
|
}
|
||||||
|
.row .name {
|
||||||
|
grid-area: name;
|
||||||
|
}
|
||||||
|
.row .value {
|
||||||
|
grid-area: value;
|
||||||
|
}
|
||||||
|
.row .track {
|
||||||
|
grid-area: track;
|
||||||
|
}
|
||||||
|
}
|
||||||
.hint {
|
.hint {
|
||||||
color: var(--mat-sys-on-surface-variant, #5f6368);
|
color: var(--mat-sys-on-surface-variant, #5f6368);
|
||||||
display: block;
|
display: block;
|
||||||
@@ -141,6 +272,8 @@ export class Readings {
|
|||||||
readonly headline = input('');
|
readonly headline = input('');
|
||||||
readonly note = input('');
|
readonly note = input('');
|
||||||
readonly modes = input.required<Mode[]>();
|
readonly modes = input.required<Mode[]>();
|
||||||
|
/** The label of the mode a section's selector chose, for the cards that follow it. */
|
||||||
|
readonly view = input<string>();
|
||||||
readonly loading = input(false);
|
readonly loading = input(false);
|
||||||
/** A measure's reading in the applied period, and the figure of a mode that has one. */
|
/** A measure's reading in the applied period, and the figure of a mode that has one. */
|
||||||
readonly read = input.required<(measure: string) => Reading | undefined>();
|
readonly read = input.required<(measure: string) => Reading | undefined>();
|
||||||
@@ -148,14 +281,19 @@ export class Readings {
|
|||||||
|
|
||||||
protected readonly chosen = signal('');
|
protected readonly chosen = signal('');
|
||||||
protected readonly mode = computed(
|
protected readonly mode = computed(
|
||||||
() => this.modes().find((m) => m.label === this.chosen()) ?? this.modes()[0],
|
() => this.modes().find((m) => m.label === (this.view() || this.chosen())) ?? this.modes()[0],
|
||||||
);
|
);
|
||||||
|
protected readonly groups = computed(() => grouped(this.mode(), this.read()));
|
||||||
protected readonly table = computed(() => bars(this.mode(), this.read()));
|
protected readonly table = computed(() => bars(this.mode(), this.read()));
|
||||||
/** The bars of a scenarios figure need more room than a donut. */
|
/** The bars of a scenarios figure need more room than a donut. */
|
||||||
protected readonly height = computed(() => {
|
protected readonly height = computed(() => {
|
||||||
const m = this.mode();
|
const m = this.mode();
|
||||||
return m.kind === 'figure' && m.figure === 'scenarios' ? 360 : 300;
|
if (m.kind !== 'figure' || m.figure !== 'scenarios') return 300;
|
||||||
|
const groups = (this.figure()?.data[0] as { y?: unknown[] } | undefined)?.y?.length ?? 3;
|
||||||
|
return Math.max(360, 190 + 44 * groups); // a slim bar per group, and room for legend and axis
|
||||||
});
|
});
|
||||||
|
/** What the card says about the categories it does not draw. */
|
||||||
|
protected readonly hidden = computed(() => hiddenNote(this.mode(), this.read()));
|
||||||
/** Patients in the period but no classification published: say it, do not draw nothing. */
|
/** Patients in the period but no classification published: say it, do not draw nothing. */
|
||||||
protected readonly missing = computed(() => unavailable(this.mode(), this.read()));
|
protected readonly missing = computed(() => unavailable(this.mode(), this.read()));
|
||||||
protected readonly figure = computed(() =>
|
protected readonly figure = computed(() =>
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ type Shown = Extract<Section, { kind: 'readings' | 'columns' | 'choice' }>;
|
|||||||
[headline]="headline()"
|
[headline]="headline()"
|
||||||
[note]="s.note ?? ''"
|
[note]="s.note ?? ''"
|
||||||
[modes]="s.modes"
|
[modes]="s.modes"
|
||||||
|
[view]="view()"
|
||||||
[loading]="of().loading"
|
[loading]="of().loading"
|
||||||
[read]="of().reading"
|
[read]="of().reading"
|
||||||
[draw]="draw()"
|
[draw]="draw()"
|
||||||
@@ -39,9 +40,25 @@ type Shown = Extract<Section, { kind: 'readings' | 'columns' | 'choice' }>;
|
|||||||
} @else {
|
} @else {
|
||||||
<h2>{{ s.title }}</h2>
|
<h2>{{ s.title }}</h2>
|
||||||
@if (s.kind === 'columns') {
|
@if (s.kind === 'columns') {
|
||||||
|
@if (s.views) {
|
||||||
|
<mat-button-toggle-group
|
||||||
|
class="views"
|
||||||
|
[attr.aria-label]="s.viewsLabel ?? s.title"
|
||||||
|
[value]="picked() || s.views[0]"
|
||||||
|
(change)="picked.set($event.value)"
|
||||||
|
>
|
||||||
|
@for (v of s.views; track v) {
|
||||||
|
<mat-button-toggle [value]="v">{{ v }}</mat-button-toggle>
|
||||||
|
}
|
||||||
|
</mat-button-toggle-group>
|
||||||
|
}
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
@for (inner of s.sections; track $index) {
|
@for (inner of s.sections; track $index) {
|
||||||
<app-section [section]="inner" [of]="of()" />
|
<app-section
|
||||||
|
[section]="inner"
|
||||||
|
[of]="of()"
|
||||||
|
[view]="inner.follows ? picked() || s.views?.[0] : undefined"
|
||||||
|
/>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
} @else {
|
} @else {
|
||||||
@@ -69,6 +86,10 @@ type Shown = Extract<Section, { kind: 'readings' | 'columns' | 'choice' }>;
|
|||||||
margin-top: 16px;
|
margin-top: 16px;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
.views {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
margin: 4px 0 8px;
|
||||||
|
}
|
||||||
.columns {
|
.columns {
|
||||||
display: grid;
|
display: grid;
|
||||||
column-gap: 16px;
|
column-gap: 16px;
|
||||||
@@ -82,6 +103,10 @@ type Shown = Extract<Section, { kind: 'readings' | 'columns' | 'choice' }>;
|
|||||||
export class ReadingsSection {
|
export class ReadingsSection {
|
||||||
readonly section = input.required<Shown>();
|
readonly section = input.required<Shown>();
|
||||||
readonly of = input.required<Source>();
|
readonly of = input.required<Source>();
|
||||||
|
/** The mode a card of a `columns` section takes from the section's selector (its label). */
|
||||||
|
readonly view = input<string>();
|
||||||
|
/** The view a columns section's selector has chosen. */
|
||||||
|
protected readonly picked = signal('');
|
||||||
protected readonly chosen = signal('');
|
protected readonly chosen = signal('');
|
||||||
|
|
||||||
protected readonly headline = computed(() => {
|
protected readonly headline = computed(() => {
|
||||||
@@ -105,7 +130,8 @@ export class ReadingsSection {
|
|||||||
{ groups: [], categories },
|
{ groups: [], categories },
|
||||||
mode.stratum ?? 'follow_up_status',
|
mode.stratum ?? 'follow_up_status',
|
||||||
name,
|
name,
|
||||||
mode.complete ? mode.order : undefined,
|
mode.order,
|
||||||
|
{ fill: mode.complete, ofAll: mode.ofAll },
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user