malawi_hiv_program_reports 1.0.27 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/services/malawi_hiv_program_reports/moh/cumulative_cohort.rb +12 -9
- data/app/services/malawi_hiv_program_reports/pepfar/tx_ml.rb +41 -40
- data/app/services/malawi_hiv_program_reports/pepfar/tx_new.rb +48 -47
- data/app/services/malawi_hiv_program_reports/pepfar/tx_rtt.rb +4 -4
- data/lib/malawi_hiv_program_reports/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c6bffbef9d85fec441ab368a631e8e730446a87ed8722d2a60d348c68ecf969
|
4
|
+
data.tar.gz: dfd3ba0bfe3a2fc65ca948d3dd2bee21c9f8bb4f7c42ade37623f46c6fb8aefb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a0217e328962a1734f08e22d28df28624f0a6eff6ca02e1eb32f021e0397758ab58bca452ddada4ccf662cac36b862952c880b98e3c08e500e4160db51af968
|
7
|
+
data.tar.gz: c6f54d2927268c90cf1e5b87ea621eb68aa5cea3d6f17095f382f7c7f91bdd0f4360a9ab4e00f8be536414a498c2dd1b3d01d8a7f88e01425dbb0e0292309a1c
|
@@ -78,14 +78,17 @@ module MalawiHivProgramReports
|
|
78
78
|
|
79
79
|
def process_data(location)
|
80
80
|
start_time = Time.now
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
81
|
+
if rebuild
|
82
|
+
cdr_other_patient_types location
|
83
|
+
external_clients location
|
84
|
+
transfer_ins location
|
85
|
+
min_drug_orders location
|
86
|
+
potential_cohort_members location
|
87
|
+
reason_for_starting_art location
|
88
|
+
cohort_members location
|
89
|
+
end
|
90
|
+
outcome = MalawiHivProgramReports::Moh::CumulativeOutcome.new(end_date:, location:, definition:, rebuild:,
|
91
|
+
start_date:)
|
89
92
|
rebuild ? outcome.find_report : outcome.update_outcomes_by_definition
|
90
93
|
end_time = Time.now
|
91
94
|
time_taken = ((end_time - start_time) / 60).round(2)
|
@@ -428,7 +431,7 @@ module MalawiHivProgramReports
|
|
428
431
|
end
|
429
432
|
clear_cohort_status
|
430
433
|
end
|
431
|
-
|
434
|
+
|
432
435
|
def clear_cohort_status
|
433
436
|
if locations.empty?
|
434
437
|
ActiveRecord::Base.connection.execute('TRUNCATE TABLE cdr_temp_cohort_status')
|
@@ -18,7 +18,8 @@ module MalawiHivProgramReports
|
|
18
18
|
|
19
19
|
def find_report
|
20
20
|
if rebuild
|
21
|
-
cohort = MalawiHivProgramReports::Moh::CumulativeCohort.new(start_date
|
21
|
+
cohort = MalawiHivProgramReports::Moh::CumulativeCohort.new(start_date: start_date.to_date, end_date: end_date.to_date, definition: 'pepfar',
|
22
|
+
locations: location.to_s, rebuild: true.to_s)
|
22
23
|
cohort.find_report
|
23
24
|
end
|
24
25
|
process_data
|
@@ -32,10 +33,10 @@ module MalawiHivProgramReports
|
|
32
33
|
patient_id = pat['patient_id'].to_i
|
33
34
|
outcome = pat['outcome']
|
34
35
|
gender = begin
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
pat['gender'].first.upcase
|
37
|
+
rescue StandardError
|
38
|
+
'Unknown'
|
39
|
+
end
|
39
40
|
age_group = pat['age_group']
|
40
41
|
|
41
42
|
if data[age_group].blank?
|
@@ -70,49 +71,49 @@ module MalawiHivProgramReports
|
|
70
71
|
|
71
72
|
def tx_ml_clients
|
72
73
|
<<~SQL
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
74
|
+
SELECT
|
75
|
+
e.patient_id,
|
76
|
+
e.birthdate,
|
77
|
+
e.gender,
|
78
|
+
e.date_enrolled,
|
79
|
+
e.earliest_start_date,
|
80
|
+
o.outcome_date,
|
81
|
+
TIMESTAMPDIFF(MONTH, DATE(e.earliest_start_date), DATE(o.outcome_date)) months,
|
82
|
+
disaggregated_age_group(e.birthdate, DATE('#{end_date}')) age_group,
|
83
|
+
o.cum_outcome outcome
|
84
|
+
FROM cdr_temp_cohort_members #{current_partition} e
|
85
|
+
INNER JOIN cdr_temp_patient_outcomes #{current_partition} o ON e.patient_id = o.patient_id AND o.cum_outcome IN ('Defaulted', 'Patient died', 'Treatment stopped', 'Patient transferred out')
|
86
|
+
WHERE e.patient_id IN (SELECT patient_id FROM cdr_temp_patient_outcomes_start #{current_partition} WHERE cum_outcome = 'On antiretrovirals')
|
87
|
+
AND DATE(e.date_enrolled) < '#{start_date.to_date}'
|
88
|
+
GROUP BY e.patient_id
|
89
|
+
SQL
|
89
90
|
end
|
90
91
|
|
91
92
|
def tx_ml_clients_new
|
92
93
|
<<~SQL
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
94
|
+
SELECT
|
95
|
+
e.patient_id,
|
96
|
+
e.birthdate,
|
97
|
+
e.gender,
|
98
|
+
e.date_enrolled,
|
99
|
+
e.earliest_start_date,
|
100
|
+
o.outcome_date,
|
101
|
+
TIMESTAMPDIFF(MONTH, DATE(e.earliest_start_date), DATE(o.outcome_date)) months,
|
102
|
+
disaggregated_age_group(e.birthdate, DATE('#{end_date}')) age_group,
|
103
|
+
o.cum_outcome outcome
|
104
|
+
FROM cdr_temp_cohort_members #{current_partition} e
|
105
|
+
INNER JOIN cdr_temp_patient_outcomes #{current_partition} o ON e.patient_id = o.patient_id AND o.cum_outcome IN ('Defaulted', 'Patient died', 'Treatment stopped', 'Patient transferred out')
|
106
|
+
WHERE e.date_enrolled BETWEEN DATE('#{start_date}') AND DATE('#{end_date}')
|
107
|
+
GROUP BY e.patient_id
|
108
|
+
SQL
|
108
109
|
end
|
109
110
|
|
110
111
|
def process_tx_ml_clients
|
111
112
|
ActiveRecord::Base.connection.select_all <<~SQL
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
113
|
+
(#{tx_ml_clients})
|
114
|
+
UNION
|
115
|
+
(#{tx_ml_clients_new})
|
116
|
+
SQL
|
116
117
|
end
|
117
118
|
end
|
118
119
|
end
|
@@ -22,7 +22,8 @@ module MalawiHivProgramReports
|
|
22
22
|
report = init_report
|
23
23
|
addittional_groups report
|
24
24
|
if rebuild
|
25
|
-
cohort = MalawiHivProgramReports::Moh::CumulativeCohort.new(start_date
|
25
|
+
cohort = MalawiHivProgramReports::Moh::CumulativeCohort.new(start_date: start_date.to_date, end_date: end_date.to_date, definition: 'pepfar',
|
26
|
+
locations: location.to_s, rebuild: true.to_s)
|
26
27
|
cohort.find_report
|
27
28
|
end
|
28
29
|
process_data report
|
@@ -120,10 +121,10 @@ module MalawiHivProgramReports
|
|
120
121
|
else
|
121
122
|
(gender == 'M' ? 'Male' : gender)
|
122
123
|
end,
|
123
|
-
cd4_less_than_200: age_group_report[
|
124
|
-
cd4_greater_than_equal_to_200: age_group_report[
|
125
|
-
cd4_unknown_or_not_done: age_group_report[
|
126
|
-
transfer_in: age_group_report[
|
124
|
+
cd4_less_than_200: age_group_report[:cd4_less_than_200],
|
125
|
+
cd4_greater_than_equal_to_200: age_group_report[:cd4_greater_than_equal_to_200],
|
126
|
+
cd4_unknown_or_not_done: age_group_report[:cd4_unknown_or_not_done],
|
127
|
+
transfer_in: age_group_report[:transfer_in]
|
127
128
|
}
|
128
129
|
end
|
129
130
|
# rubocop:enable Metrics/AbcSize
|
@@ -151,48 +152,48 @@ module MalawiHivProgramReports
|
|
151
152
|
|
152
153
|
def fetch_data
|
153
154
|
ActiveRecord::Base.connection.select_all <<~SQL
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
155
|
+
SELECT
|
156
|
+
e.patient_id,
|
157
|
+
e.gender,
|
158
|
+
disaggregated_age_group(e.birthdate, DATE('#{end_date}')) age_group,
|
159
|
+
CASE
|
160
|
+
WHEN o.value_numeric < 200 THEN 'cd4_less_than_200'
|
161
|
+
WHEN o.value_numeric = 200 AND o.value_modifier = '=' THEN 'cd4_greater_than_equal_to_200'
|
162
|
+
WHEN o.value_numeric = 200 AND o.value_modifier = '<' THEN 'cd4_less_than_200'
|
163
|
+
WHEN o.value_numeric = 200 AND o.value_modifier = '>' THEN 'cd4_greater_than_equal_to_200'
|
164
|
+
WHEN o.value_numeric > 200 THEN 'cd4_greater_than_equal_to_200'
|
165
|
+
ELSE 'cd4_unknown_or_not_done'
|
166
|
+
END cd4_count_group,
|
167
|
+
CASE
|
168
|
+
WHEN e.recorded_start_date IS NULL THEN 1
|
169
|
+
ELSE 0
|
170
|
+
END new_patient,
|
171
|
+
e.date_enrolled,
|
172
|
+
e.earliest_start_date,
|
173
|
+
preg_or_breast.name AS maternal_status,
|
174
|
+
DATE(MIN(pregnant_or_breastfeeding.obs_datetime)) AS maternal_status_date
|
175
|
+
FROM cdr_temp_cohort_members #{current_partition} e
|
176
|
+
LEFT JOIN (
|
177
|
+
SELECT max(o.obs_datetime) AS obs_datetime, o.person_id
|
178
|
+
FROM obs #{current_partition} o
|
179
|
+
INNER JOIN concept_name cn ON cn.concept_id = o.concept_id AND cn.name = 'CD4 count' AND cn.voided = 0
|
180
|
+
INNER JOIN patient_program #{current_partition} pp ON pp.patient_id = o.person_id
|
181
|
+
AND pp.program_id = #{program('HIV PROGRAM').id}
|
182
|
+
AND pp.voided = 0
|
183
|
+
INNER JOIN patient_state #{current_partition} ps ON ps.patient_program_id = pp.patient_program_id AND ps.voided = 0 AND ps.state = 7 AND ps.start_date <= DATE('#{end_date}')
|
184
|
+
WHERE o.concept_id = #{concept_name('CD4 count').concept_id} AND o.voided = 0
|
185
|
+
AND o.obs_datetime <= '#{end_date}' AND o.obs_datetime >= '#{start_date}'
|
186
|
+
GROUP BY o.person_id
|
187
|
+
) current_cd4 ON current_cd4.person_id = e.patient_id
|
188
|
+
LEFT JOIN obs #{current_partition} o ON o.person_id = e.patient_id AND o.concept_id = #{concept_name('CD4 count').concept_id} AND o.voided = 0 AND o.obs_datetime = current_cd4.obs_datetime
|
189
|
+
LEFT JOIN obs #{current_partition} pregnant_or_breastfeeding ON pregnant_or_breastfeeding.person_id = e.patient_id
|
190
|
+
AND pregnant_or_breastfeeding.concept_id IN (SELECT concept_id FROM concept_name WHERE name IN ('Breast feeding?', 'Breast feeding', 'Breastfeeding', 'Is patient pregnant?', 'patient pregnant') AND voided = 0)
|
191
|
+
AND pregnant_or_breastfeeding.voided = 0
|
192
|
+
AND pregnant_or_breastfeeding.value_coded = #{concept_name('Yes').concept_id}
|
193
|
+
LEFT JOIN concept_name preg_or_breast ON preg_or_breast.concept_id = pregnant_or_breastfeeding.concept_id AND preg_or_breast.voided = 0
|
194
|
+
WHERE e.date_enrolled <= '#{end_date}' AND e.date_enrolled >= '#{start_date}'
|
195
|
+
GROUP BY e.patient_id
|
196
|
+
SQL
|
196
197
|
end
|
197
198
|
end
|
198
199
|
# rubocop:enable Metrics/ClassLength
|
@@ -18,8 +18,8 @@ module MalawiHivProgramReports
|
|
18
18
|
|
19
19
|
def find_report
|
20
20
|
if rebuild
|
21
|
-
cohort = MalawiHivProgramReports::Moh::CumulativeCohort.new(start_date
|
22
|
-
locations: location.to_s, rebuild: true)
|
21
|
+
cohort = MalawiHivProgramReports::Moh::CumulativeCohort.new(start_date: start_date.to_date, end_date: end_date.to_date, definition: 'pepfar',
|
22
|
+
locations: location.to_s, rebuild: true.to_s)
|
23
23
|
cohort.find_report
|
24
24
|
end
|
25
25
|
process_report
|
@@ -27,8 +27,8 @@ module MalawiHivProgramReports
|
|
27
27
|
|
28
28
|
def data
|
29
29
|
if rebuild
|
30
|
-
cohort = MalawiHivProgramReports::Moh::CumulativeCohort.new(start_date
|
31
|
-
locations: location.to_s, rebuild: true)
|
30
|
+
cohort = MalawiHivProgramReports::Moh::CumulativeCohort.new(start_date: start_date.to_date, end_date: end_date.to_date, definition: 'pepfar',
|
31
|
+
locations: location.to_s, rebuild: true.to_s)
|
32
32
|
cohort.find_report
|
33
33
|
end
|
34
34
|
process_report
|