change_healthcare-eligibility 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +130 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +7 -0
  7. data/Gemfile +4 -0
  8. data/Gemfile.lock +59 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +64 -0
  11. data/Rakefile +6 -0
  12. data/bin/console +11 -0
  13. data/bin/rspec +29 -0
  14. data/bin/setup +8 -0
  15. data/change_healthcare-eligibility.gemspec +44 -0
  16. data/lib/change_healthcare/eligibility.rb +13 -0
  17. data/lib/change_healthcare/eligibility/inspector.rb +82 -0
  18. data/lib/change_healthcare/eligibility/swagger_client.rb +81 -0
  19. data/lib/change_healthcare/eligibility/swagger_client/api_client.rb +388 -0
  20. data/lib/change_healthcare/eligibility/swagger_client/api_error.rb +40 -0
  21. data/lib/change_healthcare/eligibility/swagger_client/configuration.rb +202 -0
  22. data/lib/change_healthcare/eligibility/swagger_client/eligibility_api.rb +198 -0
  23. data/lib/change_healthcare/eligibility/swagger_client/models/additional_identification.rb +266 -0
  24. data/lib/change_healthcare/eligibility/swagger_client/models/additional_information.rb +185 -0
  25. data/lib/change_healthcare/eligibility/swagger_client/models/address.rb +218 -0
  26. data/lib/change_healthcare/eligibility/swagger_client/models/benefits_additional_information.rb +376 -0
  27. data/lib/change_healthcare/eligibility/swagger_client/models/benefits_date_information.rb +340 -0
  28. data/lib/change_healthcare/eligibility/swagger_client/models/benefits_information.rb +338 -0
  29. data/lib/change_healthcare/eligibility/swagger_client/models/benefits_related_entity.rb +240 -0
  30. data/lib/change_healthcare/eligibility/swagger_client/models/benefits_service_delivery.rb +220 -0
  31. data/lib/change_healthcare/eligibility/swagger_client/models/composite_medical_procedure_identifier.rb +218 -0
  32. data/lib/change_healthcare/eligibility/swagger_client/models/eligibility_additional_information.rb +200 -0
  33. data/lib/change_healthcare/eligibility/swagger_client/models/encounter.rb +359 -0
  34. data/lib/change_healthcare/eligibility/swagger_client/models/error.rb +205 -0
  35. data/lib/change_healthcare/eligibility/swagger_client/models/health_care_diagnosis_code.rb +190 -0
  36. data/lib/change_healthcare/eligibility/swagger_client/models/health_care_information.rb +229 -0
  37. data/lib/change_healthcare/eligibility/swagger_client/models/health_check.rb +190 -0
  38. data/lib/change_healthcare/eligibility/swagger_client/models/information_receiver_name.rb +303 -0
  39. data/lib/change_healthcare/eligibility/swagger_client/models/loop_2000_cd2100_cd_segment_nm1_ref_dmg_ins_mpi_prv_notes_response_member.rb +429 -0
  40. data/lib/change_healthcare/eligibility/swagger_client/models/loop_2100_a_segments_nm1_and_per_notes_information_source_name.rb +293 -0
  41. data/lib/change_healthcare/eligibility/swagger_client/models/loop_2100_a_segments_per_element_per03_8_notes_communication.rb +194 -0
  42. data/lib/change_healthcare/eligibility/swagger_client/models/loop_2100_a_segments_per_notes_information_source_contact_information.rb +198 -0
  43. data/lib/change_healthcare/eligibility/swagger_client/models/loop_2100_bcd_segment_nm1_prv_notes_provider.rb +322 -0
  44. data/lib/change_healthcare/eligibility/swagger_client/models/loop_2100_cd_segment_trn_notes_subscriber_trace_numbers.rb +218 -0
  45. data/lib/change_healthcare/eligibility/swagger_client/models/loop_2110_cd_segments_ref_notes_subscriber_dependent_additional_identification.rb +488 -0
  46. data/lib/change_healthcare/eligibility/swagger_client/models/medical_eligibility.rb +272 -0
  47. data/lib/change_healthcare/eligibility/swagger_client/models/medical_procedure.rb +254 -0
  48. data/lib/change_healthcare/eligibility/swagger_client/models/plan_date_information.rb +340 -0
  49. data/lib/change_healthcare/eligibility/swagger_client/models/plan_status.rb +204 -0
  50. data/lib/change_healthcare/eligibility/swagger_client/models/provider.rb +304 -0
  51. data/lib/change_healthcare/eligibility/swagger_client/models/provider_information.rb +190 -0
  52. data/lib/change_healthcare/eligibility/swagger_client/models/raw_x12_request.rb +190 -0
  53. data/lib/change_healthcare/eligibility/swagger_client/models/request_dependent.rb +452 -0
  54. data/lib/change_healthcare/eligibility/swagger_client/models/request_subscriber.rb +456 -0
  55. data/lib/change_healthcare/eligibility/swagger_client/models/response.rb +322 -0
  56. data/lib/change_healthcare/eligibility/swagger_client/version.rb +17 -0
  57. data/lib/change_healthcare/eligibility/version.rb +5 -0
  58. data/lib/change_healthcare/eligibility/wrapper.rb +124 -0
  59. metadata +214 -0
@@ -0,0 +1,81 @@
1
+ # #Eligibility
2
+ #
3
+ # Reference for developers
4
+ #
5
+ # OpenAPI spec version: v3
6
+ #
7
+ # Generated by: https://github.com/swagger-api/swagger-codegen.git
8
+ # Swagger Codegen version: 2.4.17
9
+ #
10
+
11
+ # Common files
12
+ require_relative './swagger_client/api_client'
13
+ require_relative './swagger_client/api_error'
14
+ require_relative './swagger_client/version'
15
+ require_relative './swagger_client/configuration'
16
+
17
+ # Models
18
+ require_relative './swagger_client/models/additional_identification'
19
+ require_relative './swagger_client/models/additional_information'
20
+ require_relative './swagger_client/models/address'
21
+ require_relative './swagger_client/models/benefits_additional_information'
22
+ require_relative './swagger_client/models/benefits_date_information'
23
+ require_relative './swagger_client/models/benefits_information'
24
+ require_relative './swagger_client/models/benefits_related_entity'
25
+ require_relative './swagger_client/models/benefits_service_delivery'
26
+ require_relative './swagger_client/models/composite_medical_procedure_identifier'
27
+ require_relative './swagger_client/models/eligibility_additional_information'
28
+ require_relative './swagger_client/models/encounter'
29
+ require_relative './swagger_client/models/error'
30
+ require_relative './swagger_client/models/health_care_diagnosis_code'
31
+ require_relative './swagger_client/models/health_care_information'
32
+ require_relative './swagger_client/models/health_check'
33
+ require_relative './swagger_client/models/information_receiver_name'
34
+ require_relative './swagger_client/models/loop_2000_cd2100_cd_segment_nm1_ref_dmg_ins_mpi_prv_notes_response_member'
35
+ require_relative './swagger_client/models/loop_2100_a_segments_nm1_and_per_notes_information_source_name'
36
+ require_relative './swagger_client/models/loop_2100_a_segments_per_element_per03_8_notes_communication'
37
+ require_relative './swagger_client/models/loop_2100_a_segments_per_notes_information_source_contact_information'
38
+ require_relative './swagger_client/models/loop_2100_bcd_segment_nm1_prv_notes_provider'
39
+ require_relative './swagger_client/models/loop_2100_cd_segment_trn_notes_subscriber_trace_numbers'
40
+ require_relative './swagger_client/models/loop_2110_cd_segments_ref_notes_subscriber_dependent_additional_identification'
41
+ require_relative './swagger_client/models/medical_eligibility'
42
+ require_relative './swagger_client/models/medical_procedure'
43
+ require_relative './swagger_client/models/plan_date_information'
44
+ require_relative './swagger_client/models/plan_status'
45
+ require_relative './swagger_client/models/provider'
46
+ require_relative './swagger_client/models/provider_information'
47
+ require_relative './swagger_client/models/raw_x12_request'
48
+ require_relative './swagger_client/models/request_dependent'
49
+ require_relative './swagger_client/models/request_subscriber'
50
+ require_relative './swagger_client/models/response'
51
+
52
+ # APIs
53
+ require_relative './swagger_client/eligibility_api'
54
+
55
+ module ChangeHealthcare
56
+ module Eligibility
57
+ ##
58
+ # This module contains an auto-generated client based on swagger docs.
59
+ # Unfortunately Change Healthcare chose some *horrific* names for their
60
+ # models, so this is more than a little gross to actuall use.
61
+ #
62
+ # Sorry!
63
+ module SwaggerClient
64
+ class << self
65
+ # Customize default settings for the SDK using block.
66
+ # SwaggerClient.configure do |config|
67
+ # config.username = "xxx"
68
+ # config.password = "xxx"
69
+ # end
70
+ # If no block given, return the default Configuration object.
71
+ def configure
72
+ if block_given?
73
+ yield(Configuration.default)
74
+ else
75
+ Configuration.default
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,388 @@
1
+ # #Eligibility
2
+ #
3
+ # Reference for developers
4
+ #
5
+ # OpenAPI spec version: v3
6
+ #
7
+ # Generated by: https://github.com/swagger-api/swagger-codegen.git
8
+ # Swagger Codegen version: 2.4.17
9
+ #
10
+
11
+ require 'date'
12
+ require 'json'
13
+ require 'logger'
14
+ require 'tempfile'
15
+ require 'typhoeus'
16
+ require 'addressable/uri'
17
+
18
+ module ChangeHealthcare
19
+ module Eligibility
20
+ module SwaggerClient
21
+ class ApiClient
22
+ # The Configuration object holding settings to be used in the API client.
23
+ attr_accessor :config
24
+
25
+ # Defines the headers to be used in HTTP requests of all API calls by default.
26
+ #
27
+ # @return [Hash]
28
+ attr_accessor :default_headers
29
+
30
+ # Initializes the ApiClient
31
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
32
+ def initialize(config = Configuration.default)
33
+ @config = config
34
+ @user_agent = "Swagger-Codegen/#{VERSION}/ruby"
35
+ @default_headers = {
36
+ 'Content-Type' => 'application/json',
37
+ 'User-Agent' => @user_agent
38
+ }
39
+ end
40
+
41
+ def self.default
42
+ @@default ||= ApiClient.new
43
+ end
44
+
45
+ # Call an API with given options.
46
+ #
47
+ # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
48
+ # the data deserialized from response body (could be nil), response status code and response headers.
49
+ def call_api(http_method, path, opts = {})
50
+ request = build_request(http_method, path, opts)
51
+ response = request.run
52
+
53
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n" if @config.debugging
54
+
55
+ unless response.success?
56
+ if response.timed_out?
57
+ raise ApiError, 'Connection timed out'
58
+ elsif response.code.zero?
59
+ # Errors from libcurl will be made visible here
60
+ raise ApiError.new(code: 0,
61
+ message: response.return_message)
62
+ else
63
+ raise ApiError.new(code: response.code,
64
+ response_headers: response.headers.to_h,
65
+ response_body: response.body),
66
+ response.status_message
67
+ end
68
+ end
69
+
70
+ data = (deserialize(response, opts[:return_type]) if opts[:return_type])
71
+ [data, response.code, response.headers]
72
+ end
73
+
74
+ # Builds the HTTP request
75
+ #
76
+ # @param [String] http_method HTTP method/verb (e.g. POST)
77
+ # @param [String] path URL path (e.g. /account/new)
78
+ # @option opts [Hash] :header_params Header parameters
79
+ # @option opts [Hash] :query_params Query parameters
80
+ # @option opts [Hash] :form_params Query parameters
81
+ # @option opts [Object] :body HTTP body (JSON/XML)
82
+ # @return [Typhoeus::Request] A Typhoeus Request
83
+ def build_request(http_method, path, opts = {})
84
+ url = build_request_url(path)
85
+ http_method = http_method.to_sym.downcase
86
+
87
+ header_params = @default_headers.merge(opts[:header_params] || {})
88
+ query_params = opts[:query_params] || {}
89
+ form_params = opts[:form_params] || {}
90
+
91
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
92
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
93
+
94
+ req_opts = {
95
+ method: http_method,
96
+ headers: header_params,
97
+ params: query_params,
98
+ params_encoding: @config.params_encoding,
99
+ timeout: @config.timeout,
100
+ ssl_verifypeer: @config.verify_ssl,
101
+ ssl_verifyhost: _verify_ssl_host,
102
+ sslcert: @config.cert_file,
103
+ sslkey: @config.key_file,
104
+ verbose: @config.debugging
105
+ }
106
+
107
+ req_opts.merge!(multipart: true) if header_params['Content-Type'].start_with? 'multipart/'
108
+
109
+ # set custom cert, if provided
110
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
111
+
112
+ if %i[post patch put delete].include?(http_method)
113
+ req_body = build_request_body(header_params, form_params, opts[:body])
114
+ req_opts.update body: req_body
115
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n" if @config.debugging
116
+ end
117
+
118
+ request = Typhoeus::Request.new(url, req_opts)
119
+ download_file(request) if opts[:return_type] == 'File'
120
+ request
121
+ end
122
+
123
+ # Check if the given MIME is a JSON MIME.
124
+ # JSON MIME examples:
125
+ # application/json
126
+ # application/json; charset=UTF8
127
+ # APPLICATION/JSON
128
+ # */*
129
+ # @param [String] mime MIME
130
+ # @return [Boolean] True if the MIME is application/json
131
+ def json_mime?(mime)
132
+ (mime == '*/*') || !(mime =~ %r{Application/.*json(?!p)(;.*)?}i).nil?
133
+ end
134
+
135
+ # Deserialize the response to the given return type.
136
+ #
137
+ # @param [Response] response HTTP response
138
+ # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
139
+ def deserialize(response, return_type)
140
+ body = response.body
141
+
142
+ # handle file downloading - return the File instance processed in request callbacks
143
+ # note that response body is empty when the file is written in chunks in request on_body callback
144
+ return @tempfile if return_type == 'File'
145
+
146
+ return nil if body.nil? || body.empty?
147
+
148
+ # return response body directly for String return type
149
+ return body if return_type == 'String'
150
+
151
+ # ensuring a default content type
152
+ content_type = response.headers['Content-Type'] || 'application/json'
153
+
154
+ raise "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
155
+
156
+ begin
157
+ data = JSON.parse("[#{body}]", symbolize_names: true)[0]
158
+ rescue JSON::ParserError => e
159
+ if %w[String Date DateTime].include?(return_type)
160
+ data = body
161
+ else
162
+ raise e
163
+ end
164
+ end
165
+
166
+ convert_to_type data, return_type
167
+ end
168
+
169
+ # Convert data to the given return type.
170
+ # @param [Object] data Data to be converted
171
+ # @param [String] return_type Return type
172
+ # @return [Mixed] Data in a particular type
173
+ def convert_to_type(data, return_type)
174
+ return nil if data.nil?
175
+
176
+ case return_type
177
+ when 'String'
178
+ data.to_s
179
+ when 'Integer'
180
+ data.to_i
181
+ when 'Float'
182
+ data.to_f
183
+ when 'BOOLEAN'
184
+ data == true
185
+ when 'DateTime'
186
+ # parse date time (expecting ISO 8601 format)
187
+ DateTime.parse data
188
+ when 'Date'
189
+ # parse date time (expecting ISO 8601 format)
190
+ Date.parse data
191
+ when 'Object'
192
+ # generic object (usually a Hash), return directly
193
+ data
194
+ when /\AArray<(.+)>\z/
195
+ # e.g. Array<Pet>
196
+ sub_type = Regexp.last_match(1)
197
+ data.map { |item| convert_to_type(item, sub_type) }
198
+ when /\AHash<String, (.+)>\z/
199
+ # e.g. Hash<String, Integer>
200
+ sub_type = Regexp.last_match(1)
201
+ {}.tap do |hash|
202
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
203
+ end
204
+ else
205
+ # models, e.g. Pet
206
+ SwaggerClient.const_get(return_type).new.tap do |model|
207
+ model.build_from_hash data
208
+ end
209
+ end
210
+ end
211
+
212
+ # Save response body into a file in (the defined) temporary folder, using the filename
213
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
214
+ # The response body is written to the file in chunks in order to handle files which
215
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
216
+ # process can use.
217
+ #
218
+ # @see Configuration#temp_folder_path
219
+ def download_file(request)
220
+ tempfile = nil
221
+ encoding = nil
222
+ request.on_headers do |response|
223
+ content_disposition = response.headers['Content-Disposition']
224
+ if content_disposition && content_disposition =~ /filename=/i
225
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
226
+ prefix = sanitize_filename(filename)
227
+ else
228
+ prefix = 'download-'
229
+ end
230
+ prefix += '-' unless prefix.end_with?('-')
231
+ encoding = response.body.encoding
232
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
233
+ @tempfile = tempfile
234
+ end
235
+ request.on_body do |chunk|
236
+ chunk.force_encoding(encoding)
237
+ tempfile.write(chunk)
238
+ end
239
+ request.on_complete do |_response|
240
+ tempfile.close
241
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
242
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
243
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
244
+ 'explicitly with `tempfile.delete`'
245
+ end
246
+ end
247
+
248
+ # Sanitize filename by removing path.
249
+ # e.g. ../../sun.gif becomes sun.gif
250
+ #
251
+ # @param [String] filename the filename to be sanitized
252
+ # @return [String] the sanitized filename
253
+ def sanitize_filename(filename)
254
+ filename.gsub(%r{.*[/\\]}, '')
255
+ end
256
+
257
+ def build_request_url(path)
258
+ # Add leading and trailing slashes to path
259
+ path = "/#{path}".gsub(%r{/+}, '/')
260
+ Addressable::URI.encode(@config.base_url + path)
261
+ end
262
+
263
+ # Builds the HTTP request body
264
+ #
265
+ # @param [Hash] header_params Header parameters
266
+ # @param [Hash] form_params Query parameters
267
+ # @param [Object] body HTTP body (JSON/XML)
268
+ # @return [String] HTTP body data in the form of string
269
+ def build_request_body(header_params, form_params, body)
270
+ # http form
271
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
272
+ header_params['Content-Type'] == 'multipart/form-data'
273
+ data = {}
274
+ form_params.each do |key, value|
275
+ case value
276
+ when ::File, ::Array, nil
277
+ # let typhoeus handle File, Array and nil parameters
278
+ data[key] = value
279
+ else
280
+ data[key] = value.to_s
281
+ end
282
+ end
283
+ elsif body
284
+ data = body.is_a?(String) ? body : body.to_json
285
+ else
286
+ data = nil
287
+ end
288
+ data
289
+ end
290
+
291
+ # Update hearder and query params based on authentication settings.
292
+ #
293
+ # @param [Hash] header_params Header parameters
294
+ # @param [Hash] query_params Query parameters
295
+ # @param [String] auth_names Authentication scheme name
296
+ def update_params_for_auth!(header_params, query_params, auth_names)
297
+ Array(auth_names).each do |auth_name|
298
+ auth_setting = @config.auth_settings[auth_name]
299
+ next unless auth_setting
300
+
301
+ case auth_setting[:in]
302
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
303
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
304
+ else raise ArgumentError, 'Authentication token must be in `query` of `header`'
305
+ end
306
+ end
307
+ end
308
+
309
+ # Sets user agent in HTTP header
310
+ #
311
+ # @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
312
+ def user_agent=(user_agent)
313
+ @user_agent = user_agent
314
+ @default_headers['User-Agent'] = @user_agent
315
+ end
316
+
317
+ # Return Accept header based on an array of accepts provided.
318
+ # @param [Array] accepts array for Accept
319
+ # @return [String] the Accept header (e.g. application/json)
320
+ def select_header_accept(accepts)
321
+ return nil if accepts.nil? || accepts.empty?
322
+
323
+ # use JSON when present, otherwise use all of the provided
324
+ json_accept = accepts.find { |s| json_mime?(s) }
325
+ json_accept || accepts.join(',')
326
+ end
327
+
328
+ # Return Content-Type header based on an array of content types provided.
329
+ # @param [Array] content_types array for Content-Type
330
+ # @return [String] the Content-Type header (e.g. application/json)
331
+ def select_header_content_type(content_types)
332
+ # use application/json by default
333
+ return 'application/json' if content_types.nil? || content_types.empty?
334
+
335
+ # use JSON when present, otherwise use the first one
336
+ json_content_type = content_types.find { |s| json_mime?(s) }
337
+ json_content_type || content_types.first
338
+ end
339
+
340
+ # Convert object (array, hash, object, etc) to JSON string.
341
+ # @param [Object] model object to be converted into JSON string
342
+ # @return [String] JSON string representation of the object
343
+ def object_to_http_body(model)
344
+ return model if model.nil? || model.is_a?(String)
345
+
346
+ local_body = nil
347
+ local_body = if model.is_a?(Array)
348
+ model.map { |m| object_to_hash(m) }
349
+ else
350
+ object_to_hash(model)
351
+ end
352
+ local_body.to_json
353
+ end
354
+
355
+ # Convert object(non-array) to hash.
356
+ # @param [Object] obj object to be converted into JSON string
357
+ # @return [String] JSON string representation of the object
358
+ def object_to_hash(obj)
359
+ if obj.respond_to?(:to_hash)
360
+ obj.to_hash
361
+ else
362
+ obj
363
+ end
364
+ end
365
+
366
+ # Build parameter value according to the given collection format.
367
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
368
+ def build_collection_param(param, collection_format)
369
+ case collection_format
370
+ when :csv
371
+ param.join(',')
372
+ when :ssv
373
+ param.join(' ')
374
+ when :tsv
375
+ param.join("\t")
376
+ when :pipes
377
+ param.join('|')
378
+ when :multi
379
+ # return the array directly as typhoeus will handle it as expected
380
+ param
381
+ else
382
+ raise "unknown collection format: #{collection_format.inspect}"
383
+ end
384
+ end
385
+ end
386
+ end
387
+ end
388
+ end