990cab0e37
The table says its probabilities are percentages (0 to 100 %) with their 95 % interval, and its covariates under it. A model whose estimand asks for its complement (survival from a probability of dying) shows 1 − p with its interval swapped. "Riesgo acumulado" reads "probabilidad". The models' details are a table of one row per model, without the version or the batch state.
101 lines
5.2 KiB
TypeScript
101 lines
5.2 KiB
TypeScript
// Covers the patient's risk in CaMa's record: the table asks the CaMa endpoint (and CaCu's calls stay as they were), says
|
|
// whose model scored her, shows the mortality at the horizons the model gives (6, 12 and 18 months) and the model's
|
|
// index date; the CaMa record does not show it (its two analyses replace it). Fixtures: a Bundle like `GET /cama/fhir/RiskAssessment?subject=
|
|
// Patient/7` answers it (`riesgoCamaEjemplo`), and a provider that returns it.
|
|
import { TestBed } from '@angular/core/testing';
|
|
import { of } from 'rxjs';
|
|
import { CamaPatientCard } from './cama/cama-patient-card';
|
|
import { CamaPatientSummary } from './cama/cama-patient.models';
|
|
import { PacienteRiesgoTabla } from './paciente-riesgo-tabla';
|
|
import { EMPTY } from 'rxjs';
|
|
import { CamaCurvasService } from './cama/cama-curvas.service';
|
|
import { CamaRecurrenciaService } from './cama/cama-recurrencia.service';
|
|
import { PACIENTE_RIESGO_PROVIDER } from './paciente-riesgo.provider';
|
|
import { INTERVALO, prediccion } from './paciente-riesgo.testing';
|
|
|
|
const CS = 'https://isssteleon.org/fhir/CodeSystem';
|
|
|
|
/** TEST ONLY. Patient 7's current CaMa `RiskAssessment`: mortality at 6, 12 and 18 months from the model's index date. */
|
|
function riesgoCamaEjemplo(): any {
|
|
const muerte = (p: number, fin: string) => {
|
|
const item = prediccion(p, '2025-06-19', fin);
|
|
item.outcome = { coding: [{ system: `${CS}/desenlace`, code: 'muerte', display: 'Muerte por cualquier causa' }] };
|
|
return item;
|
|
};
|
|
return {
|
|
resourceType: 'Bundle', type: 'searchset', total: 1,
|
|
entry: [{
|
|
fullUrl: 'http://localhost/cama/fhir/RiskAssessment/3-7',
|
|
resource: {
|
|
resourceType: 'RiskAssessment', id: '3-7', status: 'final',
|
|
meta: { tag: [{ system: `${CS}/etiqueta`, code: 'simulado', display: 'Datos simulados' }] },
|
|
subject: { reference: 'Patient/7' }, occurrenceDateTime: '2026-01-02T10:00:00Z',
|
|
method: { coding: [{ system: `${CS}/modelo`, code: 'cama-survival', version: '1' }] },
|
|
prediction: [muerte(0.07, '2025-12-19'), muerte(0.178, '2026-06-19'), muerte(0.251, '2026-12-19')],
|
|
},
|
|
search: { mode: 'match' },
|
|
}],
|
|
};
|
|
}
|
|
|
|
const resumen = (idField: 'pac_id' | 'id_seudonimo'): CamaPatientSummary => ({
|
|
patientId: '7', idField, idLabel: 'pac_id', cutoff: '2026-01-01', ageGroup: '50-59', status: null, priority: null,
|
|
birads: 'B5', mammographyDate: '2025-06-01', histopathology: 'CARCINOMA_INVASOR', biopsyDate: '2025-06-19',
|
|
daysMammographyToDiagnosis: null, clinicalScenario: null,
|
|
});
|
|
|
|
describe('Riesgo individual de la paciente CaMa', () => {
|
|
const obtener = vi.fn();
|
|
beforeEach(() => {
|
|
obtener.mockReset().mockImplementation(() => of(riesgoCamaEjemplo()));
|
|
TestBed.configureTestingModule({ providers: [{ provide: PACIENTE_RIESGO_PROVIDER, useValue: { obtener } },
|
|
{ provide: CamaCurvasService, useValue: { escenarios: () => of(null), consulta: () => EMPTY } },
|
|
{ provide: CamaRecurrenciaService, useValue: { recurrencia: () => of(null) } }] });
|
|
});
|
|
|
|
// Fails if the table stops asking the domain it was given, or if CaCu's call changes shape (`obtener(pacId)` only).
|
|
it('asks its domain for the patient, and CaCu with the id alone', () => {
|
|
const cama = TestBed.createComponent(PacienteRiesgoTabla);
|
|
cama.componentRef.setInput('pacId', '7');
|
|
cama.componentRef.setInput('dominio', 'cama');
|
|
cama.detectChanges();
|
|
const cacu = TestBed.createComponent(PacienteRiesgoTabla);
|
|
cacu.componentRef.setInput('pacId', '7');
|
|
cacu.detectChanges();
|
|
|
|
expect(obtener).toHaveBeenNthCalledWith(1, '7', 'cama');
|
|
expect(obtener).toHaveBeenNthCalledWith(2, '7');
|
|
expect(cama.nativeElement.textContent).toContain('Riesgo individual CaMa');
|
|
expect(cacu.nativeElement.textContent).toContain('Riesgo individual CaCu');
|
|
});
|
|
|
|
// Fails if the mortality, its outcome, the model or the index date of the Bundle are not what the card shows.
|
|
it('shows the model, the index date, the outcome and the mortality at each horizon', () => {
|
|
const f = TestBed.createComponent(PacienteRiesgoTabla);
|
|
f.componentRef.setInput('pacId', '7');
|
|
f.componentRef.setInput('dominio', 'cama');
|
|
f.detectChanges();
|
|
|
|
const text = (f.nativeElement as HTMLElement).textContent!.replace(/\s+/g, ' ');
|
|
expect(text).toContain('cama-survival');
|
|
expect(text).toContain('2025-06-19');
|
|
expect(text).toContain('Muerte por cualquier causa');
|
|
expect(text).toContain('7 %');
|
|
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('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.
|
|
it('is not in the CaMa record: its analyses and their risk factors are', () => {
|
|
const f = TestBed.createComponent(CamaPatientCard);
|
|
f.componentRef.setInput('summary', resumen('pac_id'));
|
|
f.detectChanges();
|
|
|
|
expect(obtener).not.toHaveBeenCalled();
|
|
expect(f.nativeElement.querySelector('app-paciente-riesgo-tabla')).toBeNull();
|
|
expect(INTERVALO).toContain('intervalo-confianza');
|
|
});
|
|
});
|