Sha256: c3e439a7edeb30119b5f9f9dbb2f849a1f98135060dcda780cc588a31749e693

Contents?: true

Size: 1.05 KB

Versions: 21

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Renalware
  module Patients
    # Finds patients with a death modality or who have a died_on date
    class DeceasedPatientsQuery
      attr_reader :query_params

      def initialize(query_params)
        @query_params = query_params || {}
        @query_params[:s] = "family_name ASC" if @query_params[:s].blank?
      end

      def call
        search.result.where(id: ids_of_deceased_patients)
      end

      def search
        Patient
          .includes(:first_cause, current_modality: :description)
          .ransack(query_params)
      end

      private

      def ids_of_deceased_patients
        (ids_of_patients_with_death_modality + ids_of_patients_with_died_on_date).uniq
      end

      def ids_of_patients_with_death_modality
        Patient
          .extending(ModalityScopes)
          .with_current_modality_of_class(Renalware::Deaths::ModalityDescription)
          .pluck(:id)
      end

      def ids_of_patients_with_died_on_date
        Patient.where.not(died_on: nil).pluck(:id)
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/models/renalware/patients/deceased_patients_query.rb
renalware-core-2.1.0 app/models/renalware/patients/deceased_patients_query.rb
renalware-core-2.0.167 app/models/renalware/patients/deceased_patients_query.rb
renalware-core-2.0.166 app/models/renalware/patients/deceased_patients_query.rb
renalware-core-2.0.165 app/models/renalware/patients/deceased_patients_query.rb
renalware-core-2.0.164 app/models/renalware/patients/deceased_patients_query.rb
renalware-core-2.0.163 app/models/renalware/patients/deceased_patients_query.rb
renalware-core-2.0.162 app/models/renalware/patients/deceased_patients_query.rb
renalware-core-2.0.161 app/models/renalware/patients/deceased_patients_query.rb
renalware-core-2.0.160 app/models/renalware/patients/deceased_patients_query.rb
renalware-core-2.0.159 app/models/renalware/patients/deceased_patients_query.rb
renalware-core-2.0.158 app/models/renalware/patients/deceased_patients_query.rb
renalware-core-2.0.157 app/models/renalware/patients/deceased_patients_query.rb
renalware-core-2.0.156 app/models/renalware/patients/deceased_patients_query.rb
renalware-core-2.0.155 app/models/renalware/patients/deceased_patients_query.rb
renalware-core-2.0.153 app/models/renalware/patients/deceased_patients_query.rb
renalware-core-2.0.152 app/models/renalware/patients/deceased_patients_query.rb
renalware-core-2.0.151 app/models/renalware/patients/deceased_patients_query.rb
renalware-core-2.0.149 app/models/renalware/patients/deceased_patients_query.rb
renalware-core-2.0.148 app/models/renalware/patients/deceased_patients_query.rb