F1c: user fixes
Render the worklist stepper from the Patient stage and read M-CHAT, CSS and alteration count from its FHIR extensions. Keep the compact stepper private to Seguimiento and share the dated screening logic with the patient record. Use the first dated event for each step, require prior steps, and use the later date when an event predates its prerequisite. Only a good-quality EEG completes that stage. Use horizontal Plotly bars on the destination rows for elapsed spans, diamonds for completed steps, and labels for pending steps. Keep the screening order on the axis and show 30 days on either side when all completed steps share one date. Reuse the registered bar and scatter traces and the rebuild palette. Use completed months at the applied cutoff and show the marked headline association with the reference formatting. Resolve item labels from the model's ADOS-2 observation and fall back to the item code. Move the existing detail and risk actions into the patient-name cell to keep the requested ten columns. Keep raw association numbers and separate CI bounds in Excel and keep the screening dates in the follow-up export. Update the two logic specs and the follow-up, risk and record page assertions. All 34 targeted Vitest cases passed with Plotly rendering stubbed. The local TypeScript check reached the existing PDF export code and reported missing pdfmake typings. Angular and page runs are reserved for the test machines.
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
import type { Bundle, DiagnosticReport, Observation, Patient, RiskAssessment } from 'fhir/r4';
|
||||
import { EXT } from '../fhir';
|
||||
import { teaSteps } from '../paciente/tea-data';
|
||||
import { nestedDonut, shareDonut } from './figures';
|
||||
import type { Catalog } from './pages';
|
||||
import {
|
||||
ageMonths,
|
||||
associationRows,
|
||||
formatIc,
|
||||
formatOr,
|
||||
formatProbability,
|
||||
formatQ,
|
||||
matchesTeaSearch,
|
||||
teaParams,
|
||||
teaRows,
|
||||
@@ -26,6 +31,9 @@ function fixture(): Bundle {
|
||||
{ url: EXT + 'tea-step', valueCode: 'eeg' },
|
||||
{ url: EXT + 'tea-case', valueCode: 'confirmed' },
|
||||
{ url: EXT + 'tea-eeg-result', valueCode: 'normal' },
|
||||
{ url: EXT + 'tea-mchat', valueDecimal: 9 },
|
||||
{ url: EXT + 'tea-css', valueInteger: 8 },
|
||||
{ url: EXT + 'tea-alterations', valueInteger: 2 },
|
||||
],
|
||||
};
|
||||
const ados: Observation = {
|
||||
@@ -63,6 +71,8 @@ function fixture(): Bundle {
|
||||
{ url: EXT + 'association-headline', valueBoolean: true },
|
||||
{ url: EXT + 'association-reference-probability', valueDecimal: 0.35 },
|
||||
{ url: EXT + 'association-odds-ratio', valueDecimal: 2 },
|
||||
{ url: EXT + 'association-ci-low', valueDecimal: 1.2 },
|
||||
{ url: EXT + 'association-ci-high', valueDecimal: 4.5 },
|
||||
{ url: EXT + 'association-q', valueDecimal: 0.01 },
|
||||
],
|
||||
},
|
||||
@@ -74,9 +84,17 @@ function fixture(): Bundle {
|
||||
code: { coding: [{ code: 'eeg' }] },
|
||||
subject,
|
||||
effectiveDateTime: '2026-03-04',
|
||||
conclusionCode: [{ text: 'Bueno' }],
|
||||
conclusionCode: [{ coding: [{ code: 'good' }], text: 'Bueno' }],
|
||||
extension: [{ url: EXT + 'eeg-channels', valueInteger: 19 }],
|
||||
};
|
||||
const neurology: Observation = {
|
||||
resourceType: 'Observation',
|
||||
status: 'final',
|
||||
subject,
|
||||
code: { coding: [{ code: 'clinical_note.specialty' }] },
|
||||
valueCodeableConcept: { coding: [{ code: 'pediatric_neurology' }] },
|
||||
effectiveDateTime: '2026-03-03',
|
||||
};
|
||||
return {
|
||||
resourceType: 'Bundle',
|
||||
type: 'searchset',
|
||||
@@ -85,6 +103,7 @@ function fixture(): Bundle {
|
||||
{ resource: { resourceType: 'Patient', id: 'other' }, search: { mode: 'match' } },
|
||||
{ resource: ados, search: { mode: 'include' } },
|
||||
{ resource: risk, search: { mode: 'include' } },
|
||||
{ resource: neurology, search: { mode: 'include' } },
|
||||
{ resource: eeg, search: { mode: 'include' } },
|
||||
...['2026-03-01', '2026-02-27'].map((date) => ({
|
||||
search: { mode: 'include' as const },
|
||||
@@ -93,7 +112,7 @@ function fixture(): Bundle {
|
||||
status: 'final' as const,
|
||||
subject,
|
||||
code: { coding: [{ code: 'mchat.score' }] },
|
||||
valueQuantity: { value: 9 },
|
||||
valueQuantity: { value: 7 },
|
||||
effectiveDateTime: date,
|
||||
},
|
||||
})),
|
||||
@@ -169,36 +188,54 @@ describe('TEA indicators', () => {
|
||||
expect(teaParams({ cssMax: 0 })['tea-css']).toEqual(['le0']);
|
||||
});
|
||||
|
||||
it('uses follow-up codes and assembles the included dates and association headline', () => {
|
||||
it('reads the follow-up extensions and assembles the stepper and association headline', () => {
|
||||
const [row, other] = teaRows(fixture());
|
||||
expect(row.steps.map(({ date }) => date)).toEqual([
|
||||
'2026-02-27',
|
||||
'2026-03-02',
|
||||
undefined,
|
||||
'2026-03-03',
|
||||
'2026-03-04',
|
||||
]);
|
||||
expect(row.steps.map(({ completed }) => completed)).toEqual([true, true, true, true]);
|
||||
expect(row).toMatchObject({
|
||||
name: 'Ana López',
|
||||
step: 'EEG',
|
||||
case: 'confirmed',
|
||||
eegResult: 'normal',
|
||||
recordNumbers: ['123'],
|
||||
mchatScore: 9,
|
||||
css: 8,
|
||||
headline: { pair: cssPair, or: 2, q: 0.01 },
|
||||
concordance: 'Concordante',
|
||||
alterations: 2,
|
||||
headline: {
|
||||
pair: cssPair,
|
||||
title: 'Husos N2 · Central · CSS',
|
||||
or: 2,
|
||||
low: 1.2,
|
||||
high: 4.5,
|
||||
q: 0.01,
|
||||
},
|
||||
});
|
||||
expect(other.concordance).toBe('—');
|
||||
expect(other.headline).toBeUndefined();
|
||||
});
|
||||
|
||||
it('compares the headline item score with the prediction and reference', () => {
|
||||
it('titles an item association with the patient’s ADOS-2 item', () => {
|
||||
const page = fixture();
|
||||
const risk = page.entry!.find((e) => e.resource?.resourceType === 'RiskAssessment')!
|
||||
.resource as RiskAssessment;
|
||||
const prediction = risk.prediction![0];
|
||||
prediction.outcome = { coding: [{ code: 'rhythm|central|ados2_item_01' }] };
|
||||
prediction.probabilityDecimal = 0.1;
|
||||
expect(teaRows(page)[0].concordance).toBe('No concordante');
|
||||
risk.prediction![0].outcome = { coding: [{ code: 'posterior_rhythm|central|ados2_item_01' }] };
|
||||
expect(teaRows(page)[0].headline?.title).toBe(
|
||||
'Ritmo posterior · Central · Frecuencia de la vocalización espontánea dirigida a otros',
|
||||
);
|
||||
});
|
||||
|
||||
it('formats the association values like the reference list', () => {
|
||||
expect(formatOr(2)).toBe('2.00');
|
||||
expect(formatOr(undefined)).toBe('—');
|
||||
expect(formatIc(1.2, 4.5)).toBe('1.20–4.50');
|
||||
expect(formatIc(undefined, 4.5)).toBe('—');
|
||||
expect(formatQ(0.0004)).toBe('< 0.001');
|
||||
expect(formatQ(0.0123)).toBe('0.012');
|
||||
expect(formatQ(undefined)).toBe('—');
|
||||
expect(formatProbability(0.35)).toBe('35 %');
|
||||
expect(formatProbability(undefined)).toBe('—');
|
||||
});
|
||||
|
||||
it('defaults to all children and filters by association results', () => {
|
||||
@@ -222,13 +259,20 @@ describe('TEA indicators', () => {
|
||||
});
|
||||
|
||||
it('builds the follow-up workbook', () => {
|
||||
expect(teaWorkbook(teaRows(fixture()), false, DAY)).toEqual({
|
||||
expect(teaWorkbook(teaRows(fixture()), false, '2026-03-31', DAY)).toEqual({
|
||||
name: 'tea-seguimiento-2026-11-30',
|
||||
sheets: [
|
||||
expect.objectContaining({
|
||||
name: 'Seguimiento',
|
||||
rows: expect.arrayContaining([
|
||||
expect.objectContaining({ id: 'child', pair: cssPair, eeg: '2026-03-04' }),
|
||||
expect.objectContaining({
|
||||
id: 'child',
|
||||
eeg: '2026-03-04',
|
||||
mchat: 9,
|
||||
css: 8,
|
||||
eegResult: 'Normal',
|
||||
alterations: 2,
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
],
|
||||
@@ -236,10 +280,23 @@ describe('TEA indicators', () => {
|
||||
});
|
||||
|
||||
it('builds the risk workbook with children and pair details', () => {
|
||||
expect(teaWorkbook(associationRows(teaRows(fixture())), true, DAY)).toEqual({
|
||||
expect(teaWorkbook(associationRows(teaRows(fixture())), true, '2026-03-31', DAY)).toEqual({
|
||||
name: 'tea-riesgos-2026-11-30',
|
||||
sheets: [
|
||||
expect.objectContaining({ name: 'Niños' }),
|
||||
expect.objectContaining({
|
||||
name: 'Niños',
|
||||
rows: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: 'child',
|
||||
pair: 'Husos N2 · Central · CSS',
|
||||
or: 2,
|
||||
low: 1.2,
|
||||
high: 4.5,
|
||||
probability: 0.35,
|
||||
reference: 0.35,
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
name: 'Pares',
|
||||
rows: [
|
||||
@@ -255,3 +312,96 @@ describe('TEA indicators', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const observation = (field: string, day: string, value?: string): Observation => ({
|
||||
resourceType: 'Observation',
|
||||
status: 'final',
|
||||
code: { coding: [{ code: field }] },
|
||||
effectiveDateTime: day,
|
||||
...(value ? { valueCodeableConcept: { coding: [{ code: value }] } } : {}),
|
||||
});
|
||||
|
||||
const eeg = (day: string, quality: string): DiagnosticReport => ({
|
||||
resourceType: 'DiagnosticReport',
|
||||
status: 'final',
|
||||
code: { coding: [{ code: 'eeg' }] },
|
||||
effectiveDateTime: day,
|
||||
conclusionCode: [{ coding: [{ code: quality }] }],
|
||||
});
|
||||
|
||||
describe('Etapas del tamizaje TEA', () => {
|
||||
it('toma la primera fecha de cada etapa en el orden del proceso', () => {
|
||||
const steps = teaSteps(
|
||||
[
|
||||
observation('mchat.score', '2026-03-01'),
|
||||
observation('mchat.score', '2026-02-27'),
|
||||
observation('ados2', '2026-03-04'),
|
||||
observation('clinical_note.specialty', '2026-03-06', 'pediatric_neurology'),
|
||||
],
|
||||
[eeg('2026-03-10', 'good')],
|
||||
);
|
||||
expect(steps.map(({ code, label }) => ({ code, label }))).toEqual([
|
||||
{ code: 'mchat_only', label: 'M-CHAT' },
|
||||
{ code: 'psychology', label: 'Psicología' },
|
||||
{ code: 'neurology', label: 'Neuropediatría' },
|
||||
{ code: 'eeg', label: 'EEG' },
|
||||
]);
|
||||
expect(steps.map((step) => step.date)).toEqual([
|
||||
'2026-02-27',
|
||||
'2026-03-04',
|
||||
'2026-03-06',
|
||||
'2026-03-10',
|
||||
]);
|
||||
expect(steps.every((step) => step.completed)).toBe(true);
|
||||
});
|
||||
|
||||
it('completa el EEG solo con un estudio de buena calidad', () => {
|
||||
const observations = [
|
||||
observation('mchat.score', '2026-02-27'),
|
||||
observation('ados2', '2026-03-04'),
|
||||
observation('clinical_note.specialty', '2026-03-06', 'pediatric_neurology'),
|
||||
observation('eeg.lab_record_id', '2026-03-08'),
|
||||
];
|
||||
const steps = teaSteps(observations, [eeg('2026-03-10', 'bad'), eeg('2026-03-12', 'good')]);
|
||||
expect(steps[3]).toMatchObject({ date: '2026-03-12', completed: true });
|
||||
expect(teaSteps(observations, [eeg('2026-03-10', 'bad')])[3]).toMatchObject({
|
||||
date: undefined,
|
||||
completed: false,
|
||||
});
|
||||
expect(teaSteps(observations, [])[3]).toMatchObject({ date: undefined, completed: false });
|
||||
});
|
||||
|
||||
it('ignora las notas de otras especialidades', () => {
|
||||
const steps = teaSteps(
|
||||
[
|
||||
observation('mchat.score', '2026-02-27'),
|
||||
observation('ados2', '2026-03-04'),
|
||||
observation('clinical_note.specialty', '2026-03-06', 'pediatrics'),
|
||||
],
|
||||
[],
|
||||
);
|
||||
expect(steps[2]).toMatchObject({ date: undefined, completed: false });
|
||||
});
|
||||
|
||||
it('deja pendientes las etapas tras un hueco', () => {
|
||||
const steps = teaSteps(
|
||||
[observation('mchat.score', '2026-02-27'), observation('ados2', '2026-03-04')],
|
||||
[eeg('2026-03-10', 'good')],
|
||||
);
|
||||
expect(steps.map((step) => step.completed)).toEqual([true, true, false, false]);
|
||||
expect(steps[3].date).toBeUndefined();
|
||||
});
|
||||
|
||||
it('usa la etapa registrada para mostrar el avance del seguimiento', () => {
|
||||
const steps = teaSteps([], [], 'neurology');
|
||||
expect(steps.map((step) => step.completed)).toEqual([true, true, true, false]);
|
||||
});
|
||||
|
||||
it('fecha cada etapa a partir de la anterior cuando el estudio ocurrió antes', () => {
|
||||
const steps = teaSteps(
|
||||
[observation('mchat.score', '2026-02-27'), observation('ados2', '2026-02-26')],
|
||||
[],
|
||||
);
|
||||
expect(steps[1]).toMatchObject({ date: '2026-02-27', completed: true });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user