Class: ChangeHealth::Response::EligibilityData

Inherits:
ResponseData
  • Object
show all
Defined in:
lib/change_health/response/eligibility/eligibility_data.rb

Constant Summary collapse

ACTIVE =
'1'
INACTIVE =
'6'

Instance Attribute Summary

Attributes inherited from ResponseData

#raw, #response

Instance Method Summary collapse

Methods inherited from ResponseData

#errors, #errors?, #initialize, #recommend_retry?, #server_error

Constructor Details

This class inherits a constructor from ChangeHealth::Response::ResponseData

Instance Method Details

#active?(service_code: '30') ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/change_health/response/eligibility/eligibility_data.rb', line 8

def active?(service_code: '30')
  plan_status(service_code: service_code, single: false).any? {|status| ACTIVE == status['statusCode'] }
end

#benefitsObject



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/change_health/response/eligibility/eligibility_data.rb', line 56

def benefits
  kname   = "ChangeHealth::Response::EligibilityBenefits#{self.trading_partner_id&.upcase}"
  klazz   = Object.const_get(kname) if Module.const_defined?(kname)
  klazz ||= ChangeHealth::Response::EligibilityBenefits

  if klazz.respond_to?(:factory)
    klazz = klazz.factory(self)
  end

  klazz.new(self.benefitsInformation || [])
end

#dependents?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/change_health/response/eligibility/eligibility_data.rb', line 16

def dependents?
  true == self.dependents&.any?
end

#inactive?(service_code: '30') ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/change_health/response/eligibility/eligibility_data.rb', line 12

def inactive?(service_code: '30')
  plan_status(service_code: service_code, single: false).any? {|status| INACTIVE == status['statusCode'] }
end

#medicare?(**kwargs) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/change_health/response/eligibility/eligibility_data.rb', line 68

def medicare?(**kwargs)
  false == benefits.empty? && benefits.where(**kwargs).all? {|b| b.medicare? }
end

#plan?(name) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/change_health/response/eligibility/eligibility_data.rb', line 72

def plan?(name)
  self.plan_names.any? {|pname| name == pname }
end

#plan_date_rangeObject



35
36
37
38
# File 'lib/change_health/response/eligibility/eligibility_data.rb', line 35

def plan_date_range
  pd = self.date_info&.dig('plan') || ''
  pd.split('-')
end

#plan_date_range_endObject



44
45
46
# File 'lib/change_health/response/eligibility/eligibility_data.rb', line 44

def plan_date_range_end
  ChangeHealth::Models::PARSE_DATE.call(self.plan_date_range[1])
end

#plan_date_range_startObject



40
41
42
# File 'lib/change_health/response/eligibility/eligibility_data.rb', line 40

def plan_date_range_start
  ChangeHealth::Models::PARSE_DATE.call(self.plan_date_range[0])
end

#plan_namesObject



76
77
78
# File 'lib/change_health/response/eligibility/eligibility_data.rb', line 76

def plan_names
  self.planStatus&.map {|plan_status| plan_status['planDetails'] }&.compact || []
end

#plan_status(service_code:, single: true) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/change_health/response/eligibility/eligibility_data.rb', line 48

def plan_status(service_code: , single: true)
  if true == single
    self.planStatus&.find {|plan| plan.dig('serviceTypeCodes')&.include?(service_code) } || {}
  else
    self.planStatus&.select {|plan| plan.dig('serviceTypeCodes')&.include?(service_code) } || []
  end
end

#trading_partner?(name) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/change_health/response/eligibility/eligibility_data.rb', line 80

def trading_partner?(name)
  self.trading_partner_id == name
end

#trading_partner_idObject



84
85
86
# File 'lib/change_health/response/eligibility/eligibility_data.rb', line 84

def trading_partner_id
  @raw['tradingPartnerServiceId']
end