ruby_astm 0.0.9 → 1.0.0

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
  SHA1:
3
- metadata.gz: 72ade802a6dc078a0d52242e6e76d6f3a2eb1be6
4
- data.tar.gz: 58909cfdb8d0ab54b9bf363030f8025827ae314d
3
+ metadata.gz: 694ae05d26bb089e9ac086b049a61b334918554c
4
+ data.tar.gz: 7f64cc2d8ff8e65db4db2344180d09a45aba91c6
5
5
  SHA512:
6
- metadata.gz: 3e188721bcbe685dbbc312f7d7dff054c571b27993a8f022866464657e1a01e54bc2469ae5e47105491c5a2eaff057713adb159a7951e0edb2ed19030c657588
7
- data.tar.gz: 9383ecbdb2f21986b2642881871601ab0fd46848bb338a4e7ffc603b8acdbf15994cb596a710b88ec1792bdf0fac2549bd8047ab9cf4822e7e317364844b792a
6
+ metadata.gz: 76f380e0fd5b1f15c52f77cc7eed5b094e4970c52f7419a8664b9047e18619fad2e78641cbe718bba92f769c539eb841459be4b5525fa4139a27d58d6bd6301e
7
+ data.tar.gz: 512ad2242dd67761595af57c02a8d1de61f724029703a105dd63bc1c30536c710b5fca1409385cca56e18e8ffaaf81ef407c7fa050067a710844ee0e845d21fe
@@ -17,10 +17,10 @@ class Google_Lab_Interface < Poller
17
17
  SCOPES = ["https://www.googleapis.com/auth/documents","https://www.googleapis.com/auth/drive","https://www.googleapis.com/auth/script.projects","https://www.googleapis.com/auth/spreadsheets"]
18
18
 
19
19
  $service = nil
20
- SCRIPT_ID = "M7JDg7zmo0Xldo4RTWFGCsI2yotVzKYhk"
21
20
 
22
21
  attr_accessor :credentials_path
23
22
  attr_accessor :token_path
23
+ attr_accessor :script_id
24
24
 
25
25
  ##
26
26
  # Ensure valid credentials, either by restoring from the saved credentials
@@ -49,25 +49,26 @@ class Google_Lab_Interface < Poller
49
49
  ## @param[String] mpg : path to mappings file. Defaults to nil.
50
50
  ## @param[String] credentials_path : the path to look for the credentials.json file, defaults to nil ,and will raise an error unless provided
51
51
  ## @param[String] token_path : the path where the oauth token will be stored, also defaults to the path of the gem : eg. ./token.yaml - be careful with write permissions, because token.yaml gets written to this path after the first authorization.
52
- def initialize(mpg=nil,credentials_path,token_path)
52
+ def initialize(mpg=nil,credentials_path,token_path,script_id)
53
53
  super(mpg)
54
54
  self.credentials_path = credentials_path
55
55
  self.token_path = token_path
56
+ self.script_id = script_id
56
57
  raise "Please provide the full path of the google oauth credentials.json file. If you don't have this file, please go to the Apps Script project, which has your google apps script, and Choose Create Credentials -> help me choose -> and use 'Calling Scripts Api from a UI based platform'. Also ensure that your script has permissions set for Drive, Sheets, and more. Lastly in the Apps script project ensure that settings -> google apps script API is ON." if self.credentials_path.nil?
58
+ raise "Please provide a script id for your google script" if self.script_id.blank?
57
59
  AstmServer.log("Initialized Google Lab Interface")
58
60
  $service = Google::Apis::ScriptV1::ScriptService.new
59
61
  $service.client_options.application_name = APPLICATION_NAME
60
62
  $service.authorization = authorize
61
63
  end
62
64
 
63
-
65
+ ## how to decide for what to poll for the requisition.
66
+ ## this should be tested.
64
67
  def poll_LIS_for_requisition
65
68
 
66
-
67
-
68
69
  AstmServer.log("polling LIS for new requisitions")
69
70
 
70
- epoch = (Time.now - 5.days).to_i*1000
71
+ epoch = get_checkpoint
71
72
 
72
73
  pp = {
73
74
  :input => JSON.generate([epoch])
@@ -79,7 +80,7 @@ class Google_Lab_Interface < Poller
79
80
  )
80
81
 
81
82
  begin
82
- resp = $service.run_script(SCRIPT_ID, request)
83
+ resp = $service.run_script(self.script_id, request)
83
84
  if resp.error
84
85
  AstmServer.log("Response Error polling LIS for requisitions: #{resp.error.message}: #{resp.error.code}")
85
86
  else
@@ -116,7 +117,7 @@ class Google_Lab_Interface < Poller
116
117
  begin
117
118
  AstmServer.log("updating following results to LIS")
118
119
  AstmServer.log(request.parameters.to_s)
119
- resp = $service.run_script(SCRIPT_ID, request)
120
+ resp = $service.run_script(self.script_id, request)
120
121
  if resp.error
121
122
  AstmServer.log("Error updating results to LIS, message follows")
122
123
  AstmServer.log("error: #{resp.error.message} : code: #{resp.error.code}")
@@ -106,6 +106,8 @@ class Poller
106
106
  end
107
107
 
108
108
  def build_tests_hash(record)
109
+ #puts "Record is ---------------------------------------------"
110
+ #puts record
109
111
  tests_hash = {}
110
112
 
111
113
  ## key -> TUBE_NAME : eg: EDTA
@@ -118,38 +120,41 @@ class Poller
118
120
  ## fluoride -> index 31
119
121
  ## urine -> index 32
120
122
  ## esr -> index 33
121
- unless record[28].blank?
122
- tube_ids[EDTA] = record[28].to_s
123
- tests_hash[EDTA + ":" + record[28].to_s] = []
123
+ unless record[24].blank?
124
+ tube_ids[EDTA] = record[24].to_s
125
+ tests_hash[EDTA + ":" + record[24].to_s] = []
124
126
  end
125
127
 
126
- unless record[29].blank?
127
- tube_ids[SERUM] = record[29].to_s
128
- tests_hash[SERUM + ":" + record[29].to_s] = []
128
+ unless record[25].blank?
129
+ tube_ids[SERUM] = record[25].to_s
130
+ tests_hash[SERUM + ":" + record[25].to_s] = []
129
131
  end
130
132
 
131
- unless record[30].blank?
132
- tube_ids[PLASMA] = record[30].to_s
133
- tests_hash[PLASMA + ":" + record[30].to_s] = []
133
+ unless record[26].blank?
134
+ tube_ids[PLASMA] = record[26].to_s
135
+ tests_hash[PLASMA + ":" + record[26].to_s] = []
134
136
  end
135
137
 
136
- unless record[31].blank?
137
- tube_ids[FLUORIDE] = record[31].to_s
138
- tests_hash[FLUORIDE + ":" + record[31].to_s] = []
138
+ unless record[27].blank?
139
+ tube_ids[FLUORIDE] = record[27].to_s
140
+ tests_hash[FLUORIDE + ":" + record[27].to_s] = []
139
141
  end
140
142
 
141
- unless record[32].blank?
142
- tube_ids[URINE] = record[32].to_s
143
- tests_hash[URINE + ":" + record[32].to_s] = []
143
+ unless record[28].blank?
144
+ tube_ids[URINE] = record[28].to_s
145
+ tests_hash[URINE + ":" + record[28].to_s] = []
144
146
  end
145
147
 
146
- unless record[33].blank?
147
- tube_ids[ESR] = record[33].to_s
148
- tests_hash[ESR + ":" + record[33].to_s] = []
148
+ unless record[29].blank?
149
+ tube_ids[ESR] = record[29].to_s
150
+ tests_hash[ESR + ":" + record[29].to_s] = []
149
151
  end
150
152
 
153
+ tests = record[7].split(",").compact
151
154
 
152
- tests = record[8].split(",")
155
+ puts "tests are:"
156
+ puts tests.to_s
157
+ return tests_hash if tests_hash.empty?
153
158
  tests.each do |test|
154
159
  ## use the inverted mappings to
155
160
  if machine_code = $inverted_mappings[test]
@@ -159,6 +164,9 @@ class Poller
159
164
  ## now find the tests_hash which has this tube.
160
165
  ## and the machine code to its array.
161
166
  ## so how to find this.
167
+ puts "tube is : #{tube}"
168
+ puts "tests hash is:"
169
+ puts tests_hash.to_s
162
170
  tube_key = tests_hash.keys.select{|c| c=~/#{tube}/ }[0]
163
171
  tests_hash[tube_key] << machine_code
164
172
  else
@@ -185,7 +193,19 @@ class Poller
185
193
  end
186
194
  end
187
195
  end
196
+
197
+ def default_checkpoint
198
+ (Time.now - 5.days).to_i*1000
199
+ end
188
200
 
201
+ def get_checkpoint
202
+ latest_two_entries = $redis.zrange Poller::REQUISITIONS_SORTED_SET, -2, -1, {withscores: true}
203
+ unless latest_two_entries.blank?
204
+ latest_two_entries[-1][1].to_i
205
+ else
206
+ default_checkpoint
207
+ end
208
+ end
189
209
 
190
210
  ## @param[String] json_response : contains the response from the LIS
191
211
  ## it should be the jsonified version of a hash that is structured as follows:
@@ -12,20 +12,41 @@ class Query
12
12
  end
13
13
  end
14
14
 
15
+ def get_tests
16
+ tests = []
17
+ sample_tests = $redis.hget(Poller::REQUISITIONS_HASH,self.sample_id)
18
+ unless sample_tests.blank?
19
+ tests = JSON.parse(sample_tests)
20
+ end
21
+ tests
22
+ end
23
+
15
24
  ## each query will build one patient and one order inside it.
16
25
  ## the order can have many tests.
17
26
  def build_response(variables=nil)
27
+ ## so the response is thus incoming.
28
+ =begin
18
29
  variables ||= {
19
30
  :sequence_number => "0",
20
31
  :patient_id => "abcde",
21
32
  :specimen_id => self.sample_id,
22
33
  :tests => ["TRIG"],
23
34
  :priority => "R"
24
- }
35
+ }
36
+ =end
37
+
38
+ ## tests are got from the requisitions hash.
39
+ tests = get_tests
40
+
41
+ ## default sequence number is 0 (THIS MAY LEAD TO PROBLEMS.)
42
+ sequence_number = "0"
43
+
44
+ ## default patient id:
45
+ patient_id = "abcde"
25
46
 
26
- patient = Patient.new({:sequence_number => "0", :patient_id => "abcde"})
47
+ patient = Patient.new({:sequence_number => sequence_number, :patient_id => patient_id})
27
48
 
28
- order = Order.new({:sequence_number => patient.sequence_number, :specimen_id => variables[:specimen_id], :tests => variables[:tests], :priority => variables[:priority]})
49
+ order = Order.new({:sequence_number => patient.sequence_number, :specimen_id => self.sample_id, :tests => tests, :priority => "R"})
29
50
 
30
51
  return patient.build_response + order.build_response
31
52
 
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: 0.0.9
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bhargav Raut