Sha256: 62e39e786bd9c6cc53c474028134ce21a6a9f135d46f427941f1304b9ae26cf0

Contents?: true

Size: 1.68 KB

Versions: 15

Compression:

Stored size: 1.68 KB

Contents

# frozen_string_literal: true

module Renalware
  module Medications
    # Accepts a group of prescriptions -  see example usage - and renders a tabs for each of the
    # group names with their corresponding tablular content.
    # Various options - see PrescriptionGroup - drive what columns are shown.
    #
    # Example usage:
    #
    # = render Renalware::Medications::TabbedPrescriptionsListComponent.new(
    #   [
    #      { title: "Current", prescriptions: list1, show_administer_on_hd: true },
    #      { title: "EPO", prescriptions: list2, show_terminated_on: true }
    #   ]
    class TabbedPrescriptionsListComponent < ApplicationComponent
      include DrugsHelper
      attr_reader :groups

      class PrescriptionGroup
        attr_reader_initialize [
          :title,
          :prescriptions,
          show_terminated_on: true,
          show_administer_on_hd: true,
          show_drug_types: false
        ]

        # The markup expects each prescription to have been decorated with a PresriptionPresenter.
        # However there may be cases where they might have been, so we check by
        # (looking for a method which is defined by the presenter) and decorate them if necessary.
        def prescriptions
          @prescriptions.map do |presc|
            presc.respond_to?(:drug_type_names) ? presc : PrescriptionPresenter.new(presc)
          end
        end
      end

      # Map the incoming array of hashes to an array of PrescriptionGroup objects to make
      # interrogation easier in the html.
      def initialize(prescription_groups)
        @groups = Array(prescription_groups).map { |options| PrescriptionGroup.new(options) }
        super
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/components/renalware/medications/tabbed_prescriptions_list_component.rb
renalware-core-2.1.0 app/components/renalware/medications/tabbed_prescriptions_list_component.rb
renalware-core-2.0.167 app/components/renalware/medications/tabbed_prescriptions_list_component.rb
renalware-core-2.0.166 app/components/renalware/medications/tabbed_prescriptions_list_component.rb
renalware-core-2.0.165 app/components/renalware/medications/tabbed_prescriptions_list_component.rb
renalware-core-2.0.164 app/components/renalware/medications/tabbed_prescriptions_list_component.rb
renalware-core-2.0.163 app/components/renalware/medications/tabbed_prescriptions_list_component.rb
renalware-core-2.0.162 app/components/renalware/medications/tabbed_prescriptions_list_component.rb
renalware-core-2.0.161 app/components/renalware/medications/tabbed_prescriptions_list_component.rb
renalware-core-2.0.160 app/components/renalware/medications/tabbed_prescriptions_list_component.rb
renalware-core-2.0.159 app/components/renalware/medications/tabbed_prescriptions_list_component.rb
renalware-core-2.0.158 app/components/renalware/medications/tabbed_prescriptions_list_component.rb
renalware-core-2.0.157 app/components/renalware/medications/tabbed_prescriptions_list_component.rb
renalware-core-2.0.156 app/components/renalware/medications/tabbed_prescriptions_list_component.rb
renalware-core-2.0.155 app/components/renalware/medications/tabbed_prescriptions_list_component.rb