Generic (Fluent) Client removes ids from Resources contained in the Bundle

120 views
Skip to first unread message

Robert Drewniak

unread,
Jan 15, 2021, 10:30:11 AM1/15/21
to HAPI FHIR

Hello.
I'm strugging with an issue of sending a POST with the Bundle in which entries contain resources with an id element.

I need to send this Bundle to a POST server endpoint  [serverBase]/Bundle.
The Bundle is type of message and server requirement is that each resource in the Bundle needs to contain an Id. Server does not support $process-message operation.

In order to do that I'm using Generic (Fluent) Client and it's create() method.
Code looks like that:
MethodOutcome methodOutcome = client.create().resource(bundle).encodedXml().execute();

The issue is that the hapi fhir client, before sending a request, removes resource ids in the bundle under the hood.
It happens because ca.uhn.fhir.rest.client.impl.GenericClient
.CreateInternal.execute method invokes MethodUtil.createCreateInvocation which sets myOmitResourceId property to true on HttpPostClientInvocation object.
Sending such Bundle to the server results in a 400 response from server, which in details contains a message that resources are missing id elements.

Is there a way of configuring this behaviour so that client will not do anything to the Bundle during serialization (will send it as is)??

James Agnew

unread,
Jan 15, 2021, 11:11:31 AM1/15/21
to Robert Drewniak, HAPI FHIR
The FHIR spec specifically says that the server is required (SHALL) to ignore any ID provided for a FHIR create/POST operation. 

What are you trying to accomplish? If you want to specify the ID to use for a new resource, that is an update/upsert/PUT ( http://hl7.org/fhir/http.html#upsert ) and the client will preserve the ID in that case.

Cheers,
James

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/hapi-fhir/51c326ba-355d-438f-a5ac-e21a11734f0an%40googlegroups.com.

Robert Drewniak

unread,
Jan 15, 2021, 11:20:44 AM1/15/21
to HAPI FHIR
Server implements a POST [serverBase]/Bundle endpoint. It requires ID of resources to be provided in the bundle, but hapi fhir generic client is removing them before sending a request.
So I have an issue with the client - not the server.

I cannot use update method as it uses PUT Http method and server does not support that.
I, as a client, need to send a POST with a bundle that contains resources with ID.
Not sure how to do that with hapi fhir generic client, so currently as a workaround I'm using vanilla Apache HttpClient API.

James Agnew

unread,
Jan 15, 2021, 11:42:30 AM1/15/21
to Robert Drewniak, HAPI FHIR
It may be worth pointing out to the author of this server that they are not conformant. The spec specifically says they have to ignore the ID if it's populated, so requiring it is incorrect.

I'd be willing to entertain a PR to make the ID stripping configurable, but HAPI FHIR's default behaviour should be to try and encourage the correct use which is why we filter that ID.

Cheers,
James

Bruno Medeiros

unread,
Jan 18, 2021, 8:49:01 AM1/18/21
to HAPI FHIR
Hi James, I'm working with Robert on this project.

I'm not so sure the behavior of this server is not conformant. The spec states that the id of the resource in the Create is to be ignored:

> The request body SHALL be a FHIR Resource. The resource does not need to have an id element (this is one of the few cases where a resource exists without an id element). If an id is provided, the server SHALL ignore it.  - http://hl7.org/fhir/http.html#create

however I think that only applies to the id of the top-level resource being created (which is actually a Bundle resource in this case). But the ids of of the resources included in the Bundle, I don't think they should be modified/removed - in a similar way to resources in `contained` field for other resource types.

One could argue that creating Bundle resources directly is a bit weird, and maybe the server API would be better designed be using batch/transaction operations instead - but we don't have control over that, and the way they are expecting it, is still conformant from what I understand.

James Agnew

unread,
Jan 18, 2021, 9:15:26 AM1/18/21
to Bruno Medeiros, HAPI FHIR
Ahh ok, that was a nuance I didn't catch in the original message.

I would agree that IDs in resources inside the Bundle should not be removed, so I'd agree this is a HAPI FHIR bug.


Cheers,
James

The content of this email is confidential and intended for the recipient specified in message only. You may not share any part of this message with any third party, without a written consent of the sender. If you received this message by mistake, please forward this message to postm...@babylonhealth.com to ensure the mistake does not occur in the future, and follow with its deletion. Check the email for threats with proper software, as we cannot accept liability for any damage caused by viewing the content of this email, despite our security efforts to ensure the message is error and virus-free. Any opinions expressed in this email are the author’s and don’t reflect our company as a whole. The contents of this email shall not imply entering into a legally binding contract. Babylon group of companies, including Babylon Healthcare Services Limited (No.9229684) and Babylon Partners Limited (No. 08493276) with registered address 60 Sloane Avenue, London SW3 3DD.

--
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.
Reply all
Reply to author
Forward
0 new messages