Module: UsbModule
- Defined in:
- lib/ruby_astm/usb_module.rb
Constant Summary collapse
- ESR_RESULTS_HASH =
"ESR_RESULTS_HASH"
Instance Method Summary collapse
- #add_result?(barcode, result) ⇒ Boolean
- #begin_patient_results ⇒ Object
- #interpret? ⇒ Boolean
- #parse_usb_response(string_data) ⇒ Object
-
#request_results ⇒ Object
requests the last 5 tests performed.
- #request_status ⇒ Object
- #request_version ⇒ Object
Instance Method Details
#add_result?(barcode, result) ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ruby_astm/usb_module.rb', line 35 def add_result?(,result) begin Integer(result) #puts "result is: #{result}" return false if result.to_i == 0 #puts "the result is not zero" existing_result = $redis.hget(ESR_RESULTS_HASH,) #puts "existing result is: #{existing_result}" if ((existing_result.blank?) || (existing_result != result)) return true end rescue => e puts e.to_s return false end end |
#begin_patient_results ⇒ Object
9 10 11 |
# File 'lib/ruby_astm/usb_module.rb', line 9 def begin_patient_results ">00A00013" end |
#interpret? ⇒ Boolean
29 30 31 32 33 |
# File 'lib/ruby_astm/usb_module.rb', line 29 def interpret? ## if the third last is a carriage return, then interpret.l self.usb_response_bytes[-3] == 13 end |
#parse_usb_response(string_data) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ruby_astm/usb_module.rb', line 53 def parse_usb_response(string_data) string_data.bytes.to_a.each do |byte| self.usb_response_bytes.push(byte) end #puts "self usb response bytes:" #puts self.usb_response_bytes.to_s if interpret? #puts "interpret" if kk = self.usb_response_bytes[13..-4] kk.each_slice(32) do |patient_record| unless patient_record.blank? unless patient_record.size < 24 = nil = patient_record[11..23].pack('c*').gsub(/\./,'') #puts "bar code: #{bar_code}" unless .strip.blank? esr = patient_record[26] patient = Patient.new(:orders => [Order.new(:results => [Result.new(:value => esr, :name => "ESR", :report_name => "ESR")])]) patient = Patient.new({}) patient.patient_id = patient.orders = [] order = Order.new({}) result = Result.new({}) result.value = esr.to_s result.name = "ESR" result.report_name = "ESR" order.id = order.results = [] order.results << result #puts "barcode: #{bar_code}, result : #{result.value}" patient.orders << order if add_result?(,result.value) #puts patient.to_json $redis.lpush("patients",patient.to_json) $redis.hset(ESR_RESULTS_HASH,,result.value.to_i) end end end end end end self.usb_response_bytes = [] else #puts "dont interpret" end end |
#request_results ⇒ Object
requests the last 5 tests performed. last two digits before the carriage return are 00 if digits are 01 : will take the 5 penultimate tests if digits are 13 : will take the first 5 tests from memory.
25 26 27 |
# File 'lib/ruby_astm/usb_module.rb', line 25 def request_results ">0002009300\r00" end |
#request_status ⇒ Object
17 18 19 |
# File 'lib/ruby_astm/usb_module.rb', line 17 def request_status ">00000082\r00" end |
#request_version ⇒ Object
13 14 15 |
# File 'lib/ruby_astm/usb_module.rb', line 13 def request_version ">00000080\r00" end |