FHIR Chat · Collection Bundle resource POST and GET · hapi

Stream: hapi

Topic: Collection Bundle resource POST and GET


view this post on Zulip Lauri Karppinen (May 16 2019 at 07:27):

Hi! I hope this is right stream to ask this. I made a short example to present my problem. I've been testing POSTing collection bundle to FHIR test server (http://hapi.fhir.org/baseDstu3). I am able to POST/PUT my example containing Patient, Practitioner and Observation. I can GET the same bundle with id back as a bundle. I have been assuming that each resource are created to server as separated resources as well? Now if I would like to get only the patient separately from bundle it would be possible? What I have tried to do is:
1. PUT http://hapi.fhir.org/baseDstu3/Bundle/93a1e2ba-0c87-1000-b622-915900009d40, (where id = id in bundle resource) This works (201 Created)
2. GET http://hapi.fhir.org/baseDstu3/Bundle/93a1e2ba-0c87-1000-b622-915900009d40, This works (200 OK)
3. GET http://hapi.fhir.org/baseDstu3/Patient/93a14fea-0c87-1000-b132-4d4c00009619
4. GET http://hapi.fhir.org/baseDstu3/Practitioner/c04d8694-0c17-435c-ab0c-28dce1c9832c
5. GET http://hapi.fhir.org/baseDstu3/Observation/93a1e2ae-0c87-1000-b3a6-db1200003c15
What I need to add to bundle to actually create all the resources separately in the server?

Example:
`
{
"entry": [
{
"resource":
{
"birthDate": "2005-01-02",
"gender": "female",
"id": "93a14fea-0c87-1000-b132-4d4c00009619",
"name": [
{
"family": "BundleTest",
"given": [
"BundleDude",
"Seppo"
]
}
],
"resourceType": "Patient",
"text": {
"div": "<div xmlns='http://www.w3.org/1999/xhtml'>Patient<a name='mm'/></div>",
"status": "generated"
}
}

    },
    {
        "resource": {
            "id": "c04d8694-0c17-435c-ab0c-28dce1c9832c",
            "name": [
                {
                    "family": "Testinen",
                    "given": [
                        "Hoitaja",
                        "Hanna"
                    ]
                }
            ],
            "resourceType": "Practitioner",
            "text": {
                "div": "&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;Practitioner&lt;a name='mm'/&gt;&lt;/div&gt;",
                "status": "generated"
            }
        }
    },
    {
        "resource": {
            "category": [
                {
                    "coding": [
                        {
                            "code": "vital-signs",
                            "system": "http://hl7.org/fhir/observation-category"
                        }
                    ]
                }
            ],
            "code": {
                "coding": [
                    {
                        "code": "8302-2",
                        "display": "Body height",
                        "system": "http://loinc.org"
                    }
                ]
            },
            "effectiveDateTime": "2019-05-06T12:02:34Z",
            "id": "93a1e2ae-0c87-1000-b3a6-db1200003c15",
            "issued": "2019-05-06T12:02:58Z",
            "language": "en",
            "meta": {
                "profile": [
                    "http://phr.kanta.fi/StructureDefinition/fiphr-bodyheight-stu3"
                ]
            },
            "performer": [
                {
                    "reference": "Practitioner/c04d8694-0c17-435c-ab0c-28dce1c9832c"
                }
            ],
            "resourceType": "Observation",
            "status": "final",
            "subject": {
                "reference": "Patient/93a14fea-0c87-1000-b132-4d4c00009619"
            },
            "text": {
                "div": "&lt;div xmlns='http://www.w3.org/1999/xhtml'&gt;Height&lt;a name='mm'/&gt;&lt;/div&gt;",
                "status": "generated"
            },
            "valueQuantity": {
                "code": "cm",
                "system": "http://unitsofmeasure.org",
                "unit": "cm",
                "value": 155
            }
        }
    }

],
"id": "93a1e2ba-0c87-1000-b622-915900009d40",
"resourceType": "Bundle",
"type": "collection"

}
`

view this post on Zulip James Agnew (May 16 2019 at 07:51):

This sounds to me like you're looking for the FHIR transaction operation. There are example Bundles here: http://hl7.org/fhir/http.html#transaction

You need to POST this to the root of the server and not the Bundle endpoint, e.g. http://hapi.fhir.org/baseDstu3

view this post on Zulip Lauri Karppinen (May 16 2019 at 09:51):

I added request elements like this in each resource and changed type to transaction.
"request": { "method": "PUT", "url": "Patient/93a14fea-0c87-1000-b132-4d4c00009619" }
and tried to POST it to http://hapi.fhir.org/baseDstu3 (deleted /Bundle)

Now I get error: "Transaction bundle entry has missing or invalid HTTP Verb specified in Bundle.entry(0).request.method. Found value: \"null\""

view this post on Zulip James Agnew (May 16 2019 at 10:07):

That error looks like you might be missing the Bundle.entry.request.method field on one of your entries. Can you confirm that you have it for all entries in the bundle?

It might be worth stripping your bundle down to 1 entry and then expanding from there if you get it working with 1...

view this post on Zulip Lauri Karppinen (May 16 2019 at 10:16):

{
    "entry": [
        {
            "resource":
            {
                "birthDate": "2005-01-02",
                "gender": "female",
                "id": "93a14fea-0c87-1000-b132-4d4c00009619",
                "name": [
                    {
                        "family": "BundleTest",
                        "given": [
                            "BundleDude",
                            "Seppo"
                        ]
                    }
                ],
                "resourceType": "Patient",
                "text": {
                    "div": "<div xmlns='http://www.w3.org/1999/xhtml'>Patient<a name='mm'/></div>",
                    "status": "generated"
                },
                "request": {
                    "method": "PUT",
                    "url": "Patient/93a14fea-0c87-1000-b132-4d4c00009619"
                  }
            }

        }

    ],
    "id": "93a1e2ba-0c87-1000-b622-915900009d40",
    "request": {
        "method": "POST",
        "url": "Bundle"
      },
    "resourceType": "Bundle",
    "type": "transaction"
}

This should work? Does bundle resource itself has to have method. POSTing this to http://hapi.fhir.org/baseDstu3 , still gives me the same error

view this post on Zulip James Agnew (May 16 2019 at 11:45):

I'm having trouble reading that because of the way it's formatted (you can put three ` characters around it to fix that) but it looks to me like you have two "request" blocks but one is at the root of the bundle, and one is at the root of the resource, and neither of those are valid spots for that.

The request element needs to be at the entry level.

view this post on Zulip Lauri Karppinen (May 16 2019 at 11:48):

Thanks a lot for the help @James Agnew . I just noticed my mistake! Got the test working now. For some reason only the part of the JSON goes inside code when I post my questions. Got the another advice as well. ``` Thanks :slight_smile:

view this post on Zulip James Agnew (May 16 2019 at 11:57):

woohoo!


Last updated: Apr 12 2022 at 19:14 UTC