CaCu patient record shows the risk's index date

The record's index date is riesgo.fecha_indice (the model's decision point the horizons count from), not the cohort
member's; the field is optional in the contract and validated as an ISO date.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
This commit is contained in:
2026-11-20 23:02:48 -06:00
parent c32d2b6012
commit 3bb1c8dd84
6 changed files with 10 additions and 3 deletions
@@ -13,7 +13,6 @@
<dl class="metadata">
<div><dt>Definición de cohorte</dt><dd>{{ cohorte.url }}</dd></div>
<div><dt>Versión de cohorte</dt><dd>{{ cohorte.version }}</dd></div>
<div><dt>Fecha índice</dt><dd>{{ cohorte.fecha_indice }}</dd></div>
</dl>
<details>
<summary>Variables del modelo PIMM</summary>
@@ -35,6 +34,7 @@
<dl class="metadata">
<div><dt>Modelo</dt><dd>{{ riesgo.modelo_nombre }}</dd></div>
<div><dt>Versión del modelo</dt><dd>{{ riesgo.modelo_version }}</dd></div>
<div><dt>Fecha índice</dt><dd>{{ riesgo.fecha_indice ?? 'No disponible' }}</dd></div>
<div><dt>Evaluado en (UTC)</dt><dd>{{ riesgo.evaluado_en }}</dd></div>
<div><dt>Estado del lote</dt><dd>{{ riesgo.estado_lote === 'final' ? 'Final (final)' : 'Preliminar (preliminary)' }}</dd></div>
</dl>
@@ -28,6 +28,8 @@ export interface LoteRiesgoCacu {
lote_id: number;
modelo_nombre: string;
modelo_version: string;
/** The model's index date for this patient (ISO date): the horizons count from it. Absent from older APIs. */
fecha_indice?: string | null;
evaluado_en: string;
estado_lote: EstadoEvaluacionCacu;
horizontes: HorizonteRiesgoCacu[];
@@ -46,9 +46,11 @@ describe('RIESGO-CACU-02: presentación y aislamiento', () => {
expect(root.querySelector('.interval')!.textContent).toContain('5 % – 12 %');
expect(root.textContent).toContain('Final (final)');
expect(root.textContent).toContain('Preliminar (preliminary)');
for (const value of ['modelo-cacu', '2.1.0', '2026-10-01T00:00:00Z', 'cacu/cohorte_vigilancia', '0.2.0', '2023-04-15', 'incidente', 'ASC-US', 'POSITIVO']) {
for (const value of ['modelo-cacu', '2.1.0', '2026-10-01T00:00:00Z', 'cacu/cohorte_vigilancia', '0.2.0', '2026-06-01', 'incidente', 'ASC-US', 'POSITIVO']) {
expect(root.textContent).toContain(value);
}
// The index date shown is the risk's (the model's decision point), not the cohort member's.
expect(root.textContent).not.toContain('2023-04-15');
expect(root.querySelector('table')!.getAttribute('aria-describedby')).toBe('riesgo-simulado');
expect(root.querySelector('#riesgo-simulado')!.textContent).toContain('Información simulada · Entorno DEV');
expect(root.textContent).not.toMatch(/Caso nuevo observado|BAJO|INTERMEDIO|ALTO|CIN3/);
@@ -9,7 +9,7 @@ export function riesgoCacuEjemplo(): RiesgoPacienteCacu {
tipo_censura: 'incidente', c: 0, l: 0.164, r: 0.548, pap_0: 'ASC-US', hpv_0: 'POSITIVO',
},
riesgo: {
lote_id: 12, modelo_nombre: 'modelo-cacu', modelo_version: '2.1.0',
lote_id: 12, modelo_nombre: 'modelo-cacu', modelo_version: '2.1.0', fecha_indice: '2026-06-01',
evaluado_en: '2026-10-01T00:00:00Z', estado_lote: 'final',
horizontes: [
{ horizonte_anios: 1, probabilidad: 0.08, ic_bajo: 0.05, ic_alto: 0.12, estado: 'final' },
@@ -90,6 +90,8 @@ describe('RIESGO-CACU-02: frontera del contrato DEV', () => {
['lote string', v => v.riesgo.lote_id = '12'],
['modelo omitido', v => delete v.riesgo.modelo_nombre],
['versión no textual', v => v.riesgo.modelo_version = 2],
['fecha índice del riesgo inválida', v => v.riesgo.fecha_indice = '2026-02-30'],
['fecha índice del riesgo no textual', v => v.riesgo.fecha_indice = 20260601],
['evaluación fecha imposible', v => v.riesgo.evaluado_en = '2026-02-30T00:00:00Z'],
['evaluación sin UTC', v => v.riesgo.evaluado_en = '2026-10-01T00:00:00-06:00'],
['hora inválida', v => v.riesgo.evaluado_en = '2026-10-01T25:00:00Z'],
@@ -38,6 +38,7 @@ function riesgoValido(v: unknown) {
if (v === null) return true;
if (!record(v) || !Number.isSafeInteger(v['lote_id']) || !text(v['modelo_nombre']) || !text(v['modelo_version'])
|| !utcTimestamp(v['evaluado_en']) || !estado(v['estado_lote']) || !Array.isArray(v['horizontes'])) return false;
if (Object.hasOwn(v, 'fecha_indice') && v['fecha_indice'] !== null && !isoDate(v['fecha_indice'])) return false;
const horizontes = v['horizontes'];
return horizontes.every(horizonteValido)
&& horizontes.every((h, i) => i === 0 || horizontes[i - 1]['horizonte_anios'] < h['horizonte_anios']);