Skip to content

SUSHI prioritizes FHIR Core over Extensions package, contradicting Grahame's guidance #1602

@mechanik-daniel

Description

@mechanik-daniel

Bug: SUSHI prioritizes FHIR Core over Extensions package, contradicting official FHIR guidance

Summary

SUSHI's current implicit package loading order gives FHIR Core packages higher priority than Extensions packages, which contradicts the official guidance from Grahame Grieve in the FHIR chat. This causes Extensions package definitions to be overridden by Core package definitions during resolution.

Expected Behavior

According to FHIR chat guidance from Grahame Grieve, when resolving extensions that exist in both the FHIR Core package and the Extensions package, tools should prefer the Extensions package definitions over the Core package definitions.

Key exchange from the chat:

Chris Moesel: "Should tools prefer the extension in the release or the extension in the hl7.fhir.uv.extensions package?"
Grahame Grieve: "(b) prefer the extension package definitions"

Actual Behavior

SUSHI currently loads packages in this order:

  1. Automatic dependencies (Extensions, Terminology, Tools) - lowest priority
  2. User-configured dependencies - medium priority
  3. FHIR Core package - highest priority

This means Core definitions override Extensions definitions, which is the opposite of the intended behavior.

Root Cause

In src/utils/Processing.ts lines 370-372, the comments state:

// Load automatic dependencies first so they have lowest priority in resolution
await loadAutomaticDependencies(fhirVersionInfo.version, dependencies, defs);
// Then load configured dependencies, with FHIR core last so it has highest priority in resolution
await loadConfiguredDependencies(dependencies, fhirVersionInfo.version, config.filePath, defs);

Combined with the byLoadOrder(false) sort in FHIRDefinitions.ts (reverse load order), this gives precedence to packages loaded last (Core) over packages loaded first (Extensions).

Reproduction Case

The language extension binding demonstrates this issue:

  • Extensions package (hl7.fhir.uv.extensions.r4): Defines binding description as "IETF language tag"
  • Core package (hl7.fhir.r4.core): Defines binding description as "A human language."
  • Current result: Core wins, showing "A human language."
  • Expected result: Extensions should win, showing "IETF language tag"

Proposed Solution

Modify the loading order to treat automatic/implicit packages as a special exception that should have higher priority than Core, while preserving the normal expectation that Core has highest priority over regular user packages.

Recommended approach:

  1. Load automatic dependencies (Extensions, Terminology, Tools) first
  2. Load user-configured dependencies second
  3. Load FHIR Core package third
  4. Re-load automatic dependencies last (highest priority)

This targeted solution ensures that:

  • ✅ Automatic packages (Extensions, etc.) get precedence over Core per FHIR guidance
  • ✅ Core still maintains precedence over regular user packages (preserving existing expectations)
  • ✅ User packages maintain their current priority relative to each other
  • ✅ Minimal disruption to existing behavior for non-implicit packages

Alternative approach:
Modify the resolution sorting in FHIRDefinitions.ts to add special precedence rules that explicitly prioritize automatic packages over Core, regardless of load order.

FHIR Chat Reference

Full thread: https://chat.fhir.org/#narrow/stream/179239-tooling/topic/New.20Implicit.20Package/near/325318949

Environment

  • SUSHI version: 3.16.5
  • FHIR version: R4
  • Packages involved: hl7.fhir.r4.core vs hl7.fhir.uv.extensions.r4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions