Class: Renalware::Feeds::PersistMessage
- Inherits:
-
Object
- Object
- Renalware::Feeds::PersistMessage
- Defined in:
- app/models/renalware/feeds/persist_message.rb
Instance Method Summary collapse
-
#call(hl7_message) ⇒ Object
hl7_message is an HL7Message (a decorator around ::HL7::Message) If the same message is persisted twice we’ll get an ActiveRecord::RecordNotUnique error but that’s fine as we don’t want to process the same HL7 message twice.
Instance Method Details
#call(hl7_message) ⇒ Object
hl7_message is an HL7Message (a decorator around ::HL7::Message) If the same message is persisted twice we’ll get an ActiveRecord::RecordNotUnique error but that’s fine as we don’t want to process the same HL7 message twice. rubocop:disable Metrics/MethodLength
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/renalware/feeds/persist_message.rb', line 12 def call() body_hash = Digest::MD5.hexdigest(.to_hl7) Message.create!( event_code: .type, header_id: .header_id, body: .to_s, body_hash: body_hash, patient_identifier: .patient_identification&.internal_id ) rescue ActiveRecord::RecordNotUnique # If a duplicate messages comes in (we have calculated the body_hash for the message and it # turns out that body_hash is not unique in the database, meaning the message is already # stored) then raise a custom error so it can be handled upstream - ie we can choose to # ignore it. raise( DuplicateMessageError, "header_id=#{.header_id}, body_hash=#{body_hash}" ) end |