Last active
August 29, 2015 14:19
-
-
Save ninjs/d89fafbba356a45d2fc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spreadsheet' | |
def help | |
print " | |
You must pass in the path to the file to launch. | |
Usage: ruby #{__FILE__} path/to/target_file | |
" | |
end | |
class Claim | |
@@no_of_claims = 0 | |
def initialize(claim_array, claim_ext) | |
@payor = payor_name(claim_array, claim_ext).to_s | |
@patient = patient_name(claim_array, claim_ext).to_s | |
@total = get_total(claim_array, claim_ext).to_s | |
@date_range = get_range(claim_array, claim_ext).to_s | |
@sent_date = get_sent_date(claim_array, claim_ext).to_s | |
@comments = get_comments(claim_array, claim_ext).to_s | |
@loc = get_loc(claim_array, claim_ext).to_s | |
@units = get_units(claim_array, claim_ext).to_s | |
@@no_of_claims += 1 | |
end | |
def show | |
print "(#@@no_of_claims)" + @payor + ' - ' + @patient + ' - ' + @total + ' - ' + @date_range + ' - ' + @sent_date + ' - ' + @comments + ' - ' + @loc + ' - ' + @units | |
end | |
end | |
def payor_name(claim_array, claim_ext) | |
if claim_ext == '.ub4' | |
claim_array[92] | |
else | |
#something else | |
end | |
end | |
def patient_name(claim_array, claim_ext) | |
if claim_ext == '.ub4' | |
full_name = claim_array[429] | |
first_name = full_name.split(/, /)[1].capitalize | |
last_name = full_name.split(/, /)[0].capitalize | |
first_name + ' ' + last_name | |
else | |
#something else | |
end | |
end | |
def get_total(claim_array, claim_ext) | |
if claim_ext == '.ub4' | |
claim_array[146] + '.' + claim_array[145] | |
else | |
#something else | |
end | |
end | |
def get_range(claim_array, claim_ext) | |
if claim_ext == '.ub4' | |
claim_array[4] + '-' + claim_array[5] | |
else | |
#something else | |
end | |
end | |
def get_sent_date(claim_array, claim_ext) | |
if claim_ext == '.ub4' | |
claim_array[148] | |
else | |
#something else | |
end | |
end | |
def get_comments(claim_array, claim_ext) | |
if claim_ext == '.ub4' | |
"Sent on " + claim_array[148] | |
else | |
#something else | |
end | |
end | |
def get_loc(claim_array, claim_ext) | |
if claim_ext == '.ub4' | |
rev_hash = {"0116" => "DTX", "0126" => "DTX", "1002" => "RTC", "1001" => "RTC", "0913" => "PHP", "0912" => "PHP", "0906" => "IOP", "0905" => "IOP", "0915" => "GOP", "9014" => "GOP", "0300" => "POC"} | |
rev_code = claim_array[421] | |
rev_hash.fetch(rev_code, "unknown") | |
else | |
#something else | |
end | |
end | |
def get_units(claim_array, claim_ext) | |
if claim_ext == '.ub4' | |
rev_code_array = claim_array[421], claim_array[111], claim_array[112], claim_array[131], claim_array[152], claim_array[171], claim_array[172], claim_array[191], claim_array[192], claim_array[211], claim_array[212], claim_array[231], claim_array[232], claim_array[251], claim_array[252], claim_array[271], claim_array[272], claim_array[291], claim_array[292], | |
claim_array[311], claim_array[312], claim_array[132] | |
clean_code_array = rev_code_array.reject(&:empty?) | |
clean_code_array.count | |
else | |
#something else | |
end | |
end | |
def file_operation | |
dir = Dir.open(__dir__) | |
newbook = Spreadsheet::Workbook.new | |
newsheet1 = newbook.create_worksheet | |
dir.each do |file| | |
claim_ext = File.extname(file) | |
if claim_ext != '.ub4' | |
next | |
# next if claim_ext != '.npi' | |
end | |
claim_array = File.readlines(file).map(&:chomp) | |
claim = Claim.new(claim_array, claim_ext) | |
claim.show | |
end | |
# newbook.write('output.xls') | |
end | |
if ARGV == 'help' | |
help | |
exit | |
else | |
file_operation | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment