Sha256: 6ff224e842da4f70d928b8fb839e88cf50cf70470965ba3a3eb3d5d604ff0128

Contents?: true

Size: 1.34 KB

Versions: 26

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/renal"

module Renalware
  module Renal
    module Registry
      module PreflightChecks
        class DeathsQuery
          include ModalityScopes
          MODALITY_NAMES = %w(Death).freeze

          attr_reader :relation, :query_params

          def initialize(relation: nil, query_params: {})
            @relation = relation || default_relation
            @query_params = query_params
            @query_params[:s] = "modality_descriptions_name ASC" if @query_params[:s].blank?
          end

          def default_relation
            Renalware::Patient
              .preload(current_modality: [:description])
              .all
              .order(family_name: :asc)
          end

          def call
            search
              .result
              .extending(ModalityScopes)
              .with_current_modality_matching(MODALITY_NAMES)
              .joins("LEFT OUTER JOIN renal_profiles ON renal_profiles.patient_id = patients.id")
              .where("patients.first_cause_id is NULL AND renal_profiles.esrf_on IS NOT NULL")
          end

          def search
            @search ||= relation.ransack(query_params)
          end

          def self.missing_data_for(_patient)
            [
              :cause_of_death
            ]
          end
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
renalware-core-2.0.37 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.36 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.35 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.34 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.33 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.32 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.31 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.30 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.28 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.27 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.26 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.25 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.24 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.23 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.22 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.21 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.20 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.18 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.17 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.16 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb