Class: MalawiHivProgramReports::Moh::MohTpt

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

Overview

This class generates the MOH TPT report rubocop:disable Metrics/ClassLength

Instance Attribute Summary collapse

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) ⇒ MohTpt

Returns a new instance of MohTpt.



11
12
13
14
15
16
17
18
19
# File 'app/services/malawi_hiv_program_reports/moh/moh_tpt.rb', line 11

def initialize(start_date:, end_date:, **kwargs)
  @raw_end_date = end_date.to_date
  @raw_start_date = start_date.to_date
  @start_date = start_date - 9.months
  @end_date = @start_date + 3.months
  @start_of_month = @start_date.beginning_of_month
  @end_of_month = @end_date.end_of_month
  @occupation = kwargs[:occupation]
end

Instance Attribute Details

#end_dateObject (readonly)

Returns the value of attribute end_date.



9
10
11
# File 'app/services/malawi_hiv_program_reports/moh/moh_tpt.rb', line 9

def end_date
  @end_date
end

#end_of_monthObject (readonly)

Returns the value of attribute end_of_month.



9
10
11
# File 'app/services/malawi_hiv_program_reports/moh/moh_tpt.rb', line 9

def end_of_month
  @end_of_month
end

#raw_end_dateObject (readonly)

Returns the value of attribute raw_end_date.



9
10
11
# File 'app/services/malawi_hiv_program_reports/moh/moh_tpt.rb', line 9

def raw_end_date
  @raw_end_date
end

#raw_start_dateObject (readonly)

Returns the value of attribute raw_start_date.



9
10
11
# File 'app/services/malawi_hiv_program_reports/moh/moh_tpt.rb', line 9

def raw_start_date
  @raw_start_date
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



9
10
11
# File 'app/services/malawi_hiv_program_reports/moh/moh_tpt.rb', line 9

def start_date
  @start_date
end

#start_of_monthObject (readonly)

Returns the value of attribute start_of_month.



9
10
11
# File 'app/services/malawi_hiv_program_reports/moh/moh_tpt.rb', line 9

def start_of_month
  @start_of_month
end

Instance Method Details

#dataObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/malawi_hiv_program_reports/moh/moh_tpt.rb', line 21

def data
  report = init_report
  drop_tables
  initiated_on_art
  initiated_on_tpt
  create_indexes
  process_initiated_on_art report, fetch_initiated_on_art
  process_initiated_tpt report, fetch_initiated_on_tpt
  response = []
  report.each do |key, value|
    response << { age_group: key, gender: 'F', **value['F'] }
    response << { age_group: key, gender: 'M', **value['M'] }
  end
  response
end