1

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.

Kathi U.
  • 11
  • 3

3 Answers3

0

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.

Vadim Peretokin
  • 2,221
  • 3
  • 29
  • 40
0

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.)

Lloyd McKenzie
  • 6,345
  • 1
  • 13
  • 10
0

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

bogdan ioan
  • 378
  • 3
  • 7