Module: SiemensAbgElectrolyteModule
Constant Summary
collapse
- SIEMENS_ELECTROLYTE_END =
[10,10,10,10]
- ELECTROLYTE_START =
[45, 45, 45, 32]
- SIEMENS_ELEC_ABG_RESULTS_HASH =
"SIEMENS_ELEC_ABG_RESULTS_HASH"
LabInterface::ACK, LabInterface::CR, LabInterface::ENQ, LabInterface::EOT, LabInterface::ETX, LabInterface::LF, LabInterface::STX
Instance Attribute Summary collapse
Attributes included from LabInterface
#data_buffer, #data_bytes, #ethernet_connections, #ethernet_server, #headers, #mapping, #mid_frame_end_detected, #respond_to_queries, #serial_baud, #serial_connections, #serial_parity, #serial_port, #server_ip, #server_port, #test_data_bytes, #usb_baud, #usb_parity, #usb_port
Class Method Summary
collapse
Instance Method Summary
collapse
#checksum, #generate_response, #is_mid_frame_end?, #pre_process_bytes, #process_byte_file, #process_text, #process_type, #root, #send_enq, #terminator, #unbind, #write_bytes_to_file
Instance Attribute Details
#current_text_segment ⇒ Object
Returns the value of attribute current_text_segment.
14
15
16
|
# File 'lib/ruby_astm/custom/siemens_abg_electrolyte_module.rb', line 14
def current_text_segment
@current_text_segment
end
|
Class Method Details
.included(base) ⇒ Object
5
6
7
|
# File 'lib/ruby_astm/custom/siemens_abg_electrolyte_module.rb', line 5
def self.included base
base.extend ClassMethods
end
|
Instance Method Details
#add_result?(barcode, result) ⇒ Boolean
@param barcode : the barcode @param result : result_object
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/ruby_astm/custom/siemens_abg_electrolyte_module.rb', line 95
def add_result?(barcode,result)
puts "Came to add result"
return true if $redis.hget(SIEMENS_ELEC_ABG_RESULTS_HASH,barcode).blank?
existing_results = JSON.parse($redis.hget(SIEMENS_ELEC_ABG_RESULTS_HASH,barcode))
if existing_results[result.name].blank?
return true
elsif existing_results[result.name] != result.value
return true
end
false
end
|
#clear ⇒ Object
228
229
230
231
232
|
# File 'lib/ruby_astm/custom/siemens_abg_electrolyte_module.rb', line 228
def clear
self.data_buffer = ''
self.test_data_bytes = []
self.data_bytes = []
end
|
#get_cl ⇒ Object
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/ruby_astm/custom/siemens_abg_electrolyte_module.rb', line 71
def get_cl
m = []
self.current_text_segment.scan(/Cl\-\s+(?<k>(\d+)[\.\d]*)(\^|v)?\s+mmol\/L/) do |l|
n = Regexp.last_match
m << n[:k].to_s
end
raise "more than one result #{m.to_s}" if (m.size > 1)
return m[0] if m.size == 1
return nil
end
|
#get_k ⇒ Object
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/ruby_astm/custom/siemens_abg_electrolyte_module.rb', line 60
def get_k
m = []
self.current_text_segment.scan(/K\+\s+(?<k>(\d+)[\.\d]*)(\^|v)?\s+mmol\/L/) do |l|
n = Regexp.last_match
m << n[:k].to_s
end
raise "more than one result #{m.to_s}" if (m.size > 1)
return m[0] if m.size == 1
return nil
end
|
#get_na ⇒ Object
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/ruby_astm/custom/siemens_abg_electrolyte_module.rb', line 49
def get_na
m = []
self.current_text_segment.scan(/Na\+\s+(?<k>(\d+)[\.\d]*)(\^|v)?\s+mmol\/L/) do |l|
n = Regexp.last_match
m << n[:k].to_s
end
raise "more than one result #{m.to_s}" if (m.size > 1)
return m[0] if m.size == 1
return nil
end
|
#get_patient_id ⇒ Object
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/ruby_astm/custom/siemens_abg_electrolyte_module.rb', line 82
def get_patient_id
m = []
self.current_text_segment.scan(/Patient\s+ID\s+(?<k>\d+)$/) do |l|
n = Regexp.last_match
m << n[:k].to_s
end
raise "more than one result #{m.to_s}" if (m.size > 1)
return m[0] if m.size == 1
return nil
end
|
#get_pco2 ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/ruby_astm/custom/siemens_abg_electrolyte_module.rb', line 27
def get_pco2
m = []
self.current_text_segment.scan(/pCO2\s+(?<k>(\d+)(\.\d)*)(\^|v)?\s+mmHg/) do |l|
n = Regexp.last_match
m << n[:k].to_s
end
raise "more than one result #{m.to_s}" if (m.size > 1)
return m[0] if m.size == 1
return nil
end
|
#get_ph ⇒ Object
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/ruby_astm/custom/siemens_abg_electrolyte_module.rb', line 38
def get_ph
m = []
self.current_text_segment.scan(/pH\s+(?<k>(\d+)[\.\d]*)(\^|v)?\s+$/) do |l|
n = Regexp.last_match
m << n[:k].to_s
end
raise "more than one result #{m.to_s}" if (m.size > 1)
return m[0] if m.size == 1
return nil
end
|
#get_po2 ⇒ Object
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/ruby_astm/custom/siemens_abg_electrolyte_module.rb', line 16
def get_po2
m = []
self.current_text_segment.scan(/pO2\s+(?<k>(\d+)(\.\d)*)(\^|v)?\s+mmHg/) do |l|
n = Regexp.last_match
m << n[:k].to_s
end
raise "more than one result #{m.to_s}" if (m.size > 1)
return m[0] if m.size == 1
return nil
end
|
#process_electrolytes(data_bytes) ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
# File 'lib/ruby_astm/custom/siemens_abg_electrolyte_module.rb', line 114
def process_electrolytes(data_bytes)
byte_arr = data_bytes.flatten
return if byte_arr[-4..-1] != SIEMENS_ELECTROLYTE_END
self.data_bytes = []
concat = ""
byte_arr.each do |byte|
x = [byte].pack('c*').force_encoding('UTF-8')
if x == "\r"
concat+="\n"
elsif x == "\n"
concat+=x
else
concat+=x
end
end
self. ||= [Header.new]
concat.split("--------------------------------").each do |record|
self.current_text_segment = record
if patient_id = get_patient_id
self.[-1].patients ||= []
p = Patient.new
p.patient_id = patient_id
p.orders ||= []
o = Order.new
o.id = patient_id
o.results ||= {}
if sodium = get_na
r = Result.new
r.name = "SNATRIUM"
r.report_name = "Serum Electrolytes"
r.value = sodium
r.units = "mmol/L"
r.timestamp = Time.now.to_i
o.results["SNATRIUM"] = r if add_result?(patient_id,r)
end
if potassium = get_k
r = Result.new
r.name = "SPOTASSIUM"
r.report_name = "Serum Electrolytes"
r.value = potassium
r.units = "mmol/L"
r.timestamp = Time.now.to_i
o.results["SPOTASSIUM"] = r if add_result?(patient_id,r)
end
if chloride = get_cl
r = Result.new
r.name = "SCHLORIDE"
r.report_name = "Serum Electrolytes"
r.value = chloride
r.units = "mmol/L"
r.timestamp = Time.now.to_i
o.results["SCHLORIDE"] = r if add_result?(patient_id,r)
end
if ph = get_ph
r = Result.new
r.name = "pH"
r.report_name = "ABG"
r.value = ph
r.units = "mmol/L"
r.timestamp = Time.now.to_i
o.results["pH"] = r if add_result?(patient_id,r)
end
if po2 = get_po2
r = Result.new
r.name = "po2"
r.report_name = "ABG"
r.value = po2
r.units = "mmHg"
r.timestamp = Time.now.to_i
o.results["po2"] = r if add_result?(patient_id,r)
end
if pco2 = get_pco2
r = Result.new
r.name = "pco2"
r.report_name = "ABG"
r.value = pco2
r.units = "mmHg"
r.timestamp = Time.now.to_i
o.results["pco2"] = r if add_result?(patient_id,r)
end
unless o.results.blank?
p.orders << o
$redis.hset(SIEMENS_ELEC_ABG_RESULTS_HASH,patient_id,JSON.generate(o.results_values_hash))
self.[-1].patients << p
end
end
end
if self..size > 0
self.[-1].commit
clear
end
end
|
#process_text_file(full_file_path) ⇒ Object
223
224
225
226
|
# File 'lib/ruby_astm/custom/siemens_abg_electrolyte_module.rb', line 223
def process_text_file(full_file_path)
k = IO.read(full_file_path)
process_electrolytes(k.bytes)
end
|
#receive_data(data) ⇒ Object
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
# File 'lib/ruby_astm/custom/siemens_abg_electrolyte_module.rb', line 235
def receive_data(data)
begin
self.data_buffer ||= ''
concat = ""
byte_arr = data.bytes.to_a
self.test_data_bytes ||= []
self.data_bytes ||= []
self.test_data_bytes.push(byte_arr)
self.data_bytes.push(byte_arr)
concat = pre_process_bytes(byte_arr,concat)
self.data_buffer << concat
self.process_electrolytes(self.data_bytes)
=begin
if data.bytes.to_a[-1] == 4
puts "GOT EOT --- PROCESSING BUFFER, AND CLEARING."
process_text(self.data_buffer)
#root_path = File.dirname __dir
#puts "root path #{root_path}"
#IO.write((File.join root_path,'test','resources','roche_multi_frame_bytes.txt'),self.test_data_bytes.to_s)
#puts self.test_data_bytes.flatten.to_s
self.data_buffer = ''
unless self.headers.blank?
if self.headers[-1].queries.blank?
#puts "no queries in header so sending ack after getting EOT and processing the buffer"
send_data(ACK)
else
#puts "sending ENQ"
send_data(ENQ)
end
else
puts "sending catch all --------------- ACK --------------"
send_data(ACK)
end
elsif data.bytes.to_a[0] == 6
puts "GOT ACK --- GENERATING RESPONSE"
unless self.headers.blank?
header_responses = self.headers[-1].build_one_response({machine_name: self.headers[-1].machine_name})
## if no queries then, we have to send ack.
if header_responses.blank?
#puts "sending ACK since there are no queries in the header"
send_data(ACK)
end
header_responses.each_with_index {|response,key|
message_checksum = checksum(response + terminator + ETX)
final_resp = STX + response + terminator + ETX + message_checksum + "\r"
final_resp_arr = final_resp.bytes.to_a
final_resp_arr << 10
if (self.headers[-1].response_sent == false)
#puts "sending the data as follows----------------------------------------------"
#puts "response sent is:"
#puts self.headers[-1].response_sent
#puts final_resp_arr.pack('c*').gsub(/\r/,'\n')
send_data(final_resp_arr.pack('c*'))
self.headers[-1].response_sent = true if (key == (header_responses.size - 1))
else
#puts "sending EOT"
send_data(EOT)
end
}
else
#puts "NO HEADERS PRESENT --- "
end
elsif data.bytes.to_a[0] == 255
puts " ----------- got 255 data -----------, not sending anything back. "
else
#unless self.data_buffer.blank?
# puts self.data_buffer.gsub(/\r/,'\n').to_s
#end
## send the header
#puts "--------- SENT ACK -----------"
## strip non utf 8 characters from it.
self.data_buffer.encode!('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
if self.data_buffer =~ /MSH\|/
#puts " -------------- HEADERS ARE BLANK WITH HL7, sending ack. ------------ "
process_text(self.data_buffer)
self.data_buffer = ''
if self.headers.size > 0
self.headers[-1].commit
send_data(self.headers[-1].generate_ack_success_response)
end
else
#puts " -------------- HEADERS ARE BLANK NOT HL7, sending ack. ------------ "
send_data(ACK)
end
end
=end
rescue => e
AstmServer.log("data was: " + self.data_buffer + "error is:" + e.backtrace.to_s)
end
end
|