Class: MalawiHivProgramReports::Moh::CumulativeCohort
- Inherits:
-
Object
- Object
- MalawiHivProgramReports::Moh::CumulativeCohort
- Includes:
- Utils::CommonSqlQueryUtils
- Defined in:
- app/services/malawi_hiv_program_reports/moh/cumulative_cohort.rb
Overview
This is the Cumulative Cohort Builder class rubocop:disable Metrics/ClassLength
Constant Summary collapse
- LOCK_FILE =
'art_service/reports/cumulative_cohort.lock'
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#end_date ⇒ Object
readonly
Returns the value of attribute end_date.
-
#iteration ⇒ Object
readonly
Returns the value of attribute iteration.
-
#locations ⇒ Object
readonly
Returns the value of attribute locations.
-
#outcome ⇒ Object
readonly
Returns the value of attribute outcome.
-
#rebuild ⇒ Object
readonly
Returns the value of attribute rebuild.
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
-
#start_date ⇒ Object
readonly
Returns the value of attribute start_date.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
- #find_report ⇒ Object
-
#initialize(start_date:, end_date:, **kwargs) ⇒ CumulativeCohort
constructor
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
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) ⇒ CumulativeCohort
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/services/malawi_hiv_program_reports/moh/cumulative_cohort.rb', line 17 def initialize(start_date:, end_date:, **kwargs) @start_date = ActiveRecord::Base.connection.quote(start_date) @end_date = ActiveRecord::Base.connection.quote(end_date) @rebuild = kwargs[:rebuild]&.casecmp?('true') locations = kwargs[:locations] @locations = locations.present? ? locations.split(',') : [] @definition = kwargs[:definition] || 'pepfar' @iteration = Concurrent::AtomicFixnum.new(0) @start_time = Time.now prepare_redis definition = @definition.downcase raise ArgumentError, "Invalid outcomes definition: #{definition}" unless %w[moh pepfar].include?(definition) end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
12 13 14 |
# File 'app/services/malawi_hiv_program_reports/moh/cumulative_cohort.rb', line 12 def definition @definition end |
#end_date ⇒ Object (readonly)
Returns the value of attribute end_date.
12 13 14 |
# File 'app/services/malawi_hiv_program_reports/moh/cumulative_cohort.rb', line 12 def end_date @end_date end |
#iteration ⇒ Object (readonly)
Returns the value of attribute iteration.
12 13 14 |
# File 'app/services/malawi_hiv_program_reports/moh/cumulative_cohort.rb', line 12 def iteration @iteration end |
#locations ⇒ Object (readonly)
Returns the value of attribute locations.
12 13 14 |
# File 'app/services/malawi_hiv_program_reports/moh/cumulative_cohort.rb', line 12 def locations @locations end |
#outcome ⇒ Object (readonly)
Returns the value of attribute outcome.
12 13 14 |
# File 'app/services/malawi_hiv_program_reports/moh/cumulative_cohort.rb', line 12 def outcome @outcome end |
#rebuild ⇒ Object (readonly)
Returns the value of attribute rebuild.
12 13 14 |
# File 'app/services/malawi_hiv_program_reports/moh/cumulative_cohort.rb', line 12 def rebuild @rebuild end |
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
12 13 14 |
# File 'app/services/malawi_hiv_program_reports/moh/cumulative_cohort.rb', line 12 def redis @redis end |
#start_date ⇒ Object (readonly)
Returns the value of attribute start_date.
12 13 14 |
# File 'app/services/malawi_hiv_program_reports/moh/cumulative_cohort.rb', line 12 def start_date @start_date end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
12 13 14 |
# File 'app/services/malawi_hiv_program_reports/moh/cumulative_cohort.rb', line 12 def start_time @start_time end |
Instance Method Details
#find_report ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/services/malawi_hiv_program_reports/moh/cumulative_cohort.rb', line 31 def find_report handle_tables clear_cohort_status unless rebuild process_thread(locations:) end_time = Time.now time_in_minutes = ((end_time - start_time) / 60).round(2) handle_failed time_taken_for_failed = ((Time.now - end_time) / 60).round(2) Rails.logger.info("Cumulative Cohort report took #{time_in_minutes} minutes to generate for these locations: #{locations}") redis.set('cumulative_time_taken', time_in_minutes) redis.set('cumulative_status', 'completed') { cohort_time: time_in_minutes, processing_failed: time_taken_for_failed } end |