Class: Renalware::LowClearance::MDMPatientsQuery

Inherits:
Object
  • Object
show all
Includes:
ModalityScopes
Defined in:
app/models/renalware/low_clearance/mdm_patients_query.rb

Defined Under Namespace

Modules: NamedFilterScopes

Constant Summary collapse

DEFAULT_SEARCH_PREDICATE =
"hgb_date DESC"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ModalityScopes

#with_current_modality_matching, #with_current_modality_of_class

Constructor Details

#initialize(relation: LowClearance::Patient.all, query: nil, named_filter: nil) ⇒ MDMPatientsQuery

Returns a new instance of MDMPatientsQuery.



12
13
14
15
16
17
# File 'app/models/renalware/low_clearance/mdm_patients_query.rb', line 12

def initialize(relation: LowClearance::Patient.all, query: nil, named_filter: nil)
  @query = query || {}
  @named_filter = named_filter || :none
  @query[:s] = DEFAULT_SEARCH_PREDICATE if @query[:s].blank?
  @relation = relation
end

Instance Attribute Details

#named_filterObject (readonly)

Returns the value of attribute named_filter.



10
11
12
# File 'app/models/renalware/low_clearance/mdm_patients_query.rb', line 10

def named_filter
  @named_filter
end

#queryObject (readonly)

Returns the value of attribute query.



10
11
12
# File 'app/models/renalware/low_clearance/mdm_patients_query.rb', line 10

def query
  @query
end

#relationObject (readonly)

Returns the value of attribute relation.



10
11
12
# File 'app/models/renalware/low_clearance/mdm_patients_query.rb', line 10

def relation
  @relation
end

Instance Method Details

#callObject



19
20
21
# File 'app/models/renalware/low_clearance/mdm_patients_query.rb', line 19

def call
  search.result
end

#searchObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/renalware/low_clearance/mdm_patients_query.rb', line 23

def search
  @search ||= begin
    relation
      .extending(PatientTransplantScopes)
      .extending(PatientPathologyScopes)
      .extending(ModalityScopes)
      .extending(NamedFilterScopes)
      .with_registration_statuses
      .with_current_pathology
      .left_outer_joins(:current_observation_set)
      .with_current_modality_of_class(LowClearance::ModalityDescription)
      .public_send(named_filter.to_s)
      .search(query)
  end
end