fix(sdc-assemble): preserve regular items mixed with subQuestionnaire placeholders#2001
Draft
oliveregger wants to merge 1 commit into
Draft
fix(sdc-assemble): preserve regular items mixed with subQuestionnaire placeholders#2001oliveregger wants to merge 1 commit into
oliveregger wants to merge 1 commit into
Conversation
… placeholders $assemble assumed every child of a form group (item[0].item) is a sdc-questionnaire-subQuestionnaire placeholder. getItems() returns a compact list (one entry per subquestionnaire) while propagateProperties() indexes it by parent item position, so the two only align when the group is all placeholders. When a regular item is mixed in with placeholders, the child items are applied at the wrong positions: regular items get dropped and placeholders are left unresolved. Add alignItemsWithParentForm() to re-expand the compact list into an array aligned to the parent form's item positions (child items at each placeholder position, null for every regular item) before calling propagateProperties(), whose positional contract is now satisfied. Extract the subQuestionnaire URL into a SUB_QUESTIONNAIRE_EXTENSION_URL constant and an itemIsSubQuestionnaire() predicate, reused by getCanonicalUrls(). Pure-modular forms (all placeholders) assemble identically; mixed forms are now correct. Adds an end-to-end assemble test (fails without the fix) and unit tests for the new helper. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
oliveregger
marked this pull request as draft
July 13, 2026 20:58
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.
Problem
$assembleassumed every child of a form group (item[0].item) is asdc-questionnaire-subQuestionnaireplaceholder.getItems()returns a compact list (one entry per subquestionnaire, in document order) whilepropagateProperties()indexes it by parent item position. Those only align when the group is all placeholders.When a regular item is mixed in with placeholders, the child items are applied at the wrong positions — regular items are silently dropped and the placeholder is left in the output with its
subQuestionnaireextension unresolved.Reproduction
Form group mixing a regular question with a placeholder:
child
ManifestationBegin→[ beginUnknown (boolean), beginDate (date) ]manifestation,beginUnknown,beginDatebeginUnknown,beginDate,begin-ref(unresolved) —manifestationdroppedFix
Add
alignItemsWithParentForm()(utils/canonical.ts) that re-expands the compact per-subquestionnaire item list into an array aligned to the parent form's item positions — child items at each placeholder position,nullfor every regular item.assembleQuestionnaire()aligns the list before callingpropagateProperties().propagateProperties()is unchanged: its existing contract (positional array,nullwhere the parent item is not a placeholder — as its own unit tests already encode) is exactly what it now receives. Also extracts the extension URL into aSUB_QUESTIONNAIRE_EXTENSION_URLconstant and anitemIsSubQuestionnaire()predicate, reused bygetCanonicalUrls().Behaviour change
Tests
assemble.test.ts: end-to-endshould preserve regular items mixed alongside a subquestionnaire placeholder— verified it fails onmain(manifestationdropped) and passes with this change.canonical.test.ts: unit tests foralignItemsWithParentForm(regular-before-placeholder, interleaved, all-placeholder no-op, empty-form passthrough).npm run build(tsup CJS/ESM/DTS) succeeds.🤖 Generated with Claude Code