FHIR Chat · transaction bundle example? · shorthand

Stream: shorthand

Topic: transaction bundle example?


view this post on Zulip Bob Milius (Apr 05 2020 at 21:44):

Can someone provide an example of creating a transaction bundle example using other existing examples? How are fullUrls handled in examples referencing other examples? The standalone examples created by sushi have an id but resources in a transaction bundle would not, correct?

view this post on Zulip Chris Moesel (Apr 06 2020 at 13:35):

Hi @ Bob Milius -- those are some great questions. SUSHI does not populate fullUrl in bundles for you. I think that would be difficult without knowing the base FHIR URL you want to post to -- so you'd need to set that yourself.

As for including or not including the id... currently SUSHI always includes the id if you are referencing an existing instance. From a strict perspective of the spec, this is actually ok for create since it states:

The resource does not need to have an id element (this is one of the few cases where a resource exists without an id element). If an id is provided, the server SHALL ignore it.

But I can see why maybe you wouldn't want the id to show up in an example (since it's not necessary and is ignored). In the case of a transaction, however, having the id can be helpful as it allows you to specify relationships between resources -- and if the server creates a new id, it will update all references based on the old id.

I think we'd need to think about how to handle something like suppressing the id in an inlined resource... Open to suggestions.

view this post on Zulip Bob Milius (Apr 06 2020 at 13:42):

thanks, @Chris Moesel . Actually what I'd like is for the fullUrl for one resource to populate the reference in another (eg DiagnosticReport.results --> fullUrl of Observation) . Would there be a were a way to do this in the standalone examples? e.g., have the example DiagnosticReport.result point to an existing example Observation.id, then when creating the bundle example, perhaps substitute them for fullUrls? Hope that make sense.

view this post on Zulip Chris Moesel (Apr 06 2020 at 14:38):

Ah. I see. That's a bit trickier. Right now, I think it would use relative URLs in the reference (e.g., Observation/12345), right? And you want that to use full URLs instead? Hmm... you would still need to somehow tell it what the base FHIR URL should be (e.g., what to put _before_ Observation/12345) -- but assuming you want to do this to show support for resources on other servers (because relative URL would be fine otherwise), then I also assume that not every reference should use the same base URL. I have an idea, although I'm not positive that it would work. @Nick Freiter -- I think you implemented the contained resources. Would something like this work?

view this post on Zulip Chris Moesel (Apr 06 2020 at 14:38):

(Oops. Didn't mean to submit. Stand by...)

view this post on Zulip Chris Moesel (Apr 06 2020 at 14:45):

Instance: MyDiagnosticReport
InstanceOf: DiagnosticReport
Id: my-diagnostic-report
// ... stuff
* result[0] = Reference(MyObservation)

Instance: MyObservation
InstanceOf: Observation
Id: my-observation
// ... stuff

Instance: MyBundle
InstanceOf: Bundle
// ... stuff
* entry[0].fullUrl = "http://someserver.com/fhir/DiagnosticReport/my-diagnostic-report"
* entry[0].resource = MyDiagnosticReport
// and here's the questionable part, overriding a value in the contained resource
* entry[0].resource.result[0].reference = "http://someotherserver.com/fhir/Observation/my-observation"
* entry[1].fullUrl = "http://someotherserver.com/fhir/Observation/my-observation"
* entry[1].resource = MyObservation

What do you think @Nick Freiter ?

view this post on Zulip Nick Freiter (Apr 06 2020 at 14:58):

When you say "would something like this work", do you mean work currently? Because if that's the question no this couldn't currently work.

view this post on Zulip Nick Freiter (Apr 06 2020 at 15:01):

I think the only way to do this right now would be to make two different DiagnosticReport's, one specifically for use in the Bundle, that has a different DiagnosticReport.results. If you were going to do it this way, this may be a good place to use a RuleSet, since the rules for both DiagnosticReports may be identical outside of the the DiagnosticReport.results.

view this post on Zulip Bob Milius (Apr 06 2020 at 15:34):

fyi, before I stared using sushi I was using a urn:uuid:xxxx as a fullUrl and reference in my transaction bundle examples. I once tried creating local references in my standalone resource examples, but got errors in the publisher for them not existing, so then started using http://example.org/fhir/blah for those standalone examples. This got past the publisher but of course they didn't actually exist.

view this post on Zulip Bob Milius (May 18 2020 at 22:14):

I've been able to an example transaction bundle using inline instances. As I said above, I like to use urn:uuid:xxxx as a fullUrl, and this works okay. But the resulting bundle entries each contains an Id. Have you found a way to suppress that (you discussed it above)? I'm thinking the transaction bundle when posted to a FHIR server will create individual Ids as they are processed, so presumably, they wouldn't have Ids to begin with (or at least ignore them). Would it be possible to create an alias/macro that generates a uuid and saves it with an alias/variable that gets reused? Or should I just stop using uuids? I'd like to have examples that folks can POST to FHIR server to try out. Here's a snippet of bundle that currently gets created.

"entry" : [
    {
      "fullUrl" : "urn:uuid:1fb210d2-fa8c-404f-a2c3-1847e97737df",
      "resource" : {
        "resourceType" : "Observation",
        "id" : "MyObservation1",
...snip...
        "derivedFrom" : [
          {
            "reference" : "urn:uuid:5fc06349-9571-4baf-88c2-8da41d215b90"
          }
        ],
...snip...
      },
      "request" : {
        "method" : "POST",
        "url" : "Observation"
      }
    },
    {
      "fullUrl" : "urn:uuid:5fc06349-9571-4baf-88c2-8da41d215b90",
      "resource" : {
        "resourceType" : "Observation",
        "id" : "MyObservation2",
...snip...

view this post on Zulip Nick Freiter (May 19 2020 at 12:06):

If you don't want the id field to be added to a contained instance, you have to define the contained instance entirely inline on the other instance. As an example see the following:

Instance: BundleInstance
InstanceOf: Bundle
* type = #transaction
// entry[0] is defined fully inline
* entry[0].fullUrl = "urn:uuid:1fb210d2-fa8c-404f-a2c3-1847e97737df"
* entry[0].resource.resourceType = "Observation"
* entry[0].resource.valueString = "A fully inline observation"
// entry[1] references an instance defined elsewhere
* entry[1].fullUrl = "urn:uuid:5fc06349-9571-4baf-88c2-8da41d215b90"
* entry[1].resource = ObservationInstance

Instance: ObservationInstance
InstanceOf: Observation
* valueString = "A non-inline observation"

Since entry[1] references ObservationInstance, in the process of generating ObservationInstance, SUSHI will add an id to ObservationInstance. But in the case of entry[0], there is no external definition for the resource you are defining at entry[0].resource, you can define that resource entirely from within BundleInstance. In this case, you have full control, if you don't add an entry[0].resource.id, then no id will exist on this resource. Here is the output from the SUSHI posted above:

{
  "resourceType": "Bundle",
  "id": "BundleInstance",
  "type": "transaction",
  "entry": [
    {
      "fullUrl": "urn:uuid:1fb210d2-fa8c-404f-a2c3-1847e97737df",
      "resource": {
        "resourceType": "Observation",
        "valueString": "A fully inline observation"
      }
    },
    {
      "fullUrl": "urn:uuid:5fc06349-9571-4baf-88c2-8da41d215b90",
      "resource": {
        "resourceType": "Observation",
        "id": "ObservationInstance",
        "valueString": "A non-inline observation"
      }
    }
  ]
}

As you can see, the resource in entry[0] does not have an id.


Last updated: Apr 12 2022 at 19:14 UTC