Stream: hapi
Topic: Storing multiple resources at once using Bundle
Pelle Wielinga (Dec 09 2019 at 14:54):
I'm having some trouble trying to store multiple resources in a single request. If I understand correctly the best way to do this would be using a batch or transaction. Here is some Kotlin code I've been trying with Hapi (both server and client at version 3.8.0).
val bundle = Bundle() bundle.type = Bundle.BundleType.BATCH conditions.forEach { condition -> bundle.addEntry() .setResource(condition) .request .setUrl("Condition") .setMethod(Bundle.HTTPVerb.POST) } client.transaction().withBundle(bundle).execute()
Unfortunately the server is giving me the following error:
HTTP 400 : This is the base URL of FHIR server. Unable to handle this request, as it does not contain a resource type or operation name.
I've tried with Bundle.BundleType.TRANSACTION
and with client.transaction().withResources(conditions).execute()
as well but both give the same error.
If I don't use my own Hapi server but the one on https://fhirtest.uhn.ca/
it does seem to work. Here I've pasted the generated XML in the "transaction" box on the home page. Is there something I need to configure on my Hapi server to make this work?
Patrick Werner (Dec 09 2019 at 15:07):
you have to use a transaction bundle and send it against the base url of the FHIR server.
Patrick Werner (Dec 09 2019 at 15:09):
client.transaction().withBundle(bundle).execute()
would be the correct one for sending a transaction bundle to the server.
Pelle Wielinga (Dec 09 2019 at 15:20):
Well, this is what I'm doing. This is what I am doing to create the client:
val context = FhirContext.forR4().restfulClientFactory val tokenInterceptor = BearerTokenAuthInterceptor(token) client = context.newGenericClient("http://localhost:8080/fhir") client.registerInterceptor(tokenInterceptor)
I can see a request to http://localhost:8080/fhir
with the bundle as an xml body.
Last updated: Apr 12 2022 at 19:14 UTC