Class: Pf_Lab_Interface
- Includes:
- StreamModule
- Defined in:
- lib/publisher/pf_lab_interface.rb
Constant Summary collapse
- ORDERS =
"orders"- ORDERS_SORTED_SET =
"orders_sorted_set"- BARCODES =
"barcodes"- BARCODE =
"barcode"- BASE_URL =
"http://localhost:3000/"- UPDATE_QUEUE =
"update_queue"- DEFAULT_LOOK_BACK_IN_SECONDS =
will look back 12 hours if no previous request is found.
12*3600
- DEFAULT_STORAGE_TIME_FOR_ORDERS_IN_SECONDS =
time to keep old orders in memory 48 hours, expressed as seconds.
48*3600
- POLL_ENDPOINT =
the last request that was made and what it said.
"interfaces"- PUT_ENDPOINT =
"lis_update_orders"- LAST_REQUEST =
"last_request"- FROM_EPOCH =
"from_epoch"- TO_EPOCH =
"to_epoch"- SIZE =
"size"- SKIP =
"skip"- ID =
"id"- REPORTS =
"reports"- TESTS =
"tests"- RESULT_RAW =
"result_raw"- CATEGORIES =
"categories"- USE_CATEGORY_FOR_LIS =
"use_category_for_lis"- LIS_CODE =
"lis_code"- REQUIREMENTS =
"requirements"- ITEMS =
"items"- CODE =
"code"- ORDERS_TO_UPDATE_PER_CYCLE =
10- PREV_REQUEST_COMPLETED =
"prev_request_completed"- ORDERS_KEY =
"@orders"- FAILED_UPDATES =
"failed_updates"- PATIENTS_REDIS_LIST =
"patients"- PROCESSING_REDIS_LIST =
"processing"
Constants included from StreamModule
StreamModule::SECRET, StreamModule::SITE_URL
Constants inherited from Poller
Poller::COMPLETED, Poller::EDTA, Poller::ESR, Poller::FLUORIDE, Poller::LAST_REQUEST_AT, Poller::LAST_REQUEST_STATUS, Poller::PLASMA, Poller::POLL_STATUS_KEY, Poller::REQUISITIONS_HASH, Poller::REQUISITIONS_SORTED_SET, Poller::RUNNING, Poller::SERUM, Poller::URINE
Instance Attribute Summary collapse
-
#lis_security_key ⇒ Object
Returns the value of attribute lis_security_key.
-
#retry_count ⇒ Object
Returns the value of attribute retry_count.
-
#server_url_with_port ⇒ Object
should include the www.xyz.com:3000 defaults to localhost:3000.
Attributes included from StreamModule
#connection, #es, #event_source, #on_message_handler_function, #private_key_hash
Instance Method Summary collapse
- #_start ⇒ Object
- #add_barcode(code, order_id) ⇒ Object
-
#add_order(order) ⇒ Object
@param order : order object, as a hash.
- #add_test_result(order, res, lis_code) ⇒ Object
-
#all_hits_downloaded?(last_request) ⇒ Boolean
def delete_last_request $redis.del(LAST_REQUEST) end.
- #build_request(from = nil, to = nil) ⇒ Object
-
#commit_request_params_to_redis(response_hash) ⇒ Object
commits the request params to redis.
- #delete_completed_order(order_id) ⇒ Object
-
#evented_poll_LIS_for_requisition(data) ⇒ Object
this is triggered by whatever firebase sends you put this in the callback, and let me block and see what happens.
- #fresh_request_params(from, to) ⇒ Object
-
#get_barcode(barcode) ⇒ Object
@return the entry at the barcode, or nil.
- #get_last_request ⇒ Object
- #get_order(order_id) ⇒ Object
- #get_poll_url_path ⇒ Object
-
#get_priority_category(req) ⇒ Object
@param req : the requirement hash.
- #get_put_url_path ⇒ Object
-
#initialize(mpg = nil, lis_security_key, server_url_with_port, organization_id, private_key_hash) ⇒ Pf_Lab_Interface
constructor
METHODS OVERRIDDEN FROM THE BASIC POLLER.
- #new_poll_LIS_for_requisition(to_epoch = nil) ⇒ Object
-
#poll ⇒ Object
this method is redundant, and no longer used the whole thing is now purely evented.
-
#poll_LIS_for_requisition(to_epoch = nil) ⇒ Object
how it deletes records so this is called in the form of a while loop.
-
#process_update_queue ⇒ Object
data = [ { :id => “ARUBA”, :results => [ { :name => “TLCparam”, :value => 10 }, { :name => “Nparam”, :value => 23 }, { :name => “ANCparam”, :value => 25 }, { :name => “Lparam”, :value => 10 }, { :name => “ALCparam”, :value => 44 }, { :name => “Mparam”, :value => 55 }, { :name => “AMCparam”, :value => 22 }, { :name => “Eparam”, :value => 222 }, { :name => “AECparam”, :value => 21 }, { :name => “BASOparam”, :value => 222 }, { :name => “ABCparam”, :value => 300 }, { :name => “RBCparam”, :value => 2.22 }, { :name => “HBparam”, :value => 19 }, { :name => “HCTparam”, :value => 22 }, { :name => “MCVparam”, :value => 222 }, { :name => “MCHparam”, :value => 21 }, { :name => “MCHCparam”, :value => 10 }, { :name => “MCVparam”, :value => 222 }, { :name => “RDWCVparam”, :value => 12 }, { :name => “PCparam”, :value => 1.22322 } ] } ].
- #put_delete_order_event(order_id) ⇒ Object
- #queue_order_for_update(order) ⇒ Object
-
#reattempt_failed_updates ⇒ Object
this is only done on startup okay so what do we.
- #remove_barcode(barcode) ⇒ Object
-
#remove_old_orders ⇒ Object
removes any orders that start from now - 4 days ago now - 2 days ago.
-
#remove_order(order_id) ⇒ Object
UTILITY METHOD FOR THE ORDER AND BARCODE HASHES ADD AND REMOVE.
-
#request_size_completed?(response_hash) ⇒ Boolean
since we request only a certain set of orders per request we need to know if the earlier request has been completed or we still need to rerequest the same time frame again.
- #test_trigger_delete_order(order_id) ⇒ Object
- #test_trigger_lis_poll(epoch = nil) ⇒ Object
- #update(data) ⇒ Object
-
#update_LIS(args = {}) ⇒ Object
we can do this.
-
#update_order(order) ⇒ Object
start work on simple.
Methods included from StreamModule
#on_message_handler, #setup_connection, #watch, #watch_limited
Methods inherited from Poller
#assign_tube, #build_tests_hash, #default_checkpoint, #determine_tube, #get_checkpoint, #merge_with_requisitions_hash, #post_poll_LIS, #pre_poll_LIS, #prepare_redis, #process_LIS_response, #root_path
Constructor Details
#initialize(mpg = nil, lis_security_key, server_url_with_port, organization_id, private_key_hash) ⇒ Pf_Lab_Interface
370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/publisher/pf_lab_interface.rb', line 370 def initialize(mpg=nil,lis_security_key,server_url_with_port,organization_id,private_key_hash) super(mpg) self.private_key_hash = private_key_hash self.event_source = "organizations/" + organization_id self. = "evented_poll_LIS_for_requisition" self.lis_security_key = lis_security_key self.server_url_with_port = (server_url_with_port || BASE_URL) self.retry_count = 0 ## called from stream module setup_connection AstmServer.log("Initialized Lab Interface") end |
Instance Attribute Details
#lis_security_key ⇒ Object
Returns the value of attribute lis_security_key.
90 91 92 |
# File 'lib/publisher/pf_lab_interface.rb', line 90 def lis_security_key @lis_security_key end |
#retry_count ⇒ Object
Returns the value of attribute retry_count.
96 97 98 |
# File 'lib/publisher/pf_lab_interface.rb', line 96 def retry_count @retry_count end |
#server_url_with_port ⇒ Object
should include the www.xyz.com:3000 defaults to localhost:3000
94 95 96 |
# File 'lib/publisher/pf_lab_interface.rb', line 94 def server_url_with_port @server_url_with_port end |
Instance Method Details
#_start ⇒ Object
806 807 808 809 810 |
# File 'lib/publisher/pf_lab_interface.rb', line 806 def _start evented_poll_LIS_for_requisition({"trigger_lis_poll" => {"epoch" => Time.now.to_i.to_s}}) reattempt_failed_updates update_LIS end |
#add_barcode(code, order_id) ⇒ Object
270 271 272 |
# File 'lib/publisher/pf_lab_interface.rb', line 270 def (code,order_id) $redis.hset(BARCODES,code,order_id) end |
#add_order(order) ⇒ Object
@param order : order object, as a hash.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/publisher/pf_lab_interface.rb', line 198 def add_order(order) at_least_one_item_exists = false order[REPORTS].each do |report| test_machine_codes = report[TESTS].map{|c| $inverted_mappings[c[LIS_CODE]] }.compact.uniq report[REQUIREMENTS].each do |req| get_priority_category(req)[ITEMS].each do |item| if !item[BARCODE].blank? at_least_one_item_exists = true (item[BARCODE],JSON.generate( { :order_id => order[ID], :machine_codes => test_machine_codes } )) elsif !item[CODE].blank? at_least_one_item_exists = true (item[CODE],JSON.generate({ :order_id => order[ID], :machine_codes => test_machine_codes })) end end end end unless at_least_one_item_exists.blank? $redis.hset(ORDERS,order[ID],JSON.generate(order)) $redis.zadd(ORDERS_SORTED_SET,Time.now.to_i,order[ID]) end end |
#add_test_result(order, res, lis_code) ⇒ Object
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/publisher/pf_lab_interface.rb', line 243 def add_test_result(order,res,lis_code) #puts "res is:" #puts res.to_s order[REPORTS.to_sym].each do |report| #puts "doing report" report[TESTS.to_sym].each_with_index{|t,k| #puts "doing test" #puts t.to_s puts "teh test lis code to sym is:" puts t[LIS_CODE.to_sym] puts "lis code is: #{lis_code.to_s}" if t[LIS_CODE.to_sym] == lis_code.to_s puts "got equality" t[RESULT_RAW.to_sym] = res[:value] puts "set value" end } end end |
#all_hits_downloaded?(last_request) ⇒ Boolean
def delete_last_request $redis.del(LAST_REQUEST) end
283 284 285 |
# File 'lib/publisher/pf_lab_interface.rb', line 283 def all_hits_downloaded?(last_request) last_request[PREV_REQUEST_COMPLETED].to_s == "true" end |
#build_request(from = nil, to = nil) ⇒ Object
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 |
# File 'lib/publisher/pf_lab_interface.rb', line 302 def build_request(from=nil,to=nil) puts "entering build request with from: #{from} and to:#{to}" to ||= Time.now from ||= to - 1.day last_request = get_last_request params = nil if last_request.blank? AstmServer.log("no last request, making fresh request") params = fresh_request_params(from,to) else if all_hits_downloaded?(last_request) AstmServer.log("last request all hits have been downloaded, going for next request.") if last_request[TO_EPOCH].to_i == to.to_i return nil else params = fresh_request_params(last_request[TO_EPOCH],to) end else AstmServer.log("last request all hits not downloaded.") params = last_request end end params.merge!(lis_security_key: self.lis_security_key) AstmServer.log("reuqest params become: #{params}") AstmServer.log("sleeping") #sleep(10000) Typhoeus::Request.new(self.get_poll_url_path,params: params) end |
#commit_request_params_to_redis(response_hash) ⇒ Object
commits the request params to redis. the response hash is expected to have whatever parameters were sent into it in the request. so it must always return: a -> how many it was told to skip (SKIP) b -> from_epoch : from which epoch it was queried. c -> to_epoch : to which epoch it was queried.
337 338 339 340 341 342 343 |
# File 'lib/publisher/pf_lab_interface.rb', line 337 def commit_request_params_to_redis(response_hash) $redis.hset(LAST_REQUEST,SKIP,response_hash[SKIP].to_i + response_hash[ORDERS].size.to_i) $redis.hset(LAST_REQUEST,SIZE,response_hash[SIZE].to_i) $redis.hset(LAST_REQUEST,FROM_EPOCH,response_hash[FROM_EPOCH].to_i) $redis.hset(LAST_REQUEST,TO_EPOCH,response_hash[TO_EPOCH].to_i) $redis.hset(LAST_REQUEST,PREV_REQUEST_COMPLETED,request_size_completed?(response_hash).to_s) end |
#delete_completed_order(order_id) ⇒ Object
415 416 417 |
# File 'lib/publisher/pf_lab_interface.rb', line 415 def delete_completed_order(order_id) remove_order(order_id) end |
#evented_poll_LIS_for_requisition(data) ⇒ Object
this is triggered by whatever firebase sends you put this in the callback, and let me block and see what happens. we cannot watch two different endpoints ? or we can ? on the same endpoint -> will so it becomes a merged document. and both events will fire. and get triggered.
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'lib/publisher/pf_lab_interface.rb', line 392 def evented_poll_LIS_for_requisition(data) unless data.blank? data = data["data"].blank? ? data : data["data"] unless data["delete_order"].blank? puts "delete order is not blank" unless data["delete_order"]["order_id"].blank? puts "order id is not blank" puts "going to delete the completed order --------------->" delete_completed_order(data["delete_order"]["order_id"]) end end unless data["trigger_lis_poll"].blank? unless data["trigger_lis_poll"]["epoch"].blank? new_poll_LIS_for_requisition(data["trigger_lis_poll"]["epoch"].to_i) end end else end end |
#fresh_request_params(from, to) ⇒ Object
289 290 291 292 293 294 295 296 |
# File 'lib/publisher/pf_lab_interface.rb', line 289 def fresh_request_params(from,to) #puts "came to make fresh request params, with from epoch: #{from_epoch}" params = {} params[TO_EPOCH] = to.to_i params[FROM_EPOCH] = from.to_i params[SKIP] = 0 params end |
#get_barcode(barcode) ⇒ Object
@return the entry at the barcode, or nil. key (order_id) value (array of tests registered on that barcode, the names of the tests are the machine codes, and not the lis_codes) this key is generated originally in add_barcode
167 168 169 170 171 172 173 |
# File 'lib/publisher/pf_lab_interface.rb', line 167 def () if = $redis.hget(BARCODES,) JSON.parse().deep_symbolize_keys else nil end end |
#get_last_request ⇒ Object
274 275 276 |
# File 'lib/publisher/pf_lab_interface.rb', line 274 def get_last_request $redis.hgetall(LAST_REQUEST) end |
#get_order(order_id) ⇒ Object
175 176 177 178 179 180 181 |
# File 'lib/publisher/pf_lab_interface.rb', line 175 def get_order(order_id) if order_string = $redis.hget(ORDERS,order_id) JSON.parse(order_string).deep_symbolize_keys else nil end end |
#get_poll_url_path ⇒ Object
797 798 799 |
# File 'lib/publisher/pf_lab_interface.rb', line 797 def get_poll_url_path self.server_url_with_port + POLL_ENDPOINT end |
#get_priority_category(req) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/publisher/pf_lab_interface.rb', line 185 def get_priority_category(req) priority_category = req[CATEGORIES].select{|c| c[USE_CATEGORY_FOR_LIS] == 1 } if priority_category.blank? priority_category = req[CATEGORIES][0] else priority_category = priority_category[0] end priority_category end |
#get_put_url_path ⇒ Object
801 802 803 |
# File 'lib/publisher/pf_lab_interface.rb', line 801 def get_put_url_path self.server_url_with_port + PUT_ENDPOINT end |
#new_poll_LIS_for_requisition(to_epoch = nil) ⇒ Object
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
# File 'lib/publisher/pf_lab_interface.rb', line 431 def new_poll_LIS_for_requisition(to_epoch=nil) AstmServer.log(to_epoch.to_s) while true orders = [] begin Retriable.retriable(on: PfDownloadException) do self.retry_count+=1 AstmServer.log("retrying----->") request = build_request(nil,to_epoch) break if request.blank? request.run response = request.response if response.success? code = response.code time = response.total_time headers = response.headers #AstmServer.log("successfully polled server") response_hash = JSON.parse(response.body) #AstmServer.log("Pathofast LIS poll response --->") #AstmServer.log(response_hash.to_s) orders = response_hash[ORDERS] orders.each do |order| add_order(order) end commit_request_params_to_redis(response_hash) #puts "are the orders blank: #{orders.blank?}" #break if orders.blank? elsif response.timed_out? #AstmServer.log("Error polling server with code: #{code}") raise PfDownloadException.new("timeout") elsif response.code == 0 #AstmServer.log("Error polling server with code: #{code}") raise PfDownloadException.new("didnt get any http response") else #AstmServer.log("Error polling server with code: #{code}") raise PfDownloadException.new("non 200 response") end end rescue => e puts e.to_s puts "raised exception-----------> breaking." ## retryable has raised the errors again. break else ## break only if the orders are blank. break if orders.blank? end end end |
#poll ⇒ Object
this method is redundant, and no longer used the whole thing is now purely evented.
817 818 |
# File 'lib/publisher/pf_lab_interface.rb', line 817 def poll end |
#poll_LIS_for_requisition(to_epoch = nil) ⇒ Object
how it deletes records so this is called in the form of a while loop. how it handles the update response.
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 |
# File 'lib/publisher/pf_lab_interface.rb', line 488 def poll_LIS_for_requisition(to_epoch=nil) AstmServer.log(to_epoch.to_s) while true #puts "came back to true" request = build_request(nil,to_epoch) break if request.blank? request.run response = request.response code = response.code time = response.total_time headers = response.headers if code.to_s != "200" AstmServer.log("Error polling server with code: #{code}") break else AstmServer.log("successfully polled server") response_hash = JSON.parse(response.body) AstmServer.log("Pathofast LIS poll response --->") #AstmServer.log(response_hash.to_s) orders = response_hash[ORDERS] orders.each do |order| add_order(order) end commit_request_params_to_redis(response_hash) puts "are the orders blank: #{orders.blank?}" break if orders.blank? end end end |
#process_update_queue ⇒ Object
data = [
{
:id => "ARUBA",
:results => [
{
:name => "TLCparam",
:value => 10
},
{
:name => "Nparam",
:value => 23
},
{
:name => "ANCparam",
:value => 25
},
{
:name => "Lparam",
:value => 10
},
{
:name => "ALCparam",
:value => 44
},
{
:name => "Mparam",
:value => 55
},
{
:name => "AMCparam",
:value => 22
},
{
:name => "Eparam",
:value => 222
},
{
:name => "AECparam",
:value => 21
},
{
:name => "BASOparam",
:value => 222
},
{
:name => "ABCparam",
:value => 300
},
{
:name => "RBCparam",
:value => 2.22
},
{
:name => "HBparam",
:value => 19
},
{
:name => "HCTparam",
:value => 22
},
{
:name => "MCVparam",
:value => 222
},
{
:name => "MCHparam",
:value => 21
},
{
:name => "MCHCparam",
:value => 10
},
{
:name => "MCVparam",
:value => 222
},
{
:name => "RDWCVparam",
:value => 12
},
{
:name => "PCparam",
:value => 1.22322
}
]
}
]
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 |
# File 'lib/publisher/pf_lab_interface.rb', line 608 def process_update_queue #puts "came to process update queue." order_ids = [] #puts $redis.lrange UPDATE_QUEUE, 0, -1 ## first push that to patient. ## first create that order and add that barcode. ## for citrate. ## then let that get downloaded. ## so keep on test going for that. ## ## why complicate this so much. ## just do a brpop? ## ORDERS_TO_UPDATE_PER_CYCLE.times do |n| order_ids << $redis.rpop(UPDATE_QUEUE) end #puts "order ids popped" #puts order_ids.to_s order_ids.compact! order_ids.uniq! orders = order_ids.map{|c| get_order(c) }.compact #puts orders[0].to_s #puts "orders are:" #puts orders.size #exit(1) req = Typhoeus::Request.new(self.get_put_url_path, method: :put, body: {orders: orders}.to_json, params: {lis_security_key: self.lis_security_key}, headers: {Accept: 'application/json', "Content-Type".to_sym => 'application/json'}) req.on_complete do |response| if response.success? response_body = response.body orders = JSON.parse(response.body)["orders"] #puts orders.to_s orders.values.each do |order| #puts order.to_s if order["errors"].blank? else puts "got an error for the order." ## how many total error attempts to manage. end end ## here we have to raise. elsif response.timed_out? AstmServer.log("got a time out") raise PfUpdateException.new("update order timed out") elsif response.code == 0 AstmServer.log(response.) raise PfUpdateException.new("update order response code 0") else AstmServer.log("HTTP request failed: " + response.code.to_s) raise PfUpdateException.new("update order response code non success: #{response.code}") end end req.run end |
#put_delete_order_event(order_id) ⇒ Object
419 420 421 |
# File 'lib/publisher/pf_lab_interface.rb', line 419 def put_delete_order_event(order_id) puts self.connection.put(self.event_source,:order_id => order_id) end |
#queue_order_for_update(order) ⇒ Object
265 266 267 268 |
# File 'lib/publisher/pf_lab_interface.rb', line 265 def queue_order_for_update(order) update_order(order) $redis.lpush(UPDATE_QUEUE,order[ID.to_sym]) end |
#reattempt_failed_updates ⇒ Object
this is only done on startup okay so what do we
690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 |
# File 'lib/publisher/pf_lab_interface.rb', line 690 def reattempt_failed_updates $redis.scard(FAILED_UPDATES).times do if patient_results = $redis.spop(FAILED_UPDATES) patient_results = JSON.parse(patient_results) begin Retriable.retriable(on: PfUpdateException) do unless update(patient_results) raise PfUpdateException.new("didnt get any http response") end end rescue => e AstmServer.log("reattempted and failed") ensure end end end end |
#remove_barcode(barcode) ⇒ Object
158 159 160 161 |
# File 'lib/publisher/pf_lab_interface.rb', line 158 def () return if .blank? $redis.hdel(BARCODES,) end |
#remove_old_orders ⇒ Object
removes any orders that start from now - 4 days ago now - 2 days ago
674 675 676 677 678 679 680 681 |
# File 'lib/publisher/pf_lab_interface.rb', line 674 def remove_old_orders stale_order_ids = $redis.zrangebyscore(ORDERS_SORTED_SET,(Time.now.to_i - DEFAULT_STORAGE_TIME_FOR_ORDERS_IN_SECONDS*2).to_s, (Time.now.to_i - DEFAULT_STORAGE_TIME_FOR_ORDERS_IN_SECONDS)) $redis.pipelined do stale_order_ids.each do |order_id| remove_order(order_id) end end end |
#remove_order(order_id) ⇒ Object
UTILITY METHOD FOR THE ORDER AND BARCODE HASHES ADD AND REMOVE
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/publisher/pf_lab_interface.rb', line 140 def remove_order(order_id) order = get_order(order_id) puts "order id is:#{order_id} is" unless order.blank? puts "order not blank." order[:reports].each do |report| report[:tests].each do |test| (test[:barcode]) (test[:code]) end end $redis.hdel(ORDERS,order_id) $redis.zrem(ORDERS_SORTED_SET,order_id) else puts "order is blank." end end |
#request_size_completed?(response_hash) ⇒ Boolean
since we request only a certain set of orders per request we need to know if the earlier request has been completed or we still need to rerequest the same time frame again.
348 349 350 351 |
# File 'lib/publisher/pf_lab_interface.rb', line 348 def request_size_completed?(response_hash) #puts response_hash.to_s response_hash[SKIP].to_i + response_hash[ORDERS].size >= response_hash[SIZE].to_i end |
#test_trigger_delete_order(order_id) ⇒ Object
427 428 429 |
# File 'lib/publisher/pf_lab_interface.rb', line 427 def test_trigger_delete_order(order_id) puts self.connection.put(self.event_source + "/delete_order", :order_id => order_id) end |
#test_trigger_lis_poll(epoch = nil) ⇒ Object
423 424 425 |
# File 'lib/publisher/pf_lab_interface.rb', line 423 def test_trigger_lis_poll(epoch=nil) puts self.connection.put(self.event_source + "/trigger_lis_poll", :epoch => epoch) end |
#update(data) ⇒ Object
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 |
# File 'lib/publisher/pf_lab_interface.rb', line 746 def update(data) puts "data is:" puts JSON.pretty_generate(data) data[ORDERS_KEY].each do |order| puts "order is " puts order = order["id"] results = order["results"] puts "barcode is: #{barcode}, results are : #{results}" results.deep_symbolize_keys! if = () puts "barcode hash is: #{barcode_hash}" if order = get_order([:order_id]) puts "got order" ## update the test results, and add the order to the final update hash. #puts "order got from barcode is:" #puts order machine_codes = [:machine_codes] puts "machine codes: #{machine_codes}" results.keys.each do |lis_code| res = results[lis_code] add_test_result(order,res,lis_code) end =begin results.values.each do |res| if machine_codes.include? res[:name] ## so we need to update to the requisite test inside the order. puts "came to add test result" puts res add_test_result(order,res,nil) ## commit to redis ## and then end end =end #puts "came to queue order for update" queue_order_for_update(order) end else AstmServer.log("the barcode:#{barcode}, does not exist in the barcodes hash") ## does not exist. end end process_update_queue end |
#update_LIS(args = {}) ⇒ Object
we can do this. args can be used to modulate exit behaviours @param args : hash of arguments
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 |
# File 'lib/publisher/pf_lab_interface.rb', line 712 def update_LIS(args={}) prepare_redis exit_requested = false Kernel.trap( "INT" ) { exit_requested = true } while !exit_requested puts "exit not requested." if patient_results = $redis.brpoplpush(PATIENTS_REDIS_LIST,PROCESSING_REDIS_LIST,0) puts "got patient results." patient_results = JSON.parse(patient_results) puts "patient results are:" puts JSON.pretty_generate(patient_results) begin Retriable.retriable(on: PfUpdateException) do unless update(patient_results) raise PfUpdateException.new("didnt get any http response") end end exit_requested = !args[:exit_on_success].blank? #puts "exit requested becomes: #{exit_requested}" rescue => e $redis.sadd(FAILED_UPDATES,JSON.generate(patient_results)) exit_requested = !args[:exit_on_failure].blank? puts "came to eventual rescue, exit requested is: #{exit_requested}" ensure $redis.lpop("processing") end else puts "no patient results" end end end |
#update_order(order) ⇒ Object
start work on simple.
233 234 235 |
# File 'lib/publisher/pf_lab_interface.rb', line 233 def update_order(order) $redis.hset(ORDERS,order[ID.to_sym],JSON.generate(order)) end |