Skip to content

fix(code-editor): allow extension on nested elements - #150

Merged
aleksandrkislitsyn merged 2 commits into
masterfrom
fix/8121-extension-on-nested-elements
Aug 5, 2026
Merged

fix(code-editor): allow extension on nested elements#150
aleksandrkislitsyn merged 2 commits into
masterfrom
fix/8121-extension-on-nested-elements

Conversation

@aleksandrkislitsyn

Copy link
Copy Markdown
Contributor

Fixes HealthSamurai/sansara#8121.

Problem

The FHIR JSON editor flagged a valid extension on a nested element as an Unknown property, and did not offer it in autocomplete. Examples from the issue:

  • QuestionnaireResponse.item[].extension
  • Patient.contact[].extension

Both resources are valid and save fine — the editor's client-side validation was wrong.

Root cause

resolveElements (in fhir-autocomplete.ts) drives both the diagnostics and the autocomplete. It resolves the valid child elements for a path by walking the StructureDefinition differentials.

  • For a complex datatype (e.g. contact.nameHumanName), it descends via collectAllElements(typeCode), which recurses into baseDefinition (Element) and therefore picks up the inherited id/extension.
  • For a BackboneElement (e.g. QuestionnaireResponse.item), there is no named type to resolve — its children live inline in the parent resource's differential. That branch just repoints the path and returns the inline children, and never merges in the BackboneElement/Element base fields. A differential doesn't repeat inherited elements, so id/extension/modifierExtension were missing.

Result: extension on a nested backbone/complex element was neither recognized (→ false "Unknown property") nor suggested.

Fix

Append the universal element properties to resolveElements output when not already present:

  • id, extension — on every element
  • modifierExtension — additionally on BackboneElements and resources (tracked via an isBackbone flag), not on plain complex datatypes like HumanName

Because both the diagnostics and autocomplete consume resolveElements, this one change fixes both: no more false "Unknown property" on nested extensions, and autocomplete now suggests extension (and modifierExtension where valid) inside nested backbone elements. The if not already present guard makes it a no-op at the resource root and for complex types, where these fields are already present.

Verification

  • Reproduced both reported cases in the running editor; the false diagnostics are gone after the fix.
  • Autocomplete now offers extension inside QuestionnaireResponse.item / Patient.contact, and modifierExtension on backbone items but not inside a plain HumanName.
  • A genuinely invalid key is still flagged (validation not weakened).
  • biome check clean on the changed file; tsc -b no new errors.

🤖 Generated with Claude Code

resolveElements did not include the universal element properties (id,
extension, and modifierExtension for BackboneElements) for nested backbone
or complex elements, because a StructureDefinition differential does not
repeat inherited base-type elements. This caused the FHIR editor to flag a
valid `extension` on e.g. QuestionnaireResponse.item or Patient.contact as
an "Unknown property", and to omit it from autocomplete.

Append the universal properties to resolveElements output (when not already
present), gated by whether the context is a BackboneElement/resource
(modifierExtension) or a plain complex datatype (id/extension only). Both
diagnostics and autocomplete now handle nested extensions correctly.

Fixes HealthSamurai/sansara#8121

Co-Authored-By: Aleksandr Kislitsyn <aleksandr.kislitsyn@gmail.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@Aitem Aitem left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

CI `pnpm audit --audit-level=high` flagged brace-expansion advisories
(GHSA-mh99-v99m-4gvg, GHSA-rgw5-rvv9-x895) in transitive deps via
@swc/cli>minimatch and @storybook/react-*. The existing overrides did not
cover the vulnerable ranges. Override brace-expansion 2.x to >=2.1.4 and
3.x-5.x to >=5.0.9. Audit at --audit-level=high now passes (only 2 moderate
advisories remain, below the high threshold).

Co-Authored-By: Aleksandr Kislitsyn <aleksandr.kislitsyn@gmail.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@aleksandrkislitsyn
aleksandrkislitsyn merged commit bf86fae into master Aug 5, 2026
6 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