malawi_hiv_program_reports 1.1.17 → 1.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c818eb00df67da231594873c08c20bb5df18a2c53433788a96e27a7ca1211bf9
4
- data.tar.gz: fd99e8c2ca139a33ddd76a9eefbaef20dfcf6eee7c1b6290919e2240c39b9c63
3
+ metadata.gz: 59ce2b645e8862156cd2dfe62c5085eb8f92b940f3abb591d4ed90affc349a72
4
+ data.tar.gz: 2b4a8ba3fd2ee2e82ae0e645b6b52f8951bb04e2bc9f418faed1ff4052f14acf
5
5
  SHA512:
6
- metadata.gz: f61982a9e3ce30521079abacdd89144d6c03d10fde293d5fbefcb61fac57a143e5680f5216eee22e8423f37d8b88014205f602003af0644a7a95078fed7d052c
7
- data.tar.gz: ea196faf6b0a471e995e4885058acbc0a141c7fcbe948e502801648ed796fbea5e72bf1d0f28b556ea0ccd1404cbc78046928ebb5330acdcfd7068f54f16c924
6
+ metadata.gz: 645f9cbfdbeaf74c6b2da6035a3d336408d7e28663171557ecc2e68c7d53489d218408dd76980d870ef0d74dbc1238a57d388d194ac3195e3fe0953420e97d6e
7
+ data.tar.gz: f6b5ad1078a1a8c3c68faee0d74c71502dce1099797140ab72ca171d92e8bf585b00b750758c3dead290927266c5c90aa8b912e57786d04db53418c4c15e8a67
@@ -23,10 +23,7 @@ module MalawiHivProgramReports
23
23
  @definition = kwargs[:definition] || 'pepfar'
24
24
  @iteration = Concurrent::AtomicFixnum.new(0)
25
25
  @start_time = Time.now
26
- @redis = Redis.new
27
- @redis.set('cumulative_progress', 0)
28
- @redis.set('cumulative_status', 'running')
29
- @redis.set('cumulative_time_taken', 0)
26
+ prepare_redis
30
27
  definition = @definition.downcase
31
28
  raise ArgumentError, "Invalid outcomes definition: #{definition}" unless %w[moh pepfar].include?(definition)
32
29
  end
@@ -61,7 +58,7 @@ module MalawiHivProgramReports
61
58
  queue = Queue.new
62
59
  locations.each { |loc| queue << loc }
63
60
 
64
- threads = Array.new(65) do
61
+ threads = Array.new(configured_threads) do
65
62
  Thread.new do
66
63
  until queue.empty?
67
64
  loc = begin
@@ -74,7 +71,7 @@ module MalawiHivProgramReports
74
71
  ActiveRecord::Base.connection_pool.with_connection do
75
72
  process_data loc
76
73
  current_iteration = iteration.increment
77
- # update_progress(current_iteration, locations.size)
74
+ update_progress(current_iteration, locations.size)
78
75
  rescue StandardError => e
79
76
  Rails.logger.info("Error processing location #{loc}: #{e.message}")
80
77
  Rails.logger.info(e.backtrace.join("\n"))
@@ -88,6 +85,22 @@ module MalawiHivProgramReports
88
85
  end
89
86
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
90
87
 
88
+ def configured_threads
89
+ threads = ::Utils::ConfigReader.application_read('max_threads')&.to_i
90
+ Rails::logger.info("Max threads: #{threads}")
91
+ threads.positive? ? threads : 60
92
+ rescue StandardError => e
93
+ Rails.logger.info("Error reading max threads: #{e.message}")
94
+ 60
95
+ end
96
+
97
+ def prepare_redis
98
+ @redis = Redis.new
99
+ @redis.set('cumulative_progress', 0)
100
+ @redis.set('cumulative_status', 'running')
101
+ @redis.set('cumulative_time_taken', 0)
102
+ end
103
+
91
104
  # update progress in redis and channel
92
105
  def update_progress(current_iteration, total)
93
106
  percentage = (current_iteration.to_f / total * 100).round(2)
@@ -118,10 +118,8 @@ module MalawiHivProgramReports
118
118
  end
119
119
 
120
120
  def build_cohort_tables
121
- return unless rebuild_outcome || @occupation.present?
122
-
123
121
  MalawiHivProgramReports::Moh::CumulativeCohort.new(
124
- start_date:,
122
+ start_date: (end_date - 2.months).beginning_of_month,
125
123
  end_date:,
126
124
  locations: [@location.to_s],
127
125
  rebuild: rebuild_outcome
@@ -166,6 +164,8 @@ module MalawiHivProgramReports
166
164
  cn.name AS tb_status,
167
165
  GROUP_CONCAT(DISTINCT vcn.name) AS screening_methods
168
166
  FROM cdr_temp_cohort_members #{current_partition} tesd
167
+ INNER JOIN cdr_temp_patient_outcomes #{current_partition} tpo ON tpo.patient_id = tesd.patient_id
168
+ AND tpo.cum_outcome = 'On antiretrovirals'
169
169
  INNER JOIN obs #{current_partition} o ON o.person_id = tesd.patient_id
170
170
  AND o.voided = 0 AND o.concept_id = #{tb_status}
171
171
  AND o.obs_datetime BETWEEN '#{start_date}' AND '#{end_date}'
@@ -176,6 +176,11 @@ module MalawiHivProgramReports
176
176
  AND acurr.obs_datetime > o.obs_datetime
177
177
  AND acurr.obs_datetime BETWEEN '#{start_date}' AND '#{end_date}'
178
178
  AND acurr.value_coded IN (#{tb_status_results})
179
+ INNER JOIN obs #{current_partition} patient_present ON patient_present.person_id = o.person_id
180
+ AND patient_present.concept_id = #{ConceptName.find_by_name('Patient present').concept_id}
181
+ AND patient_present.value_coded = #{ConceptName.find_by_name('Yes').concept_id}
182
+ AND patient_present.voided = 0
183
+ AND patient_present.obs_datetime BETWEEN '#{start_date}' AND '#{end_date}'
179
184
  LEFT JOIN obs #{current_partition} screen_method ON screen_method.concept_id = #{tb_screening_method}
180
185
  AND screen_method.voided = 0
181
186
  AND screen_method.person_id = o.person_id
@@ -335,9 +340,15 @@ module MalawiHivProgramReports
335
340
  end
336
341
 
337
342
  def process_method(methods:, **kwargs)
338
- indicator = :symptom_screen_alone if methods.blank?
339
- indicator = :cxr_screen if methods&.include?('cxr') && !methods&.include?('mwrd')
340
- indicator = :mwrd_screen if methods&.include?('mwrd')
343
+ indicator = nil
344
+
345
+ if methods.include?('mwrd')
346
+ indicator = :mwrd_screen
347
+ elsif methods.include?('cxr')
348
+ indicator = :cxr_screen
349
+ else
350
+ indicator = :symptom_screen_alone
351
+ end
341
352
 
342
353
  process_aggreggation_rows(kwargs[:age_group], kwargs[:gender], indicator, kwargs[:patient_id], kwargs[:maternal_status])
343
354
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MalawiHivProgramReports
4
- VERSION = '1.1.17'
4
+ VERSION = '1.1.19'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: malawi_hiv_program_reports
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.17
4
+ version: 1.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roy Chanunkha
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-25 00:00:00.000000000 Z
11
+ date: 2025-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
191
  - !ruby/object:Gem::Version
192
192
  version: '0'
193
193
  requirements: []
194
- rubygems_version: 3.5.17
194
+ rubygems_version: 3.4.1
195
195
  signing_key:
196
196
  specification_version: 4
197
197
  summary: Malawi HIV PROGRAM Reports for Ruby on Rails