Class: ChangeHealth::Request::Claim::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/change_health/request/report.rb

Constant Summary collapse

ENDPOINT =
'/medicalnetwork/reports/v2'.freeze
HEALTH_CHECK_ENDPOINT =
ENDPOINT + '/healthcheck'.freeze

Class Method Summary collapse

Class Method Details

.delete_report(report_name, headers: nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/change_health/request/report.rb', line 51

def self.delete_report(report_name, headers: nil)
  return if report_name.nil? || report_name.empty?

  final_headers = ChangeHealth::Request::Claim::Report.report_headers(headers)

  individual_report_endpoint = "#{ENDPOINT}/#{report_name}"

  ChangeHealth::Connection.new.request(
    endpoint: individual_report_endpoint,
    verb: :delete,
    headers: final_headers
  )
end

.get_report(report_name, as_json_report: true, headers: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/change_health/request/report.rb', line 15

def self.get_report(report_name, as_json_report: true, headers: nil)
  return if report_name.nil? || report_name.empty?

  final_headers = ChangeHealth::Request::Claim::Report.report_headers(headers)

  individual_report_endpoint = "#{ENDPOINT}/#{report_name}"

  # https://developers.changehealthcare.com/eligibilityandclaims/docs/what-file-types-does-this-api-get-from-the-mailbox
  if as_json_report
    report_type = ChangeHealth::Response::Claim::ReportData.report_type(report_name)
    individual_report_endpoint += "/#{report_type}"
  end

  response = ChangeHealth::Connection.new.request(
    endpoint: individual_report_endpoint,
    verb: :get,
    headers: final_headers
  )
  if ChangeHealth::Response::Claim::ReportData.is_277?(report_name)
    ChangeHealth::Response::Claim::Report277Data
      .new(report_name,
           as_json_report,
           response: response)
  elsif ChangeHealth::Response::Claim::ReportData.is_835?(report_name)
    ChangeHealth::Response::Claim::Report835Data
      .new(report_name,
           as_json_report,
           response: response)
  else
    ChangeHealth::Response::Claim::ReportData
      .new(report_name,
           as_json_report,
           response: response)
  end
end

.health_checkObject



65
66
67
# File 'lib/change_health/request/report.rb', line 65

def self.health_check
  ChangeHealth::Connection.new.request(endpoint: HEALTH_CHECK_ENDPOINT, verb: :get)
end

.pingObject



69
70
71
# File 'lib/change_health/request/report.rb', line 69

def self.ping
  health_check
end

.report_headers(headers) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/change_health/request/report.rb', line 73

def self.report_headers(headers)
  return unless headers

  extra_headers = {}
  extra_headers['X-CHC-Reports-Username'] = headers[:username]
  extra_headers['X-CHC-Reports-Password'] = headers[:password]
  extra_headers
end

.report_list(headers: nil) ⇒ Object



8
9
10
11
12
13
# File 'lib/change_health/request/report.rb', line 8

def self.report_list(headers: nil)
  final_headers = ChangeHealth::Request::Claim::Report.report_headers(headers)
  ChangeHealth::Response::Claim::ReportListData.new(response: ChangeHealth::Connection.new.request(
    endpoint: ENDPOINT, verb: :get, headers: final_headers
  ))
end