Sha256: aa50c57ea7c5d891381d662ff5e932f9ea1a103ff3ef78063ed85c3e13e00271

Contents?: true

Size: 1.37 KB

Versions: 70

Compression:

Stored size: 1.37 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

70 entries across 70 versions & 1 rubygems

Version Path
renalware-core-2.0.123 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.121 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.120 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.119 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.118 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.117 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.116 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.115 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.113 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.112 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.111 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.110 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.109 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.108 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.106 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.105 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.104 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.103 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.102 app/helpers/renalware/mdm_helper.rb
renalware-core-2.0.101 app/helpers/renalware/mdm_helper.rb