FHIR Chat · complex extensions · shorthand

Stream: shorthand

Topic: complex extensions


view this post on Zulip David Hay (Jan 07 2020 at 00:03):

Creating complex extensions and getting a number of these errors: error: The slice latitude on extension must reference an existing extension, or fix a url if the extension is defined inline.

a) Would be good to include the filename in the error
b) any thoughts why I'm getting the error? sample: (based on the example from http://build.fhir.org/ig/HL7/fhir-shorthand/#defining-extensions )

Extension: geolocation
Id: geolocation
Description:  "None supplied yet"

* extension contains
    latitude 0..1

// definitions of sub-extensions
* extension[latitude] ^definition = "No description"
* extension[latitude].value[x] only decimal

view this post on Zulip David Hay (Jan 07 2020 at 00:04):

looks like I need to specify the internal url in some way...

view this post on Zulip David Hay (Jan 07 2020 at 00:24):

(deleted)

view this post on Zulip Chris Moesel (Jan 07 2020 at 14:41):

Right, I think you need to add the url for the sub-extension:

* extension[latitude].url = "latitude"

I can't access the built documentation (due to the IG Auto Build bug), but the example in the Wiki shows this approach correctly: https://github.com/HL7/fhir-shorthand/wiki/3.2-Extensions

I guess we should think about whether or not it makes sense to infer the url value from the slice name when the author doesn't provide an explicit url value. That might make sense.

view this post on Zulip Chris Moesel (Jan 07 2020 at 14:42):

Also, I thought we were showing the filename in the error messages, but maybe we missed passing in that metadata for this particular log message.

view this post on Zulip David Hay (Jan 07 2020 at 19:08):

pretty sure I tried that - but will check...

view this post on Zulip David Hay (Jan 07 2020 at 19:26):

No - you're right - that did work. Some interesting twists (using a different extension) though.

a) It only needs to be done on the first one - the following works fine (and the ED looks Ok to a cursory view)

Extension: practitioner-additional-authorizations
Id: practitioner-additional-authorizations
Description:  "None supplied yet"

* extension contains
    auth 0..1 and
    period 0..1

// definitions of sub-extensions
* extension[auth].url = "auth"
* extension[auth] ^definition = "A code identifying the additional authorisations that a practitioner is authorised to perform"
* extension[auth].value[x] only CodeableConcept

* extension[period] ^definition = "The period the additional authorization is effective"
* extension[period].value[x] only Period

b) But changing the sub extension name to 'code' results in an error. ie this definition:

* extension contains
    code 0..1 and
    period 0..1

// definitions of sub-extensions
* extension[code].url = "code"
* extension[code] ^definition = "A code identifying the additional authorisations that a practitioner is authorised to perform"
* extension[code].value[x] only CodeableConcept

* extension[period] ^definition = "The period the additional authorization is effective"
* extension[period].value[x] only Period

results in this error (I'm guessing that code is a reserved word):

error: No element found at path extension[code].url for practitioner-additional-authorizations, skipping rule
  File: /Users/davidhay/Dropbox/contracting/MOH/ResourcesForRegistryIG/shorthand/extension-practitioner-additional-authorizations.fsh
  Line: 10
error: No element found at path extension[code].value[x] for practitioner-additional-authorizations, skipping rule
  File: /Users/davidhay/Dropbox/contracting/MOH/ResourcesForRegistryIG/shorthand/extension-practitioner-additional-authorizations.fsh
  Line: 12

c) And it does not like the url being attached to the second sub extension. This definition:

* extension contains
    auth 0..1 and
    period 0..1

// definitions of sub-extensions
* extension[auth].url = "auth"
* extension[auth] ^definition = "A code identifying the additional authorisations that a practitioner is authorised to perform"
* extension[auth].value[x] only CodeableConcept

* extension[period].url = "period"
* extension[period] ^definition = "The period the additional authorization is effective"
* extension[period].value[x] only Period

results in

error: Cannot fix period to this element; a different uri is already fixed: http://hl7.org/fhir/StructureDefinition/organization-period.
  File: /Users/davidhay/Dropbox/contracting/MOH/ResourcesForRegistryIG/shorthand/extension-practitioner-additional-authorizations.fsh
  Line: 14

view this post on Zulip David Hay (Jan 07 2020 at 20:14):

Issue c) is related to using the slicename 'period' - renaming it makes it work OK...

view this post on Zulip Chris Moesel (Jan 07 2020 at 20:44):

I think a) and c) are actually related. Here is what's going on... When you say extension contains period 0..1, SUSHI looks for an already existing extension named period. If it finds one, it uses it (and fixes the url) appropriately. If it doesn't find one, it sets up the slice so the author can specify the url. In this case, core FHIR already defines an extension w/ "name": "period" (here), so SUSHI assumes that is what you want and sets it up that way.

This is why a) works . You don't need to declare the url because SUSHI is using the url from the pre-existing FHIR extension. It is also why c) fails -- because you can't overwrite an existing fixed value.

view this post on Zulip Chris Moesel (Jan 07 2020 at 20:46):

It's an interesting problem. It seems we might need to adjust how FHIR Shorthand works to make it less ambiguous -- so we know if you are intending to create a new extension or re-use an existing one... Hmmm....

view this post on Zulip Chris Moesel (Jan 07 2020 at 20:47):

As for b), I wonder if that is a parser error. It might be that code is a keyword in our grammar already and that using it in this context confuses the parser. If that's what is going on, it should be a fairly easy fix.

view this post on Zulip Chris Moesel (Jan 07 2020 at 20:51):

Oh-- I see you had already guessed it was a reserved word. Good guess! Ideally though, we don't really want it to be a "reserved" word -- we should allow you to use it in contexts like this.

view this post on Zulip David Hay (Jan 07 2020 at 20:52):

Great to understand how this works! But doesn't this approach mean that names need to be globally unique? Is 'contains' only used for defining sub-extensions?

view this post on Zulip Chris Moesel (Jan 07 2020 at 21:03):

contains is used in any context where slices apply. So... since extensions (and sub-extensions) are really just slices of extension, we use contains. But you would also use contains to slice any other element as well. Currently, however, extensions are the only context in which the slice name might refer to an external entity -- so it's the only place where we currently run into this.

Well... that's not entirely true. In any place we need to look something up by name, there is the possibility of finding the wrong one. So, for example, performer only Practitioner could refer to the resource Practitioner, but also could refer to a profile with the _name_ Practitioner (if it existed). The only real way around that is to require full URL identifiers, but that's not very user-friendly. So... we should document rules about how lookups are performed and what locations are preferred over others -- and if you want something that isn't the "preferred" result of a lookup, only _then_ do you need to use the full URL.

That still doesn't solve the extension contains problem though, since we still can't tell if you want an existing extension or a new one.

view this post on Zulip David Hay (Jan 07 2020 at 21:11):

Using name does seem a bit fragile - to take your 'performer only Practitioner' example, it sounds that it could be quite easy to muck it up. Would alias help out here?


Last updated: Apr 12 2022 at 19:14 UTC