Skip to content

Instantly share code, notes, and snippets.

@ninjs
Created April 23, 2015 15:09
Show Gist options
  • Save ninjs/11b0f909dd6f7e93b75d to your computer and use it in GitHub Desktop.
Save ninjs/11b0f909dd6f7e93b75d to your computer and use it in GitHub Desktop.
class Claim
attr_accessor :claim_array
def initialize(claim_array, claim_ext)
@claim_array = claim_array
@claim_ext = claim_ext
@replacement_first_name = "JOHN"
@replacement_last_name = "DOE"
@replacement_full_name = "DOE, JOHN"
@replacement_npi = "123456"
@replacement_license_number = "LBAH 5347"
end
def check_existing_name
if @claim_ext == '.ub4'
@claim_array[489].to_s.downcase == 'hansen' && @claim_array[490].to_s.downcase == 'joel'
else
@claim_array[46].to_s.downcase == 'hansen, joel' || @claim_array[46].to_s.downcase == 'hanson, joel dr.'
end
end
def change_claim
set_physician_name
set_npi
if @claim_ext == '.ub4'
set_license_number
end
end
def set_physician_name
if @claim_ext == '.ub4'
@claim_array[489] = @replacement_last_name
@claim_array[490] = @replacement_first_name
else
@claim_array[46] = @replacement_full_name
@claim_array[277] = @replacement_full_name
end
end
def set_npi
if @claim_ext == '.ub4'
@claim_array[491] = @replacement_npi
else
@claim_array[47] = @replacement_npi
@claim_array[85] = @replacement_npi
@claim_array[105] = @replacement_npi
@claim_array[124] = @replacement_npi
@claim_array[143] = @replacement_npi
@claim_array[162] = @replacement_npi
@claim_array[181] = @replacement_npi
end
end
def set_license_number
@claim_array[493] = @replacement_license_number
end
end
def file_operation
dir = Dir.glob("#{__dir__}/**/*.{ub4,npi}")
dir.each do |file|
claim_ext = File.extname(file)
file_name = File.basename(file)
claim_array = File.readlines(file).map(&:chomp)
claim = Claim.new(claim_array, claim_ext)
next unless claim.check_existing_name
claim.change_claim
new_claim_array = claim.claim_array
new_claim_array.each do |line|
line << "\r\n"
end
File.open(file, "w") do |file|
file.puts new_claim_array
end
puts "Changed #{file_name}."
end
puts "Operation Complete"
puts "Press any button to close..."
done_var = gets.strip
end
file_operation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment