Repository navigation
Record the profile when its id is the same as the type it profiles (fixes #1560) - #1644
Merged
cmoesel merged 2 commits intoOct 10, 2026
Merged
Conversation
Constraining a type, as opposed to a reference, to a profile whose id is the
same as the type it profiles left the element constrained to the base type
with no profile at all, so the generated StructureDefinition permitted any
instance of that type.
applyProfiles decided whether a match needed a profile recorded by comparing
the matched definition's id against the element type code:
if (match.metadata.id === newType.code && matches.length === 1)
The intent is to skip a constraint that is the type itself, since there is
nothing to profile in that case. But a profile may be given an id that is the
same as the type it profiles, and then the id and the type code are equal even
though the match is a profile, so its url was never recorded.
That also explains the rest of the reported behaviour. Naming the profile by
its canonical url does not help, because the metadata reached that way still
carries the colliding id. Restricting a reference is unaffected, because the
type code is then Reference, the comparison is false, and the reference branch
records the target profile as it should.
Compare canonical urls instead. isBaseTypeDefinition fishes for the type code
and confirms the matched metadata really is the definition of that type, so an
id collision no longer reads as the type itself, and fisher is threaded through
applyTypeIntersection to reach it. This only narrows the existing skip, so a
profile that was recorded before is still recorded.
Fixes FHIR#1560
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Member
|
Thank you @AltangerelG for this PR. I apologize for the delay in reviewing it. I had a couple of large and complicated PRs that I had to get through first. I just merged one of them (#1637) today and I'm working my way through #1641 next. I hope to review the remaining PRs soon after that. |
cmoesel
approved these changes
Oct 10, 2026
cmoesel
left a comment
Member
There was a problem hiding this comment.
Nice job, @AltangerelG. This fixes the bug nicely. I ran a regression and it found a few IGs that were hitting this bug, and your fix corrected the problem in those IGs. Thanks!
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.
Summary
Fixes #1560. Constraining a type (not a reference) to a profile whose id is the same as the type it
profiles silently dropped the profile, so the element was constrained only to the base resource.
Root cause
ElementDefinition.applyProfilesdecided whether a match needed a profile recorded with:The intent is "the constraint is the type itself, so there is nothing to profile", but the test is
the matched definition's id against the type code. A profile is free to take an id that is the
same as the type it profiles, and then
metadata.idandnewType.codeare bothClaim, so theprofile URL was never pushed onto
matchedProfiles.That accounts for all three behaviours in the issue:
still has
idofClaimnewType.codeis thenReference, the test isfalse, and the reference branch records the target profile correctly
The fix
Compare canonical URLs rather than ids. A new
isBaseTypeDefinitionhelper fishes for the typecode and confirms the matched metadata is the definition of that type, so an id collision no longer
looks like "the type itself".
fisheris threaded throughapplyTypeIntersectionto reach it.The change only ever narrows the existing skip — it cannot newly suppress a profile that
previously survived, so the blast radius is limited to the colliding-id case.
Tests
Three tests added to
test/fhirtypes/ElementDefinition.constrainType.test.ts:The first two fail on master and pass with this change. The third passes either way by design,
since it protects the behaviour the original condition was written for.
npm run checkpasses: 104 suites, 3541 tests, plus lint and prettier clean. No dependencies added.🤖 Generated with Claude Code