diff --git a/src/app/features/indicadores/paciente-detalle/paciente-detalle.html b/src/app/features/indicadores/paciente-detalle/paciente-detalle.html index 18d3a53..e540175 100644 --- a/src/app/features/indicadores/paciente-detalle/paciente-detalle.html +++ b/src/app/features/indicadores/paciente-detalle/paciente-detalle.html @@ -79,7 +79,7 @@

Riesgos y recomendaciones

- +
} diff --git a/src/app/features/indicadores/paciente-detalle/paciente-detalle.models.ts b/src/app/features/indicadores/paciente-detalle/paciente-detalle.models.ts index bbbde94..254f2f4 100644 --- a/src/app/features/indicadores/paciente-detalle/paciente-detalle.models.ts +++ b/src/app/features/indicadores/paciente-detalle/paciente-detalle.models.ts @@ -6,6 +6,8 @@ export interface PacienteResumen { identidad: IdentidadPaciente; grupoEdad: string | null; estatus: string | null; + /** The follow-up status code (`CASO`, `PRE_COLPOSCOPIA`…): it decides which probabilities the record shows. */ + estatusCodigo: string | null; corte: string; origen: 'seguimiento-demostracion'; citologia: { fecha: string; resultado: string | null; calidad: string | null } | null; diff --git a/src/app/features/indicadores/paciente-detalle/paciente-detalle.state.ts b/src/app/features/indicadores/paciente-detalle/paciente-detalle.state.ts index b323aa1..58006e3 100644 --- a/src/app/features/indicadores/paciente-detalle/paciente-detalle.state.ts +++ b/src/app/features/indicadores/paciente-detalle/paciente-detalle.state.ts @@ -45,6 +45,7 @@ export class PacienteDetalleState { identidad, grupoEdad: paciente.grupo_edad === 'sin_dato' ? null : paciente.grupo_edad, estatus: paciente.estatus.etiqueta, + estatusCodigo: paciente.estatus.codigo, corte, origen: 'seguimiento-demostracion', citologia: paciente.ultima_citologia ? { diff --git a/src/app/features/indicadores/paciente-detalle/paciente-detalle.ts b/src/app/features/indicadores/paciente-detalle/paciente-detalle.ts index d9b38c3..1361ce5 100644 --- a/src/app/features/indicadores/paciente-detalle/paciente-detalle.ts +++ b/src/app/features/indicadores/paciente-detalle/paciente-detalle.ts @@ -34,6 +34,7 @@ export class PacienteDetalleComponent implements AfterViewInit, OnDestroy { get etiquetaIdentidad() { return this.estado.tipo === 'cerrado' ? '' : ETIQUETA_IDENTIDAD[this.estado.resumen.identidad.campo]; } /** The `pac_id` the risk is read by; a row with only the legacy `id_seudonimo` has none. */ + get estatusCodigo() { return this.estado.tipo !== 'cerrado' ? this.estado.resumen.estatusCodigo : null; } get pacId() { return this.estado.tipo !== 'cerrado' && this.estado.resumen.identidad.campo === 'pac_id' ? this.estado.resumen.identidad.id : null; } temporales(tipo: TipoRegistroTemporal) { return this.registrosTemporales.filter(item => item.tipo === tipo); } 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 06052bc..a40fe00 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 @@ -12,7 +12,7 @@ import { PacienteRiesgoTabla } from './paciente-riesgo-tabla'; // What the patient's risk says about its number (the model's `[estimand]`) and the curve of its horizons. describe('Riesgo individual: qué se estima y su curva', () => { - function setup(data: unknown) { + function setup(data: unknown, estatus: string | null = null) { const react = vi.fn(() => Promise.resolve()); TestBed.configureTestingModule({ providers: [provideHttpClient(), provideHttpClientTesting(), { provide: PACIENTE_RIESGO_PROVIDER, useValue: { obtener: () => of(data) } }, @@ -20,6 +20,7 @@ describe('Riesgo individual: qué se estima y su curva', () => { addFrames: vi.fn(), deleteFrames: vi.fn() }) }] }); const fixture = TestBed.createComponent(PacienteRiesgoTabla); fixture.componentRef.setInput('pacId', '42'); + fixture.componentRef.setInput('estatus', estatus); fixture.detectChanges(); fixture.detectChanges(); return { fixture, root: fixture.nativeElement as HTMLElement }; @@ -160,4 +161,35 @@ describe('Riesgo individual: qué se estima y su curva', () => { 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.'); }); + + /** The Bundle of a patient scored by the CIN2+, cancer and survival models (survival first). */ + function conSupervivencia() { + const data = riesgoCacuDosDesenlaces(); + const muerte = structuredClone(data.entry[1].resource); + muerte.id = '14-42'; + muerte.extension[0].extension.push({ url: 'complement', valueString: 'supervivencia' }); + muerte.prediction.forEach((p: any) => { p.outcome.coding[0].code = 'muerte'; }); + data.entry.unshift({ fullUrl: 'http://localhost/cacu/fhir/RiskAssessment/14-42', resource: muerte }); + data.total = 3; + return data; + } + const encabezados = (root: HTMLElement) => [...root.querySelectorAll('table.risk thead th')].map(th => th.textContent!.trim()); + + it('a un caso solo le muestra su supervivencia, sin LIEAG+ ni cáncer, también en el detalle', () => { + // Fails if the record stops following the follow-up status, or shows a case the risk of a disease she already has. + const { root } = setup(conSupervivencia(), 'CASO'); + expect(encabezados(root)).toEqual(['Horizonte (años)', 'Probabilidad de supervivencia (%)']); + expect(root.querySelectorAll('table.models tbody tr')).toHaveLength(1); + }); + + it('antes de la colposcopia muestra LIEAG+ y cáncer; después, solo LIEAG+; sin estatus, todo', () => { + // Fails if a status shows another set of columns than the follow-up table's, or no status hides a column. + expect(encabezados(setup(conSupervivencia(), 'PRE_COLPOSCOPIA').root)) + .toEqual(['Horizonte (años)', 'Probabilidad a LIEAG+ (%)', 'Probabilidad a cáncer (%)']); + TestBed.resetTestingModule(); + expect(encabezados(setup(conSupervivencia(), 'POST_COLPOSCOPIA').root)).toEqual(['Horizonte (años)', 'Probabilidad a LIEAG+ (%)']); + TestBed.resetTestingModule(); + expect(encabezados(setup(conSupervivencia()).root)).toEqual( + ['Horizonte (años)', 'Probabilidad a LIEAG+ (%)', 'Probabilidad a cáncer (%)', 'Probabilidad de supervivencia (%)']); + }); }); 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 5416dfd..38d81bc 100644 --- a/src/app/features/indicadores/paciente-detalle/paciente-riesgo-tabla.html +++ b/src/app/features/indicadores/paciente-detalle/paciente-riesgo-tabla.html @@ -8,8 +8,8 @@ @case ('error') {

No se pudo validar o cargar el riesgo individual.

} @case ('disponible') { @let todos = lectura.datos.riesgos; - @let riesgos = conRiesgo(todos); - @let riesgo = lectura.datos.riesgo; + @let riesgos = conRiesgo(delEstatus(todos)); + @let riesgo = riesgos[0] ?? lectura.datos.riesgo; @let columnas = columnasDe(todos); @let filas = filasDe(lotesDe(columnas)); @if (filas.length) { 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 0fa8ab7..215d641 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, covariables, encabezado, etiquetaDesenlace, filasRiesgo, fraseRiesgo, porcentaje } from './paciente-riesgo.presentacion'; +import { ColumnaRiesgo, columnasRiesgo, conRiesgo, delEstatus, 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'; @@ -26,6 +26,8 @@ export class PacienteRiesgoTabla { readonly pacId = input.required(); /** The domain whose model scored her: CaCu unless said otherwise. */ readonly dominio = input('cacu'); + /** Her follow-up status code: the table shows only the probabilities that status follows (a case, her survival). */ + readonly estatus = input(null); readonly rotulo = computed(() => this.dominio() === 'cama' ? 'CaMa' : 'CaCu'); private readonly state = inject(PacienteRiesgoState); readonly estado = this.state.estado; @@ -40,7 +42,8 @@ export class PacienteRiesgoTabla { readonly filasDe = filasRiesgo; readonly conRiesgo = conRiesgo; readonly covariables = covariables; - columnasDe(riesgos: LoteRiesgoCacu[]): ColumnaRiesgo[] { return columnasRiesgo(riesgos, this.dominio()); } + columnasDe(riesgos: LoteRiesgoCacu[]): ColumnaRiesgo[] { return columnasRiesgo(riesgos, this.dominio(), this.estatus()); } + delEstatus(riesgos: LoteRiesgoCacu[]): LoteRiesgoCacu[] { return delEstatus(riesgos, this.estatus()); } lotesDe(columnas: ColumnaRiesgo[]) { return columnas.map(c => (c.lote?.horizontes.length ? c.lote : null)); } private figuraDe?: { riesgos: LoteRiesgoCacu[]; figura: PlotlyFigure }; figura(riesgos: LoteRiesgoCacu[]): PlotlyFigure { 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 da9a3ee..98b6fa7 100644 --- a/src/app/features/indicadores/paciente-detalle/paciente-riesgo.presentacion.ts +++ b/src/app/features/indicadores/paciente-detalle/paciente-riesgo.presentacion.ts @@ -1,3 +1,4 @@ +import { COLUMNAS_DE_PROBABILIDAD, ProbabilidadClave } from '../cacu-seguimiento.models'; import { HorizonteRiesgoCacu, LoteRiesgoCacu, ResultadosIndice } from './paciente-riesgo.models'; import { tieneIntervalo } from './paciente-riesgo.validation'; @@ -39,6 +40,20 @@ const COLUMNAS_FIJAS: Record const esDe = (lote: LoteRiesgoCacu, desenlace: string) => desenlace === 'cin2' ? lote.desenlace.startsWith('cin2') : lote.desenlace === desenlace; +/** The outcomes the record shows for each follow-up status, the same as the follow-up table's columns: a case + * already has the disease, so only her survival; a patient before colposcopy, LIEAG+ and cancer; after it, LIEAG+. */ +const DESENLACE_DE_LA_COLUMNA: Record = { lieag: 'cin2', cancer: 'cancer', supervivencia: 'muerte' }; +export function desenlacesDelEstatus(estatus: string | null | undefined): string[] | null { + const columnas = estatus ? COLUMNAS_DE_PROBABILIDAD[estatus] : undefined; + return columnas ? columnas.map(c => DESENLACE_DE_LA_COLUMNA[c]) : null; +} + +/** The risks of the outcomes her follow-up status shows; all of them when the status names none. */ +export function delEstatus(riesgos: LoteRiesgoCacu[], estatus: string | null | undefined): LoteRiesgoCacu[] { + const desenlaces = desenlacesDelEstatus(estatus); + return desenlaces ? riesgos.filter(r => desenlaces.some(d => esDe(r, d))) : riesgos; +} + export interface ColumnaRiesgo { encabezado: string; /** Its model's risks; `null` when no model of the outcome is current. */ @@ -49,9 +64,11 @@ export interface ColumnaRiesgo { /** The table's columns: the domain's fixed outcomes (CaCu: LIEAG+ and cancer), with or without a model, then any * other outcome she has a risk of. A column's index date shows when it isn't the first risk's. */ -export function columnasRiesgo(riesgos: LoteRiesgoCacu[], dominio = 'cacu'): ColumnaRiesgo[] { +export function columnasRiesgo(riesgos: LoteRiesgoCacu[], dominio = 'cacu', estatus: string | null = null): ColumnaRiesgo[] { + riesgos = delEstatus(riesgos, estatus); const fecha = riesgos.find(r => r.horizontes.length)?.fecha_indice ?? null; - const fijas = COLUMNAS_FIJAS[dominio] ?? []; + const desenlaces = desenlacesDelEstatus(estatus); + const fijas = (COLUMNAS_FIJAS[dominio] ?? []).filter(f => !desenlaces || desenlaces.includes(f.desenlace)); const columnas: ColumnaRiesgo[] = fijas.map(({ desenlace, etiqueta }) => { const lote = riesgos.find(r => esDe(r, desenlace)) ?? null; if (!lote) return { encabezado: `Probabilidad a ${etiqueta}`, lote: null, vacia: 'No disponible' };