Skip to content

Instantly share code, notes, and snippets.

@kenrett
Created November 16, 2013 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenrett/7504951 to your computer and use it in GitHub Desktop.
Save kenrett/7504951 to your computer and use it in GitHub Desktop.
require 'sqlite3'
require 'csv'
$db = SQLite3::Database.new "salem_hospital.db"
class Line
attr_reader :report_type, :patient_name, :service_from, :service_thru, :paid_date, :hic_num, :gross_reimb, :cash_deduct, :blood_deduct, :coins, :net_reimb
def initialize(args)
@provider_id = args[:provider_id] || 'x'
@provider_name = args[:provider_name] || 'x'
@provider_fye = args[:provider_fye] || 'x'
@report_type = args[:report_type] || 'x'
@report_num = args[:report_num] || 'x'
@paid_from = args[:paid_from] || 'x'
@paid_to = args[:paid_to] || 'x'
@report_run_date = args[:report_run_date] || 'x'
@service_period_num = args[:service_period_num] || 'x'
@service_period_from = args[:service_period_from] || 'x'
@service_period_thru = args[:service_period_thru] || 'x'
@service_from = args[:service_from] || 'x'
@service_thru = args[:service_thru] || 'x'
@patient_name = args[:patient_name] || 'x'
@patient_control_num = args[:patient_control_num] || 'x'
@med_record_num = args[:med_record_num] || 'x'
@hic_num = args[:hic_num] || 'x'
@receipt_date = args[:receipt_date] || 'x'
@paid_date = args[:paid_date] || 'x'
@dcn = args[:dcn] || 'x'
@bill_freq = args[:bill_freq] || 'x'
@trans_type = args[:trans_type] || 'x'
@pricer_rtn_cd = args[:pricer_rtn_cd] || 'x'
@processor_id = args[:processor_id] || 'x'
@zip_code = args[:zip_code] || 'x'
@esrd_condition_code = args[:esrd_condition_code] || 'x'
@weight = args[:weight] || 'x'
@height = args[:height] || 'x'
@birth_date = args[:birth_date] || 'x'
@claim_num = args[:claim_num] || 'x'
@rev_code = args[:rev_code] || 'x'
@description = args[:description] || 'x'
@hcpcs = args[:hcpcs] || 'x'
@panel_code = args[:panel_code] || 'x'
@trip_mile_ind = args[:trip_mile_ind] || 'x'
@units = args[:units] || 'x'
@charges = args[:charges] || 'x'
@gross_fee_amt = args[:gross_fee_amt] || 'x'
@gross_reimb = args[:gross_reimb] || 'x'
@gapc = args[:gapc] || 'x'
@outlier = args[:outlier] || 'x'
@deductibles = args[:deductibles] || 'x'
@cash_deduct = args[:cash_deduct] || 'x'
@blood_deduct = args[:blood_deduct] || 'x'
@coins = args[:coins] || 'x'
@msp = args[:msp] || 'x'
@med_days = args[:med_days] || 'x'
@esrd_rdctn_ntwk_payments = args[:esrd_rdctn_ntwk_payments ] || 'x'
@msp_recon = args[:msp_recon] || 'x'
@other_adjs = args[:other_adjs] || 'x'
@line_item_reimb = args[:line_item_reimb] || 'x'
@elected_coins = args[:elected_coins] || 'x'
@mods = args[:mods] || 'x'
@service_ind = args[:service_ind] || 'x'
@pymt_ind = args[:pymt_ind] || 'x'
@dscnt_fct = args[:dscnt_fct] || 'x'
@tob_incl = args[:tob_incl] || 'x'
@apc = args[:apc] || 'x'
@undup_days = args[:undup_days] || 'x'
@hours = args[:hours] || 'x'
@gross_fee_reimb = args[:gross_fee_reimb] || 'x'
@stndrd_ovrhd_amount = args[:stndrd_ovrhd_amount] || 'x'
@tot_gross_fee_sched = args[:tot_gross_fee_sched] || 'x'
@psr_report = args[:psr_report] || 'x'
@net_reimb = args[:net_reimb] || 'x'
@msp_cash_deduct = args[:msp_cash_deduct] || 'x'
@msp_blood_deduct = args[:msp_blood_deduct] || 'x'
@msp_deductibles = args[:msp_deductibles] || 'x'
@msp_coins = args[:msp_coins] || 'x'
@patient_cbsa = args[:patient_cbsa] || 'x'
@claim_interest = args[:claim_interest] || 'x'
@claim_report_splits = args[:claim_report_splits] || 'x'
@low_volume = args[:low_volume] || 'x'
@rebilling_adjustment = args[:rebilling_adjustment] || 'x'
end
end
class Parser
attr_reader :file, :records
def initialize(file)
@records = []
@file = file
parse
initialize_db
seed_db
end
def parse
return @records unless @records.empty?
i = 0
CSV.foreach(@file, encoding: "iso-8859-1:UTF-8", :headers => true, :header_converters => :symbol) do |row|
@records << Line.new(row.to_hash)
i += 1
puts i
end
@records
end
def initialize_db
$db.execute(<<-SQL
CREATE TABLE records (
id INTEGER PRIMARY KEY AUTOINCREMENT,
report_type INTEGER NOT NULL,
patient_name VARCHAR(64) NOT NULL,
service_from VARCHAR(64) NOT NULL,
service_thru VARCHAR(64) NOT NULL,
paid_date VARCHAR(64) NOT NULL,
hic_num VARCHAR(64) NOT NULL,
gross_reimb VARCHAR(64) NOT NULL,
cash_deduct VARCHAR(64) NOT NULL,
blood_deduct VARCHAR(64) NOT NULL,
coins VARCHAR(64) NOT NULL,
net_reimb VARCHAR(64) NOT NULL,
);
SQL
)
end
def seed_db
@records.each do |row|
$db.execute(
"INSERT INTO records
(report_type, patient_name, service_from, service_thru, paid_date, hic_num, gross_reimb, cash_deduct, blood_deduct, coins, net_reimb)
VALUES
('#{record.report_type}', '#{record.patient_name}', '#{record.service_from}', '#{record.service_thru}', '#{record.paid_date}', '#{record.hic_num}', '#{record.gross_reimb}', '#{record.cash}', '#{record.blood_deduct}', '#{record.coins}', '#{record.net_reimb}');")
end
end
end
parser = Parser.new('for_don.csv')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment