FHIR Chat · posting transaction bundles · python

Stream: python

Topic: posting transaction bundles


view this post on Zulip Bob Milius (Jul 23 2018 at 16:30):

How do I post a transaction bundle in python?

settings = {
    'app_id': 'my_web_app',
    'api_base': 'http://fhirtest.b12x.org/r3'
}
smart = client.FHIRClient(settings=settings)
response = bundle.create(smart.server)

will POST to the bundle endpoint, but not to the base url where it needs to go for transactions to be processed.

view this post on Zulip Bob Milius (Jul 23 2018 at 16:32):

requests.exceptions.HTTPError: 422 Client Error: Unprocessable Entity for url: http://fhirtest.b12x.org/r3/Bundle

view this post on Zulip Pascal Pfiffner (Jul 23 2018 at 17:27):

Indeed, create always posts to base_url + resource_type, you'll need to do that manually. Look at def create(...) in fhirabstractresource.py (9 lines of code, around line 114) and create a method that does the same, expect using None instead of self.relativeBase() in the post_json call.

view this post on Zulip Pascal Pfiffner (Jul 23 2018 at 17:27):

*except

view this post on Zulip Bob Milius (Jul 23 2018 at 17:49):

Thanks! @Pascal Pfiffner

view this post on Zulip Mike Halagan (Jul 23 2018 at 18:29):

If we created a new method, say "create_bundle", then it would be accessible to all resource models even though it should only be used with a bundle resource. Does checking to see if it's a Bundle transaction make sense instead of creating a new method? Adding the following lines of code to the create method works.

    base_url = self.relativeBase()
    if(self.resource_type == "Bundle"
       and self.type == "transaction"):
        base_url = None

view this post on Zulip Bob Milius (Jul 23 2018 at 18:56):

should also test for self.type == "batch" which should also be processed


Last updated: Apr 12 2022 at 19:14 UTC