Skip to content

Wrong-display message: count the choices it lists - #426

Merged
grahamegrieve merged 1 commit into
HealthIntersections:mainfrom
jmandel:fix/display-choice-count
Nov 23, 2026
Merged

grahamegrieve merged 1 commit into
HealthIntersections:mainfrom
jmandel:fix/display-choice-count

Conversation

@jmandel

@jmandel jmandel commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

What is wrong

When $validate-code rejects a display, the message says how many valid displays there are and then lists them. The number and the list come from two different functions in Designations, and they disagree whenever the concept has displays for more than one region of the requested language:

  • the number comes from displayCount(). It counts only the best kind of language match it finds: exact first, then language-region, then language only.
  • the list comes from present(), which matches on the language alone.

So for displayLanguage=en, an en-GB display is listed but not counted. For en-GB, the single en-GB display is counted, so the one-choice wording is used, but every English display is still listed.

This shows up on real requests. Validating the Danish edition SNOMED CT code 42665001 with a wrong display and displayLanguage=en gives "one of 4 choices:" followed by five displays.

Repro (test edition in tx/data/snomed-testing.cache)

POST /tx/r5/CodeSystem/$validate-code
url=http://snomed.info/sct, code=35566002, display=Wrong, displayLanguage=<lang>
displayLanguage Actual Expected
en Valid display is one of 4 choices: 'Hematoma' (en), 'Haematoma' (en-GB), 'Hematoma, NOS' (en), 'Haematoma, NOS' (en) or 'Hematoma (morphologic abnormality)' (en) one of 5 choices: ... (same list)
en-GB Valid display is 'Hematoma' (en), 'Haematoma' (en-GB), 'Hematoma, NOS' (en), 'Haematoma, NOS' (en) or 'Hematoma (morphologic abnormality)' (en) one of 5 choices: ... (same list)
en-US one of 5 choices: ... unchanged

ValueSet/$validate-code gives the same messages. A FHIR CodeSystem shows the same thing: a concept with displays in en and en-GB, validated for en, is reported as "one of 2 choices" followed by three.

Fix

  • Designations: the selection present() makes is moved into _presented(). present() formats that selection, and a new presentCount() returns how many items it holds.
  • validate.js, at both places that build this message (the code system check and the value set check): the number in the message, and the choice between the _one and _other wording, now come from presentCount(). displayCount() still decides whether there is any valid display at all (the NO_VALID_DISPLAY_* branches). That logic is unchanged.

When the count and the list already agreed, the message text does not change. Every wrong-display message in the tx-ecosystem messages-tx.fhir.org.json has a count equal to the number of displays it lists, so none of them change.

Tests

  • tests/tx/designations.test.js: unit tests for presentCount(). For en it counts the en-US display that present() lists and displayCount() leaves out, and it also counts the fallback list used when no language matches.
  • tests/tx/validate-display-choice-count.test.js (new): worker-level tests that use an in-memory CodeSystem with en and en-GB displays. They cover en and en-GB requests, through both the CodeSystem path and the ValueSet path. They build TxParameters with validating = true, as $validate-code does. Without it, an implicit * is added to the working languages, every designation counts as an exact match, and the bug does not appear.
  • tests/tx/snomed-dialect-display.test.js: the SNOMED case above, for en, en-US and en-GB, run against the committed test edition.

Without the change to tx/, the 9 new tests fail and everything else passes (npx jest tests/tx tests/library: 9 failed, 9115 passed, 64 skipped). With the change, all tests pass, including the tx-ecosystem suite tests/tx/test-cases.test.js (5666 passed across it and closure-enabled.test.js). eslint is clean on the changed files.

🤖 Generated with Claude Code

The "Valid display is one of N choices: ..." message took N from
Designations.displayCount(), which counts only the best kind of language
match (exact, then language-region, then language), while the list comes
from present(), which matches on language alone. For displayLanguage=en an
en-GB display was listed but not counted ("one of 4 choices" followed by
five); for en-GB the one-choice wording was used in front of every English
display.

present()'s selection is now in _presented(), and presentCount() returns
its size; both validate.js sites take the number, and the _one/_other
choice, from it. displayCount() still decides whether any valid display
exists.

Co-Authored-By: Claude <noreply@anthropic.com>

@grahamegrieve grahamegrieve left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok thanks

@grahamegrieve
grahamegrieve merged commit 3254a65 into HealthIntersections:main Nov 23, 2026
5 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.

2 participants