Class: Renalware::Admissions::ConsultQuery

Inherits:
Object
  • Object
show all
Defined in:
app/models/renalware/admissions/consult_query.rb

Defined Under Namespace

Modules: RansackScopes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query = nil) ⇒ ConsultQuery

Returns a new instance of ConsultQuery.



10
11
12
13
14
# File 'app/models/renalware/admissions/consult_query.rb', line 10

def initialize(query = nil)
  @query = query || {}
  @query[:ended_on_null] ||= true
  @query[:s] ||= "hospital_ward_name"
end

Instance Attribute Details

#queryObject (readonly)

Returns the value of attribute query.



8
9
10
# File 'app/models/renalware/admissions/consult_query.rb', line 8

def query
  @query
end

Instance Method Details

#callObject



16
17
18
# File 'app/models/renalware/admissions/consult_query.rb', line 16

def call
  search.result
end

#searchObject

Note we MUST join onto patients for PatientsRansackHelper.identity_match to work. It might be better to refactor PatientsRansackHelper so we can include where required eg below using .extending(PatientsRansackHelper) rather than relying on it being in included in the model file. note that adding .includes(:created_by) her creates an ambigous column ‘family_name’ error rubocop:disable Metrics/MethodLength



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/renalware/admissions/consult_query.rb', line 27

def search
  @search ||= begin
    Consult
      .extend(RansackScopes)
      .joins(:patient)
      .eager_load(patient: [current_modality: :description])
      .includes(
        :consult_site,
        :hospital_ward,
        :created_by,
        patient: { current_modality: :description }
      )
      .order(created_at: :desc)
      .ransack(query)
  end
end