Class: Renalware::HD::PatientsDialysingByScheduleQuery

Inherits:
Object
  • Object
show all
Defined in:
app/models/renalware/hd/patients_dialysing_by_schedule_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hospital_unit_id, schedule_definition_ids) ⇒ PatientsDialysingByScheduleQuery

Returns a new instance of PatientsDialysingByScheduleQuery.



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

def initialize(hospital_unit_id, schedule_definition_ids)
  @hospital_unit_id = hospital_unit_id
  @schedule_definition_ids = Array(schedule_definition_ids)
end

Instance Attribute Details

#hospital_unit_idObject (readonly)

Returns the value of attribute hospital_unit_id.



8
9
10
# File 'app/models/renalware/hd/patients_dialysing_by_schedule_query.rb', line 8

def hospital_unit_id
  @hospital_unit_id
end

#schedule_definition_idsObject (readonly)

Returns the value of attribute schedule_definition_ids.



8
9
10
# File 'app/models/renalware/hd/patients_dialysing_by_schedule_query.rb', line 8

def schedule_definition_ids
  @schedule_definition_ids
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/renalware/hd/patients_dialysing_by_schedule_query.rb', line 15

def call
  return [] if schedule_definition_ids.empty?

  Patient
    .eager_load(hd_profile: [:hospital_unit, { schedule_definition: [:diurnal_period] }])
    .where(
      hd_profiles: {
        schedule_definition_id: schedule_definition_ids,
        hospital_unit_id: hospital_unit_id
      })
    .order(:family_name, :given_name)
end