change_health 1.0.3 → 2.2.1
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 +4 -4
- data/CHANGELOG.md +56 -5
- data/README.md +154 -17
- data/lib/change_health/connection.rb +1 -1
- data/lib/change_health/models/claim/submission/claim_information.rb +31 -0
- data/lib/change_health/models/claim/submission/provider.rb +17 -0
- data/lib/change_health/models/claim/submission/service_line.rb +12 -0
- data/lib/change_health/models/claim/submission/submitter.rb +11 -0
- data/lib/change_health/models/claim/submission/subscriber.rb +15 -0
- data/lib/change_health/models/eligibility/encounter.rb +22 -0
- data/lib/change_health/models/eligibility/provider.rb +23 -0
- data/lib/change_health/models/eligibility/subscriber.rb +31 -0
- data/lib/change_health/models/error.rb +57 -0
- data/lib/change_health/models/model.rb +13 -1
- data/lib/change_health/models/{trading_partner.rb → trading_partner/trading_partner.rb} +0 -0
- data/lib/change_health/{models → request}/eligibility.rb +5 -5
- data/lib/change_health/request/report.rb +52 -0
- data/lib/change_health/request/submission.rb +58 -0
- data/lib/change_health/response/claim/report/report_data.rb +45 -0
- data/lib/change_health/response/claim/report/report_list_data.rb +13 -0
- data/lib/change_health/response/claim/submission/submission_data.rb +23 -0
- data/lib/change_health/{models → response/eligibility}/eligibility_benefit.rb +6 -6
- data/lib/change_health/{models → response/eligibility}/eligibility_benefits.rb +3 -3
- data/lib/change_health/response/eligibility/eligibility_data.rb +94 -0
- data/lib/change_health/response/response_data.rb +41 -0
- data/lib/change_health/response/{trading_partner_data.rb → trading_partner/trading_partner_data.rb} +0 -0
- data/lib/change_health/response/{trading_partners_data.rb → trading_partner/trading_partners_data.rb} +0 -0
- data/lib/change_health/version.rb +1 -1
- data/lib/change_health.rb +23 -11
- metadata +24 -12
- data/lib/change_health/models/eligibility_data.rb +0 -191
- data/lib/change_health/models/encounter.rb +0 -20
- data/lib/change_health/models/provider.rb +0 -21
- data/lib/change_health/models/subscriber.rb +0 -29
@@ -0,0 +1,58 @@
|
|
1
|
+
module ChangeHealth
|
2
|
+
module Request
|
3
|
+
module Claim
|
4
|
+
class Submission < Hashie::Trash
|
5
|
+
|
6
|
+
ENDPOINT = '/medicalnetwork/professionalclaims/v3'.freeze
|
7
|
+
HEALTH_CHECK_ENDPOINT = ENDPOINT + '/healthcheck'.freeze
|
8
|
+
SUBMISSION_ENDPOINT = ENDPOINT + '/submission'.freeze
|
9
|
+
VALIDATION_ENDPOINT = ENDPOINT + '/validation'.freeze
|
10
|
+
|
11
|
+
property :claimInformation, from: :claim_information, required: false
|
12
|
+
property :controlNumber, from: :control_number, required: true, default: ChangeHealth::Models::CONTROL_NUMBER
|
13
|
+
property :providers, required: false
|
14
|
+
property :receiver, required: false
|
15
|
+
property :submitter, required: false
|
16
|
+
property :subscriber, required: false
|
17
|
+
property :headers, required: false
|
18
|
+
# Need one or the other, trading partner id or trading partner service id
|
19
|
+
property :tradingPartnerId, from: :trading_partner_id, required: false
|
20
|
+
property :tradingPartnerServiceId, from: :trading_partner_service_id, required: false
|
21
|
+
|
22
|
+
def add_provider(provider)
|
23
|
+
self[:providers] ||= []
|
24
|
+
self[:providers] << provider
|
25
|
+
end
|
26
|
+
|
27
|
+
def submission
|
28
|
+
ChangeHealth::Response::Claim::SubmissionData.new(response: ChangeHealth::Connection.new.request(endpoint: SUBMISSION_ENDPOINT, body: self.to_h, headers: professional_headers))
|
29
|
+
end
|
30
|
+
|
31
|
+
def validation
|
32
|
+
ChangeHealth::Response::Claim::SubmissionData.new(response: ChangeHealth::Connection.new.request(endpoint: VALIDATION_ENDPOINT, body: self.to_h, headers: professional_headers))
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.health_check
|
36
|
+
ChangeHealth::Connection.new.request(endpoint: HEALTH_CHECK_ENDPOINT, verb: :get)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.ping
|
40
|
+
self.health_check
|
41
|
+
end
|
42
|
+
|
43
|
+
def professional_headers
|
44
|
+
if self[:headers]
|
45
|
+
extra_headers = {}
|
46
|
+
extra_headers["X-CHC-ClaimSubmission-SubmitterId"] = self[:headers][:submitter_id]
|
47
|
+
extra_headers["X-CHC-ClaimSubmission-BillerId"] = self[:headers][:biller_id]
|
48
|
+
extra_headers["X-CHC-ClaimSubmission-Username"] = self[:headers][:username]
|
49
|
+
extra_headers["X-CHC-ClaimSubmission-Pwd"] = self[:headers][:password]
|
50
|
+
extra_headers
|
51
|
+
else
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module ChangeHealth
|
2
|
+
module Response
|
3
|
+
module Claim
|
4
|
+
class ReportData < ChangeHealth::Response::ResponseData
|
5
|
+
attr_reader :report_name, :json
|
6
|
+
alias_method :json?, :json
|
7
|
+
|
8
|
+
def initialize(report_name, json, data: nil, response: nil)
|
9
|
+
super(data: data, response: response)
|
10
|
+
@report_name = report_name
|
11
|
+
@json = json
|
12
|
+
end
|
13
|
+
|
14
|
+
def edi?
|
15
|
+
!@json
|
16
|
+
end
|
17
|
+
|
18
|
+
def report_type
|
19
|
+
self.class.report_type(@report_name)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.report_type(report_name)
|
23
|
+
return '277' if is_277?(report_name)
|
24
|
+
return '835' if is_835?(report_name)
|
25
|
+
end
|
26
|
+
|
27
|
+
def is_277?
|
28
|
+
self.class.is_277?(@report_name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.is_277?(report_name)
|
32
|
+
report_name.start_with?('X3')
|
33
|
+
end
|
34
|
+
|
35
|
+
def is_835?
|
36
|
+
self.class.is_835?(@report_name)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.is_835?(report_name)
|
40
|
+
report_name.start_with?('R5')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ChangeHealth
|
2
|
+
module Response
|
3
|
+
module Claim
|
4
|
+
class SubmissionData < ChangeHealth::Response::ResponseData
|
5
|
+
|
6
|
+
%w(controlNumber status tradingPartnerId tradingPartnerServiceId).each do |v|
|
7
|
+
define_method(v) do
|
8
|
+
@raw.dig(v)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
alias_method :control_number, :controlNumber
|
13
|
+
alias_method :trading_partner_id, :tradingPartnerId
|
14
|
+
alias_method :trading_partner_service_id, :tradingPartnerServiceId
|
15
|
+
|
16
|
+
def trading_partner?(name)
|
17
|
+
self.trading_partner_id == name || trading_partner_service_id == name
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module ChangeHealth
|
2
|
-
module
|
2
|
+
module Response
|
3
3
|
class EligibilityBenefit < Hash
|
4
4
|
include Hashie::Extensions::MergeInitializer
|
5
5
|
include Hashie::Extensions::IndifferentAccess
|
@@ -54,7 +54,7 @@ module ChangeHealth
|
|
54
54
|
coverageLevelCode: COVERAGES,
|
55
55
|
code: CODES
|
56
56
|
}
|
57
|
-
|
57
|
+
|
58
58
|
HELPERS.each do |key, types|
|
59
59
|
types.each do |method, value|
|
60
60
|
define_method("#{method}?") do
|
@@ -99,13 +99,13 @@ module ChangeHealth
|
|
99
99
|
self.coinsurance? ? self.benefitPercent : self.benefitAmount
|
100
100
|
end
|
101
101
|
|
102
|
-
def services
|
102
|
+
def services
|
103
103
|
self['serviceTypeCodes']&.each_with_index&.map {|stc, i| [stc, self['serviceTypes']&.at(i)]} || []
|
104
104
|
end
|
105
105
|
|
106
106
|
%w(eligibilityBegin eligibilityEnd planBegin planEnd service).each do |f|
|
107
107
|
define_method(f) do
|
108
|
-
return ChangeHealth::Models::
|
108
|
+
return ChangeHealth::Models::PARSE_DATE.call(self.date_info&.dig(f))
|
109
109
|
end
|
110
110
|
end
|
111
111
|
alias_method :eligibility_begin_date, :eligibilityBegin
|
@@ -120,11 +120,11 @@ module ChangeHealth
|
|
120
120
|
end
|
121
121
|
|
122
122
|
def plan_date_range_start
|
123
|
-
ChangeHealth::Models::
|
123
|
+
ChangeHealth::Models::PARSE_DATE.call(self.plan_date_range[0])
|
124
124
|
end
|
125
125
|
|
126
126
|
def plan_date_range_end
|
127
|
-
ChangeHealth::Models::
|
127
|
+
ChangeHealth::Models::PARSE_DATE.call(self.plan_date_range[1])
|
128
128
|
end
|
129
129
|
|
130
130
|
private
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module ChangeHealth
|
2
|
-
module
|
2
|
+
module Response
|
3
3
|
class EligibilityBenefits < Array
|
4
4
|
def initialize(benefits)
|
5
|
-
super(benefits.map {|benefit| ChangeHealth::
|
5
|
+
super(benefits.map {|benefit| ChangeHealth::Response::EligibilityBenefit.new(benefit) })
|
6
6
|
end
|
7
7
|
|
8
8
|
def where(**kwargs)
|
@@ -25,7 +25,7 @@ module ChangeHealth
|
|
25
25
|
self.where(inPlanNetworkIndicatorCode: 'Y')
|
26
26
|
end
|
27
27
|
|
28
|
-
ChangeHealth::
|
28
|
+
ChangeHealth::Response::EligibilityBenefit::HELPERS.each do |key, types|
|
29
29
|
types.each do |method, value|
|
30
30
|
define_method("#{method}s") do
|
31
31
|
self.where(key => value)
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module ChangeHealth
|
2
|
+
module Response
|
3
|
+
class EligibilityData < ChangeHealth::Response::ResponseData
|
4
|
+
|
5
|
+
ACTIVE = '1'
|
6
|
+
INACTIVE = '6'
|
7
|
+
|
8
|
+
def active?(service_code: '30')
|
9
|
+
plan_status(service_code: service_code, single: false).any? {|status| ACTIVE == status['statusCode'] }
|
10
|
+
end
|
11
|
+
|
12
|
+
def inactive?(service_code: '30')
|
13
|
+
plan_status(service_code: service_code, single: false).any? {|status| INACTIVE == status['statusCode'] }
|
14
|
+
end
|
15
|
+
|
16
|
+
def dependents?
|
17
|
+
true == self.dependents&.any?
|
18
|
+
end
|
19
|
+
|
20
|
+
%w(planStatus benefitsInformation controlNumber planDateInformation dependents).each do |v|
|
21
|
+
define_method(v) do
|
22
|
+
@raw.dig(v)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
%w(eligibilityBegin planBegin service).each do |f|
|
27
|
+
define_method(f) do
|
28
|
+
return ChangeHealth::Models::PARSE_DATE.call(self.date_info&.dig(f))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
alias_method :eligibility_begin_date, :eligibilityBegin
|
32
|
+
alias_method :plan_begin_date, :planBegin
|
33
|
+
alias_method :service_date, :service
|
34
|
+
|
35
|
+
def plan_date_range
|
36
|
+
pd = self.date_info&.dig('plan') || ''
|
37
|
+
pd.split('-')
|
38
|
+
end
|
39
|
+
|
40
|
+
def plan_date_range_start
|
41
|
+
ChangeHealth::Models::PARSE_DATE.call(self.plan_date_range[0])
|
42
|
+
end
|
43
|
+
|
44
|
+
def plan_date_range_end
|
45
|
+
ChangeHealth::Models::PARSE_DATE.call(self.plan_date_range[1])
|
46
|
+
end
|
47
|
+
|
48
|
+
def plan_status(service_code: , single: true)
|
49
|
+
if true == single
|
50
|
+
self.planStatus&.find {|plan| plan.dig('serviceTypeCodes')&.include?(service_code) } || {}
|
51
|
+
else
|
52
|
+
self.planStatus&.select {|plan| plan.dig('serviceTypeCodes')&.include?(service_code) } || []
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def benefits
|
57
|
+
kname = "ChangeHealth::Response::EligibilityBenefits#{self.trading_partner_id&.upcase}"
|
58
|
+
klazz = Object.const_get(kname) if Module.const_defined?(kname)
|
59
|
+
klazz ||= ChangeHealth::Response::EligibilityBenefits
|
60
|
+
|
61
|
+
if klazz.respond_to?(:factory)
|
62
|
+
klazz = klazz.factory(self)
|
63
|
+
end
|
64
|
+
|
65
|
+
klazz.new(self.benefitsInformation || [])
|
66
|
+
end
|
67
|
+
|
68
|
+
def medicare?(**kwargs)
|
69
|
+
false == benefits.empty? && benefits.where(kwargs).all? {|b| b.medicare? }
|
70
|
+
end
|
71
|
+
|
72
|
+
def plan?(name)
|
73
|
+
self.plan_names.any? {|pname| name == pname }
|
74
|
+
end
|
75
|
+
|
76
|
+
def plan_names
|
77
|
+
self.planStatus&.map {|plan_status| plan_status['planDetails'] }&.compact || []
|
78
|
+
end
|
79
|
+
|
80
|
+
def trading_partner?(name)
|
81
|
+
self.trading_partner_id == name
|
82
|
+
end
|
83
|
+
|
84
|
+
def trading_partner_id
|
85
|
+
@raw['tradingPartnerServiceId']
|
86
|
+
end
|
87
|
+
|
88
|
+
alias_method :control_number, :controlNumber
|
89
|
+
alias_method :benefits_information, :benefitsInformation
|
90
|
+
alias_method :plan_statuses, :planStatus
|
91
|
+
alias_method :date_info, :planDateInformation
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ChangeHealth
|
2
|
+
module Response
|
3
|
+
class ResponseData
|
4
|
+
attr_reader :response, :raw
|
5
|
+
|
6
|
+
def initialize(data: nil, response: nil)
|
7
|
+
@response = response
|
8
|
+
@raw = data
|
9
|
+
|
10
|
+
begin
|
11
|
+
@raw ||= response&.parsed_response
|
12
|
+
rescue JSON::ParserError
|
13
|
+
end
|
14
|
+
|
15
|
+
@raw ||= {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def errors?
|
19
|
+
self.errors.is_a?(Array) && false == self.errors.empty?
|
20
|
+
end
|
21
|
+
|
22
|
+
def errors
|
23
|
+
errors = @raw.dig('errors') || []
|
24
|
+
|
25
|
+
errors.flatten.map {|error| ChangeHealth::Models::Error.new(error) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def recommend_retry?
|
29
|
+
return false unless errors?
|
30
|
+
|
31
|
+
return true if errors.any?(&:represents_down?)
|
32
|
+
|
33
|
+
error_codes = errors.select(&:code?)
|
34
|
+
|
35
|
+
return false if error_codes.empty?
|
36
|
+
|
37
|
+
return error_codes.all?(&:retryable?)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/change_health/response/{trading_partner_data.rb → trading_partner/trading_partner_data.rb}
RENAMED
File without changes
|
File without changes
|
data/lib/change_health.rb
CHANGED
@@ -1,22 +1,34 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
require 'hashie'
|
3
3
|
require 'change_health/version'
|
4
|
+
require 'change_health/authentication'
|
4
5
|
require 'change_health/change_health_exception'
|
5
6
|
require 'change_health/connection'
|
6
|
-
require 'change_health/authentication'
|
7
7
|
require 'change_health/extensions'
|
8
|
+
require 'change_health/models/error'
|
8
9
|
require 'change_health/models/model'
|
9
|
-
require 'change_health/models/
|
10
|
-
require 'change_health/models/
|
11
|
-
require 'change_health/models/
|
12
|
-
require 'change_health/models/
|
13
|
-
require 'change_health/models/
|
10
|
+
require 'change_health/models/claim/submission/claim_information'
|
11
|
+
require 'change_health/models/claim/submission/provider'
|
12
|
+
require 'change_health/models/claim/submission/service_line'
|
13
|
+
require 'change_health/models/claim/submission/submitter'
|
14
|
+
require 'change_health/models/claim/submission/subscriber'
|
15
|
+
require 'change_health/models/eligibility/encounter'
|
16
|
+
require 'change_health/models/eligibility/provider'
|
17
|
+
require 'change_health/models/eligibility/subscriber'
|
18
|
+
require 'change_health/models/trading_partner/trading_partner'
|
19
|
+
require 'change_health/request/eligibility'
|
20
|
+
require 'change_health/request/submission'
|
21
|
+
require 'change_health/request/report'
|
14
22
|
require 'change_health/request/trading_partner'
|
15
|
-
require 'change_health/response/
|
16
|
-
require 'change_health/response/
|
17
|
-
require 'change_health/
|
18
|
-
require 'change_health/
|
19
|
-
require 'change_health/
|
23
|
+
require 'change_health/response/response_data'
|
24
|
+
require 'change_health/response/claim/submission/submission_data'
|
25
|
+
require 'change_health/response/claim/report/report_list_data'
|
26
|
+
require 'change_health/response/claim/report/report_data'
|
27
|
+
require 'change_health/response/eligibility/eligibility_benefit'
|
28
|
+
require 'change_health/response/eligibility/eligibility_benefits'
|
29
|
+
require 'change_health/response/eligibility/eligibility_data'
|
30
|
+
require 'change_health/response/trading_partner/trading_partner_data'
|
31
|
+
require 'change_health/response/trading_partner/trading_partners_data'
|
20
32
|
|
21
33
|
module ChangeHealth
|
22
34
|
class Configuration
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: change_health
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Crockett
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -147,18 +147,30 @@ files:
|
|
147
147
|
- lib/change_health/change_health_exception.rb
|
148
148
|
- lib/change_health/connection.rb
|
149
149
|
- lib/change_health/extensions.rb
|
150
|
-
- lib/change_health/models/
|
151
|
-
- lib/change_health/models/
|
152
|
-
- lib/change_health/models/
|
153
|
-
- lib/change_health/models/
|
154
|
-
- lib/change_health/models/
|
150
|
+
- lib/change_health/models/claim/submission/claim_information.rb
|
151
|
+
- lib/change_health/models/claim/submission/provider.rb
|
152
|
+
- lib/change_health/models/claim/submission/service_line.rb
|
153
|
+
- lib/change_health/models/claim/submission/submitter.rb
|
154
|
+
- lib/change_health/models/claim/submission/subscriber.rb
|
155
|
+
- lib/change_health/models/eligibility/encounter.rb
|
156
|
+
- lib/change_health/models/eligibility/provider.rb
|
157
|
+
- lib/change_health/models/eligibility/subscriber.rb
|
158
|
+
- lib/change_health/models/error.rb
|
155
159
|
- lib/change_health/models/model.rb
|
156
|
-
- lib/change_health/models/
|
157
|
-
- lib/change_health/
|
158
|
-
- lib/change_health/
|
160
|
+
- lib/change_health/models/trading_partner/trading_partner.rb
|
161
|
+
- lib/change_health/request/eligibility.rb
|
162
|
+
- lib/change_health/request/report.rb
|
163
|
+
- lib/change_health/request/submission.rb
|
159
164
|
- lib/change_health/request/trading_partner.rb
|
160
|
-
- lib/change_health/response/
|
161
|
-
- lib/change_health/response/
|
165
|
+
- lib/change_health/response/claim/report/report_data.rb
|
166
|
+
- lib/change_health/response/claim/report/report_list_data.rb
|
167
|
+
- lib/change_health/response/claim/submission/submission_data.rb
|
168
|
+
- lib/change_health/response/eligibility/eligibility_benefit.rb
|
169
|
+
- lib/change_health/response/eligibility/eligibility_benefits.rb
|
170
|
+
- lib/change_health/response/eligibility/eligibility_data.rb
|
171
|
+
- lib/change_health/response/response_data.rb
|
172
|
+
- lib/change_health/response/trading_partner/trading_partner_data.rb
|
173
|
+
- lib/change_health/response/trading_partner/trading_partners_data.rb
|
162
174
|
- lib/change_health/version.rb
|
163
175
|
homepage: https://github.com/WeInfuse/change_health
|
164
176
|
licenses:
|
@@ -1,191 +0,0 @@
|
|
1
|
-
module ChangeHealth
|
2
|
-
module Models
|
3
|
-
class Error
|
4
|
-
attr_reader :data
|
5
|
-
|
6
|
-
SIMPLE_RETRY_CODES = %w[
|
7
|
-
42
|
8
|
-
80
|
9
|
-
].freeze
|
10
|
-
|
11
|
-
NO_RESUBMIT_MESSAGES = [
|
12
|
-
'resubmission not allowed',
|
13
|
-
'do not resubmit'
|
14
|
-
].freeze
|
15
|
-
|
16
|
-
DOWN_FIELD = 'Http Header'.freeze
|
17
|
-
|
18
|
-
DOWN_MESSAGE = 'Please review http headers for this API, please contact support if you are unsure how to resolve.'.freeze
|
19
|
-
|
20
|
-
def initialize(data)
|
21
|
-
@data = data
|
22
|
-
end
|
23
|
-
|
24
|
-
def message
|
25
|
-
field_message || code_message
|
26
|
-
end
|
27
|
-
|
28
|
-
def field_message
|
29
|
-
"#{field}: #{description}" if field?
|
30
|
-
end
|
31
|
-
|
32
|
-
def code_message
|
33
|
-
"#{code}: #{description}" if code?
|
34
|
-
end
|
35
|
-
|
36
|
-
def represents_down?
|
37
|
-
field == DOWN_FIELD && description == DOWN_MESSAGE
|
38
|
-
end
|
39
|
-
|
40
|
-
def retryable?
|
41
|
-
represents_down? ||
|
42
|
-
(code? && SIMPLE_RETRY_CODES.include?(code) && followupAction? && NO_RESUBMIT_MESSAGES.none? {|msg| followupAction.downcase.include?(msg) })
|
43
|
-
end
|
44
|
-
|
45
|
-
%w[field description code followupAction location].each do |method_name|
|
46
|
-
define_method("#{method_name}?") do
|
47
|
-
false == send(method_name).nil?
|
48
|
-
end
|
49
|
-
|
50
|
-
define_method("#{method_name}") do
|
51
|
-
@data[method_name]
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
class EligibilityData
|
57
|
-
attr_reader :response, :raw
|
58
|
-
|
59
|
-
ACTIVE = '1'
|
60
|
-
INACTIVE = '6'
|
61
|
-
|
62
|
-
PARSE_DATE = ->(d) {
|
63
|
-
begin
|
64
|
-
d = Date.strptime(d, ChangeHealth::Models::DATE_FORMAT)
|
65
|
-
rescue
|
66
|
-
end
|
67
|
-
|
68
|
-
d
|
69
|
-
}
|
70
|
-
|
71
|
-
def initialize(data: nil, response: nil)
|
72
|
-
@response = response
|
73
|
-
@raw = data
|
74
|
-
|
75
|
-
begin
|
76
|
-
@raw ||= response&.parsed_response
|
77
|
-
rescue JSON::ParserError
|
78
|
-
end
|
79
|
-
|
80
|
-
@raw ||= {}
|
81
|
-
end
|
82
|
-
|
83
|
-
def active?(service_code: '30')
|
84
|
-
plan_status(service_code: service_code, single: false).any? {|status| ACTIVE == status['statusCode'] }
|
85
|
-
end
|
86
|
-
|
87
|
-
def inactive?(service_code: '30')
|
88
|
-
plan_status(service_code: service_code, single: false).any? {|status| INACTIVE == status['statusCode'] }
|
89
|
-
end
|
90
|
-
|
91
|
-
def errors?
|
92
|
-
self.errors.is_a?(Array) && false == self.errors.empty?
|
93
|
-
end
|
94
|
-
|
95
|
-
def errors
|
96
|
-
errors = @raw.dig('errors') || []
|
97
|
-
|
98
|
-
errors.flatten.map {|error| ChangeHealth::Models::Error.new(error) }
|
99
|
-
end
|
100
|
-
|
101
|
-
def recommend_retry?
|
102
|
-
return false unless errors?
|
103
|
-
|
104
|
-
return true if errors.any?(&:represents_down?)
|
105
|
-
|
106
|
-
error_codes = errors.select(&:code?)
|
107
|
-
|
108
|
-
return false if error_codes.empty?
|
109
|
-
|
110
|
-
return error_codes.all?(&:retryable?)
|
111
|
-
end
|
112
|
-
|
113
|
-
def dependents?
|
114
|
-
true == self.dependents&.any?
|
115
|
-
end
|
116
|
-
|
117
|
-
%w(planStatus benefitsInformation controlNumber planDateInformation dependents).each do |v|
|
118
|
-
define_method(v) do
|
119
|
-
@raw.dig(v)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
%w(eligibilityBegin planBegin service).each do |f|
|
124
|
-
define_method(f) do
|
125
|
-
return PARSE_DATE.call(self.date_info&.dig(f))
|
126
|
-
end
|
127
|
-
end
|
128
|
-
alias_method :eligibility_begin_date, :eligibilityBegin
|
129
|
-
alias_method :plan_begin_date, :planBegin
|
130
|
-
alias_method :service_date, :service
|
131
|
-
|
132
|
-
def plan_date_range
|
133
|
-
pd = self.date_info&.dig('plan') || ''
|
134
|
-
pd.split('-')
|
135
|
-
end
|
136
|
-
|
137
|
-
def plan_date_range_start
|
138
|
-
ChangeHealth::Models::EligibilityData::PARSE_DATE.call(self.plan_date_range[0])
|
139
|
-
end
|
140
|
-
|
141
|
-
def plan_date_range_end
|
142
|
-
ChangeHealth::Models::EligibilityData::PARSE_DATE.call(self.plan_date_range[1])
|
143
|
-
end
|
144
|
-
|
145
|
-
def plan_status(service_code: , single: true)
|
146
|
-
if true == single
|
147
|
-
self.planStatus&.find {|plan| plan.dig('serviceTypeCodes')&.include?(service_code) } || {}
|
148
|
-
else
|
149
|
-
self.planStatus&.select {|plan| plan.dig('serviceTypeCodes')&.include?(service_code) } || []
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
def benefits
|
154
|
-
kname = "ChangeHealth::Models::EligibilityBenefits#{self.trading_partner_id&.upcase}"
|
155
|
-
klazz = Object.const_get(kname) if Module.const_defined?(kname)
|
156
|
-
klazz ||= ChangeHealth::Models::EligibilityBenefits
|
157
|
-
|
158
|
-
if klazz.respond_to?(:factory)
|
159
|
-
klazz = klazz.factory(self)
|
160
|
-
end
|
161
|
-
|
162
|
-
klazz.new(self.benefitsInformation || [])
|
163
|
-
end
|
164
|
-
|
165
|
-
def medicare?(**kwargs)
|
166
|
-
false == benefits.empty? && benefits.where(kwargs).all? {|b| b.medicare? }
|
167
|
-
end
|
168
|
-
|
169
|
-
def plan?(name)
|
170
|
-
self.plan_names.any? {|pname| name == pname }
|
171
|
-
end
|
172
|
-
|
173
|
-
def plan_names
|
174
|
-
self.planStatus&.map {|plan_status| plan_status['planDetails'] }&.compact || []
|
175
|
-
end
|
176
|
-
|
177
|
-
def trading_partner?(name)
|
178
|
-
self.trading_partner_id == name
|
179
|
-
end
|
180
|
-
|
181
|
-
def trading_partner_id
|
182
|
-
@raw['tradingPartnerServiceId']
|
183
|
-
end
|
184
|
-
|
185
|
-
alias_method :control_number, :controlNumber
|
186
|
-
alias_method :benefits_information, :benefitsInformation
|
187
|
-
alias_method :plan_statuses, :planStatus
|
188
|
-
alias_method :date_info, :planDateInformation
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module ChangeHealth
|
2
|
-
module Models
|
3
|
-
class Encounter < Model
|
4
|
-
property :beginningDateOfService, from: :beginning_date_of_service, required: false
|
5
|
-
property :dateOfService, from: :date_of_service, required: false
|
6
|
-
property :dateRange, from: :date_range, required: false, default: false
|
7
|
-
property :endDateOfService, from: :end_date_of_service, required: false
|
8
|
-
property :serviceTypeCodes, from: :service_type_codes, required: false
|
9
|
-
|
10
|
-
alias_method :dateRange?, :dateRange
|
11
|
-
alias_method :date_range?, :dateRange
|
12
|
-
alias_method :service_type_codes, :serviceTypeCodes
|
13
|
-
|
14
|
-
def add_service_type_code(code)
|
15
|
-
self[:serviceTypeCodes] ||= []
|
16
|
-
self[:serviceTypeCodes] << code
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|