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.15 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.14 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.13 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.12 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.11 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb
renalware-core-2.0.9 app/models/renalware/renal/registry/preflight_checks/deaths_query.rb