Stream: shorthand
Topic: specify path when nested
Brian Kaney (Jun 02 2020 at 00:43):
Consider a PlanDefinition with multiple nested actions. Is there a way to target say the very first action? * action.trigger 1..1
applies to all actions.
Richard Kavanagh (Jun 02 2020 at 07:08):
@Brian Kaney you can just add indexes into the repeating components, along the lines of
Instance: PlanDef1
InstanceOf: PlanDefinition
* subtitle = "bar"
* status = #draft
* action[0].trigger[0].type = #named-event
* action[0].trigger[0].name = "abc"
* action[0].trigger[1].type = #periodic
* action[0].trigger[1].name = "def"
* action[1].trigger[0].type = #data-added
* action[1].trigger[0].name = "xyz"
Richard Kavanagh (Jun 02 2020 at 07:10):
Also with FSH, when a path with a repeating element is used and the index is not included, SUSHI assumes you mean the zero index. As such
* action.trigger 1..1
is the same as
* action[0].trigger[0] 1..1
Chris Moesel (Jun 02 2020 at 13:00):
Indexes work well for defining instances, but when defining profiles, it is a little trickier to apply a constraint to only a specific element in an array -- particularly when you want to identify that element by its position.
If you have a meaningful way to slice the array, it's fairly straightforward to apply constraints to individual slices by their slice name (FSH documentation covers this fairly well, so I won't repeat it here). So that would be my first suggestion; if there is some differentiating aspect to each action
, then use slices to differentiate the actions and apply the constraints as you wish to each slice.
If you really need to apply constraints by an element's position (i.e., its index), then I think the only way you can do that is via FHIRPath invariants. That might look something like this:
Invariant: my-ig-1
Description: "The first action should have exactly one trigger"
Expression: "first().trigger.count() = 1"
Severity: #error
then in your PlanDefinition profile:
* action obeys my-ig-1
NOTE: I didn't test the FHIRPath, so I can't guarantee it's 100% right, but hopefully my example at least gets across the idea.
Chris Moesel (Jun 02 2020 at 13:03):
Also, see this thread for a related conversation: https://chat.fhir.org/#narrow/stream/215610-shorthand/topic/Constraining.20a.20Resource/near/198232962
Brian Kaney (Jun 02 2020 at 14:22):
Hi @Chris Moesel -- I didn't think of Expression
, but I think this is the direction I'll explore. Thanks again!
Keith Boone (Jun 02 2020 at 19:24):
Yeah, actually, I don't know that the FSH documentation does cover that fairly well. There's enough in the documentation to figure it out, but frankly, this needs a book to describe how to use FSH to create an IG . I know someone with experience writing books, but he might not be available for a bit... ;-)
Chris Moesel (Jun 02 2020 at 19:38):
Ha. Yeah, I know there's plenty of places where you still need to connect the dots -- and creating an IG (with or without FSH) is extremely complex. I was referring more specifically to how to reference slices by path and how to set constraints on specific slices -- which at least have some decent examples. Now... how to correctly decide what the slicing
rules should be in the first place... that's the hard part.
Last updated: Apr 12 2022 at 19:14 UTC