<commit_before>module Renalware
  module Transplants
    module Registrations
      class WaitListQuery
        def initialize(quick_filter:, q: nil)
          @quick_filter = quick_filter.to_sym
          @q = q || {}
        end

        def call
          search.result
        end

        def search
          @search ||= begin
            query = query_for_filter(@quick_filter).merge(@q)
            QueryableRegistration.search(query).tap do |s|
              s.sorts = ["patient_family_name, patient_given_name"]
            end
          end
        end

        private

        def query_for_filter(filter)
          case filter
          when :nhb_consent
            { nhb_consent_eq: "yes" }
          when :active
            { current_status_in: :active }
          when :suspended
            { current_status_in: :suspended }
          when :active_and_suspended
            # note: array must be embedded in another array as mentionned here:
            # https://github.com/activerecord-hackery/ransack#using-scopesclass-methods
            { current_status_in: [%w(active suspended)] }
          when :working_up
            { current_status_in: [%w(working_up working_up_lrf)] }
          end
        end

        class QueryableRegistration < ActiveType::Record[Registration]
          scope :current_status_in, -> (codes = %w(active)) {
            joins(statuses: :description)
              .where(transplant_registration_statuses: { terminated_on: nil })
              .where(transplant_registration_status_descriptions: { code: codes })
          }
          scope :nhb_consent_eq, -> (enum = "yes") {
            where("transplant_registrations.document @> ?", { nhb_consent: { value: enum } }.to_json )
          }

          ransacker :uk_transplant_centre_code do
            Arel.sql("transplant_registrations.document -> 'codes' ->> 'uk_transplant_centre_code'")
          end

          ransacker :crf_highest_value do
            Arel.sql("transplant_registrations.document -> 'crf' -> 'highest' ->> 'result'")
          end

          ransacker :crf_latest_value do
            Arel.sql("transplant_registrations.document -> 'crf' -> 'latest' ->> 'result'")
          end

          private_class_method :ransackable_scopes

          def self.ransackable_scopes(_auth_object = nil)
            %i(nhb_consent_eq current_status_in)
          end
        end
      end
    end
  end
end
<commit_msg>Fix style violation<commit_after>module Renalware
  module Transplants
    module Registrations
      class WaitListQuery
        def initialize(quick_filter:, q: nil)
          @quick_filter = quick_filter.to_sym
          @q = q || {}
        end

        def call
          search.result
        end

        def search
          @search ||= begin
            query = query_for_filter(@quick_filter).merge(@q)
            QueryableRegistration.search(query).tap do |s|
              s.sorts = ["patient_family_name, patient_given_name"]
            end
          end
        end

        private

        def query_for_filter(filter)
          case filter
          when :nhb_consent
            { nhb_consent_eq: "yes" }
          when :active
            { current_status_in: :active }
          when :suspended
            { current_status_in: :suspended }
          when :active_and_suspended
            # note: array must be embedded in another array as mentionned here:
            # https://github.com/activerecord-hackery/ransack#using-scopesclass-methods
            { current_status_in: [%w(active suspended)] }
          when :working_up
            { current_status_in: [%w(working_up working_up_lrf)] }
          end
        end

        class QueryableRegistration < ActiveType::Record[Registration]
          scope :current_status_in, -> (codes = %w(active)) {
            joins(statuses: :description)
              .where(transplant_registration_statuses: { terminated_on: nil })
              .where(transplant_registration_status_descriptions: { code: codes })
          }
          scope :nhb_consent_eq, -> (enum = "yes") {
            where(
              "transplant_registrations.document @> ?",
              { nhb_consent: { value: enum } }.to_json
            )
          }

          ransacker :uk_transplant_centre_code do
            Arel.sql("transplant_registrations.document -> 'codes' ->> 'uk_transplant_centre_code'")
          end

          ransacker :crf_highest_value do
            Arel.sql("transplant_registrations.document -> 'crf' -> 'highest' ->> 'result'")
          end

          ransacker :crf_latest_value do
            Arel.sql("transplant_registrations.document -> 'crf' -> 'latest' ->> 'result'")
          end

          private_class_method :ransackable_scopes

          def self.ransackable_scopes(_auth_object = nil)
            %i(nhb_consent_eq current_status_in)
          end
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.08904248831063225, 'fraction_numerical': 0.0, 'mean_word_length': 1.9043683589138134, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3315439', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1393, 'n_words': 277}