Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid type slicing when a choice is constrained to a single type #1088

Closed
cmoesel opened this issue May 16, 2022 · 0 comments
Closed

Avoid type slicing when a choice is constrained to a single type #1088

cmoesel opened this issue May 16, 2022 · 0 comments

Comments

@cmoesel
Copy link
Member

cmoesel commented May 16, 2022

For SUSHI 3.0: do not create a type slice for elements when the choice has already been restricted to a single type. For example, consider this FSH:

Profile: MyObservation
Parent: Observation
* value[x] only CodeableConcept
* valueCodeableConcept from http://example.org/foo

Currently, whenever SUSHI sees a type-specific path (like valueCodeableConcept), it uses the standard type slicing mechanism to represent it. It does this even after value[x] has been constrained to a single type (as above). So you end up w/ a differential something like this:

"differential": {
    "element": [
      {
        "id": "Observation.value[x]",
        "path": "Observation.value[x]",
        "slicing": {
          "discriminator": [
            {
              "type": "type",
              "path": "$this"
            }
          ],
          "ordered": false,
          "rules": "open"
        },
        "type": [
          {
            "code": "CodeableConcept"
          }
        ]
      },
      {
        "id": "Observation.value[x]:CodeableConcept",
        "path": "Observation.value[x]",
        "sliceName": "CodeableConcept",
        "min": 0,
        "max": "1",
        "binding": {
          "strength": "required",
          "valueSet": "http://example.org/foo"
        }
      }
    ]
  }

Technically, this type slicing is totally unnecessary since value[x] can only be a single type -- therefore you don't need slices to disambiguate. Since slicing adds complexity, we like to avoid it when we can. To that end, SUSHI should detect when this happens (type slice on a choice that has already been constrained to a single type) and apply any constraints directly to the choice element instead. This would effectively be the same as:

Profile: MyObservation
Parent: Observation
* value[x] only CodeableConcept
* value[x] from http://example.org/foo

Resulting in this much simpler differential:

"differential": {
    "element": [
      {
        "id": "Observation.value[x]",
        "path": "Observation.value[x]",
        "type": [
          {
            "code": "CodeableConcept"
          }
        ],
        "binding": {
          "strength": "required",
          "valueSet": "http://example.org/foo"
        }
      }
    ]
  }

This was proposed on Zulip and received positive feedback. See: https://chat.fhir.org/#narrow/stream/215610-shorthand/topic/Type.20Slices.20on.20Choices.20w.2F.20a.20Single.20Type/near/282241129

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant