Sha256: 9ab691811378fd19f1a6e817ced3e76daa11464f54413bf7a1796be6bc0573f0

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/pathology"

#
# When subscribed to HL7 `message_arrived` messages, gets notified of incoming HL7 messages
# and creates the observations contained therein provided the patient exists.
#
module Renalware
  module Pathology
    class MessageListener
      # Note: We are already inside a transaction here
      def message_arrived(hl7_message:, **)
        pathology_params = parse_pathology_params(hl7_message)
        create_observation_requests_and_their_child_observations_from(pathology_params)
        #
        # Note: The current_observation_set for the patient is updated by a trigger here!
        #
      end

      private

      def parse_pathology_params(hl7_message)
        ObservationRequestsAttributesBuilder.new(hl7_message).parse
      end

      def create_observation_requests_and_their_child_observations_from(pathology_params)
        return if pathology_params.nil? # e.g. patient does not exist
        CreateObservationRequests.new.call(pathology_params)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
renalware-core-2.0.46 app/models/renalware/pathology/message_listener.rb
renalware-core-2.0.45 app/models/renalware/pathology/message_listener.rb
renalware-core-2.0.44 app/models/renalware/pathology/message_listener.rb
renalware-core-2.0.43 app/models/renalware/pathology/message_listener.rb
renalware-core-2.0.42 app/models/renalware/pathology/message_listener.rb