Decir a qué citología corresponde la estimación y comparar el NCI en la misma

This commit is contained in:
2026-12-04 17:49:35 -06:00
parent 22edb0bf42
commit 4789282e17
4 changed files with 68 additions and 4 deletions
+19 -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,
@@ -35,3 +35,21 @@ describe('ineligibility', () => {
expect(ineligibility({ kind: 'error' }, '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)');
});
});
+24
View File
@@ -30,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.`,
};
}
+3
View File
@@ -272,6 +272,9 @@
@if (excluded(); as reason) { @if (excluded(); as reason) {
<p role="status" data-state="excluded">{{ reason }}</p> <p role="status" data-state="excluded">{{ reason }}</p>
} @else { } @else {
@if (currency().note; as note) {
<p class="muted route-note" data-state="toma">{{ note }}</p>
}
<app-risk-scales [groups]="groups()" /> <app-risk-scales [groups]="groups()" />
@if (riskModels().length) { @if (riskModels().length) {
<details data-section="modelos"> <details data-section="modelos">
+22 -3
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';
@@ -203,7 +203,21 @@ export class Paciente {
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. */ /** The one criterion she does not meet: nothing else of her risk is then shown. */
protected readonly excluded = computed(() => this.withheld() ?? this.riskExclusion()); 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. */ /** Whether any published series has a point to draw. */
protected readonly hasCurves = computed( protected readonly hasCurves = computed(
() => this.riskSeries.value()?.some((s) => s.points.length > 0) ?? false, () => this.riskSeries.value()?.some((s) => s.points.length > 0) ?? false,
@@ -257,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 {