Sha256: 2d7890411e5972a504660db44984284e31e74103cc3ad4b3a1de7f0affc251dd

Contents?: true

Size: 1.36 KB

Versions: 28

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module Renalware
  module MDMHelper
    def link_to_mdm(patient)
      MDMLink.new(patient).to_html
    end

    #
    # Create an html link to the MDM appropriate to the patient's current modality
    #
    class MDMLink
      include ActionView::Helpers
      include Renalware::Engine.routes.url_helpers

      def initialize(patient)
        @patient = patient
      end

      def path
        @path ||= begin
          return if modality_description.type.blank?
          case modality_description_symbol
          when :pd then patient_pd_mdm_path(patient)
          when :hd then patient_hd_mdm_path(patient)
          when :transplant then patient_transplants_mdm_path(patient)
          when :low_clearance then patient_low_clearance_mdm_path(patient)
          end
        end
      end

      def to_html
        link_to(mdm_name, path) if path
      end

      private

      attr_reader :patient
      delegate :name, to: :modality_description, prefix: true, allow_nil: true

      def modality_description
        current_modality = patient.current_modality || NullObject.instance
        current_modality.description
      end

      def mdm_name
        "#{modality_description_name} MDM"
      end

      def modality_description_symbol
        modality_description.becomes(modality_description.type.constantize).to_sym
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
renalware-core-2.0.46 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.45 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.44 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.43 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.42 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.41 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.40 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.39 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.38 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.37 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.36 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.35 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.34 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.33 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.32 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.31 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.30 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.28 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.27 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.26 app/helpers/renalware/mdm_helper.rb