Class: LIS::Transfer::ApplicationProtocol
- Inherits:
-
PacketIO::Base
- Object
- PacketIO::Base
- LIS::Transfer::ApplicationProtocol
- Defined in:
- lib/lis/transfer/application_protocol.rb
Instance Attribute Summary collapse
-
#device_name ⇒ Object
readonly
Returns the value of attribute device_name.
Instance Method Summary collapse
-
#initialize(*args) ⇒ ApplicationProtocol
constructor
A new instance of ApplicationProtocol.
- #on_request(&block) ⇒ Object
- #on_request_sent(&block) ⇒ Object
- #on_result(&block) ⇒ Object
- #receive(type, message = nil) ⇒ Object
- #received_header(message) ⇒ Object
- #received_order_record(message) ⇒ Object
- #received_patient_information(message) ⇒ Object
- #received_request_for_information(message) ⇒ Object
- #received_result(message) ⇒ Object
- #result_for(patient, order, result) ⇒ Object
- #send_pending_requests ⇒ Object
- #sending_session(data) { ... } ⇒ Object
Constructor Details
#initialize(*args) ⇒ ApplicationProtocol
Returns a new instance of ApplicationProtocol.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/lis/transfer/application_protocol.rb', line 64 def initialize(*args) super @patient_information_requests = {} @last_patient = nil @last_order = nil @handlers = { LIS::Message::Header => :received_header, LIS::Message::Patient => :received_patient_information, LIS::Message::Order => :received_order_record, LIS::Message::Result => :received_result, LIS::Message::Query => :received_request_for_information } end |
Instance Attribute Details
#device_name ⇒ Object (readonly)
Returns the value of attribute device_name.
5 6 7 |
# File 'lib/lis/transfer/application_protocol.rb', line 5 def device_name @device_name end |
Instance Method Details
#on_request(&block) ⇒ Object
11 12 13 |
# File 'lib/lis/transfer/application_protocol.rb', line 11 def on_request(&block) @on_request_callback = block end |
#on_request_sent(&block) ⇒ Object
15 16 17 |
# File 'lib/lis/transfer/application_protocol.rb', line 15 def on_request_sent(&block) @on_request_sent_callback = block end |
#on_result(&block) ⇒ Object
7 8 9 |
# File 'lib/lis/transfer/application_protocol.rb', line 7 def on_result(&block) @on_result_callback = block end |
#receive(type, message = nil) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/lis/transfer/application_protocol.rb', line 79 def receive(type, = nil) case type when :begin @last_patient = nil @last_order = nil when :idle send_pending_requests when :message @message = LIS::Message::Base.from_string() handler = @handlers[@message.class] send(handler, @message) if handler end end |
#received_header(message) ⇒ Object
19 20 21 22 |
# File 'lib/lis/transfer/application_protocol.rb', line 19 def received_header() @patient_information_requests ||= {} # delete the list of patients @device_name = .sender_name end |
#received_order_record(message) ⇒ Object
33 34 35 |
# File 'lib/lis/transfer/application_protocol.rb', line 33 def received_order_record() @last_order = end |
#received_patient_information(message) ⇒ Object
28 29 30 31 |
# File 'lib/lis/transfer/application_protocol.rb', line 28 def received_patient_information() @last_order = nil @last_patient = end |
#received_request_for_information(message) ⇒ Object
41 42 43 44 45 |
# File 'lib/lis/transfer/application_protocol.rb', line 41 def received_request_for_information() @patient_information_requests ||= {} requests = @on_request_callback.call(@device_name, .starting_range_id) @patient_information_requests[.sequence_number] = requests if requests end |
#received_result(message) ⇒ Object
37 38 39 |
# File 'lib/lis/transfer/application_protocol.rb', line 37 def received_result() result_for(@last_patient, @last_order, ) end |
#result_for(patient, order, result) ⇒ Object
24 25 26 |
# File 'lib/lis/transfer/application_protocol.rb', line 24 def result_for(patient, order, result) @on_result_callback.call(@device_name, patient, order, result) end |
#send_pending_requests ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/lis/transfer/application_protocol.rb', line 47 def send_pending_requests sending_session(@patient_information_requests) do |patient_information| patient_information.each do |sequence_nr, request_data| write :message, LIS::Message::Patient.new(sequence_nr, request_data.patient_id, request_data.patient_last_name, request_data.patient_first_name). request_data.each_type do |id, request| write :message, LIS::Message::Order.new(sequence_nr, id, request). end @on_request_sent_callback.call(@device_name, request_data) if @on_request_sent_callback end end @patient_information_requests = {} end |
#sending_session(data) { ... } ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/lis/transfer/application_protocol.rb', line 94 def sending_session(data) # don't send anything if there are no pending requests return if data.nil? or data.empty? write :begin write :message, LIS::Message::Header.new("LIS", @device_name). yield data write :message, LIS::Message::Terminator.new. write :idle end |