fhir_client 1.8.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1422a8f5a8fde728e4d0eff36ee916e27a5915c
4
- data.tar.gz: 50ad100815d6349da9acd460c1ed7996ac0945d2
3
+ metadata.gz: d67d432c6a1baf6217c47ecd7aca2c5e58cf43aa
4
+ data.tar.gz: e369651e25ebde3e51202a030efa05e460e855cd
5
5
  SHA512:
6
- metadata.gz: 2c023874bcbec48a8d01fb0ccf5fc0dabc968a949a3b89dd386d044bcf7c03693d69b7f80e5d74291b8cdd2436fa8e07450e07b4ef95e870a23df31a562f9c46
7
- data.tar.gz: 5ac8f2376cec84379adafe44f1a6eac60b57dec0650e3172ffd5b952053b439fa704ed6fffafce4d511e23efcefbf935260769fc210da02b8c3af4a7225bbda3
6
+ metadata.gz: aadd0e4070a562928dae58ef4061adf9b1c5de89b1f6be12f589422f410ec18587a8ddc1f1ce550d9e5f0aa984e1157513793d9c75237d2eb25285f610463405
7
+ data.tar.gz: b44369795be44588b0ef780047600d4561b002ec1ba5208896995f6ab2a103dcd0fa159f9a0f1c70920091d3348d10b7af0f280ef724e6d29990e9a7d240fcc3
@@ -1,10 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "2.0.0"
4
3
  - "2.1.10"
5
4
  - "2.2.5"
6
5
  - "2.3.1"
7
6
  before_install:
7
+ - gem update --system
8
8
  - gem install bundler
9
9
  services: mongodb
10
10
  script:
data/Gemfile CHANGED
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
2
2
  ruby RUBY_VERSION
3
3
 
4
4
  # gem 'fhir_models', :path => '../fhir_models'
5
+ # gem 'fhir_models', git: 'https://github.com/fhir-crucible/fhir_models.git', :branch => '3.0.0-release'
5
6
 
6
7
  gemspec
7
8
 
@@ -7,8 +7,8 @@ require 'fhir_client'
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
9
  # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
10
+ require 'pry'
11
+ Pry.start
12
12
 
13
- require 'irb'
14
- IRB.start
13
+ # require 'irb'
14
+ # IRB.start
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = 'fhir_client'
8
8
  spec.version = FHIR::Client::VERSION
9
9
  spec.authors = ['Andre Quina', 'Jason Walonoski', 'Janoo Fernandes']
10
- spec.email = ['aquina@mitre.org']
10
+ spec.email = ['jwalonoski@mitre.org']
11
11
 
12
12
  spec.summary = %q{A Gem for handling FHIR client requests in ruby}
13
13
  spec.description = %q{A Gem for handling FHIR client requests in ruby}
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_dependency 'activesupport', '>= 3'
24
24
  spec.add_dependency 'addressable', '>= 2.3'
25
- spec.add_dependency 'fhir_models', '>= 1.8.0'
25
+ spec.add_dependency 'fhir_models', '>= 3.0.0'
26
26
  spec.add_dependency 'nokogiri'
27
27
  spec.add_dependency 'oauth2', '~> 1.1'
28
28
  spec.add_dependency 'rack', '>= 1.5'
@@ -7,7 +7,6 @@ module FHIR
7
7
  class Client
8
8
  include FHIR::Sections::History
9
9
  include FHIR::Sections::Crud
10
- include FHIR::Sections::Validate
11
10
  include FHIR::Sections::Tags
12
11
  include FHIR::Sections::Feed
13
12
  include FHIR::Sections::Search
@@ -204,7 +204,7 @@
204
204
  }
205
205
  },{
206
206
  "interaction": "transaction",
207
- "path": ["/"],
207
+ "path": ["^/$"],
208
208
  "verb": "POST",
209
209
  "request": {
210
210
  "headers": {
@@ -1,6 +1,5 @@
1
1
  module FHIR
2
2
  class ClientReply
3
- @@validation_rules = JSON.parse(File.open(File.join(File.expand_path('..', File.dirname(File.absolute_path(__FILE__))), 'fhir_api_validation.json'), 'r:UTF-8', &:read))
4
3
  @@path_regexes = {
5
4
  '[type]' => "(#{FHIR::RESOURCES.join('|')})",
6
5
  '[id]' => FHIR::PRIMITIVES['id']['regex'],
@@ -97,8 +96,11 @@ module FHIR
97
96
  end
98
97
 
99
98
  def validate
99
+ rules = File.open(File.join(File.expand_path('..', File.dirname(File.absolute_path(__FILE__))), 'fhir_api_validation.json'), 'r:UTF-8', &:read)
100
+ validation_rules = JSON.parse(rules)
101
+
100
102
  errors = []
101
- @@validation_rules.each do |rule|
103
+ validation_rules.each do |rule|
102
104
  next unless rule['verb'] == @request[:method].to_s.upcase
103
105
  rule_match = false
104
106
  rule['path'].each do |path|
@@ -129,7 +131,7 @@ module FHIR
129
131
  def validate_headers(name, headers, header_rules)
130
132
  errors = []
131
133
  header_rules.each do |header, present|
132
- value = headers[header]
134
+ value = headers.detect{|x, _y| x.downcase==header.downcase}.try(:last)
133
135
  if present == true
134
136
  if value
135
137
  errors << "#{name}: Malformed value for header #{header}: #{value}" unless @@header_regexes[header] =~ value
@@ -52,6 +52,7 @@ module FHIR
52
52
  url += "/#{options[:resource].try(:name).try(:demodulize) || options[:resource].split('::').last}" if options[:resource]
53
53
  url += "/#{options[:id]}" if options[:id]
54
54
  url += '/$validate' if options[:validate]
55
+ url += '/$match' if options[:match]
55
56
 
56
57
  if options[:operation]
57
58
  opr = options[:operation]
@@ -76,7 +77,8 @@ module FHIR
76
77
 
77
78
  if options[:history]
78
79
  history = options[:history]
79
- url += "/_history/#{history[:id]}"
80
+ url += '/_history'
81
+ url += "/#{history[:id]}" if history.key?(:id)
80
82
  params[:_count] = history[:count] if history[:count]
81
83
  params[:_since] = history[:since].iso8601 if history[:since]
82
84
  end
@@ -78,7 +78,7 @@ module FHIR
78
78
  options[:format] = format
79
79
  options[:id] = id
80
80
  reply = put resource_url(options), resource, fhir_headers(options)
81
- reply.resource = parse_reply(resource.class, format, reply)
81
+ reply.resource = parse_reply(resource.class, format, reply) if reply.body.present?
82
82
  reply.resource_class = resource.class
83
83
  reply
84
84
  end
@@ -107,8 +107,10 @@ module FHIR
107
107
  # Delete the resource with the given ID.
108
108
  #
109
109
  def destroy(klass, id = nil, options = {})
110
- options = { resource: klass, id: id, format: nil }.merge options
111
- reply = delete resource_url(options), fhir_headers(options)
110
+ options = { resource: klass, id: id, format: @default_format }.merge options
111
+ headers = fhir_headers(options)
112
+ headers.delete('Content-Type')
113
+ reply = delete resource_url(options), headers
112
114
  reply.resource_class = klass
113
115
  reply
114
116
  end
@@ -145,12 +147,12 @@ module FHIR
145
147
  options[:format] = format
146
148
  reply = post resource_url(options), resource, fhir_headers(options)
147
149
  if [200, 201].include? reply.code
148
- type = reply.response[:headers][:content_type]
150
+ type = reply.response[:headers].detect{|x, _y| x.downcase=='content-type'}.try(:last)
149
151
  if !type.nil?
150
152
  reply.resource = if type.include?('xml') && !reply.body.empty?
151
- resource.class.from_xml(reply.body)
153
+ FHIR::Xml.from_xml(reply.body)
152
154
  elsif type.include?('json') && !reply.body.empty?
153
- resource.class.from_fhir_json(reply.body)
155
+ FHIR::Json.from_json(reply.body)
154
156
  else
155
157
  resource # just send back the submitted resource
156
158
  end
@@ -113,7 +113,57 @@ module FHIR
113
113
  reply
114
114
  end
115
115
 
116
- # Batch Mode Validation [base]/ValueSet/$batch
116
+ def match(resource, options = {}, format = @default_format)
117
+ options.merge!(resource: resource.class, match: true, format: format)
118
+ params = FHIR::Parameters.new
119
+ add_resource_parameter(params, 'resource', resource)
120
+ add_parameter(params, 'onlyCertainMatches', 'Boolean', options[:onlyCertainMatches]) unless options[:onlyCertainMatches].nil?
121
+ add_parameter(params, 'count', 'Integer', options[:matchCount]) if options[:matchCount].is_a?(Integer)
122
+ post resource_url(options), params, fhir_headers(options)
123
+ end
124
+
125
+ #
126
+ # Validate resource payload.
127
+ #
128
+ # @param resourceClass
129
+ # @param resource
130
+ # @param id
131
+ # @return
132
+ #
133
+ # public <T extends Resource> AtomEntry<OperationOutcome> validate(Class<T> resourceClass, T resource, String id);
134
+
135
+ def validate(resource, options = {}, format = @default_format)
136
+ options.merge!(resource: resource.class, validate: true, format: format)
137
+ params = FHIR::Parameters.new
138
+ add_resource_parameter(params, 'resource', resource)
139
+ add_parameter(params, 'profile', 'Uri', options[:profile_uri]) unless options[:profile_uri].nil?
140
+ post resource_url(options), params, fhir_headers(options)
141
+ end
142
+
143
+ def validate_existing(resource, id, options = {}, format = @default_format)
144
+ options.merge!(resource: resource.class, id: id, validate: true, format: format)
145
+ params = FHIR::Parameters.new
146
+ add_resource_parameter(params, 'resource', resource)
147
+ add_parameter(params, 'profile', 'Uri', options[:profile_uri]) unless options[:profile_uri].nil?
148
+ post resource_url(options), params, fhir_headers(options)
149
+ end
150
+
151
+ private
152
+
153
+ def add_parameter(params, name, type, value)
154
+ params.parameter ||= []
155
+ parameter = FHIR::Parameters::Parameter.new.from_hash(name: name)
156
+ parameter.method("value#{type}=").call(value)
157
+ params.parameter << parameter
158
+ end
159
+
160
+ def add_resource_parameter(params, name, resource)
161
+ params.parameter ||= []
162
+ parameter = FHIR::Parameters::Parameter.new.from_hash(name: name)
163
+ parameter.resource = resource
164
+ params.parameter << parameter
165
+ end
166
+
117
167
  end
118
168
  end
119
169
  end
@@ -1,5 +1,5 @@
1
1
  module FHIR
2
2
  class Client
3
- VERSION = '1.8.0'
3
+ VERSION = '3.0.1'
4
4
  end
5
5
  end
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: 1.8.0
4
+ version: 3.0.1
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: 2016-12-09 00:00:00.000000000 Z
13
+ date: 2017-05-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -46,14 +46,14 @@ dependencies:
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 1.8.0
49
+ version: 3.0.0
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - ">="
55
55
  - !ruby/object:Gem::Version
56
- version: 1.8.0
56
+ version: 3.0.0
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: nokogiri
59
59
  requirement: !ruby/object:Gem::Requirement
@@ -210,7 +210,7 @@ dependencies:
210
210
  version: '0'
211
211
  description: A Gem for handling FHIR client requests in ruby
212
212
  email:
213
- - aquina@mitre.org
213
+ - jwalonoski@mitre.org
214
214
  executables: []
215
215
  extensions: []
216
216
  extra_rdoc_files: []
@@ -249,7 +249,6 @@ files:
249
249
  - lib/fhir_client/sections/search.rb
250
250
  - lib/fhir_client/sections/tags.rb
251
251
  - lib/fhir_client/sections/transactions.rb
252
- - lib/fhir_client/sections/validate.rb
253
252
  - lib/fhir_client/tasks/tasks.rake
254
253
  - lib/fhir_client/version.rb
255
254
  homepage: https://github.com/fhir-crucible/fhir_client
@@ -1,46 +0,0 @@
1
- module FHIR
2
- module Sections
3
- module Validate
4
- #
5
- # Validate resource payload.
6
- #
7
- # @param resourceClass
8
- # @param resource
9
- # @param id
10
- # @return
11
- #
12
- # public <T extends Resource> AtomEntry<OperationOutcome> validate(Class<T> resourceClass, T resource, String id);
13
- def validate(resource, options = {}, format = @default_format)
14
- options.merge!(resource: resource.class, validate: true, format: format)
15
- params = FHIR::Parameters.new
16
- add_resource_parameter(params, 'resource', resource)
17
- add_parameter(params, 'profile', 'Uri', options[:profile_uri]) unless options[:profile_uri].nil?
18
- post resource_url(options), params, fhir_headers(options)
19
- end
20
-
21
- def validate_existing(resource, id, options = {}, format = @default_format)
22
- options.merge!(resource: resource.class, id: id, validate: true, format: format)
23
- params = FHIR::Parameters.new
24
- add_resource_parameter(params, 'resource', resource)
25
- add_parameter(params, 'profile', 'Uri', options[:profile_uri]) unless options[:profile_uri].nil?
26
- post resource_url(options), params, fhir_headers(options)
27
- end
28
-
29
- private
30
-
31
- def add_parameter(params, name, type, value)
32
- params.parameter ||= []
33
- parameter = FHIR::Parameters::Parameter.new.from_hash(name: name)
34
- parameter.method("value#{type}=").call(value)
35
- params.parameter << parameter
36
- end
37
-
38
- def add_resource_parameter(params, name, resource)
39
- params.parameter ||= []
40
- parameter = FHIR::Parameters::Parameter.new.from_hash(name: name)
41
- parameter.resource = resource
42
- params.parameter << parameter
43
- end
44
- end
45
- end
46
- end