ruby_astm 1.4.4 → 1.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1edecd39318ba2231234a0bd46de36f2eded3843
4
- data.tar.gz: c0da0a6d63ec31c478b083ecbf11c5772f709ab9
3
+ metadata.gz: cd2c1d542ca88df2907a1ced3c504be478562cc1
4
+ data.tar.gz: 9498ee9636238cf9320c2d7da27ac3dd117eca40
5
5
  SHA512:
6
- metadata.gz: 2b4ad9ac1b9db8eedcddf90db7fb09a2b8868388f8268591b7273900e66f4baeebf447dc93ec4772398fd87928b5edf2f591d20d895daa12a5db16e7ace0d678
7
- data.tar.gz: 72c2afa43a44ae1d6c20ea21e26e8d9ea3cd357495c291a08694fdc1d0f65289b23b5c0e5ec5b296bf9731ddc667bd6fb9aac8c849a0ed90c467cbf6b6fc9f0d
6
+ metadata.gz: c33a3270c4e96663b714eef93522f282474f77ab220bc4dd53eccc625eac332c224944403237469c93f5cc2b95f7c0063102c2be2fa80a43408d6287665a34e7
7
+ data.tar.gz: feca986fc7ade45225533c15671aa221e8285b30d5a1868a7ab46c92c385e584a738dae65ddb07c239d7e238f141b752242d1f2fcd86e4134544e2f0a96e568b
data/lib/mappings.json CHANGED
@@ -529,6 +529,23 @@
529
529
  "REPORT_NAME" : "kidney_function_tests",
530
530
  "PACKAGE_COMPONENTS" : ["CRE", "UREA", "BUN"],
531
531
  "TYPE" : "BIOCHEM"
532
+ },
533
+ "SPT" : {
534
+ "LIS_CODE" : "SPT",
535
+ "TUBE" : "SERUM",
536
+ "REPORT_NAME" : "PTAPTT",
537
+ "TYPE" : "BIOCHEM-EXL"
538
+ },
539
+ "SAPTT" : {
540
+ "LIS_CODE" : "SAPTT",
541
+ "TUBE" : "SERUM",
542
+ "REPORT_NAME" : "PTAPTT",
543
+ "TYPE" : "BIOCHEM-EXL"
544
+ },
545
+ "SINR" : {
546
+ "LIS_CODE" : "SINR",
547
+ "TUBE" : "SERUM",
548
+ "REPORT_NAME" : "PTAPTT",
549
+ "TYPE" : "BIOCHEM-EXL"
532
550
  }
533
-
534
551
  }
@@ -235,8 +235,12 @@ class Poller
235
235
  tests.keys.each do |tube_barcode|
236
236
  ## in this hash we want the key to be only the specimen id.
237
237
  ## and not prefixed by the tube type like FLUORIDE etc.
238
+ ## i don't want the individual tests,
239
+ ## i want the report name.
240
+ ## prefixed to it.
238
241
  tube_barcode.scan(/:(?<barcode>.*)$/) { |barcode|
239
242
  $redis.hset REQUISITIONS_HASH, barcode, JSON.generate(tests[tube_barcode])
243
+ $real_time_db.assign_test(barcode,tests[tube_barcode],$mappings) unless $real_time_db.blank?
240
244
  }
241
245
  end
242
246
  end
@@ -1,11 +1,27 @@
1
1
  require 'rest-firebase'
2
2
  require "resolv-replace"
3
+ require "jwt"
4
+ require "net/http"
5
+
6
+ RestFirebase.class_eval do
7
+ def query
8
+ {:access_token => auth}
9
+ end
10
+ end
11
+
3
12
  class RealTimeDb
4
13
 
5
14
  SITE_URL = ENV["FIREBASE_SITE"]
6
15
  SECRET = ENV["FIREBASE_SECRET"]
16
+ ENDPOINT = "pathofast"
17
+ ACCESSION_DONE = "ACCESSION_DONE"
18
+ PROCESSING = "PROCESSING"
19
+
20
+
7
21
  attr_accessor :connection
8
22
  attr_accessor :work_allotment_hash
23
+ attr_accessor :private_key_hash
24
+
9
25
  WORK_TYPES = {
10
26
  "IMMUNO" => "",
11
27
  "BIOCHEM" => "",
@@ -16,15 +32,50 @@ class RealTimeDb
16
32
  "OUTSOURCE" => ""
17
33
  }
18
34
 
19
- ## first i email myself the site and secret
20
- ## then we proceed.
35
+
36
+ def get_jwt
37
+ puts Base64.encode64(JSON.generate(self.private_key_hash))
38
+ # Get your service account's email address and private key from the JSON key file
39
+ $service_account_email = self.private_key_hash["client_email"]
40
+ $private_key = OpenSSL::PKey::RSA.new self.private_key_hash["private_key"]
41
+ now_seconds = Time.now.to_i
42
+ payload = {:iss => $service_account_email,
43
+ :sub => $service_account_email,
44
+ :aud => self.private_key_hash["token_uri"],
45
+ :iat => now_seconds,
46
+ :exp => now_seconds+(60*60), # Maximum expiration time is one hour
47
+ :scope => 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/firebase.database'
48
+
49
+ }
50
+ JWT.encode payload, $private_key, "RS256"
51
+
52
+ end
53
+
54
+ def generate_access_token
55
+ uri = URI.parse(self.private_key_hash["token_uri"])
56
+ https = Net::HTTP.new(uri.host, uri.port)
57
+ https.use_ssl = true
58
+ req = Net::HTTP::Post.new(uri.path)
59
+ req['Cache-Control'] = "no-store"
60
+ req.set_form_data({
61
+ grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
62
+ assertion: get_jwt
63
+ })
64
+
65
+ resp = JSON.parse(https.request(req).body)
66
+ puts "response is:"
67
+ puts resp.to_s
68
+ resp["access_token"]
69
+ end
21
70
 
22
71
  ## @param[Hash] work_allotment_hash :
23
72
  ## key => one of the work types
24
73
  ## value => name of a worker
25
- def initialize(work_allotment_hash)
74
+ def initialize(work_allotment_hash,private_key_hash)
75
+ self.private_key_hash = private_key_hash
76
+ raise "please provide the private key hash, from firebase service account -> create private key " if private_key_hash.blank?
26
77
  self.connection = RestFirebase.new :site => SITE_URL,
27
- :secret => SECRET
78
+ :secret => SECRET, :auth =>generate_access_token
28
79
  puts "initialized"
29
80
  self.work_allotment_hash = work_allotment_hash || WORK_TYPES
30
81
  end
@@ -46,31 +97,63 @@ class RealTimeDb
46
97
  self.connection.wait
47
98
  end
48
99
 
100
+ ## if the barcode exists,
101
+ ## otherwise create it.
102
+ def barcode_exists?(barcode)
103
+ begin
104
+ self.connection.get(ENDPOINT, :orderBy => 'barcode', :equalTo => barcode)
105
+ rescue
106
+ ## reestablish the connection
107
+ self.connection = RestFirebase.new :site => SITE_URL,
108
+ :secret => SECRET, :auth =>generate_access_token
109
+ true
110
+ end
111
+ end
49
112
 
50
-
113
+ ## idea is simple
114
+ ## send the image -> to one collection, as a post
115
+ ## take it -> analyze it -> update the result
116
+ ## to another collection
117
+ ## show it in the UI.
118
+ ## knock off the earlier one.
51
119
 
52
120
  ## we pass the real_time_data instance into the
53
-
54
121
  def assign_test(barcode,tests,mappings)
55
122
  ## so do we get the name of the worker.
56
- inverted_mappings = {}
57
- mappings.keys.each do |machine_code|
58
- lis_code = mappings[machine_code][LIS_CODE]
59
- inverted_mappings[lis_code] = mappings[machine_code]
60
- end
61
- worker_hash = {}
62
- tests.each do |lis_code|
63
- worker_name = "NO_ONE"
64
- unless inverted_mappings[lis_code].blank?
65
- test_type = inverted_mappings[lis_code]["TYPE"]
66
- worker_name = self.work_allotment_hash[test_type]
123
+ if barcode_exists?(barcode[0]).blank?
124
+
125
+ worker_hash = {}
126
+ tests.each do |machine_code|
127
+ worker_name = "NO_ONE"
128
+
129
+ unless mappings[machine_code].blank?
130
+ test_type = mappings[machine_code]["TYPE"]
131
+ worker_name = self.work_allotment_hash[test_type]
132
+
133
+ worker_hash[worker_name] ||= []
134
+
135
+ #puts "worker name: #{worker_name}"
136
+ #puts "lis code: #{machine_code}"
137
+ #puts mappings[machine_code].to_s
138
+ worker_hash[worker_name] << mappings[machine_code]["REPORT_NAME"]
139
+ else
140
+ worker_hash[worker_name] ||= []
141
+ worker_hash[worker_name] << machine_code
142
+ end
143
+
144
+
67
145
  end
68
- worker_hash[worker_name] ||= []
69
- worker_hash[worker_name] << lis_code
70
- end
71
- worker_hash.keys.each do |worker_name|
72
- #self.connection.post("lab/work/#{worker_name}", :tests => worker_hash[worker_name], :barcode => barcode, :timestamp => Time.now.to_i)
146
+
147
+ #puts "this is the workers hash"
148
+ #puts worker_hash.to_s
149
+ worker_hash.keys.each do |worker_name|
150
+ k = self.connection.post(ENDPOINT, :tests => worker_hash[worker_name].uniq, :barcode => barcode[0], :timestamp => Time.now.strftime("%b %-d %Y %I:%M %P"), :worker_name => worker_name, :status => ACCESSION_DONE, :next_step => PROCESSING, :combi_key => worker_name + "_pending")
151
+ #puts k.to_s
152
+ end
153
+ else
154
+ puts "this barcode: #{barcode[0]} already exists."
73
155
  end
156
+
74
157
  end
75
158
 
76
159
  end
@@ -124,6 +124,7 @@ module SiemensAbgElectrolyteModule
124
124
  p.patient_id = patient_id
125
125
  p.orders ||= []
126
126
  o = Order.new
127
+ o.id = patient_id
127
128
  o.results ||= {}
128
129
  if sodium = get_na
129
130
  r = Result.new
@@ -158,7 +159,7 @@ module SiemensAbgElectrolyteModule
158
159
  if ph = get_ph
159
160
  r = Result.new
160
161
  r.name = "pH"
161
- r.report_name = "Serum Electrolytes"
162
+ r.report_name = "ABG"
162
163
  r.value = ph
163
164
  r.units = "mmol/L"
164
165
  r.timestamp = Time.now.to_i
@@ -168,7 +169,7 @@ module SiemensAbgElectrolyteModule
168
169
  if po2 = get_po2
169
170
  r = Result.new
170
171
  r.name = "po2"
171
- r.report_name = "Serum Electrolytes"
172
+ r.report_name = "ABG"
172
173
  r.value = po2
173
174
  r.units = "mmHg"
174
175
  r.timestamp = Time.now.to_i
@@ -178,7 +179,7 @@ module SiemensAbgElectrolyteModule
178
179
  if pco2 = get_pco2
179
180
  r = Result.new
180
181
  r.name = "pco2"
181
- r.report_name = "Serum Electrolytes"
182
+ r.report_name = "ABG"
182
183
  r.value = pco2
183
184
  r.units = "mmHg"
184
185
  r.timestamp = Time.now.to_i
@@ -190,6 +191,12 @@ module SiemensAbgElectrolyteModule
190
191
  end
191
192
  end
192
193
 
194
+ if self.headers.size > 0
195
+ self.headers[-1].commit
196
+ clear
197
+ #send_data(self.headers[-1].generate_ack_success_response)
198
+ end
199
+
193
200
  end
194
201
 
195
202
  def process_text_file(full_file_path)
@@ -197,6 +204,12 @@ module SiemensAbgElectrolyteModule
197
204
  process_electrolytes(k.bytes)
198
205
  end
199
206
 
207
+ def clear
208
+ self.data_buffer = ''
209
+ self.test_data_bytes = []
210
+ self.data_bytes = []
211
+ end
212
+
200
213
 
201
214
  def receive_data(data)
202
215
 
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.4
4
+ version: 1.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bhargav Raut
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: jwt
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  description: This gem provides a server that can handle communication from medical
140
154
  instruments that send/receive information on the ASTM protocol.
141
155
  email: bhargav.r.raut@gmail.com