Stream: shorthand
Topic: How can I auto-populate constrained fields in Instances?
Martin Höcker (Feb 25 2021 at 21:47):
Early on in my SUSHI-usage, I discovered that SUSHI can automatically populate some values in Instance
s, like so:
Profile: MyPatient1
Parent: Patient
* name ^slicing.discriminator.path = "family"
* name ^slicing.discriminator.type = #pattern
* name contains bäcker 0..1
* name[bäcker].family = "Bäcker"
Instance: ExamplePatient1
InstanceOf: MyPatient1
* name[bäcker].given = "Jürgen"
In the output, the Patient's name "Jürgen Bäcker" is automatically given in full:
{
"resourceType": "Patient"
...
"name": [{
"family": "Bäcker"
"given": ["Jürgen"]
}
]
}
This feature delighted be, because it spared me from having to write "obvious", "already constrained" information twice.
But when discriminating on deeper paths, this feature did not work for me. For example:
Profile: MyPatient2
Parent: Patient
* contact ^slicing.discriminator.path = "address.text"
* contact ^slicing.discriminator.type = #pattern
* contact contains mars 0..1
* contact[mars].address.text = "Mars"
Instance: ExamplePatient2
InstanceOf: MyPatient2
* contact[mars].gender = #male
The output is
{
"resourceType": "Patient",
...
"contact": [
{
"gender": "male"
}
]
}
Is there a way to ask SUSHI to automatically populate all fields that have a fixed value (or an unambiguous pattern value)?
Nick Freiter (Feb 25 2021 at 21:57):
When adding this feature, we did not want to make it so that SUSHI would auto-populate incorrect values, since then a user would have very little way of removing those auto-populated values. So the automatic population is intentionally conservative. In this case, the contact[mars].address.text
field is constrained to the value Mars
, but this field has cardinality 0..1
, so SUSHI cannot know for sure that the value should be populated. Unfortunately there isn't a way to ask SUSHI to automatically populate all fixed values. The concern would be that such a feature could lead to many unwanted values being populated, because so many elements are optional.
Martin Höcker (Feb 25 2021 at 22:05):
Ahh, thank you, I had missed the cardinality side of it. So now I understand why the following example only worked "sometimes" for me:
Profile: MyPatient1
Parent: Patient
* active = true
* active 1..1
Instance: ExamplePatient1
InstanceOf: MyPatient1
On some real-world examples, I did not have the corresponding element fixed to 1..1.
But coming back to the slicing-example, I would argue that by using the slice I show my intent that it should be a valid slice that corresponds to my discriminator, so I would kind-of expect that the constrained element should be there. It's a minor issue though, since changing my code to
Profile: MyPatient2
Parent: Patient
* contact ^slicing.discriminator.path = "address.text"
* contact ^slicing.discriminator.type = #pattern
* contact contains mars 0..1
* contact[mars].address.text = "Mars"
* contact[mars].address 1..1
Instance: ExamplePatient2
InstanceOf: MyPatient2
* contact[mars].gender = #male
fixes the issue for me. Thank you for your help!
Martin Höcker (Feb 25 2021 at 22:37):
Short addendum: The first example I posted also discriminates on an optional element, but in that example it is automatically populated (which is helpful, I think). My proposal would be to extend this behavior to deep paths, if and only if they are used in discriminators.
Nick Freiter (Feb 26 2021 at 13:42):
That is a good point. Currently SUSHI does not really handle discriminators in a "smart" way. SUSHI doesn't do any sort of validation or interpretation of discriminator values. Ideally we would be able to detect that the constrained element should be there though.
Last updated: Apr 12 2022 at 19:14 UTC