Skip to content

Implement canonical version matching for partial versions in FHIR validation #3217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 23, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 16, 2025

This PR implements support for partial version matching in canonical URLs as per the FHIR specification, addressing the requirement to support version matching in IAsyncResourceResolver implementations.

Problem

The current implementation only supports exact version matching for canonical URLs. According to the FHIR canonical matching specification, partial version matching should be supported where "1.5" matches "1.5.0", "1.5.1", etc.

For example, this scenario would fail before this fix:

// Profile reference with partial version
var canonical = "http://fhir.abda.de/eRezeptAbgabedaten/StructureDefinition/DAV-PR-ERP-AbgabedatenBundle|1.5";
// Actual profile version in repository: "1.5.0"
var profile = resolver.ResolveByCanonicalUri(canonical); 
// Result: null (should find the 1.5.0 version)

Solution

This PR implements FHIR-compliant canonical version matching across all resolver implementations:

Modified Components

  1. ArtifactSummaryExtensions.cs (Conformance & STU3 versions): Updated FindConformanceResources method to use a new MatchesVersion helper that implements FHIR-compliant canonical matching rules

  2. InMemoryResourceResolver.cs: Enhanced ResolveByCanonicalUri method to support partial version matching for in-memory resolvers

  3. Added comprehensive test coverage to verify both backward compatibility and new functionality

FHIR Canonical Matching Rules Implemented

  • Exact matching: 1.5.0 matches exactly 1.5.0 (backward compatible)
  • Partial matching: 1.5 matches 1.5.0, 1.5.1, 1.5.10, etc.
  • Non-matching: 1.5 does not match 1.4.0, 1.6.0, or 2.5.0
  • Empty version handling: Resources without versions only match queries without versions

Example Usage

// This will now work when profile has version "1.5.0"
var canonical = "http://example.org/StructureDefinition/MyProfile|1.5";
var profile = resolver.ResolveByCanonicalUri(canonical); // ✅ Resolves successfully

// Exact matching still works as before
var exactCanonical = "http://example.org/StructureDefinition/MyProfile|1.5.0";
var exactProfile = resolver.ResolveByCanonicalUri(exactCanonical); // ✅ Still works

Testing

  • ✅ All existing tests continue to pass (backward compatibility preserved)
  • ✅ New comprehensive test validates partial version matching works correctly
  • ✅ Verified exact version matching still works as before
  • ✅ Tested edge cases like non-matching versions return null
  • ✅ Full solution builds successfully across all target frameworks

Backward Compatibility

This change is fully backward compatible. All existing exact version matching continues to work unchanged, while adding support for partial version matching as specified in the FHIR standard.

Fixes #3216.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

…idation

Co-authored-by: ewoutkramer <2276305+ewoutkramer@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Implement canonical version matching for partial versions in FHIR validation Implement canonical version matching for partial versions in FHIR validation Jul 16, 2025
@Copilot Copilot AI requested a review from ewoutkramer July 16, 2025 21:28
Copilot finished work on behalf of ewoutkramer July 16, 2025 21:28
ewoutkramer and others added 2 commits July 22, 2025 14:40
Unified duplicate MatchesVersion implementations across ArtifactSummaryExtensions and InMemoryResourceResolver by moving the logic to a public static method on the Canonical class. This eliminates code duplication and provides a centralized, reusable canonical version matching utility.

- Added Canonical.MatchesVersion() as public static method
- Updated all three implementations to use Canonical.MatchesVersion()
- Removed duplicate private MatchesVersion methods
- Maintains full backward compatibility

Co-authored-by: ewoutkramer <2276305+ewoutkramer@users.noreply.github.com>
@Copilot Copilot AI requested a review from ewoutkramer July 22, 2025 12:52
Copilot finished work on behalf of ewoutkramer July 22, 2025 12:52
@ewoutkramer ewoutkramer marked this pull request as ready for review July 22, 2025 13:12
@ewoutkramer ewoutkramer requested a review from mmsmits July 22, 2025 13:13
Co-authored-by: mmsmits <8956842+mmsmits@users.noreply.github.com>
@Copilot Copilot AI requested a review from mmsmits July 23, 2025 14:13
Copilot finished work on behalf of mmsmits July 23, 2025 14:13
@mmsmits mmsmits enabled auto-merge July 23, 2025 14:15
@mmsmits mmsmits merged commit 1afe78b into develop Jul 23, 2025
17 checks passed
@mmsmits mmsmits deleted the copilot/fix-3216 branch July 23, 2025 19:56
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.

Implement canonical version matching for partial versions in FHIR validation
3 participants