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.106 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.105 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.104 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.103 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.102 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.101 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.100 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.99 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.98 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.97 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.96 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.95 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.94 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.93 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.92 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.91 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.90 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.89 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.88 app/presenters/renalware/hd/unmet_preferences_presenter.rb
renalware-core-2.0.87 app/presenters/renalware/hd/unmet_preferences_presenter.rb