Compare commits

..

8 Commits

14 changed files with 193 additions and 79 deletions
+1 -3
View File
@@ -1467,9 +1467,7 @@ test('elegibilidad: the risk section shows the published post-treatment exclusio
expect(patientId, 'a synthetic patient with a published post-treatment exclusion').toBeDefined(); expect(patientId, 'a synthetic patient with a published post-treatment exclusion').toBeDefined();
await open(page, `/indicadores/cacu/pacientes/${patientId}`); await open(page, `/indicadores/cacu/pacientes/${patientId}`);
const box = riskBox(page); const box = riskBox(page);
await expect(box.getByRole('status')).toHaveText( await expect(box.getByRole('status')).toHaveText(/paciente ya tratada\.$/);
'No disponible por: Sin biopsia previa al tratamiento en el periodo requerido.',
);
await expect(box.locator('app-risk-scales')).toHaveCount(0); await expect(box.locator('app-risk-scales')).toHaveCount(0);
await expect(page.locator('[data-section=elegibilidad]')).toHaveCount(0); await expect(page.locator('[data-section=elegibilidad]')).toHaveCount(0);
}); });
+4
View File
@@ -19,7 +19,9 @@ export const CYTOLOGY_COLORS: Record<string, string> = {
'ASC-US': '#2778B8', 'ASC-US': '#2778B8',
LSIL: '#B19525', LSIL: '#B19525',
'ASC-H': '#7955B1', 'ASC-H': '#7955B1',
CIN2: '#E07A9C',
HSIL: '#CE4778', HSIL: '#CE4778',
CIN3: '#BC4163',
CIS: '#AA394D', CIS: '#AA394D',
no_data: NEUTRAL, no_data: NEUTRAL,
}; };
@@ -43,7 +45,9 @@ export const HPV_COLORS: Record<string, string> = {
export const BIOPSY_COLORS: Record<string, string> = { export const BIOPSY_COLORS: Record<string, string> = {
normal: '#408651', normal: '#408651',
LSIL: '#B19525', LSIL: '#B19525',
CIN2: '#E07A9C',
HSIL: '#CE4778', HSIL: '#CE4778',
CIN3: '#BC4163',
CIS: '#AA394D', CIS: '#AA394D',
carcinoma: '#8D4C79', carcinoma: '#8D4C79',
cin1_plus: '#B19525', cin1_plus: '#B19525',
+2
View File
@@ -110,6 +110,8 @@ export const LABELS: Record<string, string> = {
NILM: 'Normal (NILM)', NILM: 'Normal (NILM)',
LSIL: 'LIEBG', LSIL: 'LIEBG',
HSIL: 'LIEAG', HSIL: 'LIEAG',
CIN2: 'CIN 2',
CIN3: 'CIN 3',
normal: 'Normal', normal: 'Normal',
carcinoma: 'Carcinoma', carcinoma: 'Carcinoma',
no_data: 'Sin dato', no_data: 'Sin dato',
+2
View File
@@ -47,7 +47,9 @@ const BIOPSY: Catalog = {
categories: [ categories: [
{ code: 'normal', label: 'Normal', color: BIOPSY_COLORS['normal'], group: 'low' }, { code: 'normal', label: 'Normal', color: BIOPSY_COLORS['normal'], group: 'low' },
{ code: 'LSIL', label: 'LIEBG (CIN 1)', color: BIOPSY_COLORS['LSIL'], group: 'low' }, { code: 'LSIL', label: 'LIEBG (CIN 1)', color: BIOPSY_COLORS['LSIL'], group: 'low' },
{ code: 'CIN2', label: 'CIN 2', color: BIOPSY_COLORS['CIN2'], group: 'high' },
{ code: 'HSIL', label: 'LIEAG (CIN 2 y 3)', color: BIOPSY_COLORS['HSIL'], group: 'high' }, { code: 'HSIL', label: 'LIEAG (CIN 2 y 3)', color: BIOPSY_COLORS['HSIL'], group: 'high' },
{ code: 'CIN3', label: 'CIN 3', color: BIOPSY_COLORS['CIN3'], group: 'high' },
{ code: 'CIS', label: 'Carcinoma in situ', color: BIOPSY_COLORS['CIS'], group: 'high' }, { code: 'CIS', label: 'Carcinoma in situ', color: BIOPSY_COLORS['CIS'], group: 'high' },
{ {
code: 'carcinoma', code: 'carcinoma',
+2
View File
@@ -485,7 +485,9 @@ export const HISTORY: Record<string, History> = {
[ [
['normal', 'Normal', '#9DBFE3'], ['normal', 'Normal', '#9DBFE3'],
['LSIL', 'LIEBG (CIN 1)', '#69C242'], ['LSIL', 'LIEBG (CIN 1)', '#69C242'],
['CIN2', 'CIN 2', '#E07A9C'],
['HSIL', 'LIEAG (CIN 2 y 3)', '#C24269'], ['HSIL', 'LIEAG (CIN 2 y 3)', '#C24269'],
['CIN3', 'CIN 3', '#A8325A'],
['CIS', 'Carcinoma in situ', '#9C42C2'], ['CIS', 'Carcinoma in situ', '#9C42C2'],
['carcinoma', 'Carcinoma invasor', '#5C42C2'], ['carcinoma', 'Carcinoma invasor', '#5C42C2'],
['no_biopsy', 'Sin biopsia aún', GREY], ['no_biopsy', 'Sin biopsia aún', GREY],
+29
View File
@@ -31,6 +31,21 @@ const PERIODS: Record<string, string> = { semester: 'Semestral', month: 'Mensual
Pacientes evaluadas incluye a las pacientes con citología tomada en el periodo cuyo Pacientes evaluadas incluye a las pacientes con citología tomada en el periodo cuyo
espécimen fue insatisfactorio. espécimen fue insatisfactorio.
</p> </p>
<h4>Riesgos de referencia NCI</h4>
<p>
Los riesgos de referencia corresponden a la cohorte Kaiser Permanente Northern
California (2003–2017, pacientes de 25 a 65 años). Las guías ASCCP deciden la
conducta con el riesgo de CIN3+. Los riesgos publicados de CIN2+ y cáncer son
resultados complementarios; no son directamente comparables con las estimaciones
institucionales porque no están validados para la población de esta plataforma.
</p>
<ul>
<li><a href="https://pmc.ncbi.nlm.nih.gov/articles/PMC7147417/" target="_blank" rel="noopener noreferrer">Egemen y colaboradores: estimaciones que sustentan las guías (2020).</a></li>
<li><a href="https://doi.org/10.1097/LGT.0000000000000528" target="_blank" rel="noopener noreferrer">Cheung y colaboradores: métodos de estimación (2020).</a></li>
<li><a href="https://pmc.ncbi.nlm.nih.gov/articles/PMC7147428/" target="_blank" rel="noopener noreferrer">Perkins y colaboradores: guías de manejo ASCCP 2019.</a></li>
<li><a href="https://data.lhncbc.nlm.nih.gov/public/cervixca/AdditionalTables.zip" target="_blank" rel="noopener noreferrer">LHNCBC: libros de tablas adicionales.</a></li>
<li><a href="https://web.archive.org/web/20240710095705/https://lhncbc.nlm.nih.gov/LHC-research/LHC-projects/image-processing/cervixca.html" target="_blank" rel="noopener noreferrer">LHNCBC: página archivada de las tablas, 10 de julio de 2024.</a></li>
</ul>
} }
@if (available().length) { @if (available().length) {
<p>Periodicidad disponible: {{ available().join(', ') }}.</p> <p>Periodicidad disponible: {{ available().join(', ') }}.</p>
@@ -48,6 +63,20 @@ const PERIODS: Record<string, string> = { semester: 'Semestral', month: 'Mensual
@if (m.description) { @if (m.description) {
<p>{{ m.description }}</p> <p>{{ m.description }}</p>
} }
@if (m.relatedArtifact?.length) {
<h4>Referencias</h4>
<ul>
@for (reference of m.relatedArtifact; track $index) {
<li>
@if (reference.url) {
<a [href]="reference.url" target="_blank" rel="noopener noreferrer">{{ reference.citation || reference.display || reference.url }}</a>
} @else {
{{ reference.citation || reference.display }}
}
</li>
}
</ul>
}
<h4>Cálculo</h4> <h4>Cálculo</h4>
<p> <p>
{{ scoring[code(m.scoring) ?? ''] }} {{ scoring[code(m.scoring) ?? ''] }}
+1
View File
@@ -29,6 +29,7 @@ export const CRITERION_TEXT: Record<string, string> = {
outcome_before_index: 'Resultado CIN2+ entre tratamiento e índice', outcome_before_index: 'Resultado CIN2+ entre tratamiento e índice',
no_birth_date: 'Fecha de nacimiento desconocida', no_birth_date: 'Fecha de nacimiento desconocida',
died_by_index: 'Defunción en o antes de la visita índice', died_by_index: 'Defunción en o antes de la visita índice',
not_evaluated: 'Escenario que la plataforma no evalúa por ahora',
}; };
export interface Reason { export interface Reason {
+25 -1
View File
@@ -1,5 +1,5 @@
import type { EligibilityState, Visit } from './eligibility'; import type { EligibilityState, Visit } from './eligibility';
import { ineligibility } from './ineligibility'; import { currency, ineligibility } from './ineligibility';
const visit = (indexDate: string, ...reasons: string[]): Visit => ({ const visit = (indexDate: string, ...reasons: string[]): Visit => ({
indexDate, indexDate,
@@ -28,4 +28,28 @@ describe('ineligibility', () => {
expect(ineligibility(state, 'case', '2025-06-01')).toBeUndefined(); expect(ineligibility(state, 'case', '2025-06-01')).toBeUndefined();
expect(ineligibility({ kind: 'error' }, 'pre_colposcopy', '2025-06-01')).toBeUndefined(); expect(ineligibility({ kind: 'error' }, 'pre_colposcopy', '2025-06-01')).toBeUndefined();
}); });
it('says of a treated patient only that she was already treated', () => {
const text = 'No disponible por: paciente ya tratada.';
expect(ineligibility(state, 'post_treatment', '2025-06-01')).toBe(text);
expect(ineligibility({ kind: 'error' }, 'post_treatment', '2025-06-01')).toBe(text);
});
});
describe('currency', () => {
const pre = [{ model: 'cacu.cin2_pim', index: '2025-01-01' }];
const post = [{ model: 'cacu.cin2_pim_post_colposcopy', index: '2025-01-01' }];
it('dates the estimate and says when there is a later cytology', () => {
expect(currency(pre, ['2025-01-01', '2024-01-01']).note).toBe(
'Estimación de la citología del 2025-01-01.',
);
expect(currency(pre, ['2025-06-01', '2025-01-01']).note).toContain('posterior, del 2025-06-01');
expect(currency([], ['2025-06-01'])).toEqual({});
});
it('shows no post-colposcopy estimate once there is a later visit', () => {
expect(currency(post, ['2025-01-01']).excluded).toBeUndefined();
expect(currency(post, ['2025-06-01', '2025-01-01']).excluded).toContain('(2025-06-01)');
});
}); });
+26 -1
View File
@@ -5,7 +5,6 @@ import type { EligibilityState } from './eligibility';
const SCENARIOS: Record<string, string[]> = { const SCENARIOS: Record<string, string[]> = {
pre_colposcopy: ['pre_colposcopy', 'surveillance'], pre_colposcopy: ['pre_colposcopy', 'surveillance'],
post_colposcopy: ['post_colposcopy'], post_colposcopy: ['post_colposcopy'],
post_treatment: ['post_treatment'],
}; };
/** What the risk section says when she is not eligible in her clinical scenario, from its latest /** What the risk section says when she is not eligible in her clinical scenario, from its latest
@@ -15,6 +14,8 @@ export function ineligibility(
status: string, status: string,
day: string, day: string,
): string | undefined { ): string | undefined {
// a treated patient has no risk estimate, whatever visit was indexed
if (status === 'post_treatment') return 'No disponible por: paciente ya tratada.';
if (state.kind !== 'evaluated') return undefined; if (state.kind !== 'evaluated') return undefined;
for (const scenario of SCENARIOS[status] ?? []) { for (const scenario of SCENARIOS[status] ?? []) {
// visits come latest first // visits come latest first
@@ -29,3 +30,27 @@ export function ineligibility(
} }
return undefined; return undefined;
} }
/** Which cytology her estimates speak of, against her latest by the cut-off. After the first
* post-colposcopy visit nothing is evaluated; otherwise a later cytology is only said. */
export function currency(
estimates: { model: string; index: string }[],
cytologies: string[],
): { sample?: string; excluded?: string; note?: string } {
const sample = estimates.map((e) => e.index.slice(0, 10)).sort().at(-1);
if (!sample) return {};
const latest = cytologies.map((d) => d.slice(0, 10)).sort().at(-1);
if (!latest || latest <= sample) {
return { sample, note: `Estimación de la citología del ${sample}.` };
}
if (estimates.some((e) => e.model.includes('post_colposcopy'))) {
return {
sample,
excluded: `No disponible por: hay una citología posterior a la primera visita poscolposcopía (${latest}) y solo se evalúa esa primera visita.`,
};
}
return {
sample,
note: `Estimación de la citología del ${sample}. Hay una citología posterior, del ${latest}, que no se evalúa.`,
};
}
+18 -12
View File
@@ -131,6 +131,9 @@
@if (saveError()) { @if (saveError()) {
<p class="muted" role="alert">{{ saveError() }}</p> <p class="muted" role="alert">{{ saveError() }}</p>
} }
<p class="muted route-note">
Los pasos muestran el tamizaje actual, en curso: el de la citología que se consulta.
</p>
<div data-section="etapas"> <div data-section="etapas">
<app-stages [stages]="s" [detail]="true" /> <app-stages [stages]="s" [detail]="true" />
</div> </div>
@@ -258,19 +261,21 @@
</mat-card> </mat-card>
} }
@if ( @if (excluded() || groups().length || domain() !== 'cacu' || riskModels().length) {
riskExclusion() || withheld() || groups().length || domain() !== 'cacu' || riskModels().length
) {
<mat-card appearance="outlined" class="wide" data-section="riesgos"> <mat-card appearance="outlined" class="wide" data-section="riesgos">
@if (excluded(); as reason) {
<mat-card-header>
<mat-card-title>Sin estimación de riesgo: criterio de exclusión</mat-card-title>
</mat-card-header>
}
<mat-card-content> <mat-card-content>
@if (withheld(); as why) { @if (excluded(); as reason) {
<p role="status" data-state="withheld">{{ why }}</p> <p role="status" data-state="excluded">{{ reason }}</p>
}
@if (riskExclusion(); as reason) {
<p role="status">{{ reason }}</p>
} @else { } @else {
<app-risk-scales [groups]="groups()" /> @if (currency().note; as note) {
<p class="muted route-note" data-state="toma">{{ note }}</p>
} }
<app-risk-scales [groups]="groups()" />
@if (riskModels().length) { @if (riskModels().length) {
<details data-section="modelos"> <details data-section="modelos">
<summary>Modelos y valores</summary> <summary>Modelos y valores</summary>
@@ -309,19 +314,20 @@
</table> </table>
</details> </details>
} }
@if (!riskExclusion() && (riskModels().length || riskSeries.value()?.length)) { @if (riskModels().length || hasCurves()) {
<details class="curves" open data-section="curvas"> <details class="curves" open data-section="curvas">
<summary>Curvas de probabilidad con su intervalo</summary> <summary>Curvas de probabilidad con su intervalo</summary>
@if (riskSeries.value()?.length) { @if (hasCurves()) {
<app-risk-series [series]="riskSeries.value()!" /> <app-risk-series [series]="riskSeries.value()!" />
} @else { } @else {
<app-plot [figure]="curve()" [height]="300" [toolbar]="false" /> <app-plot [figure]="curve()" [height]="300" [toolbar]="false" />
} }
</details> </details>
} }
@if (!riskModels().length && !riskExclusion()) { @if (!riskModels().length) {
<p class="muted">Sin evaluación de un modelo en producción.</p> <p class="muted">Sin evaluación de un modelo en producción.</p>
} }
}
</mat-card-content> </mat-card-content>
</mat-card> </mat-card>
} }
+27 -2
View File
@@ -30,7 +30,7 @@ import { firstValueFrom } from 'rxjs';
import { ApiConfiguration } from '../api/api-configuration'; import { ApiConfiguration } from '../api/api-configuration';
import { ANTECEDENTS, Fact, group, hpvApart, split } from './record-groups'; import { ANTECEDENTS, Fact, group, hpvApart, split } from './record-groups';
import { eligibilityFailure, eligibilityView, type EligibilityState } from './eligibility'; import { eligibilityFailure, eligibilityView, type EligibilityState } from './eligibility';
import { ineligibility } from './ineligibility'; import { currency, ineligibility } from './ineligibility';
import { parseSeries, RiskSeries, Series } from './risk-series'; import { parseSeries, RiskSeries, Series } from './risk-series';
import { curveFigure } from './risk-curve'; import { curveFigure } from './risk-curve';
import { riskGroups, riskScales, RiskScales, survivalGroups } from './risk-scales'; import { riskGroups, riskScales, RiskScales, survivalGroups } from './risk-scales';
@@ -202,6 +202,26 @@ export class Paciente {
const patient = this.patient(); const patient = this.patient();
return patient ? ext(patient, 'risk-withheld')?.valueString : undefined; return patient ? ext(patient, 'risk-withheld')?.valueString : undefined;
}); });
/** The one criterion she does not meet: nothing else of her risk is then shown. */
protected readonly excluded = computed(
() => this.withheld() ?? this.riskExclusion() ?? this.currency().excluded,
);
/** CaCu: the cytology her estimates speak of, against her latest by the cut-off. */
protected readonly currency = computed(() =>
this.domain() === 'cacu'
? currency(
this.riskModels(),
(this.data.value()?.reports ?? [])
.filter((r) => code(r.code) === 'cervical_cytology')
.map((r) => r.effectiveDateTime ?? '')
.filter((d) => d && d.slice(0, 10) <= this.cutoff()),
)
: {},
);
/** Whether any published series has a point to draw. */
protected readonly hasCurves = computed(
() => this.riskSeries.value()?.some((s) => s.points.length > 0) ?? false,
);
/** CaCu: the route of the cytology she was opened at, else of her latest, by the cut-off. */ /** CaCu: the route of the cytology she was opened at, else of her latest, by the cut-off. */
protected readonly stages = computed(() => { protected readonly stages = computed(() => {
const cytologies = (this.data.value()?.reports ?? []).filter( const cytologies = (this.data.value()?.reports ?? []).filter(
@@ -251,7 +271,12 @@ export class Paciente {
protected readonly riskSeries = resource({ protected readonly riskSeries = resource({
params: () => params: () =>
this.domain() === 'cacu' this.domain() === 'cacu'
? { id: this.id(), cutoff: this.corte(), sample: this.citologia() } ? // the NCI's series speak of the same cytology as the institutional estimate
{
id: this.id(),
cutoff: this.corte(),
sample: this.currency().sample ?? this.citologia(),
}
: undefined, : undefined,
loader: async ({ params }): Promise<Series[] | undefined> => { loader: async ({ params }): Promise<Series[] | undefined> => {
try { try {
+3 -1
View File
@@ -331,7 +331,7 @@ export class RiskScales {
hpv: 'VPH', hpv: 'VPH',
hpv_positive: 'VPH', hpv_positive: 'VPH',
hpv_16_18: 'VPH 16/18', hpv_16_18: 'VPH 16/18',
referral_grade: 'Referencia', referral_grade: 'Citología de referencia',
bethesda: 'Citología', bethesda: 'Citología',
hpv_16: 'VPH 16', hpv_16: 'VPH 16',
hpv_18: 'VPH 18', hpv_18: 'VPH 18',
@@ -339,6 +339,8 @@ export class RiskScales {
)[name] ?? name; )[name] ?? name;
protected readonly inputValue = (name: string, value: unknown) => { protected readonly inputValue = (name: string, value: unknown) => {
if (value === null || value === undefined) return 'No documentado'; if (value === null || value === undefined) return 'No documentado';
if (name === 'referral_grade' && (value === 'high' || value === 'low'))
return value === 'high' ? 'Alto grado' : 'Bajo grado';
if (name.startsWith('hpv') && (value === 0 || value === 1 || typeof value === 'boolean')) if (name.startsWith('hpv') && (value === 0 || value === 1 || typeof value === 'boolean'))
return value ? 'Positivo' : 'Negativo'; return value ? 'Positivo' : 'Negativo';
if (name.startsWith('hpv') && value === 'positive') return 'Positivo'; if (name.startsWith('hpv') && value === 'positive') return 'Positivo';
+1 -3
View File
@@ -25,8 +25,6 @@ describe('risk series', () => {
}); });
expect(series.points).toEqual([{ years: 0, p: 0, low: undefined, high: undefined }]); expect(series.points).toEqual([{ years: 0, p: 0, low: undefined, high: undefined }]);
expect(seriesName(series)).toBe('ISSSTELEON, LIEAG+'); expect(seriesName(series)).toBe('ISSSTELEON, LIEAG+');
expect(seriesName({ ...series, source: 'NCI (tabla de ingreso)' })).toBe( expect(seriesName({ ...series, source: 'NCI', outcome: 'CIN3+' })).toBe('NCI, CIN3+');
'NCI, ingreso a LIEAG+',
);
}); });
}); });
+6 -10
View File
@@ -29,13 +29,9 @@ const OUTCOME_TEXT: Record<string, string> = {
}; };
export const seriesName = (s: Series) => { export const seriesName = (s: Series) => {
const outcome = OUTCOME_TEXT[s.outcome] ?? s.outcome; const outcome = (OUTCOME_TEXT[s.outcome] ?? s.outcome).replace(' (CIN2+)', '');
if (s.source === 'NCI (tabla de ingreso)') // the platform's own models are the hospital's
return `NCI, ingreso a ${outcome.replace(' (CIN2+)', '').replace(/^Cáncer$/, 'cáncer')}`; return `${s.source === 'Institucional' ? 'ISSSTELEON' : s.source}, ${outcome}`;
// the platform's own models are the hospital's: its name, and the outcome without its synonym
return s.source === 'Institucional'
? `ISSSTELEON, ${outcome.replace(' (CIN2+)', '')}`
: `${s.source} · ${outcome}`;
}; };
/** The series of the answer. A value absent from it stays absent. */ /** The series of the answer. A value absent from it stays absent. */
@@ -65,7 +61,6 @@ export function parseSeries(answer: Parameters): Series[] {
selector: 'app-risk-series', selector: 'app-risk-series',
imports: [CurveChooser], imports: [CurveChooser],
template: ` template: `
<p class="muted">Cada serie tiene su propio desenlace y población: no se restan entre sí.</p>
@if (available().length) { @if (available().length) {
<app-curve-chooser [choices]="choices()" [draw]="draw()" [notes]="assumptions()" /> <app-curve-chooser [choices]="choices()" [draw]="draw()" [notes]="assumptions()" />
} @else { } @else {
@@ -81,12 +76,13 @@ export function parseSeries(answer: Parameters): Series[] {
export class RiskSeries { export class RiskSeries {
readonly series = input.required<Series[]>(); readonly series = input.required<Series[]>();
protected readonly available = computed(() => this.series().filter((s) => s.points.length)); protected readonly available = computed(() => this.series().filter((s) => s.points.length));
/** the platform's own series are drawn until the user says otherwise */ /** the platform's own series and the NCI master table's CIN2+ and CIN3+ are drawn until the
* user says otherwise */
protected readonly choices = computed(() => protected readonly choices = computed(() =>
this.available().map((s) => ({ this.available().map((s) => ({
id: s.id, id: s.id,
name: seriesName(s), name: seriesName(s),
on: s.source === 'Institucional', on: s.source === 'Institucional' || ['nci-master-CIN2+', 'nci-master-CIN3+'].includes(s.id),
})), })),
); );
private readonly among = computed(() => { private readonly among = computed(() => {