Class: MalawiHivProgramReports::Clinic::TxRtt

Inherits:
Object
  • Object
show all
Includes:
Utils::CommonSqlQueryUtils
Defined in:
app/services/malawi_hiv_program_reports/clinic/tx_rtt.rb

Instance Method Summary collapse

Methods included from Utils::CommonSqlQueryUtils

#current_occupation_query, #external_client_query, #occupation_filter, #partition_by_site, #process_occupation

Constructor Details

#initialize(start_date:, end_date:, **kwargs) ⇒ TxRtt

Returns a new instance of TxRtt.



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

def initialize(start_date:, end_date:, **kwargs)
  @start_date = ActiveRecord::Base.connection.quote(start_date)
  @end_date = ActiveRecord::Base.connection.quote(end_date)
  @occupation = kwargs[:occupation]
end

Instance Method Details

#find_reportObject



15
16
17
18
19
20
21
22
23
# File 'app/services/malawi_hiv_program_reports/clinic/tx_rtt.rb', line 15

def find_report
  tx_rtt.each_with_object({}) do |patient, report|
    age_group = report[patient['age_group']] || { 'M' => [], 'F' => [], 'Unknown' => [] }
    age_group[patient['gender']&.first&.upcase || 'Unknown'] << { patient_id: patient['patient_id'],
                                                                  months: patient['months'] }

    report[patient['age_group']] = age_group
  end
end