FHIR Chat · sushi needs to handle missing array entry · shorthand

Stream: shorthand

Topic: sushi needs to handle missing array entry


view this post on Zulip David Pyke (Jun 11 2020 at 17:30):

In my haste to fix a problem in an operation, I removed an array element and left just [0] and [2]. sushi had no problem with this but inserted a null element in the output operationdefinition. This caused the IG publisher to crash with a Not a JSON Object: null that @Jose Costa Teixeira was able to find for me. Can it be handled in sushi so that people like me aren't lost?

view this post on Zulip David Pyke (Jun 11 2020 at 17:36):

I've opened issue https://github.com/FHIR/sushi/issues/486 because I'm not likely the only one to be dumb enough to do this.

view this post on Zulip Jose Costa Teixeira (Jun 11 2020 at 17:38):

To replicate: get any repeating element and create an instance with

  • element[0] = ...
  • element[2] = ...
    output json will contain a null in the list.

view this post on Zulip Jose Costa Teixeira (Jun 11 2020 at 17:39):

I think sushi should not populate nulls in the json if an array index is skipped in an instance.
Either fix it automatically (delete null) or give an error - otherwise it will throw incorrect stuff at the publisher.

view this post on Zulip Eric Haas (Jun 11 2020 at 17:53):

I see it being a feature As in what am I missing? Otherwise you would not know what you are missing

view this post on Zulip Nick Freiter (Jun 11 2020 at 18:03):

SUSHI has to be able to populate nulls, at least on arrays of primitives, because when there is an array of primitives, and some of those primitives have values, and some have child elements (extensions or ids), the values are in one array, and the child elements are in a corresponding array, and the values are matched with the child elements by padding the arrays with null https://www.hl7.org/fhir/json.html#primitive. So we would have to think carefully about how we could do something like this without breaking that use case, since the nulls are there for a reason.

view this post on Zulip Jose Costa Teixeira (Jun 11 2020 at 18:05):

yes, but also on instances?

view this post on Zulip Nick Freiter (Jun 11 2020 at 18:10):

Unless I'm misunderstanding, this would generally only occur on instances. Generally array indices aren't used on a profile in FSH. If you want to constrain arrays in a profile, you have to do it with slicing. The array indices are used when you are making an instance and wish to specify the actual value of certain elements in an array, and sometimes those values also need extensions placed on them, and in that case the array may have to be filled with null. For example, in this (very contrived) instance:

Instance: MyPatient
InstanceOf: Patient
* name.given[0] = "Name1"
* name.given[2] = "Name2"
* name.given[0].id = "id1"
* name.given[1].id = "id2"
* name.given[2].id = "id3"

The name element is represented in JSON as:

"name": [
    {
      "given": [
        "Name1",
        null,
        "Name2"
      ],
      "_given": [
        {
          "id": "id1"
        },
        {
          "id": "id2"
        },
        {
          "id": "id3"
        }
      ]
    }
  ]

view this post on Zulip Chris Moesel (Jun 11 2020 at 21:59):

@Nick Freiter is exactly right (as usual), but we will take it as a note that it would be helpful to issue a warning or an error when we detect a null element in an array (when there is no reason for it).


Last updated: Apr 12 2022 at 19:14 UTC