ruby_astm 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f3ba60a24419e04369920eb8f6ee0a465c9962b989bd6e17ae19eef14541d2d
4
- data.tar.gz: 8d27244ac7b92f552733aad743ebb9777eea930f0c0f0b44dc08ba2b4aa7d9de
3
+ metadata.gz: e495bbce6cc215d7c08b9747276962a59e1f43bddb206b3383d709962472d140
4
+ data.tar.gz: 1b076d1c574bafae7b91fa976505cf0d23ec41cf9cc00eda5f3c899ecbc0da4f
5
5
  SHA512:
6
- metadata.gz: 843087dedee93ba8361371dcfbdca936c8f8b3de4085cca8f438330c4d7e903430895abd8f414daee1fef053ac3c6c690119740dfd09b4421799d8e019b541a2
7
- data.tar.gz: 4a24373742aed3f8df00ec5c68c7eb8298bf4b76fa88eacb895cd3a355998d85cbcb995c9e1fbd30b9efaee2031048ee9d2c79ea16f5eabf6c42ff11740f2dcf
6
+ metadata.gz: 8dd76d5568de871b42efbb96c3f79d82c70d43933184bc442906e965fd18fb571a024e210bf7e2952617c959efcf47027c00f284813069e276d409387b7d2415
7
+ data.tar.gz: 42e1a222ebbd3e6a215d7de88164155b833565a1c418266a5735c4026352dc29f3bfbf99c127fc861ad04ccb56813b5f9f5a43489e13291da42ae83b37777c38
data/lib/mappings.json CHANGED
@@ -175,6 +175,11 @@
175
175
  "TUBE" : "SERUM",
176
176
  "REPORT_NAME" : "Direct Bilirubin"
177
177
  },
178
+ "CA" : {
179
+ "LIS_CODE" : "CA",
180
+ "TUBE" : "SERUM",
181
+ "REPORT_NAME" : "Serum Calcium"
182
+ },
178
183
  "BIT" : {
179
184
  "LIS_CODE" : "BIT",
180
185
  "TUBE" : "SERUM",
@@ -167,8 +167,13 @@ class Poller
167
167
  puts "tube is : #{tube}"
168
168
  puts "tests hash is:"
169
169
  puts tests_hash.to_s
170
- tube_key = tests_hash.keys.select{|c| c=~/#{tube}/ }[0]
171
- tests_hash[tube_key] << machine_code
170
+
171
+ tube_key = nil
172
+ unless tests_hash.keys.select{|c| c=~/#{tube}/ }.blank?
173
+ tube_key = tests_hash.keys.select{|c| c=~/#{tube}/ }[0]
174
+ tests_hash[tube_key] << machine_code
175
+ end
176
+
172
177
  else
173
178
  AstmServer.log("ERROR: Test: #{test} does not have an LIS code")
174
179
  end
data/lib/ruby_astm.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "ruby_astm/usb_module"
1
2
  require "ruby_astm/query"
2
3
  require "ruby_astm/frame"
3
4
  require "ruby_astm/header"
@@ -8,6 +8,7 @@ require "redis"
8
8
  class AstmServer
9
9
 
10
10
  include LabInterface
11
+ include UsbModule
11
12
 
12
13
  def self.log(message)
13
14
  puts "" + message
@@ -28,27 +29,40 @@ class AstmServer
28
29
  $record_end = "[13]"
29
30
  $frame_end = "[10]"
30
31
 
31
- def initialize(server_ip=nil,server_port=nil,mpg=nil,respond_to_queries=false)
32
+
33
+ ## DEFAULT SERIAL PORT : /dev/ttyS0
34
+ ## DEFAULT USB PORT : /dev/ttyUSB0
35
+ def initialize(server_ip=nil,server_port=nil,mpg=nil,respond_to_queries=false,serial_port='/dev/ttyS0',usb_port='/dev/ttyUSB0',serial_baud=9600,serial_parity=8,usb_baud=19200,usb_parity=8)
32
36
  $redis = Redis.new
33
37
  AstmServer.log("Initializing AstmServer")
34
38
  self.server_ip = server_ip || "127.0.0.1"
35
39
  self.server_port = server_port || 3000
36
40
  self.respond_to_queries = respond_to_queries
41
+ self.serial_port = serial_port
42
+ self.serial_baud = serial_baud
43
+ self.serial_parity = serial_parity
44
+ self.usb_port = usb_port
45
+ self.usb_baud = usb_baud
46
+ self.usb_parity = usb_parity
37
47
  $mappings = JSON.parse(IO.read(mpg || AstmServer.default_mappings))
38
48
  end
39
49
 
40
50
  def start_server
41
51
  EventMachine.run {
42
- serial = EventMachine.open_serial('/dev/ttyS0', 9600, 8,LabInterface)
43
- puts "RUNNING SERIAL ON dev/ttyS0 ------------ #{serial.to_s}"
52
+ serial = EventMachine.open_serial(serial_port, serial_baud, serial_parity,LabInterface)
53
+ puts "RUNNING SERIAL ON #{serial_port} ------------ #{serial.to_s}"
44
54
  self.ethernet_server = EventMachine::start_server self.server_ip, self.server_port, LabInterface
45
55
  AstmServer.log("Running ETHERNET SERVER on #{server_port}")
46
- #serial = EventMachine.open_serial('/dev/ttyUSB0', 9600, 8)
47
- #serial.on_data do |data|
48
- # puts "got some data"
49
- # puts data.to_s
50
- # serial.send_data("\X06")
51
- #end
56
+ usb = EventMachine.open_serial(usb_port,usb_baud,usb_parity)
57
+ self.usb_response_bytes = []
58
+ EM.add_periodic_timer(5) do
59
+ puts "running usb on #{usb_port}"
60
+ puts "sending machine data request #{request_results}"
61
+ usb.send_data(request_results)
62
+ end
63
+ usb.on_data do |data|
64
+ parse_usb_response(data)
65
+ end
52
66
  }
53
67
  end
54
68
 
@@ -11,11 +11,19 @@ module LabInterface
11
11
  EOT = "\x04"
12
12
 
13
13
 
14
-
15
- mattr_accessor :headers
16
14
  mattr_accessor :ethernet_server
17
15
  mattr_accessor :server_ip
18
16
  mattr_accessor :server_port
17
+ mattr_accessor :serial_port
18
+ mattr_accessor :serial_baud
19
+ mattr_accessor :serial_parity
20
+ mattr_accessor :usb_port
21
+ mattr_accessor :usb_baud
22
+ mattr_accessor :usb_parity
23
+
24
+
25
+
26
+ mattr_accessor :headers
19
27
  mattr_accessor :mapping
20
28
  mattr_accessor :respond_to_queries
21
29
 
@@ -83,7 +91,9 @@ module LabInterface
83
91
 
84
92
  def receive_data(data)
85
93
 
86
- #begin
94
+
95
+ begin
96
+
87
97
 
88
98
  self.data_buffer ||= ''
89
99
 
@@ -179,11 +189,13 @@ module LabInterface
179
189
  send_data(ACK)
180
190
  end
181
191
  end
182
- #rescue => e
183
- # self.headers = []
184
- # AstmServer.log("data was: " + self.data_buffer + "error is:" + e.backtrace.to_s)
185
- # send_data(EOT)
186
- #end
192
+
193
+ rescue => e
194
+ #self.headers = []
195
+ AstmServer.log("data was: " + self.data_buffer + "error is:" + e.backtrace.to_s)
196
+ #send_data(EOT)
197
+ end
198
+
187
199
  end
188
200
 
189
201
  def send_enq
@@ -10,46 +10,60 @@ class Result
10
10
 
11
11
  def set_name(args)
12
12
  if line = args[:line]
13
- puts line.to_s
14
- puts line.fields[2].to_s
15
- line.fields[2].scan(/\^+(?<name>[A-Za-z0-9\%\#\-\_\?\/]+)\^?(?<dilution>\d+)?/) { |name,dilution|
16
-
17
- self.name = lookup_mapping(name)
18
-
19
- self.report_name = lookup_report_name(name)
20
13
 
21
- }
14
+ unless line.fields[2].blank?
15
+ line.fields[2].scan(/\^+(?<name>[A-Za-z0-9\%\#\-\_\?\/]+)\^?(?<dilution>\d+)?/) { |name,dilution|
16
+
17
+ self.name = lookup_mapping(name)
18
+
19
+ self.report_name = lookup_report_name(name)
22
20
 
23
- self.name.scan(/(?<test_name>\d+)\/(?<dilution>\d+)\/(?<pre_dilution>[a-zA-Z0-9]+)/) { |test_name,dilution,pre_dilution|
21
+ }
22
+ end
24
23
 
25
- self.name = lookup_mapping(test_name)
24
+ unless self.name.blank?
25
+ self.name.scan(/(?<test_name>\d+)\/(?<dilution>\d+)\/(?<pre_dilution>[a-zA-Z0-9]+)/) { |test_name,dilution,pre_dilution|
26
26
 
27
- self.report_name = lookup_report_name(test_name)
27
+ self.name = lookup_mapping(test_name)
28
28
 
29
- self.dilution = dilution
29
+ self.report_name = lookup_report_name(test_name)
30
+
31
+ self.dilution = dilution
32
+
33
+ }
34
+ end
30
35
 
31
- }
32
36
 
33
37
  end
34
38
  end
35
39
 
36
40
  def set_value(args)
37
41
  if line = args[:line]
38
- self.value = line.fields[3].strip
39
- self.value.scan(/(?<flag>\d+)\^(?<value>\d?\.?\d+)/) {|flag,value|
40
- self.value = value
41
- }
42
- line.fields[2].scan(/\^+(?<name>[A-Za-z0-9\%\#\-\_\?\/]+)\^?(?<dilution>\d+)?/) { |name,dilution|
43
- if transform_expression = lookup_transform(name)
44
- self.value = eval(transform_expression)
45
- end
46
- }
42
+
43
+ unless line.fields[3].blank?
44
+ self.value = line.fields[3].strip
45
+ self.value.scan(/(?<flag>\d+)\^(?<value>\d?\.?\d+)/) {|flag,value|
46
+ self.value = value
47
+ }
48
+ end
49
+ unless line.fields[2].blank?
50
+ line.fields[2].scan(/\^+(?<name>[A-Za-z0-9\%\#\-\_\?\/]+)\^?(?<dilution>\d+)?/) { |name,dilution|
51
+ if transform_expression = lookup_transform(name)
52
+ self.value = eval(transform_expression)
53
+ end
54
+ }
55
+ end
56
+
47
57
  end
48
58
  end
49
59
 
50
60
  def set_flags(args)
51
61
  if line = args[:line]
52
- self.flags = line.fields[6].strip
62
+
63
+ unless line.fields[6].blank?
64
+ self.flags = line.fields[6].strip
65
+ end
66
+
53
67
  end
54
68
  end
55
69
 
@@ -69,15 +83,23 @@ class Result
69
83
 
70
84
  def set_reference_ranges(args)
71
85
  if line = args[:line]
72
- self.reference_ranges = line.fields[5].strip
86
+
87
+ unless line.fields[5].blank?
88
+ self.reference_ranges = line.fields[5].strip
89
+ end
90
+
73
91
  end
74
92
  end
75
93
 
76
94
  def set_dilution(args)
77
95
  if line = args[:line]
78
- line.fields[2].scan(/\^+(?<name>[A-Za-z0-9\%\#\-\_\?\/]+)\^?(?<dilution>\d+)?/) { |name,dilution|
79
- self.dilution = dilution unless self.dilution
80
- }
96
+
97
+ unless line.fields[2].blank?
98
+ line.fields[2].scan(/\^+(?<name>[A-Za-z0-9\%\#\-\_\?\/]+)\^?(?<dilution>\d+)?/) { |name,dilution|
99
+ self.dilution = dilution unless self.dilution
100
+ }
101
+ end
102
+
81
103
  end
82
104
  end
83
105
 
@@ -114,6 +136,7 @@ class Result
114
136
  super
115
137
  end
116
138
  =end
139
+
117
140
  end
118
141
 
119
142
  ## @return[String] the name defined in the mappings.json file, or the name that wqs passed in.
@@ -0,0 +1,75 @@
1
+ require "active_support/all"
2
+
3
+ module UsbModule
4
+
5
+ mattr_accessor :usb_response_bytes
6
+
7
+ def begin_patient_results
8
+ ">00A00013"
9
+ end
10
+
11
+ def request_version
12
+ ">00000080\r00"
13
+ end
14
+
15
+ def request_status
16
+ ">00000082\r00"
17
+ end
18
+
19
+ ## requests the last 5 tests performed.
20
+ ## last two digits before the carriage return are 00
21
+ ## if digits are 01 : will take the 5 penultimate tests
22
+ ## if digits are 13 : will take the first 5 tests from memory.
23
+ def request_results
24
+ ">0002009300\r00"
25
+ end
26
+
27
+ def interpret?
28
+ ## if the third last is a carriage return, then interpret.l
29
+
30
+ self.usb_response_bytes[-3] == 13
31
+ end
32
+
33
+ def parse_usb_response(string_data)
34
+ string_data.bytes.to_a.each do |byte|
35
+ self.usb_response_bytes.push(byte)
36
+ end
37
+ #puts "self usb response bytes:"
38
+ #puts self.usb_response_bytes.to_s
39
+ if interpret?
40
+ #puts "interpret"
41
+ self.usb_response_bytes[13..-4].each_slice(32) do |patient_record|
42
+ bar_code = nil
43
+ bar_code = patient_record[11..23].pack('c*').gsub(/\./,'')
44
+ #puts "bar code: #{bar_code}"
45
+ unless bar_code.strip.blank?
46
+ esr = patient_record[26]
47
+ patient = Patient.new(:orders => [Order.new(:results => [Result.new(:value => esr, :name => "ESR", :report_name => "ESR")])])
48
+ patient = Patient.new({})
49
+ patient.patient_id = bar_code
50
+ patient.orders = []
51
+ order = Order.new({})
52
+ result = Result.new({})
53
+ result.value = esr.to_s
54
+ result.name = "ESR"
55
+ result.report_name = "ESR"
56
+ order.id = bar_code
57
+ order.results = []
58
+ order.results << result
59
+ patient.orders << order
60
+ #puts patient.orders.size
61
+ #puts patient.orders.first.results.size
62
+ #puts patient.orders.first.results.first.to_s
63
+ #puts "patient to json is:"
64
+ puts patient.to_json
65
+ $redis.lpush("patients",patient.to_json)
66
+ end
67
+ end
68
+ self.usb_response_bytes = []
69
+ else
70
+ #puts "dont interpret"
71
+ end
72
+
73
+ end
74
+
75
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_astm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bhargav Raut
@@ -133,6 +133,7 @@ files:
133
133
  - lib/ruby_astm/patient.rb
134
134
  - lib/ruby_astm/query.rb
135
135
  - lib/ruby_astm/result.rb
136
+ - lib/ruby_astm/usb_module.rb
136
137
  homepage: https://www.github/com/wordjelly/ruby_astm
137
138
  licenses:
138
139
  - MIT