Created
April 16, 2015 17:46
-
-
Save ninjs/9c1620e835def20e0526 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' | |
class Claim | |
@@no_of_claims = 0 | |
attr_accessor :payor | |
attr_accessor :patient | |
attr_accessor :total | |
attr_accessor :date_range | |
attr_accessor :sent_date | |
attr_accessor :comments | |
attr_accessor :loc | |
attr_accessor :units | |
attr_accessor :number | |
def initialize(claim_array, claim_ext) | |
@payor = payor_name(claim_array, claim_ext) | |
@patient = patient_name(claim_array, claim_ext) | |
@total = get_total(claim_array, claim_ext).to_s | |
@date_range = get_range(claim_array, claim_ext) | |
@sent_date = get_sent_date(claim_array, claim_ext) | |
@comments = get_comments(claim_array, claim_ext) | |
@loc = get_loc(claim_array, claim_ext) | |
@units = get_units(claim_array, claim_ext) | |
@@no_of_claims += 1 | |
@number = @@no_of_claims | |
end | |
def show | |
print "(#@number)" + @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 | |
claim_array[198] | |
end | |
end | |
def patient_name(claim_array, claim_ext) | |
if claim_ext == '.ub4' | |
full_name = claim_array[429] | |
else | |
full_name = claim_array[0] | |
end | |
first_name = full_name.split(/, /)[1].capitalize | |
last_name = full_name.split(/, /)[0].capitalize | |
first_name + ' ' + last_name | |
end | |
def get_total(claim_array, claim_ext) | |
if claim_ext == '.ub4' | |
claim_array[146] + '.' + claim_array[145] | |
else | |
claim_array[184] + '.' + claim_array[185] | |
end | |
end | |
def get_range(claim_array, claim_ext) | |
if claim_ext == '.ub4' | |
claim_array[4] + '-' + claim_array[5] | |
else | |
first_date = claim_array[68] + '/' + claim_array[69] + '/' + claim_array[70] | |
second_date = claim_array[87] + '/' + claim_array[88] + '/' + claim_array[89] | |
third_date = claim_array[106] + '/' + claim_array[107] + '/' + claim_array[108] | |
fourth_date = claim_array[125] + '/' + claim_array[126] + '/' + claim_array[127] | |
fifth_date = claim_array[144] + '/' + claim_array[145] + '/' + claim_array[146] | |
sixth_date = claim_array[163] + '/' + claim_array[164] + '/' + claim_array[165] | |
date_array = first_date, second_date, third_date, fourth_date, fifth_date, sixth_date | |
clean_date_array = date_array.delete_if {|obj| obj == "//"} | |
date_array.min + '-' + date_array.max | |
end | |
end | |
def get_sent_date(claim_array, claim_ext) | |
if claim_ext == '.ub4' | |
claim_array[148] | |
else | |
claim_array[191] | |
end | |
end | |
def get_comments(claim_array, claim_ext) | |
if claim_ext == '.ub4' | |
"Sent on " + claim_array[148] | |
else | |
"Sent on " + claim_array[191] | |
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] | |
else | |
rev_hash = {'90853' => 'GOP', '90837' => 'GOP', '90834' => 'GOP', '90832' => 'GOP', '80301' => 'POC', '99205' => 'MM', '99204' => 'MM', '99215' => 'MM', '99214' => 'MM', '99213' => 'MM', 'J2315' => 'VIV', '96372' => 'VIV', '80365' => 'HCT', '80346' => 'HCT', '80353' => 'HCT', '80371' => 'HCT', '99220' => 'EVAL', '99225' => 'EVAL'} | |
rev_code = claim_array[79] | |
end | |
rev_hash.fetch(rev_code, "unknown") | |
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 | |
rev_hash = {'90853' => 'GOP', '90837' => 'GOP', '90834' => 'GOP', '90832' => 'GOP', '80301' => 'POC', '99205' => 'MM', '99204' => 'MM', '99215' => 'MM', '99214' => 'MM', '99213' => 'MM', 'J2315' => 'VIV', '96372' => 'VIV', '80365' => 'HCT', '80346' => 'HCT', '80353' => 'HCT', '80371' => 'HCT', '99220' => 'EVAL', '99225' => 'EVAL'} | |
rev_code = claim_array[79] | |
loc_code = rev_hash.fetch(rev_code, "unknown") | |
if loc_code == 'HCT' | |
1 | |
else | |
rev_code_array = claim_array[79], claim_array[95], claim_array[114], claim_array[133], claim_array[152], claim_array[171] | |
clean_code_array = rev_code_array.reject(&:empty?) | |
clean_code_array.count | |
end | |
end | |
end | |
def file_operation | |
dir = Dir.open(__dir__) | |
claims = [] | |
newbook = Spreadsheet::Workbook.new | |
newsheet1 = newbook.create_worksheet | |
dir.each do |file| | |
claim_ext = File.extname(file) | |
if claim_ext != '.ub4' | |
next if claim_ext != '.npi' | |
end | |
claim_array = File.readlines(file).map(&:chomp) | |
claim = Claim.new(claim_array, claim_ext) | |
claims << claim | |
end | |
claims.sort_by!{ |c| c.date_range } | |
claims.each_with_index { |claim, index| | |
newsheet1.row(index)[2] = claim.payor | |
newsheet1.row(index)[3] = claim.patient | |
newsheet1.row(index)[5] = claim.total | |
newsheet1.row(index)[8] = claim.date_range | |
newsheet1.row(index)[9] = claim.sent_date | |
newsheet1.row(index)[13] = claim.comments | |
newsheet1.row(index)[15] = claim.loc | |
newsheet1.row(index)[16] = claim.units | |
} | |
newbook.write('output.xls') | |
end | |
def file_move | |
dir = Dir.open(__dir__) | |
dir.each do |file| | |
if File.extname(file) != '.ub4' | |
next if File.extname(file) != '.npi' | |
end | |
file_base = File.basename(file) | |
full_name = file_base.split(/ /)[0..1].join(' ') | |
parent_full_name = '../' + full_name | |
new_file_path = parent_full_name + '/' + file_base | |
FileUtils.mkdir_p(parent_full_name) | |
FileUtils.mv(file, new_file_path) | |
end | |
end | |
file_operation | |
file_move |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment