Skip to content

Instantly share code, notes, and snippets.

@ninjs
Created April 15, 2015 21:18
Show Gist options
  • Save ninjs/0daf97629d7a87a2d063 to your computer and use it in GitHub Desktop.
Save ninjs/0daf97629d7a87a2d063 to your computer and use it in GitHub Desktop.
def file_operation
dir = Dir.open(__dir__)
newbook = Spreadsheet::Workbook.new
newsheet1 = newbook.create_worksheet
dir.each do |file|
if File.extname(file) != '.ub4'
next if File.extname(file) != '.npi'
end
claim_array = File.readlines(file).map(&:chomp)
if File.extname(file) == '.ub4'
ub04 claim_array
else
next
# elsif File.extname(file) == '.npi'
# hcfa claim_array
end
end
newbook.write('output.xls')
end
def ub04 claim_array
# Column 3 (Payor Name)
# col_3 = row[104].split(/,/)[0]
col_3 = claim_array[92]
# Column 4 (Patient Name)
# col_4 = row[9].split(/, /)[1].capitalize + " " + row[9].split(/, /)[0].capitalize
full_name = claim_array[429]
first_name = full_name.split(/, /)[1].capitalize
last_name = full_name.split(/, /)[0].capitalize
col_4 = first_name + ' ' + last_name
# Column 6 (Total)
# col_6 = row[102]
col_6 = claim_array[146] + '.' + claim_array[145]
# Column 9 (Date From - Date To)
# col_9 = row[6] + '-' + row[7]
col_9 = claim_array[4] + '-' + claim_array[5]
# Column 10 (Created Date)
# col_10 = row[101]
col_10 = claim_array[148]
# Column 14 (Created Date again)
col_14 = "Sent on " + col_10
# Column 16 (Level of Care [rev code])
rev_code = claim_array[421]
if rev_code == '0116'
col_16 = 'DTX'
elsif rev_code == '0126'
col_16 = 'DTX'
elsif rev_code == '1002'
col_16 = 'RTC'
elsif rev_code == '1001'
col_16 = 'RTC'
elsif rev_code == '0913'
col_16 = 'PHP'
elsif rev_code == '0912'
col_16 = 'PHP'
elsif rev_code == '0906'
col_16 = 'IOP'
elsif rev_code == '0905'
col_16 = 'IOP'
elsif rev_code == '0915'
col_16 = 'GOP'
elsif rev_code == '0914'
col_16 = 'GOP'
elsif rev_code == '0300'
col_16 = 'POC'
else
col_16 = 'unknown code'
end
# Column 17 (Number of Units)
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]
clearn_code_array = rev_code_array.reject(&:empty?)
col_17 = clean_code_array.count
# set all values
newsheet1.row(index)[2] = col_3
newsheet1.row(index)[3] = col_4
newsheet1.row(index)[5] = col_6
newsheet1.row(index)[8] = col_9
newsheet1.row(index)[9] = col_10
newsheet1.row(index)[13] = col_14
newsheet1.row(index)[15] = col_16
newsheet1.row(index)[16] = col_17
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