Batch/Transaction handling

940 views
Skip to first unread message

David Kincaid

unread,
Apr 14, 2016, 1:59:46 PM4/14/16
to HAPI FHIR
I am just not getting something here about how to implement a method to process batch or transaction request using HAPI-FHIR. According to the spec (https://www.hl7.org/fhir/http.html#transaction) I should be able to POST to the base url of my server with a Bundle in the body. The HAPI-FHIR documentation at http://jamesagnew.github.io/hapi-fhir/doc_rest_operations.html#System_Level_-_Transaction tells me to put a @Transaction annotation on a method and that method will be used. I don't see how to let the FHIR servlet know which method that is. Just putting it on some method in some new class in the classpath isn't working. I'm getting an error when I call my url stating "This is the basic URL of FHIR server. Unable to handle this request, as it does not contain a resource type or operation name.

So the question is where does the @Transaction annotation go so that the server is able to handle the batch POST request at the base url (e.g. http://my.url.com/fhir/v2/)?

Thanks,

Dave

David Kincaid

unread,
Apr 14, 2016, 2:56:00 PM4/14/16
to HAPI FHIR
Getting a little bit farther. I figured out to put the @Transaction method in a basic Java class and then add an instance of that class to the fhir service with setPlainProviders(). Now the problem I'm having is that I'm getting an error back from the server that "java.util.ArrayList cannot be cast to ca.uhn.fhir.rest.server.IBundleProvider" when I try to submit a batch to the server. Is the return type of that @Transaction method really supposed to be List<IResource>? That's what I'm returning and get this error.

Thanks,

Dave

Rick Riemer

unread,
Apr 14, 2016, 4:16:24 PM4/14/16
to David Kincaid, HAPI FHIR
Hi David,

We're using it like this:

@Transaction
public Bundle provideBundle(@TransactionParam Bundle bundle) {
   ...
}



Rick Riemer

Senior Software Engineer


p  +31 30 699 19 30

e  rick....@forcare.com

w www.forcare.com

forcare-logo.png



--
You received this message because you are subscribed to the Google Groups "HAPI FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hapi-fhir+...@googlegroups.com.
To post to this group, send email to hapi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/779de65a-b99b-4c0e-bffc-a72ff318c596%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


Join us at the Apps for Health Conference April 28th at Mohawk College in Hamilton Ontario.

David Kincaid

unread,
Apr 14, 2016, 4:21:08 PM4/14/16
to HAPI FHIR, kincai...@gmail.com
Thanks, Rick. So it does have to return a Bundle. Is that a defect or is it supposed to work that way? The docs on the website clearly say that the method should return List<IResource>.


- Dave

David Kincaid

unread,
Apr 14, 2016, 4:26:06 PM4/14/16
to HAPI FHIR, kincai...@gmail.com
One other question on this. Have you figured out a way to dispatch each request inside the bundle to the server easily?


On Thursday, April 14, 2016 at 3:16:24 PM UTC-5, Rick Riemer wrote:

Rick Riemer

unread,
Apr 15, 2016, 3:01:12 AM4/15/16
to David Kincaid, HAPI FHIR
Not sure what the HAPI documentation says, but the FHIR spec says that a transaction bundle should be responded to by a transaction-response bundle: https://www.hl7.org/fhir/bundle.html#transaction. And the way we've coded it seems to work.

No, I have not looked at how to individually process the transaction requests. In our use case we are just processing each request on our own. Sorry, no help there.


Rick Riemer

Senior Software Engineer


p  +31 30 699 19 30

e  rick....@forcare.com

w www.forcare.com

forcare-logo.png




For more options, visit https://groups.google.com/d/optout.

James Agnew

unread,
Apr 17, 2016, 8:04:55 PM4/17/16
to Rick Riemer, David Kincaid, HAPI FHIR
Hi All,

A couple of points- First, I think the HAPI documentation needs to be updated for transaction after looking at it. It suggests using List<IResource> as the input and output types, but as Rick points out it is possible to use Bundle. Back when we wrote the documentation, transaction was a lot simpler (according to FHIR's definitions) and using a list of resources was a reasonable thing to do but these days I don't think it's realistic to do it without manipulating the bundle itself.

In terms of actually implementing the method, unfortunately there is only so much help HAPI will give you. I suppose one might expect it to delegate the individual operations in the transaction to other methods on the server but.. well, it does not do that. There is a lot that transaction needs to handle (making everything atomic, replacing placeholder IDs across multiple resources which may even be circular, handling operations in the right order) and I don't think it's feasible for the framework to do this in a generic way.

For what it's worth, you could look at our JPA module's "transaction" method: https://github.com/jamesagnew/hapi-fhir/blob/master/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu2.java

As you can see, there is a lot going on in there.... I am definitely open to suggestions on how we could make it easier to implement transactions using the framework on non-HAPI-JPA server implementations. So far nothing obvious has leapt out at me though.

Cheers,
James

David Kincaid

unread,
Apr 17, 2016, 9:08:42 PM4/17/16
to HAPI FHIR, rick....@forcare.com, kincai...@gmail.com
Thanks for the reply, James. I think you're right that there is just too much that could go on in the transaction/batch to have the framework handle it automatically. In the use cases that we are thinking about I think I really just need to know how to call back into the servlet. For example, if one resource in the batch is a GET for Patient/1234 it seems like the easiest thing would be for my batch handler to somehow call the Patient resource provider with all the right parameters set, etc and put the result into the Bundle response. I haven't been able to figure out how to do that yet.
Reply all
Reply to author
Forward
0 new messages