class SuperEHR::AllScriptsAPI
Public Class Methods
new(ehr_username, ehr_password='', app_username, app_password, app_name, using_touchworks)
click to toggle source
API SPECIFIC HOUSEKEEPING ###
# File lib/super_ehr.rb, line 113 def initialize(ehr_username, ehr_password='', app_username, app_password, app_name, using_touchworks) # convert these to environment variables @app_username = app_username @app_password = app_password @app_name = app_name @ehr_username = ehr_username # if not using touchworks ehr, then professional ehr is used @using_touchworks = using_touchworks if (using_touchworks) base_url = "http://twlatestga.unitysandbox.com/unity/unityservice.svc" else base_url = "http://pro141ga.unitysandbox.com/Unity/unityservice.svc" end @uri = URI(base_url) end
Public Instance Methods
create_pdf_xml_params(first_name, last_name, file_name, bytes_read, offset, upload_done, docs_guid, encounter_id, organization_name="TouchWorks")
click to toggle source
create XML parameters needed for upload_document
# File lib/super_ehr.rb, line 231 def create_pdf_xml_params(first_name, last_name, file_name, bytes_read, offset, upload_done, docs_guid, encounter_id, organization_name="TouchWorks") xml = Builder::XmlMarkup.new(:indent => 2) xml.doc do |b| b.item :name => "documentCommand", :value => "i" b.item :name => "documentType", :value => (@using_touchworks ? "sEKG" : "1") b.item :name => "offset", :value => offset b.item :name => "bytesRead", :value => bytes_read b.item :name => "bDoneUpload", :value => upload_done b.item :name => "documentVar", :value => docs_guid b.item :name => "vendorFileName", :value => file_name b.item :name => "ahsEncounterID", :value => 0 b.item :name => "ownerCode", :value => get_provider_entry_code.strip b.item :name => "organizationName", :value => organization_name b.item :name => "patientFirstName", :value => first_name b.item :name => "patientLastName", :value => last_name end return xml.target! end
get_changed_patients(ts='')
click to toggle source
# File lib/super_ehr.rb, line 168 def get_changed_patients(ts='') patient_ids = get_changed_patients_ids(ts) patients = [] for id in patient_ids patients << get_patient(id) end return patients end
get_changed_patients_ids(ts='')
click to toggle source
# File lib/super_ehr.rb, line 177 def get_changed_patients_ids(ts='') params = {:Action => 'GetChangedPatients', :Parameter1 => ts} response = make_request("POST", "json/MagicJson", params)[0] patient_ids = [] if response.key?("getchangedpatientsinfo") patient_ids = response["getchangedpatientsinfo"].map {|x| x["patientid"] } end return patient_ids end
get_default_params()
click to toggle source
# File lib/super_ehr.rb, line 133 def get_default_params return {:Action => '', :AppUserID => @ehr_username, :Appname => @app_name, :PatientID => '', :Token => refresh_token, :Parameter1 => '', :Parameter2 => '', :Parameter3 => '', :Parameter4 => '', :Parameter5 => '', :Parameter6 => '', :Data => ''} end
get_patient(patient_id)
click to toggle source
API CALLS ###
# File lib/super_ehr.rb, line 156 def get_patient(patient_id) params = {:Action => 'GetPatient', :PatientID => patient_id} response = make_request("POST", "json/MagicJson", params)[0] patient_info = {} if response.key?("getpatientinfo") if not response["getpatientinfo"].empty? patient_info = response["getpatientinfo"][0] end end return patient_info end
get_request_headers()
click to toggle source
# File lib/super_ehr.rb, line 146 def get_request_headers return { 'Content-Type' => 'application/json' } end
get_request_url(endpoint)
click to toggle source
# File lib/super_ehr.rb, line 150 def get_request_url(endpoint) return "#{@uri}/#{endpoint}" end
get_scheduled_patients(day)
click to toggle source
# File lib/super_ehr.rb, line 187 def get_scheduled_patients(day) params = {:Action => 'GetSchedule', :Parameter1 => day} response = make_request("POST", "json/MagicJson", params)[0] patients = [] if response.key?("getscheduleinfo") if not response["getscheduleinfo"].empty? for scheduled_patient in response["getscheduleinfo"] patients << scheduled_patient end end end return patients end
refresh_token()
click to toggle source
# File lib/super_ehr.rb, line 140 def refresh_token credentials = {:Username => @app_username, :Password => @app_password} # last two params prevents usage of default params and output to json return make_request("POST", "json/GetToken", credentials, false, false) end
upload_document(patient_id, filepath, description)
click to toggle source
UPLOAD PDF IMPLEMENTATION ##
# File lib/super_ehr.rb, line 203 def upload_document(patient_id, filepath, description) patient = get_patient(patient_id) first_name = patient["Firstname"] last_name = patient["LastName"] File.open(filepath, "r:UTF-8") do |file| file_contents = file.read() buffer = Base64.encode64(file_contents) # first call to push the contents save_pdf_xml = create_pdf_xml_params(first_name, last_name, filepath, file.size, 0, "false", "", "0") params = {:Action => 'SaveDocumentImage', :PatientID => patient_id, :Parameter1 => save_pdf_xml, :Parameter6 => buffer} out = make_request("POST", "json/MagicJson", params) # second call to push file information and wrap up upload doc_guid = out[0]["savedocumentimageinfo"][0]["documentVar"].to_s save_pdf_xml = create_pdf_xml_params(first_name, last_name, filepath, file.size, 0, "true", doc_guid, "0") params = {:Action => 'SaveDocumentImage', :PatientID => patient_id, :Parameter1 => save_pdf_xml, :Parameter6 => nil} out = make_request("POST", "json/MagicJson", params) return out end end
Private Instance Methods
get_encounter(patient_id)
click to toggle source
# File lib/super_ehr.rb, line 260 def get_encounter(patient_id) params = {:Action => 'GetEncounter', :PatientID => patient_id, :Parameter1 => "NonAppt", :Parameter2 => Time.new.strftime("%b %d %Y %H:%M:%S"), :Parameter3 => true, :Parameter4 => 'N'} out = make_request("POST", "json/MagicJson", params) return out[0]["getencounterinfo"][0]["EncounterID"] end
get_provider_entry_code()
click to toggle source
necessary to create the xml params for upload_document
# File lib/super_ehr.rb, line 254 def get_provider_entry_code() params = {:Action => 'GetProvider', :Parameter2 => @ehr_username} out = make_request("POST", "json/MagicJson", params) return out[0]["getproviderinfo"][0]["EntryCode"] end