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

MODALITY_NAMES =
"HD"
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, #with_current_pathology

Methods included from ModalityScopes

#with_current_modality_matching, #with_current_modality_of_class

Constructor Details

#initialize(params:) ⇒ MDMPatientsQuery

Returns a new instance of MDMPatientsQuery.



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

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

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



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

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



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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)
      .with_current_pathology
      .with_registration_statuses
      .with_current_modality_matching(MODALITY_NAMES)
      .search(params)
  end
end