Created
March 17, 2009 19:06
-
-
Save ebot/80716 to your computer and use it in GitHub Desktop.
P0MB - Summit Rename Exit Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -wKU | |
#http://gist.github.com/80716 | |
require 'rubygems' | |
require 'fastercsv' | |
begin | |
csv_options = {:col_sep => ';', :headers => :first_row, :write_headers => true} | |
index_file = FasterCSV.open '../index.txt', csv_options | |
new_index = [] | |
header = nil | |
index_file.each do |row| | |
if row['hospital_service_code'] == 'MMS' or row['hospital_service_code'] == 'MWK' then | |
# Delete the file, these services should not be sent to summit. | |
File.delete("../data/#{row['file_name']}") | |
puts " Deleted #{row['hospital_service_code']} - #{row['file_name']}." | |
else | |
# Get the document name parts. | |
doc_info = row['file_name'].split('.') | |
file_extension = doc_info[doc_info.length - 1] | |
doc_id = doc_info[0].split('_')[0] | |
page_number = doc_info[0].split('_')[1] | |
# Rename the file and update the csv file with the new name. | |
new_file_name = "emrsummit_#{row['hospital_service_code']}_" << | |
"#{row['encounter_number']}_#{doc_id}_" << | |
"#{row['document_type']}_#{page_number}." << | |
"#{file_extension}" | |
puts "Renaming #{row['file_name']} to #{new_file_name}" | |
File.rename("../data/#{row['file_name']}", "../data/#{new_file_name}") | |
row['file_name'] = new_file_name | |
# Store the row data to write it out when we are done processing. | |
new_index << row | |
header = row.headers if header.nil? | |
end | |
end | |
csv_options[:headers] = header | |
csv = FasterCSV.open("../index.txt", "w", csv_options) | |
new_index.each { |row| csv << row } | |
puts "Finished custom rename for Pinnacle-Summit." | |
rescue Exception => e | |
puts e.message | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment