Stream: implementers
Topic: Can you Specialize a Constrained StructureDefinition?
Mark Kramer (May 21 2018 at 20:31):
Is it possible to create a StructureDefinition whose derivation is "specialization" and whose baseDefinition is a StructureDefinition whose derivation is "constraint"? It appears that this is not possible if the parent SD has a sliced element (because of sdf-1 unique path rule) but if the baseDefinition has not sliced, then I don't see any constraint that would prevent this. Is it legal?
Grahame Grieve (May 21 2018 at 20:57):
we've certainly not thought about this before. I don't know whether it's legal or whether the tools support it.
Grahame Grieve (May 21 2018 at 20:58):
but I wonder whether you really need it...
Mark Kramer (May 21 2018 at 21:01):
Yes, we need it in CIMI. We build hierarchies in the logical model and apply constraints intermixed with definition of new "native" properties. It would be good to actually have a way in logical models to do both constraints and new elements in the same SD, and use that as a baseDefinition for another SD that adds both constraints and new elements, etc.
Grahame Grieve (May 21 2018 at 21:02):
i wonder whether you really do. you can apply constraints to existing elements in a specialization
Mark Kramer (May 21 2018 at 21:07):
Really? I thought that was illegal to add constraints to a specialization. That's what Chris Moesel says -- didn't you say that to him?
https://chat.fhir.org/#narrow/stream/4-implementers/topic/Logical.20Models.20and.20Inheritance
Grahame Grieve (May 21 2018 at 21:09):
so there's some misunderstanding there. You can't mix both. but adding constraints to an element is not what I had in mind there - you can do that when specializing. kind = constraint vs kind = specialization has special meaning in the typing system, but is orthogonal to adding constraints to an existing element
Grahame Grieve (May 21 2018 at 21:10):
my apologies to @Chris Moesel if that means I misunderstood him
Chris Moesel (May 21 2018 at 21:12):
I don't know if you misunderstood me or I misunderstood you, @Grahame Grieve, but apology accepted and likewise extended if applicable. ;-)
Grahame Grieve (May 21 2018 at 21:13):
well, generally, misunderstandings are mutual.
Chris Moesel (May 21 2018 at 21:15):
So to be clear, if A has an element mycode
, and B is a specialization of A, then B can apply a new constraint on the inherited mycode
element?
Grahame Grieve (May 21 2018 at 21:15):
but let's try and be clear:
- you can't mix constraint and specialization, because they are mutually exclusive in the typing system
- but when specializing a structure, you can add new rules about an existing element:
** tighter bindings
** new invariants
** narrower documentation
** tighter cardinality constraints
Grahame Grieve (May 21 2018 at 21:16):
and possible others... and yes, a new constraint
Mark Kramer (May 21 2018 at 21:16):
And, see my original message, it seems slicing might be an exception, because of the unique path invariant?
Grahame Grieve (May 21 2018 at 21:17):
yes, slicing is an exception
Grahame Grieve (May 21 2018 at 21:17):
just like you couldn't slice in an OO class
Mark Kramer (May 21 2018 at 21:17):
Thanks!
Grahame Grieve (May 21 2018 at 21:17):
no problems
Mark Kramer (May 21 2018 at 22:51):
Just a thought -- but -- since slicing is an outlier -- would you be open to a tracker that proposed removing constraint sdf-1?
Grahame Grieve (May 21 2018 at 22:55):
we can certainly talk about it. But I'm extremely dubious about the idea. Slicing is hard. And I think that it's important to be able to generate code for concrete classes
Last updated: Apr 12 2022 at 19:14 UTC