Class: Renalware::Feeds::MessageProcessor

Inherits:
Object
  • Object
show all
Includes:
Broadcasting
Defined in:
app/models/renalware/feeds/message_processor.rb

Overview

Responsible for coordinating the processing sequences of a raw HL7 message.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Broadcasting

#broadcasting_to_configured_subscribers

Instance Attribute Details

#feed_messageObject (readonly)

Returns the value of attribute feed_message.



13
14
15
# File 'app/models/renalware/feeds/message_processor.rb', line 13

def feed_message
  @feed_message
end

#hl7_messageObject (readonly)

Returns the value of attribute hl7_message.



13
14
15
# File 'app/models/renalware/feeds/message_processor.rb', line 13

def hl7_message
  @hl7_message
end

#raw_messageObject (readonly)

Returns the value of attribute raw_message.



13
14
15
# File 'app/models/renalware/feeds/message_processor.rb', line 13

def raw_message
  @raw_message
end

Instance Method Details

#call(raw_message) ⇒ Object

We want to wrap message processing in a transaction because if message processing fails we don’t want to leave an unprocessed message in the feed_messages table. If we did, and the same FeedJob retires a few minutes later, if will try to save to feed_messages with the same MD5 body_hash (the message is identical to one already saved) resulting in unique key violation. Using a transaction here prevents any orphaned records if there is an error. However we should be aware that any listeners raising an error will prevent successful in all other listeners. So a listener should be careful to catch errors and not re-raise them, or use the :message_processed message (lower down) which is safer.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/renalware/feeds/message_processor.rb', line 24

def call(raw_message)
  @raw_message = raw_message

  parse_raw_message_into_hl7_object
  ActiveRecord::Base.transaction do
    create_feed_message_using_raw_message_and_basic_extracted_patient_data
    allow_listeners_to_process_the_message
  end

  allow_listeners_to_post_process_the_message
rescue StandardError => exception
  notify_exception(exception)
  raise exception
end