ruby_astm 1.4.7 → 1.4.9

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: 2e92b2e6071300c63a2c9cf237c68daf4e139a8806e451382eb3ad84b5ff7143
4
- data.tar.gz: '08e321353b2f109d2994ab9f6e12720f564e4cff195b95fae4a6cc4b69145f1b'
3
+ metadata.gz: 6abc78dc8d0ed2abe9b877e3727155c0aacfe008b40f8e68678f8953c41b3230
4
+ data.tar.gz: 2c477c41fb604d712da07752e0468bd6468a51ca0ca3e86c24985a99a5003b1d
5
5
  SHA512:
6
- metadata.gz: 8a41a9637d497c4135adc2f846b45cfaefaa0b878259380c81440c7a32b6fcc098c7f2cfd99e0269d995cc6540f2d7760dcb66e4106af81a0690c58a5f1b382b
7
- data.tar.gz: a743e98d90ed2a7c022ac75a8a64c42987f717e61e679a3ba5ed5cdaf4a70a16231544dcfdd34bb7e4a5920bfa6ab98250dabbab508577d2a34f8dc47bf1401f
6
+ metadata.gz: c1c5b8d38e039fb84feee8ce501a5fc648ffe7fd79aa088f4018c4dd18c60d6611ba75deac6652b3d558778adf02f827aee3a716e4000e19b762b7459a943385
7
+ data.tar.gz: 49e0c42b89413aabb1d40ca9a5b2e8ccdedd34ad3a3919a4de6de827f7b33237ab329d96d88679b00850be09f16b6f05be85d9059b4057bc863d431821d8ac40
@@ -59,6 +59,9 @@ class Google_Lab_Interface < Poller
59
59
  AstmServer.log("Initialized Google Lab Interface")
60
60
  $service = Google::Apis::ScriptV1::ScriptService.new
61
61
  $service.client_options.application_name = APPLICATION_NAME
62
+ $service.client_options.send_timeout_sec = 1200
63
+ $service.client_options.open_timeout_sec = 1200
64
+ $service.request_options.retries = 3
62
65
  $service.authorization = authorize
63
66
  end
64
67
 
@@ -74,12 +77,16 @@ class Google_Lab_Interface < Poller
74
77
  :input => JSON.generate([epoch])
75
78
  }
76
79
 
80
+
81
+
77
82
  request = Google::Apis::ScriptV1::ExecutionRequest.new(
78
83
  function: 'get_latest_test_information',
79
84
  parameters: pp
80
85
  )
81
86
 
82
- begin
87
+ puts "params are: #{pp}"
88
+
89
+ #begin
83
90
  resp = $service.run_script(self.script_id, request)
84
91
  if resp.error
85
92
  AstmServer.log("Response Error polling LIS for requisitions: #{resp.error.message}: #{resp.error.code}")
@@ -87,13 +94,13 @@ class Google_Lab_Interface < Poller
87
94
  process_LIS_response(resp.response["result"])
88
95
  AstmServer.log("Successfully polled lis for requisitions: #{resp.response}")
89
96
  end
90
- rescue => e
91
- AstmServer.log("Rescue Error polling LIS for requisitions: #{e.to_s}")
92
- AstmServer.log("Error backtrace")
93
- AstmServer.log(e.backtrace.to_s)
94
- ensure
97
+ #rescue => e
98
+ #AstmServer.log("Rescue Error polling LIS for requisitions: #{e.to_s}")
99
+ #AstmServer.log("Error backtrace")
100
+ #AstmServer.log(e.backtrace.to_s)
101
+ #ensure
95
102
 
96
- end
103
+ #end
97
104
 
98
105
  end
99
106
 
@@ -253,7 +253,24 @@ class Poller
253
253
  def get_checkpoint
254
254
  latest_two_entries = $redis.zrange Poller::REQUISITIONS_SORTED_SET, -2, -1, {withscores: true}
255
255
  unless latest_two_entries.blank?
256
- latest_two_entries[-1][1].to_i
256
+ last_entry = latest_two_entries[-1][1].to_i
257
+ #one_year_back = Time.now - 1.year
258
+ #one_year_back = one_year_back.to_i
259
+ #time_now = Time.now.to_i
260
+ #puts "diff is: #{time_now*1000 - one_year_back*1000}"
261
+ #puts "one year back is "
262
+ #puts "last entry is: #{last_entry}"
263
+ #puts "last entry - Time.now is :#{Time.now.to_i*1000 - last_entry}"
264
+ #puts "default checkpoint is :#{default_checkpoint}"
265
+ #last_entry
266
+ #default_checkpoint
267
+ if (((Time.now.to_i)*1000) - last_entry) >= 86400*1000
268
+ puts "diff is too great"
269
+ default_checkpoint
270
+ else
271
+ puts "taking the last entry"
272
+ last_entry
273
+ end
257
274
  else
258
275
  default_checkpoint
259
276
  end
@@ -78,6 +78,17 @@ module LabInterface
78
78
  File.dirname __dir__
79
79
  end
80
80
 
81
+
82
+ def process_byte_file(full_file_path)
83
+ bytes = eval(IO.read(full_file_path))
84
+ bytes = bytes.flatten
85
+ text = pre_process_bytes(bytes,"")
86
+ text.each_line do |line|
87
+ line.split('\\r').each do |txt|
88
+ process_text(txt)
89
+ end
90
+ end
91
+ end
81
92
  ## can process a file which contains ASTM output.
82
93
  ## this method is added so that you can load previously generated ASTM output into your database
83
94
  ## it also simplifies testing.
@@ -209,76 +220,7 @@ module LabInterface
209
220
 
210
221
  end
211
222
 
212
- ## @param[Array] :
213
- ## [[bytes],[bytes]....]
214
- def process_electrolytes(data_bytes)
215
- #puts "came to process electrolytes_plain_text"
216
- byte_arr = data_bytes.flatten
217
- #puts "the end part of the arr is"
218
- return if byte_arr[-4..-1] != SIEMENS_ELECTROLYTE_END
219
- self.data_bytes = []
220
- concat = ""
221
- byte_arr.each do |byte|
222
- x = [byte].pack('c*').force_encoding('UTF-8')
223
- if x == "\r"
224
- concat+="\n"
225
- elsif x == "\n"
226
- #puts "new line found --- "
227
- concat+=x
228
- #puts "last thing in concat."
229
- #puts concat[-1].to_s
230
- else
231
- concat+=x
232
- end
233
- end
234
- ## nwo write concat to file
235
- ## File.open("electrolytes_plain_text.txt", 'a+') { |file| file.write(concat) }
236
- ## Header
237
- ## Patient
238
- ## Order
239
- ## Result
240
- ## Terminator
241
-
242
- ## GET PO2
243
- concat.scan(/pCO2\s+(?<pco>(\d+)(\.\d)*)(\^|v)?\s+mmHg/) do |k|
244
- n = Regexp.last_match
245
- puts n[:pco].to_s
246
- end
247
-
248
- ## GET PCO2
249
- concat.scan(/pO2\s+(?<po>(\d+)(\.\d)*)(\^|v)?\s+mmHg/) do |k|
250
- n = Regexp.last_match
251
- puts n[:po].to_s
252
- end
253
-
254
- ## GET PH
255
-
256
- ## GET NA+
257
-
258
- ## GET K+
259
-
260
- ## GET CL-
261
-
262
- ## GET PATIENT_ID
263
-
264
- ## GET DATE AND TIME
265
-
266
- start_measure = false
267
-
268
- concat.split(/\n/).each do |line|
269
- if line =~ /348\-D718/
270
- header = Header.new({:line => line})
271
- self.headers ||= []
272
- self.headers << header
273
- elsif line =~ /\-{32}/
274
- elsif line =~ /Patient\s+ID/
275
- elsif line =~ /Measured/
276
- elsif line =~ /outside ref/
277
- else
278
- end
279
- end
280
-
281
- end
223
+
282
224
 
283
225
  def receive_data(data)
284
226
 
@@ -324,10 +266,10 @@ module LabInterface
324
266
  if data.bytes.to_a[-1] == 4
325
267
  puts "GOT EOT --- PROCESSING BUFFER, AND CLEARING."
326
268
  process_text(self.data_buffer)
327
- #root_path = File.dirname __dir
328
- #puts "root path #{root_path}"
329
- #IO.write((File.join root_path,'test','resources','roche_multi_frame_bytes.txt'),self.test_data_bytes.to_s)
330
- #puts self.test_data_bytes.flatten.to_s
269
+ root_path = File.dirname __dir__
270
+ puts "root path #{root_path}"
271
+ #IO.write((File.join root_path,'../test','resources','stago.txt'),self.test_data_bytes.to_s)
272
+ puts self.test_data_bytes.flatten.to_s
331
273
  self.data_buffer = ''
332
274
  unless self.headers.blank?
333
275
  if self.headers[-1].queries.blank?
@@ -467,7 +409,10 @@ module LabInterface
467
409
  end
468
410
  end
469
411
  when "Result"
412
+ puts "GOT RESULT------------------>"
413
+ puts "line is :#{line}"
470
414
  result = Result.new({:line => line})
415
+ puts "made new result"
471
416
  unless self.headers.blank?
472
417
  unless self.headers[-1].patients.blank?
473
418
  unless self.headers[-1].patients[-1].orders[-1].blank?
@@ -74,6 +74,7 @@ class Order
74
74
  end
75
75
 
76
76
  def initialize(args={})
77
+ puts "------------ INITIALIZING ORDER -------------- "
77
78
  set_id(args)
78
79
  set_priority(args)
79
80
  set_sequence_number(args)
@@ -9,9 +9,12 @@ class Result
9
9
  attr_accessor :dilution
10
10
 
11
11
  def set_name(args)
12
+ puts "came to set name"
12
13
  if line = args[:line]
13
-
14
+ puts "line fields is: #{line.fields}"
14
15
  unless line.fields[2].blank?
16
+ puts "line fields 2 is:"
17
+ puts line.fields[2]
15
18
  line.fields[2].scan(/^\^+(?<name>[A-Za-z0-9\%\#\-\_\?\/]+)\^?(?<dilution>\d+)?/) { |name,dilution|
16
19
 
17
20
  self.name = lookup_mapping(name)
@@ -47,6 +50,9 @@ class Result
47
50
  }
48
51
  end
49
52
  unless line.fields[2].blank?
53
+ puts "line fields 2 is:"
54
+ puts line.fields[2]
55
+ puts "----------------------------"
50
56
  line.fields[2].scan(/\^+(?<name>[A-Za-z0-9\%\#\-\_\?\/]+)\^?(?<dilution>\d+)?/) { |name,dilution|
51
57
  if transform_expression = lookup_transform(name)
52
58
  self.value = eval(transform_expression)
@@ -107,6 +113,7 @@ class Result
107
113
 
108
114
  ## here will call mappings and check the result correlation
109
115
  def initialize(args={})
116
+ puts "called initialize result"
110
117
  set_name(args)
111
118
  set_flags(args)
112
119
  set_value(args)
@@ -4,6 +4,8 @@ module UsbModule
4
4
 
5
5
  mattr_accessor :usb_response_bytes
6
6
 
7
+ ESR_RESULTS_HASH = "ESR_RESULTS_HASH"
8
+
7
9
  def begin_patient_results
8
10
  ">00A00013"
9
11
  end
@@ -30,6 +32,24 @@ module UsbModule
30
32
  self.usb_response_bytes[-3] == 13
31
33
  end
32
34
 
35
+ def add_result?(barcode,result)
36
+ begin
37
+ Integer(result)
38
+ #puts "result is: #{result}"
39
+ return false if result.to_i == 0
40
+ #puts "the result is not zero"
41
+ existing_result = $redis.hget(ESR_RESULTS_HASH,barcode)
42
+ #puts "existing result is: #{existing_result}"
43
+ if ((existing_result.blank?) || (existing_result != result))
44
+ return true
45
+ end
46
+ rescue => e
47
+ puts e.to_s
48
+ return false
49
+ end
50
+
51
+ end
52
+
33
53
  def parse_usb_response(string_data)
34
54
  string_data.bytes.to_a.each do |byte|
35
55
  self.usb_response_bytes.push(byte)
@@ -40,31 +60,35 @@ module UsbModule
40
60
  #puts "interpret"
41
61
  if kk = self.usb_response_bytes[13..-4]
42
62
  kk.each_slice(32) do |patient_record|
43
- bar_code = nil
44
- bar_code = patient_record[11..23].pack('c*').gsub(/\./,'')
45
- #puts "bar code: #{bar_code}"
46
- unless bar_code.strip.blank?
47
- esr = patient_record[26]
48
- patient = Patient.new(:orders => [Order.new(:results => [Result.new(:value => esr, :name => "ESR", :report_name => "ESR")])])
49
- patient = Patient.new({})
50
- patient.patient_id = bar_code
51
- patient.orders = []
52
- order = Order.new({})
53
- result = Result.new({})
54
- result.value = esr.to_s
55
- result.name = "ESR"
56
- result.report_name = "ESR"
57
- order.id = bar_code
58
- order.results = []
59
- order.results << result
60
- patient.orders << order
61
- #puts patient.orders.size
62
- #puts patient.orders.first.results.size
63
- #puts patient.orders.first.results.first.to_s
64
- #puts "patient to json is:"
65
- puts patient.to_json
66
- $redis.lpush("patients",patient.to_json)
67
- end
63
+ unless patient_record.blank?
64
+ unless patient_record.size < 24
65
+ bar_code = nil
66
+ bar_code = patient_record[11..23].pack('c*').gsub(/\./,'')
67
+ #puts "bar code: #{bar_code}"
68
+ unless bar_code.strip.blank?
69
+ esr = patient_record[26]
70
+ patient = Patient.new(:orders => [Order.new(:results => [Result.new(:value => esr, :name => "ESR", :report_name => "ESR")])])
71
+ patient = Patient.new({})
72
+ patient.patient_id = bar_code
73
+ patient.orders = []
74
+ order = Order.new({})
75
+ result = Result.new({})
76
+ result.value = esr.to_s
77
+ result.name = "ESR"
78
+ result.report_name = "ESR"
79
+ order.id = bar_code
80
+ order.results = []
81
+ order.results << result
82
+ #puts "barcode: #{bar_code}, result : #{result.value}"
83
+ patient.orders << order
84
+ if add_result?(bar_code,result.value)
85
+ #puts patient.to_json
86
+ $redis.lpush("test_patients",patient.to_json)
87
+ $redis.hset(ESR_RESULTS_HASH,bar_code,result.value.to_i)
88
+ end
89
+ end
90
+ end
91
+ end
68
92
  end
69
93
  end
70
94
  self.usb_response_bytes = []
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.4.7
4
+ version: 1.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bhargav Raut