Sha256: 922cd109516caae9bca79a15545e1875de8268908ca53d464c636bd798efca34

Contents?: true

Size: 1.31 KB

Versions: 17

Compression:

Stored size: 1.31 KB

Contents

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

17 entries across 17 versions & 1 rubygems

Version Path
renalware-core-2.0.8 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.7 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.5 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.4 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.3 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.2 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.1 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.0 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.0.pre.rc13 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.0.pre.rc11 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.0.pre.rc10 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.0.pre.rc9 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.0.pre.rc8 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.0.pre.rc7 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.0.pre.rc6 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.0.pre.rc5 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.0.pre.rc4 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb