Sha256: 34d98edd652da0620e1ad82a4debe1c751bf1f97211639089359d149abec31e5

Contents?: true

Size: 1.44 KB

Versions: 15

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(q:, relation: PD::Patient.all, 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

15 entries across 15 versions & 1 rubygems

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