malawi_hiv_program_reports 1.1.13 → 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7648d6a581512a4f62341d93358beb5dd3895ed261d97aa849e0f143bb16645d
|
4
|
+
data.tar.gz: 87f0a1eb2a33f5839a97bc9af592b9a4f18bbf15236406b56a163ae0e2641de1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
@@ -154,7 +154,6 @@ module MalawiHivProgramReports
|
|
154
154
|
INNER JOIN cdr_temp_current_state_start #{current_partition} c ON c.patient_id = e.patient_id
|
155
155
|
INNER JOIN cdr_temp_max_drug_orders #{current_partition} ord ON ord.patient_id = e.patient_id
|
156
156
|
LEFT JOIN obs #{current_partition} cd4_result ON cd4_result.person_id = e.patient_id AND cd4_result.concept_id = #{concept_name('CD4 count').concept_id} AND cd4_result.voided = 0
|
157
|
-
WHERE e.date_enrolled < #{start_date}
|
158
157
|
GROUP BY e.patient_id
|
159
158
|
SQL
|
160
159
|
end
|
@@ -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
|
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.
|
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-
|
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
|