Sha256: 1ace336b269d2db1d02888ae7bdf26ac6bbd66e3698c66e71d00ca2aecacd5fa

Contents?: true

Size: 1.49 KB

Versions: 6

Compression:

Stored size: 1.49 KB

Contents

#
# 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 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

6 entries across 6 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.beta9 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.0.pre.beta8 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.0.pre.beta7 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.0.pre.beta6 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.0.pre.beta5 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.0.pre.beta4 app/presenters/renalware/hd/unmet_preferences_presenter.rb