Sha256: 5870ea914e5f48fb26f8027c3e6946f42f0ef79f5706acac0d59105c4253a553

Contents?: true

Size: 1.66 KB

Versions: 31

Compression:

Stored size: 1.66 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/admin"

module Renalware
  module Feeds
    class HL7TestMessagesController < BaseController
      def new
        authorize [:renalware, :admin, :devops], :show?
        test_messages = HL7TestMessage.all
        render locals: { form: HL7TestForm.new, test_messages: test_messages }
      end

      # rubocop:disable Metrics/MethodLength
      def create
        authorize [:renalware, :admin, :devops], :create?
        body = replace_placeholders_in_hl7_message(form_params[:body])
        job = FeedJob.new(body)
        job.perform
        test_patient
        version = test_patient.reload.versions.order(created_at: :desc).last&.object_changes
        json_version = version && JSON.pretty_generate(version)
        respond_to do |format|
          format.js do
            render locals: {
              a: "asas",
              test_patient: test_patient,
              version: json_version
            }
          end
        end
        # rubocop:enable Metrics/MethodLength

        # # Delayed::Job.enqueue job
        # redirect_to(
        #   renalware.new_feeds_hl7_test_message_path,
        #   notice: "Hl7 message queued"
        # )
      end

      private

      def form_params
        params.require(:feeds_hl7_test_form).permit(:body)
      end

      def test_patient
        @test_patient ||= Patient.find_by!(local_patient_id: "Z100001")
      end

      def replace_placeholders_in_hl7_message(message)
        message
          .gsub("{{message_id}}", SecureRandom.hex(12))
          .gsub("{{local_patient_id}}", test_patient.local_patient_id)
          .gsub("\r\n", "\r")
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/controllers/renalware/feeds/hl7_test_messages_controller.rb
renalware-core-2.1.0 app/controllers/renalware/feeds/hl7_test_messages_controller.rb
renalware-core-2.0.167 app/controllers/renalware/feeds/hl7_test_messages_controller.rb
renalware-core-2.0.166 app/controllers/renalware/feeds/hl7_test_messages_controller.rb
renalware-core-2.0.165 app/controllers/renalware/feeds/hl7_test_messages_controller.rb
renalware-core-2.0.164 app/controllers/renalware/feeds/hl7_test_messages_controller.rb
renalware-core-2.0.163 app/controllers/renalware/feeds/hl7_test_messages_controller.rb
renalware-core-2.0.162 app/controllers/renalware/feeds/hl7_test_messages_controller.rb
renalware-core-2.0.161 app/controllers/renalware/feeds/hl7_test_messages_controller.rb
renalware-core-2.0.160 app/controllers/renalware/feeds/hl7_test_messages_controller.rb
renalware-core-2.0.159 app/controllers/renalware/feeds/hl7_test_messages_controller.rb
renalware-core-2.0.158 app/controllers/renalware/feeds/hl7_test_messages_controller.rb
renalware-core-2.0.157 app/controllers/renalware/feeds/hl7_test_messages_controller.rb
renalware-core-2.0.156 app/controllers/renalware/feeds/hl7_test_messages_controller.rb
renalware-core-2.0.155 app/controllers/renalware/feeds/hl7_test_messages_controller.rb
renalware-core-2.0.153 app/controllers/renalware/feeds/hl7_test_messages_controller.rb
renalware-core-2.0.152 app/controllers/renalware/feeds/hl7_test_messages_controller.rb
renalware-core-2.0.151 app/controllers/renalware/feeds/hl7_test_messages_controller.rb
renalware-core-2.0.149 app/controllers/renalware/feeds/hl7_test_messages_controller.rb
renalware-core-2.0.148 app/controllers/renalware/feeds/hl7_test_messages_controller.rb