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



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



41
42
43
44
45
# File 'app/models/renalware/renal/registry/preflight_checks/deaths_query.rb', line 41

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

Instance Method Details

#callObject



28
29
30
31
32
33
34
35
# File 'app/models/renalware/renal/registry/preflight_checks/deaths_query.rb', line 28

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

#default_relationObject



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

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

#searchObject



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

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