Stream: shorthand
Topic: slicing with complex $this
John Moehrke (Dec 08 2021 at 15:20):
I am struggling with more complex slicing beyond simple type. I have a need to slice on a extension which is a Reference, and need to slice on the Reference.Identifier.type element. I have a minimal FSH implementation guide that shows what I am trying to do. Would be glad to offer the working solution that we eventually come to as sample for others.
John Moehrke (Dec 08 2021 at 15:22):
I have ^slicing.discriminator.path = "(value as Reference).identifier.type"
today, and Grahame says it needs to be $this.value.ofType(Reference).identifier.type
, but that fails to build.
John Moehrke (Dec 08 2021 at 15:23):
so I presume there is some translation of what Grahame is saying into sushi that I need
John Moehrke (Dec 08 2021 at 15:23):
https://github.com/JohnMoehrke/SlicingSlicedExtension
Chris Moesel (Dec 08 2021 at 15:47):
Hmmm... I didn't think that the $this.
prefix would be necessary since the context is assumed to be this (e.g., I thought that value
would implicitly be $this.value
). Either way, $this.value
certainly is not wrong. I also think that the cast is valid, but agree that ofType
is better (I actually forgot about the ofType
function). So... the discriminator that Grahame suggested looks ok to me. I'll have to look into this further when I have a chance later.
John Moehrke (Dec 08 2021 at 16:44):
I feel stuck between a rock (IG builder) and a hard place (sushi). I only want to do the right thing, but can't figure out what the right thing is.
John Moehrke (Dec 08 2021 at 16:46):
putting Grahame's recommendation into my FSH gives me a different error in the IG builder
Slicing cannot be evaluated: illegal use of ofType() in discriminator - Multiple possible types on Extension.value[x] (@char 1)
John Moehrke (Dec 08 2021 at 16:47):
sushi does seem to create the right thing...
"slicing": {
"discriminator": [
{
"type": "pattern",
"path": "$this.value.ofType(Reference).identifier.type"
}
],
"rules": "open"
}
John Moehrke (Dec 08 2021 at 17:03):
I added my small IG added to IG build
http://build.fhir.org/ig/JohnMoehrke/SlicingSlicedExtension/branches/main/index.html
Chris Moesel (Dec 08 2021 at 17:27):
It seems like ofType
should be allowed there (based on the spec). I'm not sure why it is not. That said, maybe you can get by without it? Have you tried: $this.value.identifier.type
?
John Moehrke (Dec 08 2021 at 18:23):
I get this error with that
Slicing cannot be evaluated: Error in discriminator at Extension.value[x]: no children, multiple types (@char 1)
Chris Moesel (Dec 08 2021 at 18:47):
Ha. OK. The way to fix that would be ofType(Reference)
, but you know how that goes!
John Moehrke (Dec 08 2021 at 18:53):
yup, back to that rock and hard-place
John Moehrke (Dec 22 2021 at 14:21):
so, Grahame has provided examples in his validation github that he indicates work. The only difference I see in the json is that the id for the slice in his does not use the '/' character. And that character seems to be illegal in an id. Sushi is creating these id values... so, can this pattern be cleaned? (Note, I am very willing to be the failure, just not noticing any other difference between Grahames validation examples and what sushi creates from my sample IG.
John Moehrke (Dec 22 2021 at 14:25):
{
"id": "AuditEvent.agent:user.extension:otherIdnpi",
"path": "AuditEvent.agent.extension",
"sliceName": "otherId-npi",
"min": 0,
"max": "1"
},
John Moehrke (Dec 22 2021 at 14:26):
vs what I get out of sushi
{
"id": "AuditEvent.agent:user.extension:otherId/npi",
"path": "AuditEvent.agent.extension",
"sliceName": "otherId/npi",
"min": 0,
"max": "1"
},
John Moehrke (Dec 22 2021 at 14:29):
reminder that my github for my test IG for this use-case is https://github.com/JohnMoehrke/SlicingSlicedExtension
Chris Moesel (Dec 22 2021 at 14:47):
I replied over in #IG creation too, but here is what I said there:
I have not had the time to look at Grahame's example, but the
/
character is used when you are re-slicing. In other words, if there is an existing slice defined and you need to create sub-slices within that slice, this is called re-slicing. And in re-slicing, the sliceName is${parentSliceName}/{subSliceName}
. See Re-profiling and Re-slicing (particularly the last paragraph).
While it is true that the id
datatype does not allow /
, that does not apply here because ElementDefinition.id
is a string
, not an id
(despite its name). This is why element IDs are also allowed to use :
(which happens quite a lot).
I'll have to look at Grahame's example further to see how he is slicing it (without re-slicing), but AFAIK, re-slicing should work too.
John Moehrke (Dec 22 2021 at 14:48):
turns out it is not that
John Moehrke (Dec 22 2021 at 14:51):
the second profile has sliceName:otherId
that Grahame does not have. Removing that clears the error
{
"id": "AuditEvent.agent:user.extension:otherId",
"path": "AuditEvent.agent.extension",
~~ "sliceName": "otherId",~~
"slicing": {
"discriminator": [
{
"type": "pattern",
"path": "$this.value.ofType(Reference).identifier.type"
}
],
"rules": "open"
}
},
John Moehrke (Dec 22 2021 at 15:00):
so otherId
is an extension defined in the first profile. Is sushi thinking that the .extension[otherId]
is a slice and not an index?
Chris Moesel (Dec 22 2021 at 15:33):
I'm not sure I follow. .extension[otherId]
is a slice (not an index). Extensions are, in reality, just slices of extension
with url
as the discriminator.path
. SUSHI includes the sliceName
because we've been told in the past (and it might be documented somewhere, but I'd need to check) that you must always include the sliceName
in the differential -- even if it is not different (i.e., it's inherited). Isn't that the case, @Grahame Grieve? Or has that changed?
John Moehrke (Dec 22 2021 at 15:38):
thanks for continuing to work on this. the extension is defined in the first slice, as is the user
slice is not replicated in the second one, just the extension slice
Chris Moesel (Dec 22 2021 at 15:48):
I'm looking at Grahame's test case now. @Grahame Grieve -- I'm a little confused by this. Here are some things I'm seeing that I am not sure of:
-
The element with id
AuditEvent.agent:user.extension:otherId
does not redeclare thesliceName
(otherId
), but I think it is supposed to. -
The element with id
AuditEvent.agent:user.extension:otherIdnpi
is supposed to be a re-slice ofotherId
, so shouldn't the last part of the element id beotherId/npi
? -
The children of the
AuditEvent.agent:user.extension:otherIdnpi
element have ids likeAuditEvent.agent:user.extension:otherId/npi.valueReference
(note they do have the/
) -- which further seems to indicate that the first id is wrong. -
Most of the
sliceName
values do not match the slice name in the id. For example, the element with idAuditEvent.agent:user.extension:otherId/provider-id
has sliceNameotherId-provider-id
. Shouldn't those match?
John Moehrke (Dec 23 2021 at 13:17):
John Moehrke said:
the second profile has
sliceName:otherId
that Grahame does not have. Removing that clears the error{ "id": "AuditEvent.agent:user.extension:otherId", "path": "AuditEvent.agent.extension", ~~ "sliceName": "otherId",~~ "slicing": { "discriminator": [ { "type": "pattern", "path": "$this.value.ofType(Reference).identifier.type" } ], "rules": "open" } },
so, removing this one line produces good output. So either Sushi should not put it in, or validator should not complain that it is there.
Last updated: Apr 12 2022 at 19:14 UTC