era_835_parser 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 24ced3bdbddf24e71641f9b339c2892c68a5f15333a0b3f3ed0fd81fc2ede024
4
+ data.tar.gz: 67e81a3c9890bd5bda989b31250d68afb9e8d37748569528d04c56f0f64e1f4b
5
+ SHA512:
6
+ metadata.gz: e5e36bbad1c296bb6f31790bc4ccf58d7a4455377cf22d3908b2bb23c069a5f76fd9e0c1e1b07e9837b22da564c302c40123e5ebcd74109e4a8a2113b082c064
7
+ data.tar.gz: 581d746f8f3cbf3beb1826a7cc7611b0709e51e8e28ee217e6c71efc932e8cbd3790ab537a385230c1a70d0d23c173aa5a77177aee2ca6fe8cdc8664672b9dcb
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .DS_Store
16
+ .vscode/launch.json
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
File without changes
@@ -0,0 +1,22 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
6
+
7
+ Examples of unacceptable behavior by participants include:
8
+
9
+ * The use of sexualized language or imagery
10
+ * Personal attacks
11
+ * Trolling or insulting/derogatory comments
12
+ * Public or private harassment
13
+ * Publishing other's private information, such as physical or electronic addresses, without explicit permission
14
+ * Other unethical or unprofessional conduct
15
+
16
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
17
+
18
+ This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
19
+
20
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
21
+
22
+ This Code of Conduct is adapted from the Contributor Covenant, version 1.2.0, available from http://contributor-covenant.org/version/1/2/0/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+ group :test do
3
+ gem 'simplecov'
4
+ gem 'codeclimate-test-reporter'
5
+ end
6
+ # Specify your gem's dependencies in pragmatic_segmenter.gemspec
7
+ gemspec
@@ -0,0 +1,23 @@
1
+
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2019 Kevin S. Dias
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,108 @@
1
+ # Electronic Remittance Advice (ERA) 835 parser
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/era_835_parser.svg)](http://badge.fury.io/rb/era_835_parser) [![Code Climate](https://codeclimate.com/github/diasks2/era_835_parser/badges/gpa.svg)](https://codeclimate.com/github/diasks2/era_835_parser) [![Build Status](https://travis-ci.org/diasks2/era_835_parser.png)](https://travis-ci.org/diasks2/era_835_parser) [![Test Coverage](https://codeclimate.com/github/diasks2/era_835_parser/badges/coverage.svg)](https://codeclimate.com/github/diasks2/era_835_parser) [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/diasks2/era_835_parser/blob/master/LICENSE.txt)
4
+
5
+ This is a gem to parse ERAs, the electronic equivalent of a paper Explanation of Benefits (EOB). An electronic remittance advice (ERA) is an electronic data interchange (EDI) version of a medical insurance payment explanation. It provides details about providers' claims payment, and if the claims are denied, it would then contain the required explanations.
6
+
7
+ ## Install
8
+
9
+ **Ruby**
10
+ ```
11
+ gem install era_835_parser
12
+ ```
13
+
14
+ **Ruby on Rails**
15
+ Add this line to your application’s Gemfile:
16
+ ```ruby
17
+ gem 'era_835_parser'
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ era = Era835Parser::Parser.new(file_path: '/Desktop/era.txt').parse
24
+
25
+ # The output is grouped by check number with each claim grouped under its respective check
26
+ era[:checks].each do |check_number, check|
27
+ puts check[:check_number] # Check number
28
+ puts check[:amount] # Check amount
29
+ puts check[:number_of_claims] # Number of claims this check covers (integer)
30
+ puts check[:npi_tax_id] # NPI or Tax ID of payee
31
+ puts check[:payee] # Check payee
32
+ puts check[:date] # Check date (string mm/dd/yyyy)
33
+ check[:eras].each do |era_counter, era|
34
+ puts era[:patient_id] # Patient ID
35
+ puts era[:patient_name] # Patient name
36
+ puts era[:patient_last_name] # Patient last name (titlized)
37
+ puts era[:patient_first_name] # Patient first name (titlized)
38
+ puts era[:charge_amount] # Total charge amount (integer)
39
+ puts era[:payment_amount] # Total payment amount (integer)
40
+ puts era[:account_number] # Account number
41
+ puts era[:status] # Status
42
+ puts era[:payer_name] # Payer name
43
+ puts era[:payer_address] # Payer address
44
+ puts era[:payer_city] # Payer city
45
+ puts era[:payer_state] # Payer state
46
+ puts era[:payer_zip_code] # Payer zip code
47
+ puts era[:payer_tax_id] # Payer tax id
48
+ puts era[:payer_claim_control_number] # Payer claim control number
49
+ puts era[:claim_statement_period_start] # Claim statement period start
50
+ puts era[:claim_statement_period_end] # Claim statement period end
51
+ era[:line_items].each do |line_item_counter, line_item|
52
+ puts line_item[:service_date] # Date of service (string mm/dd/yyyy)
53
+ puts line_item[:cpt_code] # CPT code
54
+ puts line_item[:charge_amount] # Charge amount (integer)
55
+ puts line_item[:payment_amount] # Payment amount (integer)
56
+ puts line_item[:total_adjustment_amount] # Total adjustment amount (integer)
57
+ puts line_item[:remarks] # Remarks
58
+ line_item[:adjustment_groups].each do |adjustment_group_counter, adjustment_group|
59
+ puts adjustment_group[:adjustment_group] # Adjustment group
60
+ puts adjustment_group[:adjustment_amount] # Adjustment amount (integer)
61
+ puts adjustment_group[:translated_reason_code] # Translated reason code
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ # View any adjustments
68
+ era[:adjustments].each do |adjustment|
69
+ puts adjustment[:adjustment_date] # Adjustment date (string mm/dd/yyyy)
70
+ puts adjustment[:provider_id] # Provider ID
71
+ puts adjustment[:reference_id] # Reference ID
72
+ puts adjustment[:adjustment_amount] # Adjustment amount (integer)
73
+ puts adjustment[:reason] # reason
74
+ end
75
+
76
+ ```
77
+
78
+ ## Contributing
79
+
80
+ 1. Fork it ( https://github.com/diasks2/era_835_parser/fork )
81
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
82
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
83
+ 4. Push to the branch (`git push origin my-new-feature`)
84
+ 5. Create a new Pull Request
85
+
86
+ ## License
87
+
88
+ The MIT License (MIT)
89
+
90
+ Copyright (c) 2019 Kevin S. Dias
91
+
92
+ Permission is hereby granted, free of charge, to any person obtaining a copy
93
+ of this software and associated documentation files (the "Software"), to deal
94
+ in the Software without restriction, including without limitation the rights
95
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
96
+ copies of the Software, and to permit persons to whom the Software is
97
+ furnished to do so, subject to the following conditions:
98
+
99
+ The above copyright notice and this permission notice shall be included in
100
+ all copies or substantial portions of the Software.
101
+
102
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
103
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
104
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
105
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
106
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
107
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
108
+ THE SOFTWARE.
@@ -0,0 +1,5 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'era_835_parser/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "era_835_parser"
8
+ spec.version = Era835Parser::VERSION
9
+ spec.authors = ["Kevin S. Dias"]
10
+ spec.email = ["diasks2@gmail.com"]
11
+ spec.summary = %q{Electronic Remittance Advice (ERA) 835 parser}
12
+ spec.description = %q{This is a gem to parse ERAs, the electronic equivalent of a paper Explanation of Benefits (EOB). An electronic remittance advice (ERA) is an electronic data interchange (EDI) version of a medical insurance payment explanation. It provides details about providers' claims payment, and if the claims are denied, it would then contain the required explanations.}
13
+ spec.homepage = "https://github.com/diasks2/era_835_parser"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,3 @@
1
+ require "set"
2
+ require "era_835_parser/version"
3
+ require "era_835_parser/parser"
@@ -0,0 +1,237 @@
1
+ require 'open-uri'
2
+
3
+ # Era835Parser::Parser.new(file_path: "../era_835_parser/spec/test_era.txt").parse
4
+ module Era835Parser
5
+ class Parser
6
+ attr_reader :file_path
7
+ def initialize(file_path:)
8
+ @file_path = file_path
9
+ end
10
+
11
+ def parse
12
+ # hash initialization
13
+ era = Hash.new
14
+ checks = Hash.new
15
+ line_items = Hash.new
16
+ adjustment_groups = Hash.new
17
+ adjustments = Hash.new
18
+ individual_era = Hash.new
19
+ individual_line_item = Hash.new
20
+ check_number = ''
21
+
22
+ # counters
23
+ adjustment_counter = 0
24
+
25
+ # trigger variables
26
+ adjustments_start = false
27
+ checks_start = false
28
+ eras_start = false
29
+ next_line_check_number = false
30
+ next_line_address = false
31
+ next_line_city = false
32
+ next_line_tax_id = false
33
+ next_line_payer_claim_control = false
34
+ next_line_claim_statement_period = false
35
+ next_line_line_item = false
36
+ next_line_adjustment_group = false
37
+
38
+ open(file_path).readlines.each do |line|
39
+
40
+ if line !~ /={10,}/i && adjustments_start == true
41
+ adjustment = Hash.new
42
+ adjustment[:adjustment_date] = /\d+\/\d+\/\d+/.match(line)[0].strip if !/\d+\/\d+\/\d+/.match(line).nil?
43
+ adjustment[:provider_id] = /\d+\/\d+\/\d+\s+\d+\s+[^\s]+/.match(line)[0].split(" ")[1].strip if !/\d+\/\d+\/\d+\s+\d+\s+[^\s]+/.match(line).nil?
44
+ adjustment[:reference_id] = /\d+\/\d+\/\d+\s+\d+\s+[^\s]+/.match(line)[0].split(" ")[2].strip if !/\d+\/\d+\/\d+\s+\d+\s+[^\s]+/.match(line).nil?
45
+ adjustment[:adjustment_amount] = (/\d+\/\d+\/\d+\s+\d+\s+[^\s]+\s+[\-\d\.]+/.match(line)[0].split(" ")[3].strip.to_f * 100).to_i if !/\d+\/\d+\/\d+\s+\d+\s+[^\s]+\s+[\-\d\.]+/.match(line).nil?
46
+ adjustment[:reason] = line.gsub(/\d+\/\d+\/\d+\s+\d+\s+[^\s]+\s+[\-\d\.]+/, "").strip
47
+ adjustments[adjustment_counter] = adjustment
48
+ adjustment_counter += 1
49
+ end
50
+
51
+ if line !~ /={10,}/i && checks_start == true && line !~ /^\s+$/ && line !~ /-{10,}/i
52
+ check = Hash.new
53
+ check[:check_number] = /^[^\s]+(?=\s)/.match(line)[0] if !/^[^\s]+(?=\s)/.match(line).nil?
54
+ check[:amount] = (/^[^\s]+\s+\d+\.\d+(?=\s)/.match(line)[0].split(" ")[1].strip.to_f * 100).to_i if !/^[^\s]+\s+\d+\.\d+(?=\s)/.match(line).nil?
55
+ check[:number_of_claims] = /^[^\s]+\s+\d+\.\d+\s+\d+(?=\s)/.match(line)[0].split(" ")[2].strip.to_i if !/^[^\s]+\s+\d+\.\d+\s+\d+(?=\s)/.match(line).nil?
56
+ check[:npi_tax_id] = /^[^\s]+\s+\d+\.\d+\s+\d+\s+[^\s]+/.match(line)[0].split(" ")[3].strip if !/^[^\s]+\s+\d+\.\d+\s+\d+\s+[^\s]+/.match(line).nil?
57
+ check[:date] = /\d+\/\d+\/\d+/.match(line)[0] if !/\d+\/\d+\/\d+/.match(line).nil?
58
+ check[:payee] = line.gsub(check[:check_number].to_s, "").gsub(check[:npi_tax_id].to_s, "").gsub(check[:amount].to_s, "").gsub(/\d/, "").gsub(/\./, "").gsub(/\//, "").strip
59
+ checks[check[:check_number]] = check
60
+ end
61
+
62
+ if next_line_line_item
63
+ individual_line_item = Hash.new
64
+ adjustment_groups = Hash.new
65
+ end
66
+
67
+ if line.include?("Line Item:") || line =~ /-{10,}/i || line =~ /^\s+$/
68
+ next_line_adjustment_group = false
69
+ end
70
+
71
+ if next_line_adjustment_group &&
72
+ individual_adjustment_group_item = Hash.new
73
+ individual_adjustment_group_item[:adjustment_group] = /.+\s+\-?\d+\.\d+/.match(line)[0].strip.split(/\s+\-?\d+/)[0].strip if !/.+\s+\-?\d+\.\d+/.match(line).nil?
74
+ individual_adjustment_group_item[:adjustment_amount] = (/\-?\d+\.\d+/.match(line)[0].strip.to_f * 100).to_i if !/\-?\d+\.\d+/.match(line).nil?
75
+ individual_adjustment_group_item[:translated_reason_code] = /\-?\d+\.\d+\s+.+/.match(line)[0].strip.split(/(?:\d)\s/)[1].strip if !/\-?\d+\.\d+\s+.+/.match(line).nil?
76
+ if adjustment_groups.nil?
77
+ adjustment_groups[0] = individual_adjustment_group_item
78
+ else
79
+ adjustment_groups[adjustment_groups.count] = individual_adjustment_group_item
80
+ end
81
+ individual_line_item[:adjustment_groups] = adjustment_groups
82
+ end
83
+
84
+ if line.include?("Adjustment Group")
85
+ next_line_adjustment_group = true
86
+ end
87
+
88
+ if next_line_line_item
89
+ individual_line_item[:service_date] = /\d+\/\d+\/\d+/.match(line)[0].strip if !/\d+\/\d+\/\d+/.match(line).nil?
90
+ individual_line_item[:cpt_code] = /\d+\/\d+\/\d+\s\d+/.match(line)[0].strip.split(" ")[1] if !/\d+\/\d+\/\d+\s\d+/.match(line).nil?
91
+ individual_line_item[:charge_amount] = (/\d+\/\d+\/\d+\s\d+\s+\-?\d+\.\d+/.match(line)[0].strip.split(" ")[2].to_f * 100).to_i if !/\d+\/\d+\/\d+\s\d+\s+\-?\d+\.\d+/.match(line).nil?
92
+ individual_line_item[:payment_amount] = (/\d+\/\d+\/\d+\s\d+\s+\-?\d+\.\d+\s+\-?\d+\.\d+/.match(line)[0].strip.split(" ")[3].to_f * 100).to_i if !/\d+\/\d+\/\d+\s\d+\s+\-?\d+\.\d+\s+\-?\d+\.\d+/.match(line).nil?
93
+ individual_line_item[:total_adjustment_amount] = (/\d+\/\d+\/\d+\s\d+\s+\-?\d+\.\d+\s+\-?\d+\.\d+\s+\-?\d+\.\d+/.match(line)[0].strip.split(" ")[4].to_f * 100).to_i if !/\d+\/\d+\/\d+\s\d+\s+\-?\d+\.\d+\s+\-?\d+\.\d+\s+\-?\d+\.\d+/.match(line).nil?
94
+ individual_line_item[:remarks] = line.gsub(/\d+\/\d+\/\d+\s\d+\s+\-?\d+\.\d+\s+\-?\d+\.\d+\s+\-?\d+\.\d+/, "").strip if !/\d+\/\d+\/\d+\s\d+\s+\-?\d+\.\d+\s+\-?\d+\.\d+\s+\-?\d+\.\d+/.match(line).nil?
95
+ if line_items.nil?
96
+ line_items[0] = individual_line_item
97
+ else
98
+ line_items[line_items.count] = individual_line_item
99
+ end
100
+ next_line_line_item = false
101
+ end
102
+
103
+ if line.include?("Line Item:")
104
+ next_line_line_item = true
105
+ end
106
+
107
+ if next_line_claim_statement_period && line.include?("Claim Statement Period")
108
+ individual_era[:claim_statement_period_start] = line.gsub("Claim Statement Period:", "").strip.split("-")[0].strip
109
+ individual_era[:claim_statement_period_end] = line.gsub("Claim Statement Period:", "").strip.split("-")[1].strip
110
+ next_line_claim_statement_period = false
111
+ elsif next_line_claim_statement_period
112
+ next_line_claim_statement_period = false
113
+ end
114
+
115
+ if next_line_payer_claim_control && line.include?("Payer Claim Control Number")
116
+ individual_era[:payer_claim_control_number] = line.gsub("Payer Claim Control Number:", "").strip
117
+ next_line_payer_claim_control = false
118
+ next_line_claim_statement_period = true
119
+ elsif next_line_payer_claim_control
120
+ next_line_payer_claim_control = false
121
+ next_line_claim_statement_period = true
122
+ end
123
+
124
+ if next_line_tax_id && line.include?("Tax ID")
125
+ individual_era[:payer_tax_id] = line.gsub("Tax ID:", "").strip
126
+ next_line_tax_id = false
127
+ next_line_payer_claim_control = true
128
+ elsif next_line_tax_id
129
+ next_line_tax_id = false
130
+ next_line_payer_claim_control = true
131
+ end
132
+
133
+ if next_line_city
134
+ individual_era[:payer_city] = line.strip.split(",")[0].strip
135
+ individual_era[:payer_state] = line.strip.split(",")[1].split(" ")[0].strip
136
+ individual_era[:payer_zip_code] = line.strip.split(",")[1].split(" ")[1].strip
137
+ next_line_city = false
138
+ next_line_tax_id = true
139
+ end
140
+
141
+ if next_line_address
142
+ individual_era[:payer_address] = line.strip
143
+ next_line_address = false
144
+ next_line_city = true
145
+ end
146
+
147
+ if next_line_check_number
148
+ check_number = /^[^\s]+(?=\s)/.match(line)[0].strip if !/^[^\s]+(?=\s)/.match(line).nil?
149
+ next_line_check_number = false
150
+ individual_era[:patient_id] = /^[^\s]+(?=\s)\s+[^\s]+/.match(line)[0].strip.split(" ")[1] if !/^[^\s]+(?=\s)\s+[^\s]+/.match(line).nil?
151
+ individual_era[:patient_name] = /\s\D*,\D*\s/.match(line)[0].strip if !/\s\D*,\D*\s/.match(line).nil?
152
+ individual_era[:patient_last_name] = individual_era[:patient_name].split(",")[0].downcase.split(" ").map { |word| word.capitalize }.join(" ")
153
+ individual_era[:patient_first_name] = individual_era[:patient_name].split(",")[1].downcase.split(" ").map { |word| word.capitalize }.join(" ")
154
+ individual_era[:charge_amount] = (/,\D+\d+\.\d+\s/.match(line)[0].gsub(/[a-zA-Z,]/, "").strip.to_f * 100).to_i if !/,\D+\d+\.\d+\s/.match(line).nil?
155
+ individual_era[:payment_amount] = (/\.\d+\s+\-?\d+\.\d+\s/.match(line)[0].strip.split(" ")[1].strip.to_f * 100).to_i if !/\.\d+\s+\-?\d+\.\d+\s/.match(line).nil?
156
+ individual_era[:account_number] = /\.\d+\s+\-?\d+\.\d+\s+[A-Z\d]+\s/.match(line)[0].strip.split(" ")[2] if !/\.\d+\s+\-?\d+\.\d+\s+[A-Z\d]+\s/.match(line).nil?
157
+ if !/PROCESSED AS PRIMARY\s+.+$/.match(line).nil? && !/^[^\s]+(?=\s)/.match(line).nil?
158
+ individual_era[:status] = "PROCESSED AS PRIMARY"
159
+ individual_era[:payer_name] = /PROCESSED AS PRIMARY\s+.+$/.match(line)[0].gsub("PROCESSED AS PRIMARY", "").strip
160
+ elsif !/PROCESSED AS PRIMARY,\sFWDED\s+.+$/.match(line).nil? && !/^[^\s]+(?=\s)/.match(line).nil?
161
+ individual_era[:status] = "PROCESSED AS PRIMARY, FWDED"
162
+ individual_era[:payer_name] = /PROCESSED AS PRIMARY,\sFWDED\s+.+$/.match(line)[0].gsub("PROCESSED AS PRIMARY, FWDED", "").strip
163
+ elsif !/PROCESSED AS SECONDARY\s+.+$/.match(line).nil? && !/^[^\s]+(?=\s)/.match(line).nil?
164
+ individual_era[:status] = "PROCESSED AS SECONDARY"
165
+ individual_era[:payer_name] = /PROCESSED AS SECONDARY\s+.+$/.match(line)[0].gsub("PROCESSED AS SECONDARY", "").strip
166
+ elsif !/DENIED\s+.+$/.match(line).nil? && !/^[^\s]+(?=\s)/.match(line).nil?
167
+ individual_era[:status] = "DENIED"
168
+ individual_era[:payer_name] = /DENIED\s+.+$/.match(line)[0].gsub("DENIED", "").strip
169
+ elsif !/OTHER\s+.+$/.match(line).nil? && !/^[^\s]+(?=\s)/.match(line).nil?
170
+ individual_era[:status] = "OTHER"
171
+ individual_era[:payer_name] = /OTHER\s+.+$/.match(line)[0].gsub("OTHER", "").strip
172
+ end
173
+ next_line_address = true
174
+ end
175
+
176
+ if line.include?("Check#") && line.include?("Patient ID")
177
+ next_line_check_number = true
178
+ individual_era = Hash.new
179
+ line_items = Hash.new
180
+ end
181
+
182
+ if eras_start == true && !line.include?("Check#")
183
+ if line =~ /-{10,}/i
184
+ if era[:checks][check_number][:eras].nil?
185
+ era_counter = 0
186
+ eras = Hash.new
187
+ individual_era[:line_items] = line_items
188
+ eras[era_counter] = individual_era
189
+ era[:checks][check_number][:eras] = eras
190
+ else
191
+ era_counter = era[:checks][check_number][:eras].count
192
+ eras = Hash.new
193
+ individual_era[:line_items] = line_items
194
+ eras[era_counter] = individual_era
195
+ era[:checks][check_number][:eras] = era[:checks][check_number][:eras].merge(eras)
196
+ end
197
+ end
198
+ end
199
+
200
+ if line.include?("Adjustment Date")
201
+ adjustments_start = true
202
+ end
203
+
204
+ if line.include?("Check#") && line.include?("# Claims")
205
+ checks_start = true
206
+ end
207
+
208
+ if line =~ /={10,}/i && adjustments_start == true && adjustments != {}
209
+ adjustments_start = false
210
+ end
211
+
212
+ if line =~ /-{10,}/i && checks_start == true && checks != {}
213
+ checks_start = false
214
+ era[:adjustments] = adjustments
215
+ era[:checks] = checks
216
+ eras_start = true
217
+ end
218
+ end
219
+
220
+ if era[:checks][check_number][:eras].nil?
221
+ era_counter = 0
222
+ eras = Hash.new
223
+ individual_era[:line_items] = line_items
224
+ eras[era_counter] = individual_era
225
+ era[:checks][check_number][:eras] = eras
226
+ else
227
+ era_counter = era[:checks][check_number][:eras].count
228
+ eras = Hash.new
229
+ individual_era[:line_items] = line_items
230
+ eras[era_counter] = individual_era
231
+ era[:checks][check_number][:eras] = era[:checks][check_number][:eras].merge(eras)
232
+ end
233
+
234
+ return era
235
+ end
236
+ end
237
+ end