Class: ChangeHealth::Response::Claim::Report835Data

Inherits:
ReportData show all
Defined in:
lib/change_health/response/claim/report/report_835_data.rb

Overview

Methods only return meaningful data for json reports

Instance Attribute Summary

Attributes inherited from ReportData

#json, #report_name

Attributes inherited from ResponseData

#raw, #response

Instance Method Summary collapse

Methods inherited from ReportData

#edi?, #initialize, #is_277?, is_277?, is_835?, #is_835?, #presence, report_type, #report_type

Methods inherited from ResponseData

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

Constructor Details

This class inherits a constructor from ChangeHealth::Response::Claim::ReportData

Instance Method Details

#claimsObject



23
24
25
# File 'lib/change_health/response/claim/report/report_835_data.rb', line 23

def claims
  payments.flat_map(&:claims).compact
end

#payer_identificationObject



10
11
12
# File 'lib/change_health/response/claim/report/report_835_data.rb', line 10

def payer_identification
  transactions&.first&.dig('payer', 'payerIdentificationNumber')
end

#payer_nameObject

Only one payer per report



15
16
17
# File 'lib/change_health/response/claim/report/report_835_data.rb', line 15

def payer_name
  transactions&.first&.dig('payer')&.dig('name')
end

#paymentsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/change_health/response/claim/report/report_835_data.rb', line 27

def payments
  report_payments = []

  transactions&.each do |transaction|
    payment_id = transaction.dig('id')
    check_or_eft_trace_number = transaction.dig('paymentAndRemitReassociationDetails', 'checkOrEFTTraceNumber')
    check_issue_or_eft_effective_date =
      ChangeHealth::Models::PARSE_DATE.call(
        transaction.dig('financialInformation', 'checkIssueOrEFTEffectiveDate')
      )
    payer_identifier = transaction.dig('financialInformation', 'payerIdentifier')
    payment_method_code = transaction.dig('financialInformation', 'paymentMethodCode')
    payer_address = transaction.dig('payer', 'address')
    provider_adjustments = transaction['providerAdjustments']&.map do |provider_adjustment|
      adjustments = provider_adjustment['adjustments']&.map do |adjustment|
        {
          amount: adjustment['providerAdjustmentAmount'],
          identifier: adjustment['providerAdjustmentIdentifier'],
          reason_code: adjustment['adjustmentReasonCode']
        }
      end
      Report835ProviderAdjustment.new(
        adjustments: adjustments,
        fiscal_period_date: ChangeHealth::Models::PARSE_DATE.call(provider_adjustment['fiscalPeriodDate']),
        provider_identifier: provider_adjustment['providerIdentifier']
      )
    end

    report_creation_date = ChangeHealth::Models::PARSE_DATE.call(transaction['productionDate'])
    total_actual_provider_payment_amount =
      transaction.dig('financialInformation', 'totalActualProviderPaymentAmount')
    claims = transaction['detailInfo']&.flat_map do |detail_info|
      claim_id = detail_info.dig('id')
      detail_info['paymentInfo']&.map do |payment_info|
        claim_payment_amount = payment_info.dig('claimPaymentInfo', 'claimPaymentAmount')
        claim_status_code = payment_info.dig('claimPaymentInfo', 'claimStatusCode')
        patient_control_number = payment_info.dig('claimPaymentInfo', 'patientControlNumber')
        patient_first_name = payment_info.dig('patientName', 'firstName')
        patient_last_name = payment_info.dig('patientName', 'lastName')
        patient_member_id =
          presence(payment_info.dig('patientName', 'memberId')) ||
          presence(payment_info.dig('subscriber', 'memberId'))
        payer_claim_control_number = payment_info.dig('claimPaymentInfo', 'payerClaimControlNumber')
        service_provider_npi =
          presence(payment_info.dig('renderingProvider', 'npi')) ||
          presence(detail_info.dig('providerSummaryInformation', 'providerIdentifier')) ||
          presence(transaction.dig('payee', 'npi'))
        total_charge_amount = payment_info.dig('claimPaymentInfo', 'totalClaimChargeAmount')

        claim_payment_remark_codes = []
        claim_payment_remark_codes_index = 1

        loop do
          current_claim_payment_remark_code = payment_info
                                              .dig(
                                                'outpatientAdjudication',
                                                "claimPaymentRemarkCode#{claim_payment_remark_codes_index}"
                                              )
          break unless presence(current_claim_payment_remark_code)

          claim_payment_remark_codes << current_claim_payment_remark_code
          claim_payment_remark_codes_index += 1
        end

        claim_adjustments = adjustments(payment_info['claimAdjustments'])

        service_date_begin = nil
        service_date_end = nil
        service_lines = payment_info['serviceLines']&.map do |service_line|
          service_line_date = ChangeHealth::Models::PARSE_DATE.call(service_line['serviceDate'])
          unless service_line_date.nil?
            if service_date_begin.nil? || service_line_date < service_date_begin
              service_date_begin = service_line_date
            end
            if service_date_end.nil? || service_date_end < service_line_date
              service_date_end = service_line_date
            end
          end

          adjudicated_procedure_code = service_line.dig('servicePaymentInformation', 'adjudicatedProcedureCode')
          allowed_actual = service_line.dig('serviceSupplementalAmounts', 'allowedActual')
          line_item_charge_amount = service_line.dig('servicePaymentInformation', 'lineItemChargeAmount')
          line_item_provider_payment_amount = service_line.dig('servicePaymentInformation',
                                                               'lineItemProviderPaymentAmount')

          service_adjustments = adjustments(service_line['serviceAdjustments'])

          health_care_check_remark_codes = presence(service_line['healthCareCheckRemarkCodes']&.filter_map do |health_care_check_remark_code|
            remark_code = health_care_check_remark_code['remarkCode']
            next unless presence(remark_code)

            Report835HealthCareCheckRemarkCode.new(
              code_list_qualifier_code: health_care_check_remark_code['codeListQualifierCode'],
              code_list_qualifier_code_value: health_care_check_remark_code['codeListQualifierCodeValue'],
              remark_code: remark_code
            )
          end)

          Report835ServiceLine.new(
            adjudicated_procedure_code: adjudicated_procedure_code,
            allowed_actual: allowed_actual,
            line_item_charge_amount: line_item_charge_amount,
            line_item_provider_payment_amount: line_item_provider_payment_amount,
            service_adjustments: service_adjustments,
            health_care_check_remark_codes: health_care_check_remark_codes
          )
        end

        if service_date_begin.nil? && service_date_end.nil?
          service_date_begin = ChangeHealth::Models::PARSE_DATE.call(payment_info['claimStatementPeriodStart'])
          service_date_end = ChangeHealth::Models::PARSE_DATE.call(payment_info['claimStatementPeriodEnd'])
        end

        Report835Claim.new(
          claim_adjustments: claim_adjustments,
          claim_payment_amount: claim_payment_amount,
          claim_payment_remark_codes: claim_payment_remark_codes,
          claim_status_code: claim_status_code,
          id: claim_id,
          patient_control_number: patient_control_number,
          patient_first_name: patient_first_name,
          patient_last_name: patient_last_name,
          patient_member_id: patient_member_id,
          payer_claim_control_number: payer_claim_control_number,
          payer_identification: payer_identification,
          payer_name: payer_name,
          report_creation_date: report_creation_date,
          report_name: report_name,
          service_date_begin: service_date_begin,
          service_date_end: service_date_end,
          service_lines: service_lines,
          service_provider_npi: service_provider_npi,
          total_charge_amount: total_charge_amount
        )
      end
    end
    report_payments << Report835Payment.new(
      check_issue_or_eft_effective_date: check_issue_or_eft_effective_date,
      check_or_eft_trace_number: check_or_eft_trace_number,
      claims: claims,
      id: payment_id,
      payer_identifier: payer_identifier,
      payer_name: payer_name,
      payer_address: payer_address,
      payment_method_code: payment_method_code,
      provider_adjustments: provider_adjustments,
      report_creation_date: report_creation_date,
      report_name: report_name,
      total_actual_provider_payment_amount: total_actual_provider_payment_amount
    )
  end

  report_payments
end

#report_creation_dateObject



19
20
21
# File 'lib/change_health/response/claim/report/report_835_data.rb', line 19

def report_creation_date
  payments.map(&:report_creation_date).min
end

#transactionsObject



6
7
8
# File 'lib/change_health/response/claim/report/report_835_data.rb', line 6

def transactions
  @raw['transactions']
end