diff --git a/src/app/paciente/ineligibility.spec.ts b/src/app/paciente/ineligibility.spec.ts index 226baf7..05e494b 100644 --- a/src/app/paciente/ineligibility.spec.ts +++ b/src/app/paciente/ineligibility.spec.ts @@ -1,5 +1,5 @@ import type { EligibilityState, Visit } from './eligibility'; -import { ineligibility } from './ineligibility'; +import { currency, ineligibility } from './ineligibility'; const visit = (indexDate: string, ...reasons: string[]): Visit => ({ indexDate, @@ -35,3 +35,21 @@ describe('ineligibility', () => { 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)'); + }); +}); diff --git a/src/app/paciente/ineligibility.ts b/src/app/paciente/ineligibility.ts index a642cb9..3cb07cf 100644 --- a/src/app/paciente/ineligibility.ts +++ b/src/app/paciente/ineligibility.ts @@ -30,3 +30,27 @@ export function ineligibility( } 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.`, + }; +} diff --git a/src/app/paciente/paciente.html b/src/app/paciente/paciente.html index e8cfbba..a2a7517 100644 --- a/src/app/paciente/paciente.html +++ b/src/app/paciente/paciente.html @@ -272,6 +272,9 @@ @if (excluded(); as reason) {
{{ reason }}
} @else { + @if (currency().note; as note) { +{{ note }}
+ }