Sha256: b5423da859df7107a13e2afe10649a27d69d2491850426e8e6b5236b0a7a7532

Contents?: true

Size: 1.53 KB

Versions: 96

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

#
# A presenter which, for a patient, displays any HD preferences (for example when or where they
# have HD) that do not match their current HD profile.
#
require_dependency "renalware/hd"

module Renalware
  module HD
    class UnmetPreferencesPresenter
      include ActionView::Helpers
      COMMON_ATTRIBUTES = %i(schedule_definition other_schedule hospital_unit).freeze
      delegate(*COMMON_ATTRIBUTES, to: :hd_preference_set, prefix: :preferred, allow_nil: true)
      delegate(*COMMON_ATTRIBUTES, to: :hd_profile, prefix: :current, allow_nil: true)
      delegate(:notes, :entered_on, to: :hd_preference_set)
      delegate(:to_s, :to_param, :hd_profile, :hd_preference_set, to: :patient)

      def initialize(patient)
        @patient = patient
      end

      # Returns the HD::PreferenceSet setting if it differs from that in the HD::Profile
      # If the preference is unmet, wrap in a <b> tag. Yield the value so the template
      # has a chance to format it before it is wrapped.
      def preferred(attribute)
        value = public_send(:"preferred_#{attribute}")
        value = yield(value) if block_given?
        return value if preference_satisfied?(attribute)

        content_tag(:b, value)
      end

      def preference_satisfied?(attribute)
        preferred = public_send(:"preferred_#{attribute}")
        current = public_send(:"current_#{attribute}")
        return true if preferred.blank? || preferred == current

        false
      end

      private

      attr_reader :patient
    end
  end
end

Version data entries

96 entries across 96 versions & 1 rubygems

Version Path
renalware-core-2.0.149 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.148 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.147 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.146 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.145 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.144 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.143 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.142 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.141 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.140 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.139 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.138 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.137 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.136 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.135 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.134 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.133 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.132 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.131 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.130 app/presenters/renalware/hd/unmet_preferences_presenter.rb