FHIR Chat · Container reference violates `ref-1`? · implementers

Stream: implementers

Topic: Container reference violates `ref-1`?


view this post on Zulip Preston TW (Sep 18 2019 at 19:34):

Hello!

I'm reading over the specification for Reference (https://www.hl7.org/fhir/references.html). Its ref-1 constraint expression is:

reference.startsWith('#').not() or (reference.substring(1).trace('url') in %resource.contained.id.trace('ids'))

However, later in this page, it describes contained resources (https://www.hl7.org/fhir/references.html#contained). Quoting from that section:

For a resource that references the container, the reference is "#"

Thus it seems like the above expression is missing a case. Am I reading this correctly?

Thank you,
Preston

view this post on Zulip Chris Moesel (Sep 18 2019 at 19:37):

The above expression says that a reference either:

  • does NOT start with #
  • OR the part after the # must match one of the contained resource IDs

So that seems right to me, unless I'm misunderstanding your question.

view this post on Zulip Preston TW (Sep 18 2019 at 19:39):

Thank you, @Chris Moesel, I misread how constraint expressions work. I thought the expression must be true to satisfy the constraint, rather than evaluating to true means the constraint is violated. Is the latter interpretation correct?

view this post on Zulip Chris Moesel (Sep 18 2019 at 19:42):

Hi @Preston TW -- no, you had it right the first time. If the constraint evaluates to true then the data is good. If it evaluates to false, then the data is bad (constraint violated).

view this post on Zulip Chris Moesel (Sep 18 2019 at 19:43):

I have to step out a quick minute, but glad to walk through it. Just a minute...

view this post on Zulip Preston TW (Sep 18 2019 at 19:50):

As a concrete example, the docs give this resource:

<Patient xmlns="http://hl7.org/fhir">
  <id value="something"/>
  <contained>
    <Provenance>
      <!-- no id necessary (though still allowed) -->
      <target>
        <reference value="#"/>
      </target>
    </Provenance>
  </contained>
  <!-- other attributes -->
</Patient>

How is this reference valid wrt ref-1?

view this post on Zulip Chris Moesel (Sep 18 2019 at 19:54):

@Preston TW -- you are 100% correct. I'm sorry, I misread your original message. I agree -- if just "#" is intended to be used to reference the "container" (e.g., the resource that has the contained resources), then there does seem to be a missing phrase in the constraint. I'm sorry for the confusion!

view this post on Zulip Preston TW (Sep 18 2019 at 19:57):

Thank you, @Chris Moesel, for clearing that up!

view this post on Zulip Preston TW (Sep 18 2019 at 20:10):

Is there a process for opening a ticket?

view this post on Zulip Grahame Grieve (Sep 18 2019 at 20:13):

# is not a valid reference. I have no idea what's up with that example above.

view this post on Zulip Grahame Grieve (Sep 18 2019 at 20:13):

to create a ticket, there's a link at the bottom of every page - "propose a change"

view this post on Zulip Chris Moesel (Sep 18 2019 at 20:20):

I initially didn't expect it either, @Grahame Grieve , but it's not just the example that uses # as a reference. The text itself says to use just # to reference the container from a contained resource.

And this approach is further supported by DOM-3 in DomainResource, which contains the following clause: descendants().where(reference = '#').exists().

view this post on Zulip Grahame Grieve (Sep 18 2019 at 20:20):

oh

view this post on Zulip Grahame Grieve (Sep 18 2019 at 20:21):

yes now I'm waking up. this is to reference the container

view this post on Zulip Lloyd McKenzie (Sep 18 2019 at 20:42):

@Grahame Grieve and it looks like the original poster is correct that the FHIRPath is insufficient - it doesn't allow for a bare "#" as the reference when the reference appears in a contained resource - and it needs to.

view this post on Zulip Grahame Grieve (Sep 18 2019 at 20:44):

looks like another technical correction

view this post on Zulip Chris Moesel (Sep 18 2019 at 20:45):

Yep. So the constraint needs to check for references that are # and are in the contained resources.
Maybe something more like this?

reference.startsWith('#').not()
  or (reference.substring(1).trace('url') in %resource.contained.id.trace('ids'))
  or (reference = '#' and $this in %resource.contained.descendants())

I'm not sure if that's the right / best way to check if the reference is in the contained resources of the container. Another possible approach might be checking the path of reference.elementDefinition(). I don't have a FHIRPath parser on hand that knows how to do %resource or elementDefintion(), so I can't test this constraint.

view this post on Zulip Grahame Grieve (Sep 18 2019 at 20:45):

something like that, yes. I'd also have to test

view this post on Zulip Preston TW (Sep 30 2019 at 19:24):

@Chris Moesel @Grahame Grieve quick followup, why do you need the descendants()? Can you just have ... or (reference = '#' and $this in %resource.contained)? From https://www.hl7.org/fhir/references.html#contained: "Contained resources SHALL NOT contain additional contained resources."

view this post on Zulip Chris Moesel (Sep 30 2019 at 20:02):

@Preston TW -- IIRC, this is a constraint on the Reference data type, so $this refers to an instance of a Reference. In your concrete example further up the thread, Reference's $this would refer to the part inside the <target> tags. That being the case, the Reference instance is not an item directly in contained -- it's nested within the contained object. That's why I used descendants() -- because we don't know exactly where it should be in a contained resource (depends on the resource) -- but we know it should be a descendant node of one of the contained resources.


Last updated: Apr 12 2022 at 19:14 UTC