Kathi U.
Kathi U.

Reputation: 11

How to get a sorted/nested FHIR Bundle-Response?

I am really new to fhir and i am wondering if it is possible to do an api call for a Bundle so that the response is more sorted/nested? So my request should be something like "give me all encounters for that organization with the associated patient":

[Base]/Encounter?service-provider=Organization/<id>&_include=Encounter:subject

Actually the response is a bundle like this (abbreviated version):

{
  "resourceType": "Bundle",
  "entry": [
    {
      "resource": {
        "resourceType": "Encounter",
      }
    },
    {
      "resource": {
        "resourceType": "Encounter",
      }
    },
    {
      "resource": {
        "resourceType": "Patient",
      }
    },
    {
      "resource": {
        "resourceType": "Patient",
      }
    }
  ],
  [...]
}

But I want something like that, a more nested object where i don´t need to sort the patients to the encounters:

{
  "resourceType": "Bundle",
  "entry": [
    {
      "resource": {
        "resourceType": "Encounter",
        "subject": {
            "resource": {
               "resourceType": "Patient",
             }
         }
    },
    {
      "resource": {
        "resourceType": "Encounter",
        "subject": {
            "resource": {
               "resourceType": "Patient",
             }
         }
    },
  ],
  [...]
}

Is there a way to do this? Or do I need to use something like fhirpath for sorting the result? I need a solution for client side, because there will be different fhir-servers using my app.

Upvotes: 1

Views: 1083

Answers (3)

bogdan ioan
bogdan ioan

Reputation: 458

It is, but not on your provided URI. You can implement a custom FHIR operation which will do whatever you need. Check this link https://www.hl7.org/fhir/operations.html#extensibility

Upvotes: 0

Lloyd McKenzie
Lloyd McKenzie

Reputation: 6803

FHIR doesn't allow nesting of resources because there's no implicit hierarchy in FHIR. When extensions are taken into account, it's possible for a single resource to be associated with multiple patients, multiple encounters, etc. (possibly using different relationships). So any hierarchy/network needs to be re-established in memory by traversing the relationships present in the resources found in the Bundle.

Sorting is possible though - there's an _sort search parameter that can be used when looking at search sets. Details can be found here. (In other types of Bundles - e.g. documents, batches, transactions, etc. order is generally meaningless and can't be controlled with the exception that documents and messages always start with a special resource - Composition and MessageHeader, respectively.)

Upvotes: 0

Vadim Peretokin
Vadim Peretokin

Reputation: 2846

It's not possible to ask the server to embed the resources in the way you describe here. Using the result you're already getting is the way to go.

Upvotes: 0

Related Questions