Class: Renalware::PD::MDMPatientsQuery

Inherits:
Object
  • Object
show all
Includes:
ModalityScopes, Renalware::PatientPathologyScopes
Defined in:
app/models/renalware/pd/mdm_patients_query.rb

Constant Summary collapse

DEFAULT_SEARCH_PREDICATE =
"hgb_date desc"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Renalware::PatientPathologyScopes

extended, pathology_date_sort_predicate, pathology_result_sort_predicate, sanitize, #with_current_pathology

Methods included from ModalityScopes

#with_current_modality_matching, #with_current_modality_of_class

Constructor Details

#initialize(relation: PD::Patient.all, q:, named_filter: nil) ⇒ MDMPatientsQuery

Returns a new instance of MDMPatientsQuery.



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

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

Instance Attribute Details

#named_filterObject (readonly)

Returns the value of attribute named_filter.



9
10
11
# File 'app/models/renalware/pd/mdm_patients_query.rb', line 9

def named_filter
  @named_filter
end

#qObject (readonly)

Returns the value of attribute q.



9
10
11
# File 'app/models/renalware/pd/mdm_patients_query.rb', line 9

def q
  @q
end

#relationObject (readonly)

Returns the value of attribute relation.



9
10
11
# File 'app/models/renalware/pd/mdm_patients_query.rb', line 9

def relation
  @relation
end

Instance Method Details

#callObject



18
19
20
# File 'app/models/renalware/pd/mdm_patients_query.rb', line 18

def call
  search.result
end

#searchObject

rubocop:disable Metrics/MethodLength



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

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