F5: No evaluable alterations draw no plots
- tea-data: evaluable(metric) is the single rule (a metric with no outside result is not evaluable) - tea-sections: the Alteraciones block takes its head map and age norm from metricCharts, which yields none for a not evaluable metric; the block keeps title, z and Resultado with the reason - paciente: loadNorms skips not evaluable metrics instead of fetching their curves - tea-patient.spec: a not evaluable metric yields no charts and no chart entries in the PDF content The risk page needs no change: zBars already drops rows without z, so a not evaluable metric adds no empty plot.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -229,6 +229,10 @@ function metric(o: Observation) {
|
||||
|
||||
export type Metric = ReturnType<typeof metric>;
|
||||
|
||||
export function evaluable(m: Pick<Metric, 'outside'>): boolean {
|
||||
return m.outside != null;
|
||||
}
|
||||
|
||||
function study(report: DiagnosticReport, observations: Map<string | undefined, Observation>) {
|
||||
const results = (report.result ?? [])
|
||||
.map((r) => observations.get(r.reference?.split('/').pop()))
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -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<string, Chart>): Section[] {
|
||||
const gantt = timeline(patient.steps);
|
||||
return [
|
||||
@@ -65,20 +83,14 @@ export function recordSections(patient: TeaPatient, norms: ReadonlyMap<string, C
|
||||
{
|
||||
title: 'Alteraciones',
|
||||
blocks: patient.studies.flatMap((eeg) =>
|
||||
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}`)),
|
||||
})),
|
||||
),
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user