diff --git a/openapi.json b/openapi.json index fb42ba6..bca8f76 100644 --- a/openapi.json +++ b/openapi.json @@ -183,6 +183,7 @@ "cervical_biopsy", "mammography", "breast_biopsy", + "breast_treatment", "clinical_note", "death", "mchat", @@ -298,6 +299,7 @@ "cervical_biopsy", "mammography", "breast_biopsy", + "breast_treatment", "clinical_note", "death", "mchat", @@ -818,6 +820,7 @@ "cervical_biopsy", "mammography", "breast_biopsy", + "breast_treatment", "clinical_note", "death", "mchat", @@ -1120,6 +1123,7 @@ "cervical_biopsy", "mammography", "breast_biopsy", + "breast_treatment", "clinical_note", "death", "mchat", @@ -2391,6 +2395,7 @@ "cervical_biopsy", "mammography", "breast_biopsy", + "breast_treatment", "clinical_note", "death", "mchat", @@ -2497,6 +2502,7 @@ "cervical_biopsy", "mammography", "breast_biopsy", + "breast_treatment", "clinical_note", "death", "mchat", diff --git a/src/app/api/fn/review/conflicts.ts b/src/app/api/fn/review/conflicts.ts index af1408c..4632473 100644 --- a/src/app/api/fn/review/conflicts.ts +++ b/src/app/api/fn/review/conflicts.ts @@ -9,7 +9,7 @@ import { RequestBuilder } from '../../request-builder'; export interface Conflicts$Params { - entity: 'identity' | 'cervical_cytology' | 'cervical_biopsy' | 'mammography' | 'breast_biopsy' | 'clinical_note' | 'death' | 'mchat' | 'ados2' | 'eeg'; + entity: 'identity' | 'cervical_cytology' | 'cervical_biopsy' | 'mammography' | 'breast_biopsy' | 'breast_treatment' | 'clinical_note' | 'death' | 'mchat' | 'ados2' | 'eeg'; } export function conflicts(http: HttpClient, rootUrl: string, params: Conflicts$Params, context?: HttpContext): Observable; kind?: 'fhir'; diff --git a/src/app/api/models/rejection.ts b/src/app/api/models/rejection.ts index 4cfd27b..823b2f9 100644 --- a/src/app/api/models/rejection.ts +++ b/src/app/api/models/rejection.ts @@ -2,7 +2,7 @@ /* Code generated by ng-openapi-gen DO NOT EDIT. */ export interface Rejection { - entity: 'identity' | 'cervical_cytology' | 'cervical_biopsy' | 'mammography' | 'breast_biopsy' | 'clinical_note' | 'death' | 'mchat' | 'ados2' | 'eeg'; + entity: 'identity' | 'cervical_cytology' | 'cervical_biopsy' | 'mammography' | 'breast_biopsy' | 'breast_treatment' | 'clinical_note' | 'death' | 'mchat' | 'ados2' | 'eeg'; reason: string; record: string; } diff --git a/src/app/api/models/target.ts b/src/app/api/models/target.ts index 98be101..ea0da43 100644 --- a/src/app/api/models/target.ts +++ b/src/app/api/models/target.ts @@ -8,7 +8,7 @@ import { Position } from '../models/position'; * one `link` node among the inputs. Rule breaks are held for review. */ export interface Target { - entity: 'identity' | 'cervical_cytology' | 'cervical_biopsy' | 'mammography' | 'breast_biopsy' | 'clinical_note' | 'death' | 'mchat' | 'ados2' | 'eeg'; + entity: 'identity' | 'cervical_cytology' | 'cervical_biopsy' | 'mammography' | 'breast_biopsy' | 'breast_treatment' | 'clinical_note' | 'death' | 'mchat' | 'ados2' | 'eeg'; id: string; inputs?: Array; kind?: 'target'; diff --git a/src/app/gobernanza/figures.spec.ts b/src/app/gobernanza/figures.spec.ts index 0547cd8..76bfc70 100644 --- a/src/app/gobernanza/figures.spec.ts +++ b/src/app/gobernanza/figures.spec.ts @@ -13,6 +13,29 @@ describe('governance figures', () => { expect((found.figure.data[2] as any).error_y.array[0]).toBeCloseTo(0.05); }); + it("draws each survival scenario after the cohort's curves, titled with its deaths", () => { + const scenario = { + escenario: 'HER2+ · ≥60 años · estadio III–IV (Alto)', + n: 1142, + fallecidos: 308, + horizons_months: [6, 12, 18], + km: { months: [0, 12], S: [1, 0.8], low: [1, 0.75], high: [1, 0.85] }, + weibull: { t: [0, 12], S: [1, 0.8] }, + weibull_fractional: { t: [0, 12], S: [1, 0.79] }, + points: { COMB: { S: [0.86, 0.8, 0.74], low: [0.85, 0.78, 0.72], high: [0.88, 0.82, 0.76] } }, + }; + const found = interpretabilityFigures({ + kind: 'curves', + curves: [{ name: 'Kaplan-Meier', months: [0], survival: [1], low: [1], high: [1] }], + predicted: { name: 'Modelo', months: [6], survival: [0.9], low: [0.8], high: [0.95] }, + escenarios: [scenario], + }); + expect(found.length).toBe(2); + expect(found[1].title).toContain('fallecidos = 308'); + expect(found[1].figure.data.length).toBe(5); // band, KM, Weibull, fractional, points + expect((found[1].figure.data[4] as any).x).toEqual([6, 12, 18]); + }); + it('draws a recurrence scenario: KM band, both Weibulls and the model points', () => { const [found] = interpretabilityFigures({ kind: 'scenarios', diff --git a/src/app/gobernanza/figures.ts b/src/app/gobernanza/figures.ts index c5474fa..ae8741c 100644 --- a/src/app/gobernanza/figures.ts +++ b/src/app/gobernanza/figures.ts @@ -70,6 +70,15 @@ export function interpretabilityFigures( }, }, }, + // Its clinical scenarios, those with enough deaths to draw. + ...((report['escenarios'] ?? []) as any[]).map((e) => + scenarioFigure( + `${e.escenario} (n = ${e.n.toLocaleString('es-MX')}, fallecidos = ${e.fallecidos.toLocaleString('es-MX')})`, + e, + e.horizons_months, + 'Supervivencia S(t)', + ), + ), ]; } case 'subgroups': @@ -139,43 +148,16 @@ export function interpretabilityFigures( ]; } case 'scenarios': - return (report['recurrencia']['escenarios'] as any[]).slice(0, 6).map((e) => ({ - title: `${e.cohorte_nombre} · ${e.escenario} (n = ${e.n}, ${e.recaidas} recaídas)`, - figure: { - data: [ - ...banded( - 'Kaplan-Meier (IC 95 %)', - { x: e.km.months, y: e.km.S, low: e.km.low, high: e.km.high }, - PALETTE[0], - ), - { - x: e.weibull.t, - y: e.weibull.S, - name: 'Weibull', - type: 'scatter', - mode: 'lines', - line: { color: PALETTE[1], dash: 'dot' }, - }, - { - x: e.weibull_fractional.t, - y: e.weibull_fractional.S, - name: 'Weibull fraccional', - type: 'scatter', - mode: 'lines', - line: { color: PALETTE[2] }, - }, - points( - 'Modelo (IC 95 % bootstrap)', - report['recurrencia']['horizons_months'], - e.points.COMB, - ), - ], - layout: { - xaxis: { title: { text: 'Meses desde el diagnóstico' } }, - yaxis: { title: { text: 'Supervivencia libre de recaída' } }, - }, - }, - })); + return (report['recurrencia']['escenarios'] as any[]) + .slice(0, 6) + .map((e) => + scenarioFigure( + `${e.cohorte_nombre} · ${e.escenario} (n = ${e.n}, ${e.recaidas} recaídas)`, + e, + report['recurrencia']['horizons_months'], + 'Supervivencia libre de recaída', + ), + ); case 'age_curves': { // The metric's own curve; a topography has only electrodes: its first one. const value = report['curves']['value'] ?? Object.values(report['curves'])[0]; @@ -228,6 +210,49 @@ export function interpretabilityFigures( } } +/** One clinical scenario: Kaplan-Meier with its band, the classic and fractional Weibull, + * and the model's points with their bootstrap band. */ +function scenarioFigure( + title: string, + e: any, + horizons: number[], + yTitle: string, +): { title: string; figure: Figure } { + return { + title, + figure: { + data: [ + ...banded( + 'Kaplan-Meier (IC 95 % Greenwood)', + { x: e.km.months, y: e.km.S, low: e.km.low, high: e.km.high }, + PALETTE[0], + ), + { + x: e.weibull.t, + y: e.weibull.S, + name: 'Weibull', + type: 'scatter', + mode: 'lines', + line: { color: PALETTE[1] }, + }, + { + x: e.weibull_fractional.t, + y: e.weibull_fractional.S, + name: 'Weibull fraccional', + type: 'scatter', + mode: 'lines', + line: { color: PALETTE[2], dash: 'dash' }, + }, + points('LR + HBN combinado (IC 95 % bootstrap)', horizons, e.points.COMB), + ], + layout: { + xaxis: { title: { text: 'Meses desde el diagnóstico' } }, + yaxis: { title: { text: yTitle } }, + }, + }, + }; +} + function points( name: string, x: number[], diff --git a/src/app/revision/revision.ts b/src/app/revision/revision.ts index 1933221..3bfb1cc 100644 --- a/src/app/revision/revision.ts +++ b/src/app/revision/revision.ts @@ -32,6 +32,7 @@ const ENTITIES: Record = { identity: 'Identidad', mammography: 'Mastografía', breast_biopsy: 'Biopsia de mama', + breast_treatment: 'Tratamiento de cáncer de mama', mchat: 'M-CHAT', ados2: 'ADOS-2', eeg: 'Electroencefalograma',