Class: Renalware::HD::MDMPatientsQuery

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

Defined Under Namespace

Modules: QueryablePatient

Constant Summary collapse

DEFAULT_SEARCH_PREDICATE =
"hgb_date desc"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from 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(params:, named_filter:) ⇒ MDMPatientsQuery

Returns a new instance of MDMPatientsQuery.



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

def initialize(params:, named_filter:)
  @params = params || {}
  @params[:s] = DEFAULT_SEARCH_PREDICATE if @params[:s].blank?
  @named_filter = named_filter || :none
end

Instance Attribute Details

#named_filterObject (readonly)

Returns the value of attribute named_filter.



11
12
13
# File 'app/models/renalware/hd/mdm_patients_query.rb', line 11

def named_filter
  @named_filter
end

#paramsObject (readonly)

Returns the value of attribute params.



11
12
13
# File 'app/models/renalware/hd/mdm_patients_query.rb', line 11

def params
  @params
end

Instance Method Details

#callObject



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

def call
  search.result
end

#searchObject

rubocop:disable Metrics/MethodLength, Metrics/AbcSize



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/renalware/hd/mdm_patients_query.rb', line 24

def search
  @search ||= begin
    HD::Patient
      .include(QueryablePatient)
      .extending(PatientTransplantScopes)
      .merge(Accesses::Patient.with_current_plan)
      .merge(Accesses::Patient.with_profile)
      .eager_load(hd_profile: [:hospital_unit])
      .extending(ModalityScopes)
      .extending(PatientPathologyScopes)
      .extending(NamedFilterScopes)
      .with_current_pathology
      .with_registration_statuses
      .with_current_modality_of_class(Renalware::HD::ModalityDescription)
      .public_send(named_filter.to_s)
      .ransack(params)
  end
end