malawi_hiv_program_reports 1.0.20 → 1.0.22

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: 20d2d8f58b51e76a9e2338c73f4649128827925aaea7bed0bf5c072fe047877a
4
- data.tar.gz: 190ec9f058e23928a2295663cdea975eaf0a819860382728539bdb9d80b69895
3
+ metadata.gz: 9c5eda4737dd9269c63b370e6cb50a0189778b2bf740b26891dd69765356a81a
4
+ data.tar.gz: 9b9ddbc36fdd5b5e0c16c909c5dfd8ea979a69c9ea7736abe1fddb4bb6af4ca7
5
5
  SHA512:
6
- metadata.gz: e615fa021b3a87a7c40832513d64f9746ef35eaeb49ff60cb7c5ad4ffdd3d3f27f8672e86bc1fae3a5a7c2903f4faf49e1cbf7d912457d56a1358c6803fb6378
7
- data.tar.gz: cb09473dc350e4afaafecda703f65958823a3ff91c06c0538bfb1dfbb6f955b873473d568e9cb3c2a56d09105cb008610224e9ae474b259f187b164952c60f01
6
+ metadata.gz: 22544af6a23a6e6babe971dcbd9ce6a1366150e61f80e24f94ed2f4570c19a93417f7d3a05db3d2e60df6634ad04663be428af3bfe4ca52c7700a68d72b07dda
7
+ data.tar.gz: 1c2bf313e182a4bcfa73fa3ee3bd9c497ae99f172cf12fefbc4ec371e6ac0219de847b5280b5d4c2ed355b36056ce3a3df8d795700ea9fe57098d09d47653d6c
@@ -69,6 +69,7 @@ module MalawiHivProgramReports
69
69
  # rubocop:enable Metrics/MethodLength
70
70
 
71
71
  def process_data(location)
72
+ start_time = Time.now
72
73
  cdr_other_patient_types location
73
74
  external_clients location
74
75
  transfer_ins location
@@ -78,6 +79,9 @@ module MalawiHivProgramReports
78
79
  cohort_members location
79
80
  outcome = MalawiHivProgramReports::Moh::CumulativeOutcome.new(end_date:, location:, definition:, rebuild:)
80
81
  outcome.find_report
82
+ end_time = Time.now
83
+ time_taken = ((end_time - start_time) / 60).round(2)
84
+ save_completed_site(location:, time_taken:)
81
85
  end
82
86
 
83
87
  # rubocop:disable Metrics/CyclomaticComplexity
@@ -89,9 +93,30 @@ module MalawiHivProgramReports
89
93
  create_external_clients_table unless check_if_table_exists('cdr_temp_external_clients')
90
94
  create_temp_cohort_members_table unless check_if_table_exists('cdr_temp_cohort_members')
91
95
  create_cdr_reason_for_starting_art unless check_if_table_exists('cdr_reason_for_starting_art')
96
+ create_cdr_temp_cohort_status unless check_if_table_exists('cdr_temp_cohort_status')
92
97
  end
93
98
  # rubocop:enable Metrics/CyclomaticComplexity
94
99
 
100
+ def save_completed_site(location:, time_taken:)
101
+ ActiveRecord::Base.connection.execute <<~SQL
102
+ INSERT INTO cdr_temp_cohort_status
103
+ VALUES (#{location}, DATE(#{start_date}), DATE(#{end_date}), 'completed', #{time_taken})
104
+ SQL
105
+ end
106
+
107
+ def create_cdr_temp_cohort_status
108
+ ActiveRecord::Base.connection.execute <<~SQL
109
+ CREATE TABLE IF NOT EXISTS cdr_temp_cohort_status (
110
+ site_id INT NOT NULL,
111
+ start_date DATE NOT NULL,
112
+ end_date DATE NOT NULL,
113
+ status VARCHAR(50) NOT NULL,
114
+ time_taken DECIMAL(40,2) DEFAULT NULL,
115
+ PRIMARY KEY (site_id, start_date, end_date)
116
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8
117
+ SQL
118
+ end
119
+
95
120
  def create_external_clients_table
96
121
  ActiveRecord::Base.connection.execute <<~SQL
97
122
  CREATE TABLE IF NOT EXISTS cdr_temp_external_clients (
@@ -383,6 +408,7 @@ module MalawiHivProgramReports
383
408
  ActiveRecord::Base.connection.execute('TRUNCATE TABLE cdr_temp_cohort_members')
384
409
  ActiveRecord::Base.connection.execute('TRUNCATE TABLE cdr_temp_external_clients')
385
410
  ActiveRecord::Base.connection.execute('TRUNCATE TABLE cdr_reason_for_starting_art')
411
+ ActiveRecord::Base.connection.execute('TRUNCATE TABLE cdr_temp_cohort_status')
386
412
  else
387
413
  ActiveRecord::Base.connection.execute("DELETE FROM cdr_other_patient_types WHERE site_id IN (#{locations.join(',')})")
388
414
  ActiveRecord::Base.connection.execute("DELETE FROM cdr_temp_potential_cohort_members WHERE site_id IN (#{locations.join(',')})")
@@ -391,6 +417,7 @@ module MalawiHivProgramReports
391
417
  ActiveRecord::Base.connection.execute("DELETE FROM cdr_temp_cohort_members WHERE site_id IN (#{locations.join(',')})")
392
418
  ActiveRecord::Base.connection.execute("DELETE FROM cdr_temp_external_clients WHERE site_id IN (#{locations.join(',')})")
393
419
  ActiveRecord::Base.connection.execute("DELETE FROM cdr_reason_for_starting_art WHERE site_id IN (#{locations.join(',')})")
420
+ ActiveRecord::Base.connection.execute("DELETE FROM cdr_temp_cohort_status WHERE site_id IN (#{locations.join(',')})")
394
421
  end
395
422
  end
396
423
  end
@@ -16,15 +16,10 @@ module MalawiHivProgramReports
16
16
  end
17
17
 
18
18
  def find_report
19
- start_time = Time.now
20
19
  prepare_tables
21
20
  clear_tables if rebuild
22
21
  update_steps unless rebuild
23
22
  process_data
24
- end_time = Time.now
25
- total_time_in_minutes = ((end_time - start_time) / 60).round(2)
26
- Rails.logger.info("Cumulative Outcome report completed in #{total_time_in_minutes} minutes for location: #{location}")
27
- { cumulative_outcome_time: total_time_in_minutes, definition: }
28
23
  end
29
24
 
30
25
  private
@@ -531,12 +526,14 @@ module MalawiHivProgramReports
531
526
  ActiveRecord::Base.connection.execute('TRUNCATE cdr_temp_min_auto_expire_date')
532
527
  ActiveRecord::Base.connection.execute('TRUNCATE cdr_temp_max_patient_state')
533
528
  ActiveRecord::Base.connection.execute('TRUNCATE cdr_temp_max_patient_appointment')
529
+ ActiveRecord::Base.connection.execute('TRUNCATE cdr_temp_cohort_status')
534
530
  else
535
531
  ActiveRecord::Base.connection.execute("DELETE FROM cdr_temp_patient_outcomes WHERE site_id = #{location}")
536
532
  ActiveRecord::Base.connection.execute("DELETE FROM cdr_temp_max_drug_orders WHERE site_id = #{location}")
537
533
  ActiveRecord::Base.connection.execute("DELETE FROM cdr_temp_min_auto_expire_date WHERE site_id = #{location}")
538
534
  ActiveRecord::Base.connection.execute("DELETE FROM cdr_temp_max_patient_state WHERE site_id = #{location}")
539
535
  ActiveRecord::Base.connection.execute("DELETE FROM cdr_temp_max_patient_appointment WHERE site_id = #{location}")
536
+ ActiveRecord::Base.connection.execute("DELETE FROM cdr_temp_cohort_status WHERE site_id = #{location}")
540
537
  end
541
538
  end
542
539
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MalawiHivProgramReports
4
- VERSION = '1.0.20'
4
+ VERSION = '1.0.22'
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.0.20
4
+ version: 1.0.22
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-04-29 00:00:00.000000000 Z
11
+ date: 2024-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails