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

Slicing on non-array elements #5644

Closed
albertsaradin opened this issue Dec 9, 2024 · 4 comments · Fixed by #5661
Closed

Slicing on non-array elements #5644

albertsaradin opened this issue Dec 9, 2024 · 4 comments · Fixed by #5661

Comments

@albertsaradin
Copy link

Hi team, Great work!

I was trying to use the US Core Smoking Status profile and encountered an issue with Medplum: Slicing can only happen on arrays.

The Smoking Status profile defines slices on value[x], which is not an array. Is there an issue there?

@mattwiller
Copy link
Member

Hi @albertsaradin — great find! This is an interesting mismatch between the FHIR spec indicating that slicing is applicable to "an element that may occur more than once (e.g. in a list)" and the Smoking Status profile using a slice on an element with maximum cardinality of 1. We'll look into what it would take to support this nonstandard case

@mattwiller
Copy link
Member

Quick follow up: I was able to step through our code and it looked to me like the valueCodeableConcept slice was actually being validated correctly. Was there a specific error you were seeing in your environment?

Separately, I think that the current version of the Smoking Status profile (STU7) is not well-defined. The relevant bits of the profile StructureDefinition are these three elements:

{
  "id" : "Observation.value[x]",
  "path" : "Observation.value[x]",
  "slicing" : {
    "discriminator" : [{
      "type" : "type",
      "path" : "$this"
    }],
    "ordered" : false,
    "rules" : "open"
  },
  "min" : 1,
  "max" : "1",
  "base" : {
    "path" : "Observation.value[x]",
    "min" : 0,
    "max" : "1"
  },
  "type" : [
    { "code" : "Quantity" },
    { "code" : "CodeableConcept" },
    { "code" : "string" },
    { "code" : "boolean" },
    { "code" : "integer" },
    { "code" : "Range" },
    { "code" : "Ratio" },
    { "code" : "SampledData" },
    { "code" : "time" },
    { "code" : "dateTime" },
    { "code" : "Period" }
  ]
}
{
  "id" : "Observation.value[x]:valueQuantity",
  "path" : "Observation.value[x]",
  "sliceName" : "valueQuantity",
  "min" : 0,
  "max" : "1",
  "base" : {
    "path" : "Observation.value[x]",
    "min" : 0,
    "max" : "1"
  },
  "type" : [{ "code" : "Quantity" }],
  "binding" : {
    "strength" : "required",
    "valueSet" : "http://terminology.hl7.org/ValueSet/v3-UnitsOfMeasureCaseSensitive"
  }
}
{
  "id" : "Observation.value[x]:valueCodeableConcept",
  "path" : "Observation.value[x]",
  "sliceName" : "valueCodeableConcept",
  "min" : 0,
  "max" : "1",
  "base" : {
    "path" : "Observation.value[x]",
    "min" : 0,
    "max" : "1"
  },
  "type" : [{ "code" : "CodeableConcept" }],
  "binding" : {
    "strength" : "extensible",
    "valueSet" : "http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113762.1.4.1267.3"
  }
}

While this looks like it should restrict the field to two specific types, I don't believe it will work as intended. The use of optional (minimum cardinality 0) slices without restricting ElementDefinition.type for value[x] actually means that all types are considered valid, and the required terminology binding is not strictly enforced. Internally we're using a modified version of this profile to work around the issue for now

@albertsaradin
Copy link
Author

Hi @mattwiller , Thank you for following up!

It throws error and doesn't validates when I try.

I attempted to debug the issue (though I'm not very experienced). The error I encountered is Expected array value for sliced element in packages/core/src/default-values.ts: 210.

      if (!Array.isArray(elementValue)) {
        throw new Error('Expected array value for sliced element');
      }

I used the latest medplum from the github.

@albertsaradin
Copy link
Author

Hi @mattwiller,

Thank you! You're fast man! I tried the code, and it works great.

However, there's a small UI problem. I'm not sure if we should create a separate issue or mention it here.

FYI, please go to the app:
app -> Resource Type: "Observation" -> "New..." -> Profiles -> "US Core Smoking Status Observation Profile"

The Value [CodeableConcept] should show the binding valueset, but unfortunately, it doesn't.

I hope that is also as easy to fix as this one!

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

Successfully merging a pull request may close this issue.

3 participants