module Sunnyside
definitely a work in progress.
Constants
- DB
- DRIVE
- PRIVATE_CLIENTS
- VERSION
Public Class Methods
access_ftp()
click to toggle source
# File lib/sunnyside/ftp.rb, line 5 def self.access_ftp Login.all.each do |login| access = SunnyFTP.new(site: login.site, username: login.username, password: login.password, provider: login.provider) access.log_on puts "Logged into #{access.name}..." access.check_for_new_files end end
add_denial_data()
click to toggle source
# File lib/sunnyside/models/db_setup.rb, line 143 def add_denial_data # CSV.foreach('examples/denial_data.csv', 'r') { |row| DB[:denials].insert(denial_code: row[0], denial_explanation: row[1]) } end
add_provider_to_ftp()
click to toggle source
# File lib/sunnyside/advanced.rb, line 52 def self.add_provider_to_ftp Provider.all.each { |prov| puts "#{prov.id}: #{prov.name}"} print "Type in the corresponding ID Number for the provider you would like to add to FTP: " provider = Provider[gets.chomp].abbreviation puts "You've selected #{provider}" print "Type in the ftp address now: " site = gets.chomp print "Type in the username now: " username = gets.chomp print "Type in the password now: " password = gets.chomp review = "-------Provider: #{provider}, Site: #{site}, Username: #{username}, Password: #{password}--------------" puts "Please review the following information: " puts '-' * review.length puts review puts '-' * review.length puts "Is this correct? Type Y or N." if gets.chomp.downcase == 'y' Login.insert(site: site, username: username, password: password, provider: provider) Dir.mkdir("#{DRIVE}/sunnyside-files/ftp/835/#{provider}") Dir.mkdir("#{DRIVE}/sunnyside-files/ftp/837/#{provider}") else puts 'Please try again.' Sunnyside.add_provider_to_ftp end end
add_providers()
click to toggle source
# File lib/sunnyside/models/db_setup.rb, line 147 def add_providers DB[:providers].insert(:credit_account=>1206, :fund=>500, :debit_account=>5005, :name=>"AMERIGROUP 2", :abbreviation=>"AMG", :prov_type=>"MCO") DB[:providers].insert(:credit_account=>1207, :fund=>300, :debit_account=>5007, :name=>"CHILDREN'S AID SOCIETY", :abbreviation=>"CAS", :prov_type=>"MLTC") DB[:providers].insert(:credit_account=>1226, :fund=>300, :debit_account=>5026, :name=>"COMPREHENSIVE CARE MANAGEMENT", :abbreviation=>"CCM", :prov_type=>"MLTC") DB[:providers].insert(:credit_account=>1203, :fund=>300, :debit_account=>5002, :name=>"DOMINICAN SISTERS FAM HLTH", :abbreviation=>"DSF", :prov_type=>"MLTC") DB[:providers].insert(:credit_account=>1209, :fund=>300, :debit_account=>5009, :name=>"ELDERSERVE HEALTH", :abbreviation=>"ELD", :prov_type=>"MLTC") DB[:providers].insert(:credit_account=>1212, :fund=>300, :debit_account=>5012, :name=>"EMBLEM HEALTH", :abbreviation=>"EMB", :prov_type=>"MLTC") DB[:providers].insert(:credit_account=>1201, :fund=>300, :debit_account=>5001, :name=>"GUILDNET", :abbreviation=>"G", :prov_type=>"MLTC") DB[:providers].insert(:credit_account=>1227, :fund=>500, :debit_account=>5027, :name=>"HEALTH CARE PARTNERS", :abbreviation=>"HCP", :prov_type=>"MCO") DB[:providers].insert(:credit_account=>1218, :fund=>500, :debit_account=>5018, :name=>"HEALTH FIRST", :abbreviation=>"HFS", :prov_type=>"MCO") DB[:providers].insert(:credit_account=>1216, :fund=>500, :debit_account=>5016, :name=>"HEALTH INSURANCE PLAN OF NY", :abbreviation=>"HIP", :prov_type=>"MCO") DB[:providers].insert(:credit_account=>1223, :fund=>300, :debit_account=>5023, :name=>"HHH LONG TERM HOME HLTH CARE", :abbreviation=>"HHH", :prov_type=>"MLTC") DB[:providers].insert(:credit_account=>1228, :fund=>300, :debit_account=>5028, :name=>"INDEPENDENCE CARE SYSTEMS", :abbreviation=>"ICS", :prov_type=>"MLTC") DB[:providers].insert(:credit_account=>1217, :fund=>500, :debit_account=>5017, :name=>"METROPLUS HEALTH", :abbreviation=>"MPH", :prov_type=>"MCO") DB[:providers].insert(:credit_account=>1219, :fund=>500, :debit_account=>5019, :name=>"NEIGHBORHOOD HEALTH PROVIDERS", :abbreviation=>"NHP", :prov_type=>"MCO") DB[:providers].insert(:credit_account=>1221, :fund=>500, :debit_account=>5021, :name=>"NYS CATHOLIC/FIDELIS", :abbreviation=>"FID", :prov_type=>"MCO") DB[:providers].insert(:credit_account=>1200, :fund=>300, :debit_account=>5000, :name=>"PRIVATE", :abbreviation=>"P", :prov_type=>"MLTC") DB[:providers].insert(:credit_account=>1204, :fund=>300, :debit_account=>5004, :name=>"SENIOR HEALTH PARTNERS", :abbreviation=>"SHP", :prov_type=>"MLTC") DB[:providers].insert(:credit_account=>1202, :fund=>300, :debit_account=>5003, :name=>"SUNNYSIDE COMMUNITY SERVICES", :abbreviation=>"SCS", :prov_type=>"MLTC") DB[:providers].insert(:credit_account=>1213, :fund=>500, :debit_account=>5013, :name=>"UNITED HEALTH CARE", :abbreviation=>"UHC", :prov_type=>"MCO") DB[:providers].insert(:credit_account=>1229, :fund=>500, :debit_account=>5029, :name=>"VNSNY CHOICE SELECT HEALTH", :abbreviation=>"VCS", :prov_type=>"MCO") DB[:providers].insert(:credit_account=>1224, :fund=>500, :debit_account=>5024, :name=>"WELCARE OF NEW YORK, INC.", :abbreviation=>"WEL", :prov_type=>"MCO") DB[:providers].insert(:credit_account=>1310, :fund=>300, :debit_account=>5030, :name=>"VILLAGE CARE MAX", :abbreviation=>"VIL", :prov_type=>"MLTC") DB[:providers].insert(:credit_account=>1222, :fund=>500, :debit_account=>5022, :name=>"AFFINITY HEALTH PLUS", :abbreviation=>"AFF", :prov_type=>"MCO") DB[:providers].insert(:credit_account=>1218, :fund=>500, :debit_account=>5018, :name=>"HEALTH PLUS PHSP,INC", :abbreviation=>"HFS", :prov_type=>"MCO") end
advanced_opts()
click to toggle source
# File lib/sunnyside/advanced.rb, line 2 def self.advanced_opts puts "1.) Add new provider" puts "2.) Export A/R denials" case gets.chomp when '1' print "Type in the provider name _EXACTLY_ how it appears on the SanData archive report files (e.g. Guildnet is always GUILDNET): " provider = gets.chomp print "Now type in the abbreviation (batch initials - e.g. MetroPlus Health is MPH): " abbrev = gets.chomp print "Now type in the CREDIT account that is used in FUND EZ: " credit = gets.chomp print "Now type in the DEBIT account that is used in FUND EZ: " debit = gets.chomp print "And finally, type in the FUND number that is used in FUND EZ: " fund = gets.chomp review = "--------Name: #{provider}, Credit Account: #{credit}, Debit Account: #{debit}, Fund: #{fund}, Abbreviation: #{abbrev}--------" puts "Please review the below information." puts '-' * review.length puts review puts '-' * review.length print "Is this correct? (Y for yes, N for No): " raise 'You have an empty field! Start over!' if [provider, credit, debit, fund, abbrev].any? { |elem| elem.empty? } if gets.chomp.upcase == 'Y' provider = Provider.insert(name: provider, credit_account: credit, debit_account: debit, fund: fund, abbreviation: abbrev) puts "#{Provider[provider].name} added." else Sunnyside.advanced_opts end else exit end end
cash_receipt()
click to toggle source
# File lib/sunnyside/cash_receipts/cash_receipt.rb, line 3 def self.cash_receipt puts "1.) EDI PAYMENT" puts "2.) MANUAL PAYMENT" puts "3.) RESET A/R SPREADSHEET" case gets.chomp when '1' cash_receipt = CashReceipt.new(:electronic) when '2' cash_receipt = CashReceipt.new(:manual) when '3' CSV.open("#{DRIVE}/sunnyside-files/cash_receipts/EDI-citywide-import.csv", "w") { |row| row << ['Seq','Receipt','post_date','other id','invoice','header memo','batch','doc date','detail memo','fund','account','cc1','cc2','cc3','debit','credit'] } end cash_receipt.collate if cash_receipt end
check_prompt() { |payment| ... }
click to toggle source
# File lib/sunnyside/reports/report.rb, line 93 def self.check_prompt Provider.all.each { |prov| puts "#{prov.id}: #{prov.name}"} print "Type in the Provider ID: " provider = Provider[gets.chomp] Payment.where(provider_id: provider.id).all.each { |check| puts "#{check.id}: Number - #{check.check_number} Amount - #{check.check_total}"} print "Type in the Check ID: " payments = gets.chomp.split.map { |chk| Payment[chk] } # For ICS checks, since for some reason the check number doesn't match the EDI TRN field. payments.each do |payment| if payment.provider_id == 12 print "type in the correct ICS check #: " payment.update(:check_number => gets.chomp) end yield payment end end
create_folders()
click to toggle source
# File lib/sunnyside/models/db_setup.rb, line 4 def create_folders folders = ['db', '835', '837', 'summary', 'cash_receipts', 'new-ledger', 'private', 'private/archive', 'summary/archive', '837/archive', '835/archive', 'ftp', 'ftp/837', 'ftp/837/GUILDNET', 'ftp/837/CPHL', 'ftp/837/ELDERSERVE', 'ftp/835', 'ftp/835/GUILDNET', 'ftp/835/CPHL', 'ftp/835/ELDERSERVE', 'pdf-reports' ] Dir.mkdir("#{DRIVE}/sunnyside-files") folders.each { |folder| Dir.mkdir("#{DRIVE}/sunnyside-files/#{folder}") } end
create_tables()
click to toggle source
# File lib/sunnyside/models/db_setup.rb, line 13 def create_tables DB.create_table :logins do primary_key :id String :site String :username String :password String :provider end DB.create_table :charges do primary_key :id foreign_key :invoice_id, :invoices foreign_key :provider_id, :providers Date :dos Float :amount Float :units String :service_code String :filename end DB.create_table :invoices do Integer :invoice_number, :primary_key=>true index :invoice_number Float :amount Date :post_date, :default=>Date.today foreign_key :client_id, :clients foreign_key :provider_id, :providers foreign_key :filelib_id, :filelibs Integer :service_number String :auth String :client_name Float :rate Float :hours String :recipient_id end DB.create_table :payments do primary_key :id foreign_key :provider_id, :providers foreign_key :filelib_id, :filelibs Float :check_total Date :post_date, :default=>Date.today String :status Integer :check_number end DB.create_table :claims do primary_key :id index :id String :control_number foreign_key :payment_id, :payments foreign_key :invoice_id, :invoices foreign_key :client_id, :clients Float :paid Float :billed String :status String :recipient_id foreign_key :provider_id, :providers Date :post_date end DB.create_table :services do primary_key :id foreign_key :claim_id, :claims foreign_key :payment_id, :payments foreign_key :invoice_id, :invoices foreign_key :client_id, :clients String :service_code Float :paid Float :billed String :denial_reason Float :units Date :dos end DB.create_table :clients do Integer :client_number, :primary_key=>true String :client_name String :fund_id String :recipient_id foreign_key :provider_id, :providers String :prov_type, :default=>'MLTC' Date :dob end DB.create_table :providers do primary_key :id Integer :credit_account Integer :fund Integer :debit_account String :name String :abbreviation String :prov_type String :edi_identifier end DB.create_table :filelibs do primary_key :id String :filename String :purpose String :file_type Time :created_at end DB.create_table :visits do primary_key :id String :service_code String :modifier foreign_key :invoice_id, :invoices foreign_key :client_id, :clients Float :amount Float :units Date :dos end DB.create_table :denials do primary_key :denial_code, :primary_key=>true String :denial_explanation end DB.create_table :authorizations do primary_key :id String :auth foreign_key :client_id, :clients Integer :service_id Date :start_date Date :end_date end end
determine_browser()
click to toggle source
# File lib/sunnyside/advanced.rb, line 44 def self.determine_browser if Dir.exist?("#{DRIVE}/Program Files (x86)") Dir.chdir("#{DRIVE}/Program Files (x86)/Mozilla Firefox") else Dir.chdir("#{DRIVE}/Program Files/Mozilla Firefox") end end
edi_parser()
click to toggle source
# File lib/sunnyside/ledger/edi.rb, line 2 def self.edi_parser print "checking for new files...\n" Dir["#{DRIVE}/sunnyside-files/835/*.txt"].each do |file| if Filelib.where(filename: file).count > 0 puts "This file has been processed already. File removed." File.delete(file) else print "processing #{file}...\n" file_data = File.open(file) data = file_data.read # Detect to see if the EDI file already has new lines inserted. If so, the newlines are removed before the file gets processed. data.gsub!(/\n/, '') data = data.split(/~CLP\*/) edi_file = EdiReader.new(data) edi_file.parse_claims Filelib.insert(filename: File.basename(file), purpose: '835') file_data.close FileUtils.mv(file, "#{DRIVE}/sunnyside-files/835/archive/#{File.basename(file)}") end end end
expiring_auth()
click to toggle source
# File lib/sunnyside/expiring_auth.rb, line 2 def self.expiring_auth Dir["data/exp auth/*.txt"].each do |file| file = File.open(file) data = file.read.split("\n").reject { |line| line =~ /\f/} data.each { |line| if line =~ /^.{27}\d{7}\s+\d{7}\s/ client = line.slice!(0..26) line = line.split(' ').keep_if { |elem| elem.length >= 4 } data = ExpiringAuth.new(file, client, line) print "#{line}\n" end } file.close FileUtils.mv(file, "data/exp auth/previous/#{File.basename(file)}") end clients = Authorization.map(:client_number).uniq clients.each { |client| most_recent_auth = Authorization.where(client_number: client).exclude(auth: 'Blanket').order(:end_date).last # that gets the most recent auth that isnt a blanket. # visits = Visit.where(member_id: client).where('dos > ?', most_recent_auth.end_date) if !most_recent_auth.nil? # puts "#{client} #{visits.count}" if !visits.nil? # that gets all the visits that has that particular client number that is also GREATER than the most_recent_auth's end date # client.each { |x| puts x.client } auth_data = Authorization.where(client_number: client) auth = auth_data.order(:end_date).all.last AuthReport.new(auth_data, auth).create_csv } end
ledger_file()
click to toggle source
This should be redone.
# File lib/sunnyside/ledger/ledger.rb, line 4 def self.ledger_file files = Dir["#{DRIVE}/sunnyside-files/summary/*.PDF"] files.each do |file| if Filelib.where(filename: file).count == 0 puts "processing #{file}..." ledger = Ledger.new(file) ledger.process_file Filelib.insert(filename: file, purpose: 'summary') FileUtils.mv(file, "#{DRIVE}/sunnyside-files/summary/archive/#{File.basename(file)}") ledger.export_to_csv end end if files.size == 0 puts "It appears there are no new files to process. Do you wish to create a csv file for a specific post date? (Y or N) " if gets.chomp.downcase == 'y' print "enter the date (YYYY-MM-DD): " post_date = Date.parse(gets.chomp) puts "File being created..." LedgerReport.new(post_date) end end end
parse_pdf()
click to toggle source
REG LOC is the only repeating element that would indicate that there's a new client being read. So instead of reading the pdf report page by page, it would be best to compress the text from every page into a single string and then parse from there.
# File lib/sunnyside/ledger/auth_report.rb, line 6 def self.parse_pdf files = Dir["#{DRIVE}/sunnyside-files/837/*.PDF"].select { |file| Filelib.where(filename: file).count == 0 } files.each do |file| puts "processing #{file}..." data = PDF::Reader.new(file).pages.map { |page| page.raw_content.gsub(/^\(\s|\)'$/, '') }.join data.split(/(?=REG\s+LOC)/).each { |entry| ParseInvoice.new(entry).process } Filelib.insert(filename: file, purpose: '837') FileUtils.mv(file, "#{DRIVE}/sunnyside-files/837/archive/#{File.basename(file)}") end end
private_clients()
click to toggle source
# File lib/sunnyside/reports/private.rb, line 4 def self.private_clients Dir.mkdir("#{DRIVE}/sunnyside-files/pdf-reports/private") if !Dir.exist?("#{DRIVE}/sunnyside-files/pdf-reports/private") file = Dir["#{DRIVE}/sunnyside-files/private/archive/*.PDF"].last post_date = Date.parse(File.basename(file)[0..7]) Invoice.where(post_date: post_date, provider_id: 16).all.each { |inv| puts "#{inv.client_id} #{Client[inv.client_id].client_name}"} puts "Type in the IDs next to the client's name, each separated by a space. " clients = gets.chomp.split.map { |client| Client[client].client_name }.push('SUNNYSIDE COMMUNITY') private_client = PrivateClient.new(file, post_date) clients.each { |client| private_client.create_doc(client) } end
process_private()
click to toggle source
# File lib/sunnyside/ledger/private.rb, line 2 def self.process_private Dir["#{DRIVE}/sunnyside-files/private/*.PDF"].each do |file| if Filelib.where(filename: file).count == 0 puts "processing #{file}..." PDF::Reader.new(file).pages.each { |inv| page = inv.text.split(/\n/) InvoiceParse.new(page).process if page.include?('Remit') } end Filelib.insert(filename: file, purpose: 'private client visit data') FileUtils.mv(file, "#{DRIVE}/sunnyside-files/private/archive/#{File.basename(file)}") end end
query()
click to toggle source
# File lib/sunnyside/query/query.rb, line 5 def self.query puts "1.) VIEW CLIENTS BY PROVIDER" puts "2.) " case gets.chomp when '1' Provder.all.each { |prov| puts "#{prov.id}: #{prov.name}"} print "Type in the provider ID number: " provider = Provider[gets.chomp] query = Query.new(provider) query.show_options # puts 'Type in post date (YYYY-MM-DD)' # date = Date.parse(gets.chomp) # if date.is_a?(Date) # Invoice.where(post_date: date).all.each { |invoice| Sunnyside.payable_csv(invoice, date) } # end end end
rails_server()
click to toggle source
# File lib/sunnyside/advanced.rb, line 36 def self.rails_server puts "Please wait..." Dir.chdir("R:/Departments/AR Department/sunnyside-app") %x(rails s) end
run_mco_mltc()
click to toggle source
# File lib/sunnyside/reports/mco_mltc.rb, line 2 def self.run_mco_mltc print "Type in post date (YYYY-MM-DD): " post_date = gets.chomp Provider.map(:name).each do |provider| ReportMCO.new(provider, post_date).run end end
run_report()
click to toggle source
# File lib/sunnyside/reports/pdf_report.rb, line 5 def self.run_report print "Type in the post date (YYYY-MM-DD): " post_date = Date.parse(gets.chomp) self.check_prompt { |payment| provider = Provider[payment.provider_id] report = Reporter.new(payment, post_date, provider) report.check_header } end
Public Instance Methods
payable_csv(inv, post_date)
click to toggle source
# File lib/sunnyside/reports/report.rb, line 51 def payable_csv(inv, post_date) prov = Provider[inv.provider_id] if Client[inv.client_id].fund_id.empty? puts "Whoops! It appears #{Client[inv.client_id].client_name} for #{prov.name} doesn't have a fund id. Please retrieve it from FUND EZ and type it in now." Client.where(client_number: inv.client_id).update(:fund_id => gets.chomp) end prov_name = if prov.name == 'AMERIGROUP 2' 'AMERIGROUP' else prov.name end fund_id = Client[inv.client_id].fund_id CSV.open("#{DRIVE}/sunnyside-files/new-ledger/#{inv.post_date}-IMPORT-FUND-EZ-LEDGER.csv", "a+") do |row| row << [1, inv.invoice_number, post_date.strftime('%m/%d/%y'), fund_id, prov_name, post_date.strftime('%m/%d/%y'), "To Record #{post_date.strftime('%m/%d/%y')} Billing", "#{post_date.strftime('%m')}/#{post_date.strftime('%y')}#{prov.abbreviation}", post_date.strftime('%m/%d/%y'), "To Rec for W/E #{post_date - 6} Billing", prov.fund, prov.credit_account, '', '', '', inv.amount, ''] row << [2, inv.invoice_number, post_date.strftime('%m/%d/%y'), fund_id, prov_name, post_date.strftime('%m/%d/%y'), "To Record #{post_date.strftime('%m/%d/%y')} Billing", "#{post_date.strftime('%m')}/#{post_date.strftime('%y')}#{prov.abbreviation}", post_date.strftime('%m/%d/%y'), "To Rec for W/E #{post_date - 6} Billing", prov.fund, prov.debit_account, prov.fund, '', prov.prov_type, '', inv.amount] end end
receivable_csv(claim, payment, post_date)
click to toggle source
# File lib/sunnyside/reports/report.rb, line 2 def receivable_csv(claim, payment, post_date) total = claim.paid prov = Provider[claim.provider_id] if Client[claim.client_id].fund_id.empty? puts "Whoops! It appears #{Client[claim.client_id].client_name} doesn't have a fund id. Please retrieve it from FUND EZ and type it in now." Client.where(client_number: claim.client_id).update(:fund_id => gets.chomp) end fund_id = Client[claim.client_id].fund_id puts "#{total.round(2)} #{Client[claim.client_id].client_name} " CSV.open("#{DRIVE}/sunnyside-files/cash_receipts/EDI-citywide-import.csv", "a+") do |row| # #{post_date.gsub(/\//, '-')}- row << [1, payment.check_number, post_date, fund_id, claim.invoice_id, claim.invoice_id, "#{post_date.strftime('%m')}/#{post_date.strftime('%y')}#{prov.abbreviation}", post_date, claim.invoice_id, prov.fund, prov.credit_account,'','','', 0, total] row << [2, payment.check_number, post_date, fund_id, claim.invoice_id, claim.invoice_id, "#{post_date.strftime('%m')}/#{post_date.strftime('%y')}#{prov.abbreviation}", post_date, claim.invoice_id, 100, 1000,'','','', total, 0] row << [3, payment.check_number, post_date, fund_id, claim.invoice_id, claim.invoice_id, "#{post_date.strftime('%m')}/#{post_date.strftime('%y')}#{prov.abbreviation}", post_date, claim.invoice_id, prov.fund, 3990, '', '', '', total, 0] row << [4, payment.check_number, post_date, fund_id, claim.invoice_id, claim.invoice_id, "#{post_date.strftime('%m')}/#{post_date.strftime('%y')}#{prov.abbreviation}", post_date, claim.invoice_id, 100, 3990, '', '', '', 0, total] end end