diff --git a/src/app/paciente/paciente.ts b/src/app/paciente/paciente.ts index 323d6f2..4ea5b07 100644 --- a/src/app/paciente/paciente.ts +++ b/src/app/paciente/paciente.ts @@ -37,7 +37,7 @@ import { LABELS, name, PRIORITY } from '../indicadores/measures'; import { Figure, PALETTE, Plot } from '../plot'; import { Loading } from '../loading'; import { Factores, ScenarioFactors } from './factores'; -import { identityRows, loadTeaPatient, Study } from './tea-data'; +import { evaluable, identityRows, loadTeaPatient, Study } from './tea-data'; import { ageNorm } from './tea-figures'; import { TeaSection } from './tea-section'; import { @@ -395,6 +395,7 @@ export class Paciente { const model = /^tea\.([^/]+)\/([1-9]\d*)$/.exec(metric.model ?? ''); if ( !model || + !evaluable(metric) || metric.key === 'paroxysmal_spikes' || metric.value == null || eeg.age == null diff --git a/src/app/paciente/tea-data.ts b/src/app/paciente/tea-data.ts index 3e36e13..2847e21 100644 --- a/src/app/paciente/tea-data.ts +++ b/src/app/paciente/tea-data.ts @@ -229,6 +229,10 @@ function metric(o: Observation) { export type Metric = ReturnType; +export function evaluable(m: Pick): boolean { + return m.outside != null; +} + function study(report: DiagnosticReport, observations: Map) { const results = (report.result ?? []) .map((r) => observations.get(r.reference?.split('/').pop())) diff --git a/src/app/paciente/tea-patient.spec.ts b/src/app/paciente/tea-patient.spec.ts index 36b3e8f..d9f9e70 100644 --- a/src/app/paciente/tea-patient.spec.ts +++ b/src/app/paciente/tea-patient.spec.ts @@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest'; import { EXT, Fhir } from '../fhir'; import { alteration, + evaluable, identityRows, loadTeaPatient, Metric, @@ -425,6 +426,22 @@ describe('Expediente TEA', () => { ]); }); + it('no dibuja mapa ni norma de una métrica no evaluable', () => { + const unmeasured = { ...metric, z: undefined, outside: undefined, reason: 'no-n3' }; + const norm = { title: 'Norma por edad', figure: ageNorm(centiles, metric, eeg.age) }; + expect(evaluable(metric)).toBe(true); + expect(evaluable(unmeasured)).toBe(false); + const sections = recordSections( + { ...record, studies: [{ ...eeg, metrics: [metric, unmeasured] }] }, + new Map([[`eeg-1|${metric.key}`, norm]]), + ); + const blocks = sections.find((s) => s.title === 'Alteraciones')?.blocks; + expect(blocks?.[0].charts).toHaveLength(2); + expect(blocks?.[1].charts).toEqual([]); + const content = teaPdfContent('Expediente TEA', sections, ['mapa', 'norma']); + expect(content.slice(-2)).toEqual(['z · —', 'Resultado · No evaluable · sin N3']); + }); + it('lee los motivos de la métrica y del estudio desde FHIR', async () => { const reason = (valueCode: string) => ({ url: EXT + 'eeg-reason', valueCode }); const bundle = { diff --git a/src/app/paciente/tea-sections.ts b/src/app/paciente/tea-sections.ts index ba6b323..a00c4b7 100644 --- a/src/app/paciente/tea-sections.ts +++ b/src/app/paciente/tea-sections.ts @@ -1,7 +1,17 @@ import { downloadPdf, safeName, type PdfContent } from '../export'; import type { Figure } from '../plot'; import plotly from '../plotly-bundle'; -import { adosItems, adosSummary, alteration, Pair, percent, shown, TeaPatient } from './tea-data'; +import { + adosItems, + adosSummary, + alteration, + evaluable, + Metric, + Pair, + percent, + shown, + TeaPatient, +} from './tea-data'; import { forest, headMap, probabilityCurve, timeline, zBars } from './tea-figures'; type Table = { headers: string[]; rows: string[][] }; @@ -34,6 +44,14 @@ function associationRows(pairs: Pair[]): string[][] { ]); } +function metricCharts(m: Metric, norm: Chart | undefined): Chart[] { + if (!evaluable(m)) return []; + return [ + ...(m.sites.length ? [{ title: 'Mapa de la cabeza', figure: headMap(m.sites) }] : []), + ...(norm ? [norm] : []), + ]; +} + export function recordSections(patient: TeaPatient, norms: ReadonlyMap): Section[] { const gantt = timeline(patient.steps); return [ @@ -65,20 +83,14 @@ export function recordSections(patient: TeaPatient, norms: ReadonlyMap - eeg.metrics.map((m) => { - const norm = norms.get(`${eeg.id}|${m.key}`); - return { - title: `${eeg.date} · ${m.title}`, - fields: [ - ['z', shown(m.z)], - ['Resultado', alteration(m.outside, m.reason)], - ], - charts: [ - ...(m.sites.length ? [{ title: 'Mapa de la cabeza', figure: headMap(m.sites) }] : []), - ...(norm ? [norm] : []), - ], - }; - }), + eeg.metrics.map((m) => ({ + title: `${eeg.date} · ${m.title}`, + fields: [ + ['z', shown(m.z)], + ['Resultado', alteration(m.outside, m.reason)], + ], + charts: metricCharts(m, norms.get(`${eeg.id}|${m.key}`)), + })), ), }, {