Class: MalawiHivProgramReports::Clinic::PatientsOnAntiretrovirals

Inherits:
Object
  • Object
show all
Defined in:
app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_date:, end_date:, **_kwargs) ⇒ PatientsOnAntiretrovirals

Returns a new instance of PatientsOnAntiretrovirals.



9
10
11
12
# File 'app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb', line 9

def initialize(start_date:, end_date:, **_kwargs)
  @start_date = start_date
  @end_date = end_date
end

Instance Attribute Details

#end_dateObject (readonly)

Returns the value of attribute end_date.



7
8
9
# File 'app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb', line 7

def end_date
  @end_date
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



7
8
9
# File 'app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb', line 7

def start_date
  @start_date
end

Class Method Details

.within(start_date, end_date) ⇒ Object



14
15
16
17
# File 'app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb', line 14

def self.within(start_date, end_date)
  PatientsOnAntiretrovirals.new(start_date:, end_date:)
                           .patients
end

Instance Method Details

#find_reportObject



19
20
21
# File 'app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb', line 19

def find_report
  patients
end

#patientsObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb', line 23

def patients
  ::DrugOrder.select('orders.patient_id AS patient_id')
             .joins(:order)
             .merge(art_orders)
             .where(drug_inventory_id: ArtService::RegimenEngine.arv_drugs,
                    quantity: 1..Float::INFINITY)
             .where('start_date BETWEEN :start_date AND :end_date
                   OR auto_expire_date BETWEEN :start_date AND :end_date
                   OR (start_date <= :start_date AND auto_expire_date >= :end_date)',
                    start_date:, end_date:)
             .group('orders.patient_id')
end