Repository navigation
Wrong-display message: count the choices it lists - #426
Merged
grahamegrieve merged 1 commit intoNov 23, 2026
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is wrong
When
$validate-coderejects 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 inDesignations, and they disagree whenever the concept has displays for more than one region of the requested language:displayCount(). It counts only the best kind of language match it finds: exact first, then language-region, then language only.present(), which matches on the language alone.So for
displayLanguage=en, anen-GBdisplay is listed but not counted. Foren-GB, the singleen-GBdisplay 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=engives "one of 4 choices:" followed by five displays.Repro (test edition in tx/data/snomed-testing.cache)
enValid 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-GBValid 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-USone of 5 choices: ...ValueSet/$validate-codegives the same messages. A FHIR CodeSystem shows the same thing: a concept with displays inenanden-GB, validated foren, is reported as "one of 2 choices" followed by three.Fix
Designations: the selectionpresent()makes is moved into_presented().present()formats that selection, and a newpresentCount()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_oneand_otherwording, now come frompresentCount().displayCount()still decides whether there is any valid display at all (theNO_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.jsonhas a count equal to the number of displays it lists, so none of them change.Tests
tests/tx/designations.test.js: unit tests forpresentCount(). Forenit counts theen-USdisplay thatpresent()lists anddisplayCount()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 withenanden-GBdisplays. They coverenanden-GBrequests, through both the CodeSystem path and the ValueSet path. They buildTxParameterswithvalidating = true, as$validate-codedoes. 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, foren,en-USanden-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 suitetests/tx/test-cases.test.js(5666 passed across it andclosure-enabled.test.js). eslint is clean on the changed files.🤖 Generated with Claude Code