Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jjh professional #663

Merged
merged 5 commits into from
Sep 26, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
65 changes: 30 additions & 35 deletions lib/tasks/import_professional_services.rake
Original file line number Diff line number Diff line change
Expand Up @@ -9,74 +9,69 @@ namespace :data do

skipped_services = CSV.open("tmp/skipped_pb_services_#{Time.now.strftime('%m%d%Y%T')}.csv", "wb")

skipped_services << ['REASON','EAP ID','CPT Code','Charge Code','Revenue Code','Send to Epic','Procedure Name','Service Rate','Corporate Rate ','Federal Rate','Member Rate','Other Rate','Is One Time Fee?','Clinical Qty Type','Unit Factor','Qty Min','Display Date','Effective Date']
skipped_services << ['REASON','EAP ID','CPT Code','Charge Code','Revenue Code','Send to Epic','Procedure Name','Service Rate','Corporate Rate','Federal Rate','Member Rate','Other Rate','Is One Time Fee?','Clinical Qty Type','Unit Factor','Qty Min','Display Date','Effective Date']

ranges = {}
# Hash value defaults to an empty array
ranges = Hash.new { |h, k| h[k] = [] }
CSV.foreach(ENV['range_file'], :headers => true, :encoding => 'windows-1251:utf-8') do |row|
### POS used so that we can have same org with different ranges
org_plus_pos = row['ORG ID'] + "-" + row['POS']
ranges[org_plus_pos] = Range.new(row['From'].to_i, row['To'].to_i)
ranges[org_plus_pos] = []

justification = row['From'].size

Range.new(row['From'].to_i, row['To'].to_i).each do |r|
ranges[org_plus_pos] << r.to_s.rjust(justification, '0')
end
ranges[row.fetch('ORG ID')] << Range.new(row.fetch('From'), row.fetch('To'))
end

Service.transaction do
CSV.foreach(ENV['pb_file'], :headers => true, :encoding => 'windows-1251:utf-8') do |row|
begin
eap_id = row['EAP ID']
eap_id = row.fetch('EAP ID')

range = ranges.select{|k,v| v.include? eap_id}
# ranges that contain our eap_id
range = ranges.select do |org_id, org_ranges|
org_ranges.any? { |org_range| org_range.include?(eap_id) }
end

if range.empty?
puts "No EAP ID range exists, skipping #{eap_id} - #{row['Procedure Name']}"
puts "No EAP ID range exists, skipping #{eap_id} - #{row.fetch('Procedure Name')}"
skipped_services << ['No EAP ID range found'] + row.fields
elsif range.size > 1
raise "Overlapping ranges: :\n\n#{row.inspect}\n\n#{ranges.inspect}"
skipped_services << ['Multiple EAP ID ranges found'] + row.fields
else
organization_id = range.keys.first.split('-').first # looks like 123-1
organization_id = range.keys.first.to_i

attrs = {:eap_id => row['EAP ID'], :organization_id => organization_id}
attrs = {:eap_id => row.fetch('EAP ID'), :organization_id => organization_id}

service = Service.where(attrs).first || Service.new(attrs)

service.assign_attributes(
:organization_id => organization_id,
:cpt_code => row['CPT Code'],
:send_to_epic => (row['Send to Epic'] == 'Y' ? true : false),
:name => row['Procedure Name'],
:abbreviation => row['Procedure Name'],
:cpt_code => row.fetch('CPT Code'),
:send_to_epic => (row.fetch('Send to Epic') == 'Y' ? true : false),
:name => row.fetch('Procedure Name'),
:abbreviation => row.fetch('Procedure Name'),
:order => 1,
:one_time_fee => (row['Is One Time Fee?'] == 'Y' ? true : false),
:one_time_fee => (row.fetch('Is One Time Fee?') == 'Y' ? true : false),
:is_available => true)

service.tag_list = "epic" if row['Send to Epic'] == 'Y'
service.tag_list = "epic" if row.fetch('Send to Epic') == 'Y'

full_rate = Service.dollars_to_cents(row['Service Rate'].to_s.strip.gsub("$", "").gsub(",", ""))
corporate_rate = Service.dollars_to_cents(row['Corporate Rate'].to_s.strip.gsub("$", "").gsub(",", ""))
federal_rate = Service.dollars_to_cents(row['Federal Rate'].to_s.strip.gsub("$", "").gsub(",", ""))
member_rate = Service.dollars_to_cents(row['Member Rate'].to_s.strip.gsub("$", "").gsub(",", ""))
other_rate = Service.dollars_to_cents(row['Other Rate'].to_s.strip.gsub("$", "").gsub(",", ""))
full_rate = Service.dollars_to_cents(row.fetch('Service Rate').to_s.strip.gsub("$", "").gsub(",", ""))
corporate_rate = Service.dollars_to_cents(row.fetch('Corporate Rate').to_s.strip.gsub("$", "").gsub(",", ""))
federal_rate = Service.dollars_to_cents(row.fetch('Federal Rate').to_s.strip.gsub("$", "").gsub(",", ""))
member_rate = Service.dollars_to_cents(row.fetch('Member Rate').to_s.strip.gsub("$", "").gsub(",", ""))
other_rate = Service.dollars_to_cents(row.fetch('Other Rate').to_s.strip.gsub("$", "").gsub(",", ""))

effective_date = row['Effective Date'].match("[0-1]?[0-9]/[0-3]?[0-9]/[0-9]{4}") ? Date.strptime(row['Effective Date'], "%m/%d/%Y") : Date.strptime(row['Effective Date'], "%m/%d/%y") # four digit or two digit year makes a difference
display_date = row['Display Date'].match("[0-1]?[0-9]/[0-3]?[0-9]/[0-9]{4}") ? Date.strptime(row['Display Date'], "%m/%d/%Y") : Date.strptime(row['Display Date'], "%m/%d/%y") # see above
effective_date = row.fetch('Effective Date').match("[0-1]?[0-9]/[0-3]?[0-9]/[0-9]{4}") ? Date.strptime(row.fetch('Effective Date'), "%m/%d/%Y") : Date.strptime(row.fetch('Effective Date'), "%m/%d/%y") # four digit or two digit year makes a difference
display_date = row.fetch('Display Date').match("[0-1]?[0-9]/[0-3]?[0-9]/[0-9]{4}") ? Date.strptime(row.fetch('Display Date'), "%m/%d/%Y") : Date.strptime(row.fetch('Display Date'), "%m/%d/%y") # see above

pricing_map = service.pricing_maps.build(
:full_rate => full_rate,
:corporate_rate => corporate_rate,
:federal_rate => federal_rate,
:member_rate => member_rate,
:other_rate => other_rate,
:unit_type => (row['Is One Time Fee?'] == 'Y' ? nil : row['Clinical Qty Type']),
:quantity_type => (row['Is One Time Fee?'] != 'Y' ? nil : row['Clinical Qty Type']),
:unit_factor => row['Unit Factor'],
:unit_minimum => (row['Is One Time Fee?'] == 'Y' ? nil : row['Qty Min']),
:quantity_minimum => (row['Is One Time Fee?'] != 'Y' ? nil : row['Qty Min']),
:unit_type => (row['Is One Time Fee?'] == 'Y' ? nil : row.fetch('Clinical Qty Type')),
:quantity_type => (row['Is One Time Fee?'] != 'Y' ? nil : row.fetch('Clinical Qty Type')),
:unit_factor => row.fetch('Unit Factor'),
:unit_minimum => (row['Is One Time Fee?'] == 'Y' ? nil : row.fetch('Qty Min')),
:quantity_minimum => (row['Is One Time Fee?'] != 'Y' ? nil : row.fetch('Qty Min')),
:display_date => display_date,
:effective_date => effective_date
)
Expand Down