Sha256: 210dbfcc86fa95b61c029af7366cfbbee7494f6b48640cc78a236224d72dbb25

Contents?: true

Size: 1.44 KB

Versions: 44

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module Renalware
  module PD
    class MDMPatientsQuery
      include ModalityScopes
      include PatientPathologyScopes
      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_of_class(Renalware::PD::ModalityDescription)
            .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

44 entries across 44 versions & 1 rubygems

Version Path
renalware-core-2.0.153 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.152 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.151 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.149 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.148 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.147 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.146 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.145 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.144 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.143 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.142 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.141 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.140 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.139 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.138 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.137 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.136 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.135 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.134 app/models/renalware/pd/mdm_patients_query.rb
renalware-core-2.0.133 app/models/renalware/pd/mdm_patients_query.rb