malawi_hiv_program_reports 1.1.14 → 1.1.15

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: fc0de20bb02853130fbacab1b12c9e9e667a71878f94b84e0dc1aba4c163ae18
4
- data.tar.gz: 1ea0e938f5bc3d05c220eeb3b9eb9213bf21436f364f855577a60c7af63e3742
3
+ metadata.gz: 7648d6a581512a4f62341d93358beb5dd3895ed261d97aa849e0f143bb16645d
4
+ data.tar.gz: 87f0a1eb2a33f5839a97bc9af592b9a4f18bbf15236406b56a163ae0e2641de1
5
5
  SHA512:
6
- metadata.gz: b30e62d1b8f79936a519092c4d3a0e4fca6d06a811c8fabcc1d3f5f80e8484f38ddc5f77ff253de38a594f77478363b3cde92aa480b233955d3c22582c904be7
7
- data.tar.gz: 792d7a3ea09e61b3cee18dcd1d739b8e6fb2f3d718d4abfcb5ca5d647a0d3c00806e3dd1a02f171e98d6de89b50ab9e6226f39c7e338f71d2654c21e8c1fbe78
6
+ metadata.gz: 803bdb400dd06a631cc42c0712f507fc7750e7922c6a9709e13820037bc54f9dbae24360b6d93465f400ca59cb2a609c4dd015f05def601c15742cb6b4e22a8b
7
+ data.tar.gz: 365656a38cf502c597cb4536f3aff8adb95241b176f2f3be20ebc6e42a4e8e7f861324a9ecdb35839d7c96157b433f85c31bc4868c6f7b93f59238e0528dd4ff
@@ -0,0 +1,119 @@
1
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Style/Documentation
2
+ # frozen_string_literal: true
3
+
4
+ require 'parallel'
5
+
6
+ module MalawiHivProgramReports
7
+ module Pepfar
8
+ class TxCurrMmd
9
+ include Utils
10
+ include MalawiHivProgramReports::Utils::CommonSqlQueryUtils
11
+ include MalawiHivProgramReports::Adapters::Moh::Custom
12
+
13
+ attr_accessor :report, :start_date, :end_date, :org, :location
14
+
15
+ def initialize(start_date:, end_date:, **kwargs)
16
+ @start_date = start_date.to_date.strftime('%Y-%m-%d 00:00:00')
17
+ @end_date = end_date.to_date.strftime('%Y-%m-%d 23:59:59')
18
+ @org = kwargs[:definition]
19
+ @location = kwargs[:location]
20
+ raise 'Location is required' if @location.blank?
21
+
22
+ @report = init_report
23
+ end
24
+
25
+ def find_report
26
+ process_data
27
+ flatten_the_report
28
+ rescue StandardError => e
29
+ Rails.logger.error e.message
30
+ Rails.logger.error e.backtrace.join("\n")
31
+ raise e
32
+ end
33
+
34
+ private
35
+
36
+ GENDER = %w[Male Female Unknown].freeze
37
+
38
+ def init_report
39
+ pepfar_age_groups.each_with_object({}) do |age_group, report|
40
+ report[age_group] = GENDER.each_with_object({}) do |gender, age_group_report|
41
+ age_group_report[gender] = {
42
+ less_than_three_months: [],
43
+ three_to_five_months: [],
44
+ greater_than_six_months: []
45
+ }
46
+ end
47
+ end
48
+ end
49
+
50
+ def process_age_group_report(age_group, gender, age_group_report)
51
+ {
52
+ age_group:,
53
+ gender:,
54
+ less_than_three_months: age_group_report[:less_than_three_months],
55
+ three_to_five_months: age_group_report[:three_to_five_months],
56
+ greater_than_six_months: age_group_report[:greater_than_six_months]
57
+ }
58
+ end
59
+
60
+ def flatten_the_report
61
+ result = []
62
+ report.each do |age_group, age_group_report|
63
+ age_group_report.each_key do |gender|
64
+ result << process_age_group_report(age_group, gender, age_group_report[gender])
65
+ end
66
+ end
67
+
68
+ new_group = pepfar_age_groups.map { |age_group| age_group }
69
+ new_group << 'All'
70
+ gender_scores = { 'Female' => 0, 'Male' => 1, 'FNP' => 3, 'FP' => 2, 'FBf' => 4 }
71
+ result_scores = result.sort_by do |item|
72
+ gender_score = gender_scores[item[:gender]] || 999
73
+ age_group_score = new_group.index(item[:age_group]) || 999
74
+ [gender_score, age_group_score]
75
+ end
76
+ # remove all unknown age groups
77
+ result_scores.reject { |item| item[:age_group].match?(/unknown/i) }
78
+ end
79
+
80
+ def process_data
81
+ patients = ActiveRecord::Base.connection.select_all <<~SQL
82
+ SELECT tesd.patient_id,
83
+ CASE tesd.gender
84
+ WHEN 'M' THEN 'Male'
85
+ WHEN 'F' THEN 'Female'
86
+ ELSE 'Unknown'
87
+ END gender,
88
+ disaggregated_age_group(tesd.birthdate, '#{end_date}') age_group,
89
+ TIMESTAMPDIFF(DAY, tcm.start_date, tcm.auto_expire_date) prescribed_days
90
+ FROM cdr_temp_cohort_members #{current_partition} tesd#{' '}
91
+ INNER JOIN cdr_temp_patient_outcomes #{current_partition} tpo ON tpo.patient_id = tesd.patient_id AND tpo.cum_outcome = 'On antiretrovirals'
92
+ INNER JOIN cdr_temp_min_auto_expire_date #{current_partition} tcm ON tcm.patient_id = tesd.patient_id
93
+ WHERE tesd.date_enrolled <= '#{end_date}'
94
+ SQL
95
+
96
+ return report if patients.blank?
97
+
98
+ patients.each do |patient|
99
+ prescribe_days = patient['prescribed_days'].to_i
100
+ age_group = patient['age_group']
101
+ gender = patient['gender']
102
+
103
+ indicator = if prescribe_days < 90
104
+ 'less_than_three_months'
105
+ elsif prescribe_days >= 90 && prescribe_days <= 150
106
+ 'three_to_five_months'
107
+ elsif prescribe_days > 150
108
+ 'greater_than_six_months'
109
+ end
110
+
111
+ report[age_group][gender][indicator.to_sym] << patient['patient_id']
112
+ end
113
+
114
+ report
115
+ end
116
+ end
117
+ end
118
+ end
119
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Style/Documentation
@@ -52,7 +52,8 @@ module MalawiHivProgramReports
52
52
  'HYPERTENSION_REPORT' => MalawiHivProgramReports::Clinic::HypertensionReport,
53
53
  'TX_NEW' => MalawiHivProgramReports::Pepfar::TxNew,
54
54
  'CUMULATIVE_COHORT' => MalawiHivProgramReports::Moh::CumulativeCohort,
55
- 'CUMULATIVE_OUTCOME' => MalawiHivProgramReports::Moh::CumulativeOutcome
55
+ 'CUMULATIVE_OUTCOME' => MalawiHivProgramReports::Moh::CumulativeOutcome,
56
+ 'TX_CURR_MMD' => MalawiHivProgramReports::Pepfar::TxCurrMmd
56
57
  }.freeze
57
58
  end
58
59
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MalawiHivProgramReports
4
- VERSION = '1.1.14'
4
+ VERSION = '1.1.15'
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.14
4
+ version: 1.1.15
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-06-29 00:00:00.000000000 Z
11
+ date: 2024-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -151,6 +151,7 @@ files:
151
151
  - app/services/malawi_hiv_program_reports/pepfar/tb_prev2.rb
152
152
  - app/services/malawi_hiv_program_reports/pepfar/tb_prev3.rb
153
153
  - app/services/malawi_hiv_program_reports/pepfar/tpt_status.rb
154
+ - app/services/malawi_hiv_program_reports/pepfar/tx_curr_mmd.rb
154
155
  - app/services/malawi_hiv_program_reports/pepfar/tx_ml.rb
155
156
  - app/services/malawi_hiv_program_reports/pepfar/tx_new.rb
156
157
  - app/services/malawi_hiv_program_reports/pepfar/tx_rtt.rb