diff --git a/src/app/features/indicadores/paciente-detalle/paciente-riesgo-cama.spec.ts b/src/app/features/indicadores/paciente-detalle/paciente-riesgo-cama.spec.ts index 423dc9d..6e3f422 100644 --- a/src/app/features/indicadores/paciente-detalle/paciente-riesgo-cama.spec.ts +++ b/src/app/features/indicadores/paciente-detalle/paciente-riesgo-cama.spec.ts @@ -84,7 +84,7 @@ describe('Riesgo individual de la paciente CaMa', () => { expect(text).toContain('17.8 %'); expect(text).toContain('25.1 %'); expect(text).not.toMatch(/Información simulada|Entorno DEV|Sin evaluación clínica/); - expect([...(f.nativeElement as HTMLElement).querySelectorAll('tbody th')].map(th => th.textContent!.trim())).toEqual(['0.5', '1', '1.5']); + expect([...(f.nativeElement as HTMLElement).querySelectorAll('table.risk tbody th')].map(th => th.textContent!.trim())).toEqual(['0.5', '1', '1.5']); }); // Fails if the CaMa record goes back to showing the individual risk table, which its two analyses replace. diff --git a/src/app/features/indicadores/paciente-detalle/paciente-riesgo-estimando.spec.ts b/src/app/features/indicadores/paciente-detalle/paciente-riesgo-estimando.spec.ts index cb6363f..a0d0257 100644 --- a/src/app/features/indicadores/paciente-detalle/paciente-riesgo-estimando.spec.ts +++ b/src/app/features/indicadores/paciente-detalle/paciente-riesgo-estimando.spec.ts @@ -5,7 +5,7 @@ import { of } from 'rxjs'; import { PLOTLY_LOADER } from '../../../shared/plotly/plotly-runtime'; import { PACIENTE_RIESGO_PROVIDER } from './paciente-riesgo.provider'; import { riesgoCacuCancerSinEstimar, riesgoCacuConEstimando, riesgoCacuDosDesenlaces, riesgoCacuEjemplo, riesgoCacuVista } from './paciente-riesgo.testing'; -import { conIntervalo, encabezado, fraseRiesgo, porcentaje } from './paciente-riesgo.presentacion'; +import { conIntervalo, covariables, encabezado, fraseRiesgo, porcentaje } from './paciente-riesgo.presentacion'; import { riesgoPacienteResponse } from './paciente-riesgo.validation'; import { figuraRiesgoPaciente } from './paciente-riesgo-figura'; import { PacienteRiesgoTabla } from './paciente-riesgo-tabla'; @@ -27,8 +27,8 @@ describe('Riesgo individual: qué se estima y su curva', () => { it('lee el estimando conocido e ignora claves que no conoce (también el método del intervalo, que es del reporte); sin extensión queda en null', () => { expect(riesgoPacienteResponse(riesgoCacuConEstimando(), '42')!.riesgo.estimando).toEqual({ - quantity: 'Riesgo acumulado', description: 'Probabilidad de CIN2+ antes de cada horizonte.', - outcome: 'CIN2+: biopsia LIEAG, CIS o carcinoma', horizons_unit: 'años' }); + quantity: 'Probabilidad', description: 'Probabilidad de CIN2+ antes de cada horizonte.', + outcome: 'CIN2+: biopsia LIEAG, CIS o carcinoma', horizons_unit: 'años', covariates: 'VPH y citología índice' }); expect(riesgoPacienteResponse(riesgoCacuEjemplo(), '42')).toEqual(riesgoCacuVista()); }); @@ -40,7 +40,7 @@ describe('Riesgo individual: qué se estima y su curva', () => { it('nombra el número, su desenlace y la unidad de los horizontes en la ficha', () => { const { root } = setup(riesgoCacuConEstimando()); - expect([...root.querySelectorAll('thead th')].map(th => th.textContent!.trim())) + expect([...root.querySelectorAll('table.risk thead th')].map(th => th.textContent!.trim())) .toEqual(['Horizonte (años)', 'Probabilidad a LIEAG+ (%)', 'Probabilidad a cáncer (%)']); expect(root.querySelector('details.risk-details summary')!.textContent).toContain('Detalle del modelo'); for (const value of ['Qué se estima', 'CIN2+: biopsia LIEAG, CIS o carcinoma']) { @@ -52,7 +52,7 @@ describe('Riesgo individual: qué se estima y su curva', () => { it('dibuja la curva solo al abrir su sección', async () => { const { fixture, root } = setup(riesgoCacuConEstimando()); const details = root.querySelector('details.risk-curve') as HTMLDetailsElement; - expect(details.querySelector('summary')!.textContent).toContain('Curva de riesgo acumulado'); + expect(details.querySelector('summary')!.textContent).toContain('Curva de probabilidad'); expect(root.querySelector('app-plotly-chart')).toBeNull(); details.open = true; details.dispatchEvent(new Event('toggle')); @@ -66,7 +66,7 @@ describe('Riesgo individual: qué se estima y su curva', () => { expect(banda.data).toHaveLength(3); expect(banda.data[2]['y']).toEqual([8, 21, 34]); expect(banda.data[1]['y']).toEqual([5, 15, 26]); - expect((banda.layout['yaxis'] as any).title.text).toBe('Riesgo acumulado (%)'); + expect((banda.layout['yaxis'] as any).title.text).toBe('Probabilidad (%)'); const parcial = { ...riesgo, horizontes: riesgo.horizontes.map((h, i) => i === 0 ? { ...h, ic_bajo: null, ic_alto: null } : h) }; const barras = figuraRiesgoPaciente([parcial]); @@ -76,9 +76,9 @@ describe('Riesgo individual: qué se estima y su curva', () => { it('pone una columna por desenlace, LIEAG+ primero, con el IC entre paréntesis', () => { const { root } = setup(riesgoCacuDosDesenlaces()); - expect([...root.querySelectorAll('thead th')].map(th => th.textContent!.trim())) + expect([...root.querySelectorAll('table.risk thead th')].map(th => th.textContent!.trim())) .toEqual(['Horizonte (años)', 'Probabilidad a LIEAG+ (%)', 'Probabilidad a cáncer (%)']); - const fila = [...root.querySelectorAll('tbody tr')][2]; + const fila = [...root.querySelectorAll('table.risk tbody tr')][2]; expect([...fila.querySelectorAll('td')].map(td => td.textContent!.replace(/\s+/g, ' ').trim())) .toEqual(['34 % (26 – 44 %)', '1.5 % (0.8 – 2.8 %)']); }); @@ -86,8 +86,8 @@ describe('Riesgo individual: qué se estima y su curva', () => { it('la frase dice los resultados índice y los dos riesgos al horizonte más largo, respectivamente', () => { const { riesgos } = riesgoPacienteResponse(riesgoCacuDosDesenlaces(), '42')!; expect(riesgos.map(r => r.desenlace)).toEqual(['cin2_mas', 'cancer']); - expect(fraseRiesgo(riesgos)).toBe('Un resultado de VPH positivo y una citología LIEBG (2026-06-01) tienen un riesgo ' - + 'acumulado a 5 años de estar presente o de aparecer LIEAG+ y cáncer de 34 % (26 – 44 %) y 1.5 % (0.8 – 2.8 %), ' + expect(fraseRiesgo(riesgos)).toBe('Un resultado de VPH positivo y una citología LIEBG (2026-06-01) tienen una probabilidad ' + + 'a 5 años de estar presente o de aparecer LIEAG+ y cáncer de 34 % (26 – 44 %) y 1.5 % (0.8 – 2.8 %), ' + 'respectivamente.'); expect(fraseRiesgo(riesgoPacienteResponse(riesgoCacuEjemplo(), '42')!.riesgos)).toBeNull(); }); @@ -113,19 +113,19 @@ describe('Riesgo individual: qué se estima y su curva', () => { const muerte = { ...riesgos[1], desenlace: 'muerte', fecha_indice: '2024-03-01' }; expect(encabezado(muerte, riesgos[0].fecha_indice)).toBe('Probabilidad a muerte desde 2024-03-01'); expect(fraseRiesgo([riesgos[0], muerte])).toBe('Un resultado de VPH positivo y una citología LIEBG (2026-06-01) ' - + 'tienen un riesgo acumulado a 5 años de estar presente o de aparecer LIEAG+ de 34 % (26 – 44 %).'); + + 'tienen una probabilidad a 5 años de estar presente o de aparecer LIEAG+ de 34 % (26 – 44 %).'); }); it('sin modelo de un desenlace su columna dice No disponible', () => { const { root } = setup(riesgoCacuConEstimando()); - const celdas = [...root.querySelectorAll('tbody tr')].map(tr => tr.querySelectorAll('td')[1].textContent!.trim()); + const celdas = [...root.querySelectorAll('table.risk tbody tr')].map(tr => tr.querySelectorAll('td')[1].textContent!.trim()); expect(celdas).toEqual(['No disponible', 'No disponible', 'No disponible']); }); it('con un modelo que no la estima su columna lo dice, con el motivo, y no entra en la curva ni en la frase', () => { const data = riesgoCacuCancerSinEstimar(); const { root } = setup(data); - const celdas = [...root.querySelectorAll('tbody tr')].map(tr => tr.querySelectorAll('td')[1].textContent!.trim()); + const celdas = [...root.querySelectorAll('table.risk tbody tr')].map(tr => tr.querySelectorAll('td')[1].textContent!.trim()); expect(celdas).toEqual(['No estimada para su grupo', 'No estimada para su grupo', 'No estimada para su grupo']); expect(root.querySelector('.unavailable-note')!.textContent).toContain('queda fuera de su población'); const { riesgos, riesgo } = riesgoPacienteResponse(data, '42')!; @@ -134,4 +134,28 @@ describe('Riesgo individual: qué se estima y su curva', () => { expect(figuraRiesgoPaciente(riesgos.filter(r => r.horizontes.length)).data.filter(t => t['mode'] === 'lines+markers')) .toHaveLength(1); }); + + it('una supervivencia se muestra como 1 − la probabilidad de morir, con el IC invertido', () => { + const data = riesgoCacuConEstimando(); + const r = data.entry[0].resource; + r.extension[0].extension.push({ url: 'complement', valueString: 'supervivencia' }); + r.prediction.forEach((p: any) => { p.outcome.coding[0].code = 'muerte'; }); + const lote = riesgoPacienteResponse(data, '42')!.riesgo; + expect(lote.horizontes[0]).toMatchObject({ horizonte_anios: 1 }); + expect(lote.horizontes[0].probabilidad).toBeCloseTo(0.92); + expect(lote.horizontes[0].ic_bajo).toBeCloseTo(0.88); + expect(lote.horizontes[0].ic_alto).toBeCloseTo(0.95); + expect(encabezado(lote)).toBe('Probabilidad de supervivencia'); + }); + + it('pone las covariables al pie de la tabla y el detalle en una fila por modelo, sin versión ni estado', () => { + const { root } = setup(riesgoCacuDosDesenlaces()); + expect(root.querySelector('.covariates-note')!.textContent).toBe('Covariables: VPH y citología índice.'); + expect(root.querySelectorAll('table.models tbody tr')).toHaveLength(2); + expect(root.textContent).not.toMatch(/Versión del modelo|Estado del lote/); + expect(root.querySelector('caption')!.textContent).toContain('Probabilidad en porcentaje (0 a 100 %)'); + const { riesgos } = riesgoPacienteResponse(riesgoCacuDosDesenlaces(), '42')!; + riesgos[1].estimando = { ...riesgos[1].estimando, covariates: 'otras' }; + expect(covariables(riesgos)).toBe('Covariables: Probabilidad a LIEAG+: VPH y citología índice; Probabilidad a cáncer: otras.'); + }); }); diff --git a/src/app/features/indicadores/paciente-detalle/paciente-riesgo-tabla.html b/src/app/features/indicadores/paciente-detalle/paciente-riesgo-tabla.html index 6cbd5f0..5416dfd 100644 --- a/src/app/features/indicadores/paciente-detalle/paciente-riesgo-tabla.html +++ b/src/app/features/indicadores/paciente-detalle/paciente-riesgo-tabla.html @@ -14,9 +14,9 @@ @let filas = filasDe(lotesDe(columnas)); @if (filas.length) {
- - +
{{ riesgo.estimando?.quantity ?? 'Probabilidad' }} por horizonte desde la fecha índice - ({{ riesgo.fecha_indice }}), con su intervalo de confianza entre paréntesis
+ @for (c of columnas; track c.encabezado) { } @@ -36,25 +36,31 @@ @for (c of columnas; track c.encabezado) { @if (c.lote?.sin_estimacion; as motivo) {

{{ c.encabezado }}: {{ motivo }}.

} } + @if (covariables(riesgos); as texto) {

{{ texto }}

}
Detalle del modelo - @for (r of riesgos; track r.id) { - @if (riesgos.length > 1) {
{{ encabezado(r) }}
} - - } +
+
Probabilidad en porcentaje (0 a 100 %) por horizonte desde la fecha índice + ({{ riesgo.fecha_indice }}), con su intervalo de confianza de 95 % entre paréntesis
Horizonte ({{ riesgo.estimando?.horizons_unit ?? 'años' }}){{ c.encabezado }} (%)
+ + + + + + + @for (r of riesgos; track r.id) { + + + + + + + + + + } + +
ProbabilidadModeloQué se estimaDesenlaceDesdeFecha índiceEvaluado en
{{ encabezado(r) }}{{ r.modelo_nombre }}{{ r.estimando?.description ?? '—' }}{{ r.estimando?.outcome ?? r.desenlace_texto ?? r.desenlace }}{{ r.estimando?.index_date ?? '—' }}{{ r.fecha_indice }}
+
@if (filas.length > 1) {
@@ -62,7 +68,7 @@ @if (frase(riesgos); as texto) {

{{ texto }}

} @if (curvaAbierta()) { + [label]="'Curvas de probabilidad individual ' + rotulo() + ' por horizonte'" /> }
} diff --git a/src/app/features/indicadores/paciente-detalle/paciente-riesgo-tabla.scss b/src/app/features/indicadores/paciente-detalle/paciente-riesgo-tabla.scss index 768e31a..5b1677d 100644 --- a/src/app/features/indicadores/paciente-detalle/paciente-riesgo-tabla.scss +++ b/src/app/features/indicadores/paciente-detalle/paciente-riesgo-tabla.scss @@ -24,3 +24,5 @@ tbody tr:last-child > * { border-bottom: 0; } .risk-details h6 { margin: .75rem 0 .25rem; font-size: .95rem; } .unavailable { color: var(--issste-text-secondary); } .unavailable-note { color: var(--issste-text-secondary); font-size: .85rem; margin: .5rem 0 0; } +.covariates-note { color: var(--issste-text-secondary); font-size: .85rem; margin: .5rem 0 0; } +table.models { min-width: 48rem; } diff --git a/src/app/features/indicadores/paciente-detalle/paciente-riesgo-tabla.ts b/src/app/features/indicadores/paciente-detalle/paciente-riesgo-tabla.ts index 1cb53c2..0fa8ab7 100644 --- a/src/app/features/indicadores/paciente-detalle/paciente-riesgo-tabla.ts +++ b/src/app/features/indicadores/paciente-detalle/paciente-riesgo-tabla.ts @@ -3,7 +3,7 @@ import { LowerCasePipe } from '@angular/common'; import { PlotlyChart } from '../../../shared/plotly/plotly-chart'; import { PlotlyFigure } from '../indicadores.models'; import { figuraRiesgoPaciente } from './paciente-riesgo-figura'; -import { ColumnaRiesgo, columnasRiesgo, conRiesgo, encabezado, etiquetaDesenlace, filasRiesgo, fraseRiesgo, porcentaje } from './paciente-riesgo.presentacion'; +import { ColumnaRiesgo, columnasRiesgo, conRiesgo, covariables, encabezado, etiquetaDesenlace, filasRiesgo, fraseRiesgo, porcentaje } from './paciente-riesgo.presentacion'; import { DominioRiesgo, LoteRiesgoCacu } from './paciente-riesgo.models'; import { PacienteRiesgoState } from './paciente-riesgo.state'; import { tieneIntervalo } from './paciente-riesgo.validation'; @@ -39,6 +39,7 @@ export class PacienteRiesgoTabla { readonly frase = fraseRiesgo; readonly filasDe = filasRiesgo; readonly conRiesgo = conRiesgo; + readonly covariables = covariables; columnasDe(riesgos: LoteRiesgoCacu[]): ColumnaRiesgo[] { return columnasRiesgo(riesgos, this.dominio()); } lotesDe(columnas: ColumnaRiesgo[]) { return columnas.map(c => (c.lote?.horizontes.length ? c.lote : null)); } private figuraDe?: { riesgos: LoteRiesgoCacu[]; figura: PlotlyFigure }; diff --git a/src/app/features/indicadores/paciente-detalle/paciente-riesgo.models.ts b/src/app/features/indicadores/paciente-detalle/paciente-riesgo.models.ts index 9da4a44..f2bf13e 100644 --- a/src/app/features/indicadores/paciente-detalle/paciente-riesgo.models.ts +++ b/src/app/features/indicadores/paciente-detalle/paciente-riesgo.models.ts @@ -16,13 +16,17 @@ export interface HorizonteRiesgoCacu { /** What the model's number is (the scenario's `[estimand]`, extension `estimando`); each field may be missing. */ export interface EstimandoRiesgo { - /** e.g. "Riesgo acumulado"; also `method.text`. */ + /** e.g. "Probabilidad"; also `method.text`. */ quantity?: string; description?: string; outcome?: string; index_date?: string; /** The unit the horizons are counted in, e.g. "años". */ horizons_unit?: string; + /** The variables the model uses, in words, as the record writes them under the table. */ + covariates?: string; + /** `supervivencia`: the model gives the probability of the outcome (dying) and the record shows its complement. */ + complement?: string; } /** The results of the cytology sampled on the risk's index date (extension `resultados-indice`), as recorded. */ diff --git a/src/app/features/indicadores/paciente-detalle/paciente-riesgo.presentacion.ts b/src/app/features/indicadores/paciente-detalle/paciente-riesgo.presentacion.ts index f31c557..da9a3ee 100644 --- a/src/app/features/indicadores/paciente-detalle/paciente-riesgo.presentacion.ts +++ b/src/app/features/indicadores/paciente-detalle/paciente-riesgo.presentacion.ts @@ -5,7 +5,7 @@ import { tieneIntervalo } from './paciente-riesgo.validation'; export function etiquetaDesenlace(lote: LoteRiesgoCacu): string { if (lote.desenlace.startsWith('cin2')) return 'LIEAG+'; if (lote.desenlace === 'cancer') return 'cáncer'; - if (lote.desenlace === 'muerte') return 'muerte'; + if (lote.desenlace === 'muerte') return lote.estimando?.complement === 'supervivencia' ? 'supervivencia' : 'muerte'; return lote.desenlace_texto ?? lote.desenlace; } @@ -13,7 +13,8 @@ export function etiquetaDesenlace(lote: LoteRiesgoCacu): string { * `fechaComun` (a survival model counts from the invasive biopsy, not from the cytology). */ export function encabezado(lote: LoteRiesgoCacu, fechaComun: string | null = null): string { const desde = fechaComun && lote.fecha_indice !== fechaComun ? ` desde ${lote.fecha_indice}` : ''; - return `Probabilidad a ${etiquetaDesenlace(lote)}${desde}`; + const etiqueta = etiquetaDesenlace(lote); + return `${etiqueta === 'supervivencia' ? 'Probabilidad de supervivencia' : `Probabilidad a ${etiqueta}`}${desde}`; } /** A probability as a percentage with the decimals a small risk needs, without trailing zeros: 0.178 -> "17.8", @@ -110,6 +111,15 @@ export function fraseRiesgo(todos: LoteRiesgoCacu[]): string | null { const desenlaces = junta(riesgos.map(etiquetaDesenlace)); const valores = junta(ultima.celdas.map(c => conIntervalo(c!))); const anios = ultima.horizonte_anios === 1 ? '1 año' : `${ultima.horizonte_anios} años`; - return `${inicio} (${fecha}) tienen un riesgo acumulado a ${anios} de estar presente o de aparecer ${desenlaces} ` + return `${inicio} (${fecha}) tienen una probabilidad a ${anios} de estar presente o de aparecer ${desenlaces} ` + `de ${valores}${riesgos.length > 1 ? ', respectivamente' : ''}.`; } + +/** The covariates under the table: each model's, by its column, or once when every model uses the same ones. */ +export function covariables(riesgos: LoteRiesgoCacu[]): string | null { + const con = riesgos.filter(r => r.estimando?.covariates); + if (!con.length) return null; + const textos = [...new Set(con.map(r => r.estimando!.covariates!))]; + if (textos.length === 1) return `Covariables: ${textos[0]}.`; + return `Covariables: ${con.map(r => `${encabezado(r)}: ${r.estimando!.covariates}`).join('; ')}.`; +} diff --git a/src/app/features/indicadores/paciente-detalle/paciente-riesgo.spec.ts b/src/app/features/indicadores/paciente-detalle/paciente-riesgo.spec.ts index 684d4e0..f8cb645 100644 --- a/src/app/features/indicadores/paciente-detalle/paciente-riesgo.spec.ts +++ b/src/app/features/indicadores/paciente-detalle/paciente-riesgo.spec.ts @@ -45,13 +45,14 @@ describe('RIESGO-CACU-02: presentación y aislamiento', () => { const f = setup({ obtener }), root: HTMLElement = f.nativeElement; expect(obtener).toHaveBeenCalledExactlyOnceWith('42'); // horizon, CIN2+ (LIEAG+) and cancer (without a model here: "No disponible"), each risk with its interval - expect(root.querySelectorAll('thead th')).toHaveLength(3); - expect([...root.querySelectorAll('thead th')].every(th => th.getAttribute('scope') === 'col')).toBe(true); - expect(root.querySelectorAll('tbody th[scope="row"]')).toHaveLength(3); + expect(root.querySelectorAll('table.risk thead th')).toHaveLength(3); + expect([...root.querySelectorAll('table.risk thead th')].every(th => th.getAttribute('scope') === 'col')).toBe(true); + expect(root.querySelectorAll('table.risk tbody th[scope="row"]')).toHaveLength(3); expect([...root.querySelectorAll('.percentage')].map(c => c.textContent!.trim())).toEqual(['8 %', '21 %', '34 %']); expect(root.querySelector('.interval')!.textContent).toContain('(5 – 12 %)'); - expect(root.textContent).toContain('Final (final)'); - for (const value of ['modelo-cacu', '2.1.0', '2026-10-01 00:00 UTC', '2026-06-01', 'CIN2+ por biopsia']) { + // the record names the model, its index date and outcome, not its version nor the batch's state + expect(root.textContent).not.toMatch(/Final \(final\)|2\.1\.0/); + for (const value of ['modelo-cacu', '2026-10-01 00:00 UTC', '2026-06-01', 'CIN2+ por biopsia']) { expect(root.textContent).toContain(value); } // The record no longer shows the cohort's internals (its definition, version or model variables). @@ -73,7 +74,7 @@ describe('RIESGO-CACU-02: presentación y aislamiento', () => { expect(getComputedStyle(scroll).overflow).toBe('auto'); expect(getComputedStyle(scroll).maxWidth).toBe('100%'); expect(getComputedStyle(root.querySelector('table')!).minWidth).toBe('36rem'); - expect(getComputedStyle(root.querySelector('thead th')!).position).toBe('sticky'); + expect(getComputedStyle(root.querySelector('table.risk thead th')!).position).toBe('sticky'); }); it('renderiza horizontes parciales/dinámicos y extremos cero y uno con IC opcionales', () => { @@ -85,10 +86,10 @@ describe('RIESGO-CACU-02: presentación y aislamiento', () => { prediccion(0.00123, '2026-06-01', '2038-09-01'), ]; const f = setup({ obtener: () => of(data) }), root: HTMLElement = f.nativeElement; - expect([...root.querySelectorAll('tbody th')].map(c => c.textContent!.trim())).toEqual(['0.5', '8', '12.25']); + expect([...root.querySelectorAll('table.risk tbody th')].map(c => c.textContent!.trim())).toEqual(['0.5', '8', '12.25']); expect([...root.querySelectorAll('.percentage')].map(c => c.textContent!.trim())).toEqual(['0 %', '100 %', '0.123 %']); expect([...root.querySelectorAll('.interval')].map(c => c.textContent!.trim())).toEqual(['(0 – 0 %)', '(IC no disponible)', '(IC no disponible)']); - expect(root.textContent).toContain('Preliminar (preliminary)'); + expect(root.textContent).not.toContain('Preliminar (preliminary)'); }); it.each([[[]], [[{ code: 'real' }]], [undefined]])('no expone una respuesta no simulada (%j)', tag => { diff --git a/src/app/features/indicadores/paciente-detalle/paciente-riesgo.testing.ts b/src/app/features/indicadores/paciente-detalle/paciente-riesgo.testing.ts index c3d0eea..e69b7b6 100644 --- a/src/app/features/indicadores/paciente-detalle/paciente-riesgo.testing.ts +++ b/src/app/features/indicadores/paciente-detalle/paciente-riesgo.testing.ts @@ -57,9 +57,10 @@ export function riesgoCacuVista(): RiesgoPacienteCacu { export function riesgoCacuConEstimando(): any { const data = riesgoCacuEjemplo(); const resource = data.entry[0].resource; - resource.method.text = 'Riesgo acumulado'; + resource.method.text = 'Probabilidad'; resource.extension = [{ url: ESTIMANDO, extension: [ - { url: 'quantity', valueString: 'Riesgo acumulado' }, + { url: 'quantity', valueString: 'Probabilidad' }, + { url: 'covariates', valueString: 'VPH y citología índice' }, { url: 'description', valueString: 'Probabilidad de CIN2+ antes de cada horizonte.' }, { url: 'outcome', valueString: 'CIN2+: biopsia LIEAG, CIS o carcinoma' }, { url: 'horizons_unit', valueString: 'años' }, diff --git a/src/app/features/indicadores/paciente-detalle/paciente-riesgo.validation.ts b/src/app/features/indicadores/paciente-detalle/paciente-riesgo.validation.ts index 932bf4b..46e826d 100644 --- a/src/app/features/indicadores/paciente-detalle/paciente-riesgo.validation.ts +++ b/src/app/features/indicadores/paciente-detalle/paciente-riesgo.validation.ts @@ -13,7 +13,7 @@ const ESTIMAND = 'https://isssteleon.org/fhir/StructureDefinition/estimando'; const NOT_SCORED = 'https://isssteleon.org/fhir/StructureDefinition/sin-estimacion'; const INDEX_RESULTS = 'https://isssteleon.org/fhir/StructureDefinition/resultados-indice'; const INDEX_RESULT_KEYS: readonly (keyof ResultadosIndice)[] = ['escamosas', 'glandulares', 'vph']; -const ESTIMAND_KEYS: readonly (keyof EstimandoRiesgo)[] = ['quantity', 'description', 'outcome', 'index_date', 'horizons_unit']; +const ESTIMAND_KEYS: readonly (keyof EstimandoRiesgo)[] = ['quantity', 'description', 'outcome', 'index_date', 'horizons_unit', 'covariates', 'complement']; function utcTimestamp(v: unknown): v is string { return typeof v === 'string' @@ -138,6 +138,17 @@ function simulated(resource: Record): boolean { return record(meta) && Array.isArray(meta['tag']) && meta['tag'].some(t => record(t) && t['code'] === SIMULATED); } +/** A model whose estimand asks for its complement (survival from a probability of dying): each horizon becomes + * 1 − p, and its interval 1 − high to 1 − low. */ +function complemento(lote: LoteRiesgoCacu): void { + if (lote.estimando?.complement !== 'supervivencia') return; + lote.horizontes = lote.horizontes.map(h => ({ + ...h, probabilidad: 1 - h.probabilidad, + ic_bajo: h.ic_alto == null ? h.ic_alto ?? null : 1 - h.ic_alto, + ic_alto: h.ic_bajo == null ? h.ic_bajo ?? null : 1 - h.ic_bajo, + })); +} + /** Where an outcome goes among the patient's risks: CIN2+ first, then cancer, then any other. */ export function ordenDesenlace(desenlace: string): number { return desenlace.startsWith('cin2') ? 0 : desenlace === 'cancer' ? 1 : 2; @@ -157,6 +168,7 @@ export function riesgoPacienteResponse(v: unknown, pacId: string | null = null): if (!record(resource) || !simulated(resource)) invalid(); return riskAssessment(structuredClone(resource), pacId); }); + riesgos.forEach(complemento); riesgos.sort((a, b) => ordenDesenlace(a.desenlace) - ordenDesenlace(b.desenlace)); return { simulado: true, riesgo: riesgos.find(r => r.horizontes.length) ?? riesgos[0], riesgos }; }