Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing conditions in parse_reply method #127

Open
rouaneta opened this issue Dec 5, 2019 · 2 comments
Open

Confusing conditions in parse_reply method #127

rouaneta opened this issue Dec 5, 2019 · 2 comments

Comments

@rouaneta
Copy link

rouaneta commented Dec 5, 2019

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
Copy link
Member

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
Copy link
Author

rouaneta commented Dec 6, 2019

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:

res = if(@fhir_version == :dstu2 || klass&.ancestors&.include?(FHIR::DSTU2::Model))
if(format.include?('xml'))
FHIR::DSTU2::Xml.from_xml(response.body)
else
FHIR::DSTU2::Json.from_json(response.body)
end
elsif(@fhir_version == :r4 || klass&.ancestors&.include?(FHIR::Model))
if(format.include?('xml'))
FHIR::Xml.from_xml(response.body)
else
FHIR::Json.from_json(response.body)
end
else
if(format.include?('xml'))
FHIR::STU3::Xml.from_xml(response.body)
else
FHIR::STU3::Json.from_json(response.body)
end
end

It appears that the behaviour is as follows (assuming that the format is xml - same behaviour for json):

  • case (i) if the client version is dstu2 I would go through FHIR::DSTU2::Xml.from_xml anyway
  • case (ii) if the client version is r4 I would go through FHIR::Xml.from_xml , except if I explicitly call FHIR::DSTU2::...Read, in which case I would go through FHIR::DSTU2::Xml.from_xml
  • case (iii) if the client version is stu3 it depends only on the module I call the read method on:
    FHIR::DSTU2::...Read -> FHIR::DSTU2::Xml.from_xml
    FHIR::...Read -> FHIR::Xml.from_xml
    FHIR::STU3::...Read -> FHIR::STU3::Xml.from_xml

In other words:

  • case (i) The client version takes precedence over the module called
  • case (ii) No clear priority between the client version and the module called
  • case (iii) The module takes precedence over the client version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants