fhir_client 3.0.5 → 3.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.rubocop.yml +4 -0
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/lib/fhir_client/client.rb +37 -22
- data/lib/fhir_client/ext/model.rb +5 -1
- data/lib/fhir_client/ext/reference.rb +20 -1
- data/lib/fhir_client/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b3ea696abc5f4af913b2cd11a96299090f49fcd5859e53631bff94e48e68a665
|
4
|
+
data.tar.gz: 0e3b5a443b3f71bd73c0183f964a832b6eabe67e6e4b2e2b961087cefd320dee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2099e5b55c14de2726db9cac85f042f1974d51f6621fdd3589c6c25e52d4f6a05f2a375dde770b60b1aa8b0cf783e714714fb989901ff2e3c4e1314e43aa0312
|
7
|
+
data.tar.gz: 9ad4e0543eda624b54653aa6ac7cfa9bb4371426757af02a1df4012e1b33cc80083d74940f4758f333d5f158588ee1fa1a3663a06e0339109014109c55f57f5f
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -175,7 +175,7 @@ options = client.get_oauth2_metadata_from_conformance
|
|
175
175
|
if options.empty?
|
176
176
|
puts 'This server does not support the expected OAuth2 extensions.'
|
177
177
|
else
|
178
|
-
client.set_oauth2_auth(client_id,client_secret,options[:
|
178
|
+
client.set_oauth2_auth(client_id, client_secret, options[:authorize_url] ,options[:token_url], options[:site])
|
179
179
|
reply = client.read_feed(FHIR::Patient)
|
180
180
|
puts reply.body
|
181
181
|
end
|
data/lib/fhir_client/client.rb
CHANGED
@@ -2,7 +2,6 @@ require 'rest_client'
|
|
2
2
|
require 'nokogiri'
|
3
3
|
require 'addressable/uri'
|
4
4
|
require 'oauth2'
|
5
|
-
|
6
5
|
module FHIR
|
7
6
|
class Client
|
8
7
|
include FHIR::Sections::History
|
@@ -23,6 +22,7 @@ module FHIR
|
|
23
22
|
attr_accessor :default_format
|
24
23
|
attr_accessor :fhir_version
|
25
24
|
attr_accessor :cached_capability_statement
|
25
|
+
attr_accessor :additional_headers
|
26
26
|
|
27
27
|
# Call method to initialize FHIR client. This method must be invoked
|
28
28
|
# with a valid base server URL prior to using the client.
|
@@ -130,13 +130,13 @@ module FHIR
|
|
130
130
|
# secret -- client secret
|
131
131
|
# authorize_path -- absolute path of authorization endpoint
|
132
132
|
# token_path -- absolute path of token endpoint
|
133
|
-
def set_oauth2_auth(client, secret, authorize_path, token_path)
|
133
|
+
def set_oauth2_auth(client, secret, authorize_path, token_path, site = nil)
|
134
134
|
FHIR.logger.info 'Configuring the client to use OpenID Connect OAuth2 authentication.'
|
135
135
|
@use_oauth2_auth = true
|
136
136
|
@use_basic_auth = false
|
137
137
|
@security_headers = {}
|
138
138
|
options = {
|
139
|
-
site: @base_service_url,
|
139
|
+
site: site || @base_service_url,
|
140
140
|
authorize_url: authorize_path,
|
141
141
|
token_url: token_path,
|
142
142
|
raise_errors: true
|
@@ -172,32 +172,22 @@ module FHIR
|
|
172
172
|
# </service>
|
173
173
|
# <description value="SMART on FHIR uses OAuth2 for authorization"/>
|
174
174
|
# </security>
|
175
|
-
def get_oauth2_metadata_from_conformance
|
175
|
+
def get_oauth2_metadata_from_conformance(strict=true)
|
176
176
|
options = {
|
177
177
|
authorize_url: nil,
|
178
178
|
token_url: nil
|
179
179
|
}
|
180
|
-
oauth_extension = 'http://fhir-registry.smarthealthit.org/StructureDefinition/oauth-uris'
|
181
|
-
authorize_extension = 'authorize'
|
182
|
-
token_extension = 'token'
|
183
180
|
begin
|
184
181
|
capability_statement.rest.each do |rest|
|
185
|
-
|
186
|
-
service.
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
when authorize_extension
|
191
|
-
options[:authorize_url] = ext.value
|
192
|
-
when "#{oauth_extension}\##{authorize_extension}"
|
193
|
-
options[:authorize_url] = ext.value
|
194
|
-
when token_extension
|
195
|
-
options[:token_url] = ext.value
|
196
|
-
when "#{oauth_extension}\##{token_extension}"
|
197
|
-
options[:token_url] = ext.value
|
198
|
-
end
|
182
|
+
if strict
|
183
|
+
rest.security.service.each do |service|
|
184
|
+
service.coding.each do |coding|
|
185
|
+
next unless coding.code == 'SMART-on-FHIR'
|
186
|
+
options.merge! get_oauth2_metadata_from_service_definition(rest)
|
199
187
|
end
|
200
188
|
end
|
189
|
+
else
|
190
|
+
options.merge! get_oauth2_metadata_from_service_definition(rest)
|
201
191
|
end
|
202
192
|
end
|
203
193
|
rescue => e
|
@@ -208,6 +198,29 @@ module FHIR
|
|
208
198
|
options
|
209
199
|
end
|
210
200
|
|
201
|
+
def get_oauth2_metadata_from_service_definition(rest)
|
202
|
+
oauth_extension = 'http://fhir-registry.smarthealthit.org/StructureDefinition/oauth-uris'
|
203
|
+
authorize_extension = 'authorize'
|
204
|
+
token_extension = 'token'
|
205
|
+
options = {
|
206
|
+
authorize_url: nil,
|
207
|
+
token_url: nil
|
208
|
+
}
|
209
|
+
rest.security.extension.find{|x| x.url == oauth_extension}.extension.each do |ext|
|
210
|
+
case ext.url
|
211
|
+
when authorize_extension
|
212
|
+
options[:authorize_url] = ext.value
|
213
|
+
when "#{oauth_extension}\##{authorize_extension}"
|
214
|
+
options[:authorize_url] = ext.value
|
215
|
+
when token_extension
|
216
|
+
options[:token_url] = ext.value
|
217
|
+
when "#{oauth_extension}\##{token_extension}"
|
218
|
+
options[:token_url] = ext.value
|
219
|
+
end
|
220
|
+
end
|
221
|
+
options
|
222
|
+
end
|
223
|
+
|
211
224
|
# Method returns a capability statement for the system queried.
|
212
225
|
def capability_statement(format = @default_format)
|
213
226
|
conformance_statement(format)
|
@@ -267,6 +280,8 @@ module FHIR
|
|
267
280
|
end
|
268
281
|
|
269
282
|
def fhir_headers(options = {})
|
283
|
+
options.merge!(additional_headers) unless additional_headers.nil?
|
284
|
+
|
270
285
|
FHIR::ResourceAddress.new.fhir_headers(options, @use_format_param)
|
271
286
|
end
|
272
287
|
|
@@ -685,7 +700,7 @@ module FHIR
|
|
685
700
|
end
|
686
701
|
|
687
702
|
def build_url(path)
|
688
|
-
if
|
703
|
+
if /^\w+:\/\//.match? path
|
689
704
|
path
|
690
705
|
else
|
691
706
|
"#{base_path(path)}#{path}"
|
@@ -56,7 +56,7 @@ module FHIR
|
|
56
56
|
end
|
57
57
|
|
58
58
|
module ClassMethods
|
59
|
-
|
59
|
+
|
60
60
|
def client
|
61
61
|
FHIR::Model.client
|
62
62
|
end
|
@@ -107,6 +107,10 @@ module FHIR
|
|
107
107
|
handle_response client.conditional_create(model, params)
|
108
108
|
end
|
109
109
|
|
110
|
+
def partial_update(id, patchset, options = {})
|
111
|
+
handle_response client.partial_update(self, id, patchset, options)
|
112
|
+
end
|
113
|
+
|
110
114
|
def all(client = self.client)
|
111
115
|
handle_response client.read_feed(self)
|
112
116
|
end
|
@@ -4,9 +4,15 @@ module FHIR
|
|
4
4
|
reference.to_s.start_with?('#')
|
5
5
|
end
|
6
6
|
|
7
|
+
def has_version?
|
8
|
+
/history/.match reference.to_s
|
9
|
+
end
|
10
|
+
|
7
11
|
def reference_id
|
8
12
|
if contained?
|
9
13
|
reference.to_s[1..-1]
|
14
|
+
elsif has_version?
|
15
|
+
reference.to_s.split('/').second
|
10
16
|
else
|
11
17
|
reference.to_s.split('/').last
|
12
18
|
end
|
@@ -16,11 +22,24 @@ module FHIR
|
|
16
22
|
reference.to_s.split('/').first unless contained?
|
17
23
|
end
|
18
24
|
|
25
|
+
def version_id
|
26
|
+
if has_version?
|
27
|
+
reference.to_s.split('/').last
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
19
31
|
def read
|
20
32
|
return if contained? || type.blank? || (id.blank? && reference.blank?)
|
21
33
|
rid = id || reference_id
|
22
34
|
resource_class.read(rid, client)
|
23
35
|
end
|
36
|
+
|
37
|
+
def vread
|
38
|
+
return if contained? || type.blank? || (id.blank? && reference.blank?) || version_id.blank?
|
39
|
+
rid = id || reference_id
|
40
|
+
resource_class.vread(rid, version_id, client)
|
41
|
+
end
|
42
|
+
|
24
43
|
end
|
25
44
|
end
|
26
45
|
|
@@ -38,7 +57,7 @@ module FHIR
|
|
38
57
|
module DSTU2
|
39
58
|
class Reference
|
40
59
|
include FHIR::ReferenceExtras
|
41
|
-
|
60
|
+
|
42
61
|
def resource_class
|
43
62
|
"FHIR::DSTU2::#{type}".constantize unless contained?
|
44
63
|
end
|
data/lib/fhir_client/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fhir_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andre Quina
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2018-
|
13
|
+
date: 2018-09-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -284,7 +284,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
284
284
|
version: '0'
|
285
285
|
requirements: []
|
286
286
|
rubyforge_project:
|
287
|
-
rubygems_version: 2.
|
287
|
+
rubygems_version: 2.7.7
|
288
288
|
signing_key:
|
289
289
|
specification_version: 4
|
290
290
|
summary: A Gem for handling FHIR client requests in ruby
|