FHIR / sushi

SUSHI (aka "SUSHI Unshortens Short Hand Inputs") is a reference implementation command-line interpreter/compiler for FHIR Shorthand (FSH).
Apache License 2.0
146 stars 43 forks source link

Sushi examples should preserve the order of fields in the output #1340

Open rbrush opened 1 year ago

rbrush commented 1 year ago

Example resources can be difficult for users to inspect and understand since the fields are produced in a surprising order. Here's a minimal example of a simple patient -- notice the active and gender fields are moved to the bottom of the generated resource:

Instance: SimplePatient
InstanceOf: Patient
* active = true
* gender = #female
* address[+]
  * use = #work
* address[+]
  * use = #home

And the example output:

{
  "resourceType": "Patient",
  "id": "SimplePatient",
  "address": [
    {
      "use": "work"
    },
    {
      "use": "home"
    }
  ],
  "active": true,
  "gender": "female"
}
cmoesel commented 1 year ago

Thanks for the suggestion. Technically, the order of properties in JSON does not matter to machines; but as you noted, sometimes it matters to humans! We'll have to take a look and see what is causing them to be re-ordered in SUSHI. To be honest, I'm not sure. I thought maybe we were outputting the elements in the order they're defined in the Patient resource, but that doesn't seem to be the case. So... we'll need to investigate.

rbrush commented 1 year ago

Thanks for looking into it, Chris! For some reason it seems to be shifting some primitive fields after repeated structs . You're right it doesn't impact machine usage, but it has created some confusion for humans reading examples at https://build.fhir.org/ig/FHIR/sql-on-fhir-v2/artifacts.html.

Normally I'd look into contributing a fix myself, but I'm TypeScript novice and am entirely unfamiliar with the code base; so I greatly appreciate your expertise here.