Skip to content
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

Problems constraining an element's type in Profile A to a profiled type (Profile B) with child elements that have slices when Profile A's parent has constrained child element's of the element type first #1555

Open
cmoesel opened this issue Jan 15, 2025 · 0 comments

Comments

@cmoesel
Copy link
Member

cmoesel commented Jan 15, 2025

This is a tricky one that is best explained via an example.

If you have a profile that constrains a child element of one of its element's that is a complex type (e.g., a Patient profile that constrains meta.lastUpdated):

Profile: BaseParentPatientProfile
Parent: Patient
* meta.lastUpdated MS // force parent to expand all child elements of meta

And you define a profile on that same complex type (e.g., a profile on Meta) that introduces slicing on one of the complex type's children (e.g., slicing on Meta.security) and at least one slice (e.g., Meta.security[ABC]):

Profile: MetaWithABCSecuritySlice
Parent: Meta
* security ^slicing.discriminator.type = #value
* security ^slicing.discriminator.path = "system"
* security ^slicing.rules = #closed
* security ^slicing.description = "Slice on system value"
* security contains ABC 1..1
* security[ABC].system = "http://example.org/system/abc"

And then you define a child profile of the first parent profile that constrains the complex type element to the profile of the the complex element (e.g., a profile of BaseParentPatientProfile that constrains meta to MetaWithABCSecuritySlice) and then reference the slice defined in the complex type's profile (e.g., meta.security[ABC]):

Profile: BrokenPatientProfile
Parent: BaseParentPatientProfile
* meta only MetaWithABCSecuritySlice
* meta.security[ABC] MS

Then SUSHI will fail to find the element corresponding to the slice defined in the complex type's profile:

error No element found at path meta.security[ABC] for FlagRule in BrokenPatientProfile, skipping rule

I think this is because the parent profile (e.g., BaseParentPatientProfile) has to expand all the children of the complex type element (e.g., children of Patient.meta) to apply the constraint on a child element (e.g., Patient.meta.lastUpdated). When the type constraint (e.g., meta only MetaWithABCSecuritySlice) is applied to that element in a child profile, SUSHI does not merge the type's profile elements with the already expanded child elements from the parent profile -- so when it tries to reference a child element from the type's profile in the context of the profile that applied the type, it can't find it.

A potential workaround is to reintroduce the slicing and slices from the complex type profile into the profile that applies the complex type. E.g.:

Profile: WorkaroundPatientProfile
Parent: BaseParentPatientProfile
* meta only MetaWithABCSecuritySlice
* meta.security ^slicing.discriminator.type = #value
* meta.security ^slicing.discriminator.path = "system"
* meta.security ^slicing.rules = #closed
* meta.security ^slicing.description = "Slice on system value"
* meta.security contains ABC 1..1
* meta.security[ABC] MS

This causes some redundancy in the definitions, but I don't think it is harmful as long as the slicing definition and slices are a perfect match to what was in the complex type's profile.

Full Example on FSH Online

NOTE: I suspect the correct fix for this is that when a type constraint is applied to an element whose children have already been expanded, that type's elements should be merged with the existing expanded elements. I'm not sure how difficult such a merge would be.

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

No branches or pull requests

1 participant