fhir-crucible / fhir_client

Ruby FHIR Client
Apache License 2.0
164 stars 61 forks source link

Confusing conditions in `parse_reply` method #127

Open rouaneta opened 4 years ago

rouaneta commented 4 years ago

I am having troubles reading the CommunicationRequest.requester.agent (please find an example of payload here).

Our client uses the STU3 version. We call the method use_stu3 on our client. We usually read CommunicationRequest using the syntax FHIR::CommunicationRequest.read("123456"). I realized that to be able to read the attribute requester.agent, I had to use the syntax FHIR::STU3::Communication.read("123456").

Should the method used to parse the fhir payload not be based on the fhir_version of the client in priority ? So that I can call FHIR::CommunicationRequest.read("123456") and the resource will be read correctly according to the client version.

jawalonoski commented 4 years ago

The issue is that the FHIR:: module contains R4 resources only, and the FHIR::STU3:: module contains STU3 resources only, and the FHIR::DSTU2:: module contains DSTU2 resources only.

The client can parse different FHIR versions, but it does not monkey-patch any of the FHIR modules.

So, when you explicitly call FHIR::CommunicationRequest... you are explicitly saying "use R4 CommunicationRequest."

Apologies if this was not obvious or a point of confusion. We hope to improve the documentation and examples for this gem in the future. This should be a topic we cover.

rouaneta commented 4 years ago

Thanks @jawalonoski for the quick reply. The problem is that the behaviour is not the same for each client version. If we look more closely to the parse_reply method: https://github.com/fhir-crucible/fhir_client/blob/59ccd55c4130c821d7ace4e992296850fc9e6291/lib/fhir_client/client.rb#L320-L338 It appears that the behaviour is as follows (assuming that the format is xml - same behaviour for json):

In other words: