Merge parity/F1c
# Conflicts: # src/app/indicadores/tea-indicators.spec.ts
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { Bundle, DiagnosticReport, Observation, Patient, RiskAssessment } from 'fhir/r4';
|
||||
import { EXT } from '../fhir';
|
||||
import { teaSteps } from '../paciente/tea-data';
|
||||
import {
|
||||
ageStack,
|
||||
nestedDonut,
|
||||
@@ -9,10 +10,15 @@ import {
|
||||
teaSankey,
|
||||
teaSexDonut,
|
||||
} from './figures';
|
||||
import { teaSteps } from '../paciente/tea-data';
|
||||
import type { Catalog } from './pages';
|
||||
import {
|
||||
ageMonths,
|
||||
associationRows,
|
||||
formatIc,
|
||||
formatOr,
|
||||
formatProbability,
|
||||
formatQ,
|
||||
matchesTeaSearch,
|
||||
teaParams,
|
||||
teaRows,
|
||||
@@ -34,6 +40,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 = {
|
||||
@@ -71,6 +80,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 },
|
||||
],
|
||||
},
|
||||
@@ -82,9 +93,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',
|
||||
@@ -93,6 +112,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 },
|
||||
@@ -101,7 +121,7 @@ function fixture(): Bundle {
|
||||
status: 'final' as const,
|
||||
subject,
|
||||
code: { coding: [{ code: 'mchat.score' }] },
|
||||
valueQuantity: { value: 9 },
|
||||
valueQuantity: { value: 7 },
|
||||
effectiveDateTime: date,
|
||||
},
|
||||
})),
|
||||
@@ -177,36 +197,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', () => {
|
||||
@@ -230,13 +268,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,
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
],
|
||||
@@ -244,10 +289,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: [
|
||||
@@ -361,3 +419,96 @@ describe('TEA clinical figures', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
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