Skip to content

fix: show error alert when answerOption $lookup fails instead of displaying raw codes (issue #1931)#2000

Draft
MaryamMehd wants to merge 5 commits into
mainfrom
issue/1931-answer-option-lookup-failure
Draft

fix: show error alert when answerOption $lookup fails instead of displaying raw codes (issue #1931)#2000
MaryamMehd wants to merge 5 commits into
mainfrom
issue/1931-answer-option-lookup-failure

Conversation

@MaryamMehd

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1931

When a questionnaire has answerOption codings without display values, the renderer calls CodeSystem/$lookup to fetch human-readable labels. If the terminology server is unavailable, the lookups silently fail and the UI falls back to showing raw codes (e.g. 133932002) — confusing for end users.

Changes:

  • addDisplayToAnswerOptions now returns a lookupFailedLinkIds: Set<string> alongside the resolved options, recording any linkId where at least one coding had no display and the lookup request failed
  • answerOptionsLookupFailures is threaded through QuestionnaireModel, QuestionnaireStoreType, and useQuestionnaireStore so field components can detect failure per linkId
  • ChoiceSelectAnswerOptionFields and OpenChoiceSelectAnswerOptionField now render the same StyledAlert error box used by answerValueSet fields when lookup fails — replacing the dropdown entirely (consistent UI, no raw codes visible)
  • Unit test added to addDisplayToCodings.test.ts reproducing the failure scenario and asserting lookupFailedLinkIds is populated correctly

Before / After

Scenario "Type" dropdown
Working terminology server Human-readable labels (Caregiver, Other related person) ✅
Server unavailable — before fix Raw SNOMED codes (133932002, 394738000) ❌
Server unavailable — after fix Pink error alert: "Unable to load option labels — terminology server may be unavailable" ✅

Test plan

  • Run npm run build:smart-forms-renderer — build passes cleanly
  • Run unit tests: cd packages/smart-forms-renderer && npx jest --testPathPattern="addDisplayToCodings" — all 26 tests pass
  • In the Playground, load a questionnaire with answerOption codings that have no display, set the terminology server to a URL that validates but lacks SNOMED (e.g. https://hapi.fhir.org/baseR4), build the form — error alert appears, no raw codes shown
  • With the real terminology server, the dropdown shows proper labels as before

Made with Cursor

MARYAMMEHDIZ and others added 5 commits July 10, 2026 14:29
… codes (issue #1931)

Co-authored-by: Cursor <cursoragent@cursor.com>
… error

Co-authored-by: Cursor <cursoragent@cursor.com>
)

Co-authored-by: Cursor <cursoragent@cursor.com>
…sue #1931)

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@MaryamMehd MaryamMehd requested a review from leoniedickson July 10, 2026 07:58
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.

answerOption list being displayed is a list of codes when $lookup fails

2 participants