Class: Renalware::Renal::Registry::PreflightChecks::DeathsQuery

Inherits:
Object
  • Object
show all
Includes:
ModalityScopes
Defined in:
app/models/renalware/renal/registry/preflight_checks/deaths_query.rb

Constant Summary collapse

MODALITY_NAMES =
%w(Death).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ModalityScopes

#with_current_modality_matching, #with_current_modality_of_class

Constructor Details

#initialize(relation: nil, query_params: {}) ⇒ DeathsQuery

Returns a new instance of DeathsQuery.



15
16
17
18
19
# File 'app/models/renalware/renal/registry/preflight_checks/deaths_query.rb', line 15

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

Instance Attribute Details

#query_paramsObject (readonly)

Returns the value of attribute query_params.



13
14
15
# File 'app/models/renalware/renal/registry/preflight_checks/deaths_query.rb', line 13

def query_params
  @query_params
end

#relationObject (readonly)

Returns the value of attribute relation.



13
14
15
# File 'app/models/renalware/renal/registry/preflight_checks/deaths_query.rb', line 13

def relation
  @relation
end

Class Method Details

.missing_data_for(_patient) ⇒ Object



38
39
40
41
42
# File 'app/models/renalware/renal/registry/preflight_checks/deaths_query.rb', line 38

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

Instance Method Details

#callObject



25
26
27
28
29
30
31
32
# File 'app/models/renalware/renal/registry/preflight_checks/deaths_query.rb', line 25

def call
  search
    .result
    .extending(ModalityScopes)
    .preload(current_modality: [:description])
    .with_current_modality_matching(MODALITY_NAMES)
    .where("patients.first_cause_id is NULL AND renal_profiles.esrf_on IS NOT NULL")
end

#default_relationObject



21
22
23
# File 'app/models/renalware/renal/registry/preflight_checks/deaths_query.rb', line 21

def default_relation
  Renalware::Renal::Patient.left_outer_joins(:profile)
end

#searchObject



34
35
36
# File 'app/models/renalware/renal/registry/preflight_checks/deaths_query.rb', line 34

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