Skip to content

fix(instrument-utils): leave measures on unrevealed dynamic questions out of the results summary - #1606

Merged
joshunrau merged 2 commits into
DouglasNeuroInformatics:mainfrom
joshunrau:fix/summary-hidden-dynamic-measures
Oct 4, 2026
Merged

joshunrau merged 2 commits into
DouglasNeuroInformatics:mainfrom
joshunrau:fix/summary-hidden-dynamic-measures

Conversation

@joshunrau

Copy link
Copy Markdown
Collaborator

Closes #1098

What changed

Two fixes to computeInstrumentMeasures, which only feeds the results summary (after submission and on the datahub record page). Exports, tables and graphs use the measures the API stores, so they are unaffected.

  1. Const measures are read through their ref. The summary looked up a const measure's value and label by its key in instrument.measures rather than by measure.ref, which is what the API stores. A measure keyed apart from its field showed another field's value, showed "NA", or threw a TypeError when the key named no field. To index data by ref without a suppression, the measures record is widened to InstrumentMeasures<any, Language>. Under an interactive instrument's Json data type, ConditionalKeys turns ref into a union of Json[] members. The widening also makes the @ts-expect-error on the computed branch unnecessary.
  2. Measures on dynamic questions the respondent never saw are left out. If a const measure's field is kind: 'dynamic' and its render(data) returns null (the new isFieldHidden in form.ts, which builds on getFormFields), the measure is skipped quietly, whether or not it has a label. Before, a labeled measure showed "Label: NA", and an unlabeled one disappeared only because its label lookup failed, which also logged a spurious console.error. An optional static field the respondent saw and skipped still shows "NA".

The InstrumentSummary test fixture gets content: {}: the summary now reads a form's content for its const measures, and real form instruments always have one.

Verification

  • Unit (instrument-utils): src/__tests__/measures.test.ts covers a measure keyed apart from its ref, a labeled measure on a hidden dynamic field (absent) and on a revealed one (present), an unlabeled hidden one (absent, with no console.error), and an unanswered static field (still present). src/__tests__/form.test.ts covers isFieldHidden. Each new test failed before its fix.
  • E2E: testing/src/specs/playground.spec.ts adds two cases for a form whose pet-name question appears only when "Has Pet" is true: the name's measure is absent when the toggle is false and listed when it is true. With the fix reverted, the "absent" case fails with Expected: 0, Received: 1.
  • pnpm lint passes (34/34). pnpm test passes (1585/1585). On chromium, the playground spec passes 14/14, and instrument-completion, form-block, form-reset and subject-detail pass 21/21.

Not run: the full pnpm test:e2e suite, and the firefox project. Neither new e2e test is @smoke.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

joshunrau and others added 2 commits October 4, 2026 10:09
…lts summary

The results summary looked up a const measure's value and label by the measure's own key instead
of its `ref`, which is what the API stores. A measure keyed apart from its field showed another
field's value, showed "NA", or threw when the key named no field at all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… out of the results summary

A const measure on a dynamic form field whose render function returned null for the submitted data
still appeared in the results summary as "<label>: NA" whenever the measure had a label, although
the respondent never saw the question. Without a label it was dropped only because its label could
not be resolved, and logged a spurious error.

The summary now skips a const measure whose field is a dynamic one that the data keeps hidden,
whether or not it has a label. A static field left unanswered still shows as NA.

Closes DouglasNeuroInformatics#1098

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@joshunrau
joshunrau merged commit 0ee6e22 into DouglasNeuroInformatics:main Oct 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Measure with a label always present in final measures section even when never revealed/answered in form.

1 participant