Sha256: ce59d1881f093ae1ba0cb2a96b1f9cede467e2824092d4a372ce7bff2bbcf4c2

Contents?: true

Size: 1.45 KB

Versions: 38

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

module Renalware
  module PD
    class MDMPatientsQuery
      include ModalityScopes
      include PatientPathologyScopes
      MODALITY_NAMES = "PD"
      DEFAULT_SEARCH_PREDICATE = "hgb_date desc"
      attr_reader :q, :relation, :named_filter

      def initialize(relation: PD::Patient.all, q:, named_filter: nil)
        @q = q || {}
        @q[:s] = DEFAULT_SEARCH_PREDICATE if @q[:s].blank?
        @relation = relation
        @named_filter = named_filter || :none
      end

      def call
        search.result
      end

      # rubocop:disable Metrics/MethodLength
      def search
        @search ||= begin
          relation
            .extending(PatientTransplantScopes)
            .extending(ModalityScopes)
            .extending(PatientPathologyScopes)
            .extending(NamedFilterScopes)
            .with_current_modality_matching(MODALITY_NAMES)
            .with_current_pathology
            .with_registration_statuses
            .left_outer_joins(:current_observation_set)
            .public_send(named_filter.to_s)
            .ransack(q)
        end
      end
      # rubocop:enable Metrics/MethodLength
    end

    module NamedFilterScopes
      def none
        self # NOOP
      end

      def patients_on_the_worry_board
        joins("RIGHT OUTER JOIN patient_worries ON patient_worries.patient_id = patients.id")
      end
      alias_method :on_worryboard, :patients_on_the_worry_board
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
renalware-core-2.0.105 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.104 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.103 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.102 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.101 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.100 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.99 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.98 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.97 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.96 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.95 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.94 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.93 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.92 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.91 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.90 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.89 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.88 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.87 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.86 app/models/renalware/pd/mdm_patients_query.rb