Sha256: 51fd6219048aa8d57e36c28777c815f0f02bd7311178504f7b64608b0f07e723

Contents?: true

Size: 1.4 KB

Versions: 71

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

require "renalware/letters"
require "attr_extras"

module Renalware
  module Letters
    # Given a hash of letter part classes (i.e. the class names for each Part that should be
    # included in the letter, where each Part is responsible for rendering a part of the letter)
    # and other options, this class filters out certain parts based on conditions,
    # for example if a site does not want pathology, the recent_pathology_results key is
    # removed from the hash.
    class PartClassFilter
      pattr_initialize [:part_classes!, :include_pathology_in_letter_body!]

      def to_h
        filtered_part_classes
      end

      private

      def filtered_part_classes
        remove_recent_observations_part_if_no_pathology_required_in_body(part_classes)
      end

      # Some sites may not require pathology in letters. This is determined by the boolean
      # #include_pathology_in_letter_body flag on the letterhead, which is site-specific.
      # TODO: It might be better to link the letterhead to the Hospitals::Site and
      # put the site-specific configuration in say a jsonb field on the Site.
      def remove_recent_observations_part_if_no_pathology_required_in_body(part_klasses)
        unless include_pathology_in_letter_body
          part_klasses = part_klasses.reject{ |key| key == :recent_pathology_results }
        end
        part_klasses
      end
    end
  end
end

Version data entries

71 entries across 71 versions & 1 rubygems

Version Path
renalware-core-2.0.77 app/presenters/renalware/letters/part_class_filter.rb
renalware-core-2.0.76 app/presenters/renalware/letters/part_class_filter.rb
renalware-core-2.0.75 app/presenters/renalware/letters/part_class_filter.rb
renalware-core-2.0.74 app/presenters/renalware/letters/part_class_filter.rb
renalware-core-2.0.73 app/presenters/renalware/letters/part_class_filter.rb
renalware-core-2.0.72 app/presenters/renalware/letters/part_class_filter.rb
renalware-core-2.0.71 app/presenters/renalware/letters/part_class_filter.rb
renalware-core-2.0.70 app/presenters/renalware/letters/part_class_filter.rb
renalware-core-2.0.69 app/presenters/renalware/letters/part_class_filter.rb
renalware-core-2.0.68 app/presenters/renalware/letters/part_class_filter.rb
renalware-core-2.0.67 app/presenters/renalware/letters/part_class_filter.rb
renalware-core-2.0.64 app/presenters/renalware/letters/part_class_filter.rb
renalware-core-2.0.63 app/presenters/renalware/letters/part_class_filter.rb
renalware-core-2.0.62 app/presenters/renalware/letters/part_class_filter.rb
renalware-core-2.0.61 app/presenters/renalware/letters/part_class_filter.rb
renalware-core-2.0.60 app/presenters/renalware/letters/part_class_filter.rb
renalware-core-2.0.58 app/presenters/renalware/letters/part_class_filter.rb
renalware-core-2.0.57 app/presenters/renalware/letters/part_class_filter.rb
renalware-core-2.0.56 app/presenters/renalware/letters/part_class_filter.rb
renalware-core-2.0.55 app/presenters/renalware/letters/part_class_filter.rb