malawi_hiv_program_reports 1.1.16 → 1.1.17

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,36 +19,48 @@ module MalawiHivProgramReports
19
19
  end
20
20
 
21
21
  def find_report
22
- drop_temporary_tables unless @location
23
- delete_patients_in_temp_table if @location
24
-
25
- create_temp_earliest_start_date unless temp_eartliest_start_date_exists?
26
22
  init_report
27
23
  build_cohort_tables
28
- process_tb_screening
29
- process_tb_confirmed_and_on_treatment
30
24
  process_patients_alive_and_on_art
31
25
  process_tb_screened
32
26
  process_tb_confirmed
33
- report
27
+ flatten_the_report
28
+ rescue StandardError => e
29
+ Rails.logger.error("Error generating TxTb report: #{e.message}")
30
+ Rails.logger.error(e.backtrace.join("\n"))
31
+ raise e
32
+ end
33
+
34
+ def process_tb_data
35
+ delete_patients_in_temp_table
36
+ process_tb_screening
37
+ process_tb_confirmed_and_on_treatment
34
38
  end
35
39
 
36
40
  private
37
41
 
42
+ GENDER = %w[Male Female].freeze
43
+
38
44
  def init_report
39
45
  @report = initialize_report_structure
46
+ addittional_groups
40
47
  end
41
48
 
42
49
  def initialize_report_structure
43
50
  pepfar_age_groups.each_with_object({}) do |age_group, report|
44
- genders = %i[M F]
45
- genders.each do |gender|
46
- report[age_group] ||= {}
47
- report[age_group][gender] = initialize_gender_metrics
51
+ report[age_group] = GENDER.each_with_object({}) do |gender, age_group_report|
52
+ age_group_report[gender] = initialize_gender_metrics
48
53
  end
49
54
  end
50
55
  end
51
56
 
57
+ def addittional_groups
58
+ @report['All'] = {}
59
+ %w[Male FP FNP FBf].each do |key|
60
+ @report['All'][key] = initialize_gender_metrics
61
+ end
62
+ end
63
+
52
64
  def initialize_gender_metrics
53
65
  {
54
66
  tx_curr: [],
@@ -64,85 +76,114 @@ module MalawiHivProgramReports
64
76
  }
65
77
  end
66
78
 
67
- def delete_patients_in_temp_table
68
- if ActiveRecord::Base.connection.table_exists?('temp_tb_screened')
69
- execute_action("DELETE FROM temp_tb_screened WHERE site_id = #{@location}")
70
- end
71
- if ActiveRecord::Base.connection.table_exists?('temp_tb_confirmed_and_on_treatment')
72
- execute_action("DELETE FROM temp_tb_confirmed_and_on_treatment WHERE site_id = #{@location}")
79
+ def flatten_the_report
80
+ result = []
81
+ @report.each do |age_group, age_group_report|
82
+ next if age_group == 'Unknown'
83
+
84
+ age_group_report.each_key do |gender|
85
+ next if gender == 'Unknown'
86
+
87
+ result << process_age_group_report(age_group, gender, age_group_report[gender])
88
+ end
89
+ end
90
+
91
+ new_group = pepfar_age_groups.map { |age_group| age_group }
92
+ new_group << 'All'
93
+ gender_scores = { 'Female' => 0, 'Male' => 1, 'FNP' => 3, 'FP' => 2, 'FBf' => 4 }
94
+ result_scores = result.sort_by do |item|
95
+ gender_score = gender_scores[item[:gender]] || 999
96
+ age_group_score = new_group.index(item[:age_group]) || 999
97
+ [gender_score, age_group_score]
73
98
  end
99
+ # remove all unknown age groups
100
+ result_scores.reject { |item| item[:age_group].match?(/unknown/i) }
74
101
  end
75
102
 
76
- def drop_temporary_tables
77
- execute_action("DROP TABLE IF EXISTS temp_tb_screened;")
78
- execute_action("DROP TABLE IF EXISTS temp_tb_confirmed_and_on_treatment;")
103
+ def process_age_group_report(age_group, gender, age_group_report)
104
+ {
105
+ age_group:,
106
+ gender:,
107
+ **age_group_report
108
+ }
109
+ end
110
+
111
+ def delete_patients_in_temp_table
112
+ if ActiveRecord::Base.connection.table_exists?('cdr_tb_screened')
113
+ execute_action("DELETE FROM cdr_tb_screened WHERE site_id = #{@location}")
114
+ end
115
+ return unless ActiveRecord::Base.connection.table_exists?('cdr_tb_confirmed_and_on_treatment')
116
+
117
+ execute_action("DELETE FROM cdr_tb_confirmed_and_on_treatment WHERE site_id = #{@location}")
79
118
  end
80
119
 
81
120
  def build_cohort_tables
82
121
  return unless rebuild_outcome || @occupation.present?
83
122
 
84
123
  MalawiHivProgramReports::Moh::CumulativeCohort.new(
85
- start_date: start_date,
86
- end_date: end_date,
124
+ start_date:,
125
+ end_date:,
87
126
  locations: [@location.to_s],
88
127
  rebuild: rebuild_outcome
89
128
  ).find_report
90
129
  end
91
130
 
92
131
  def process_tb_screening
93
- execute_action(create_temp_tb_screened_query)
94
132
  execute_action(insert_temp_tb_screened_query)
95
133
  end
96
134
 
97
- def create_temp_tb_screened_query
98
- <<~SQL
99
- CREATE TABLE IF NOT EXISTS temp_tb_screened(
100
- patient_id INT(11) NOT NULL,
101
- gender VARCHAR(255) NULL,
102
- screened_date DATE NULL,
103
- enrollment_date DATE NULL,
104
- age_group VARCHAR(255) NULL,
105
- tb_status VARCHAR(255) NULL,
106
- screening_methods VARCHAR(255) DEFAULT NULL,
107
- site_id INT(11) DEFAULT 1,
108
- PRIMARY KEY (patient_id, site_id)
109
- )
110
- SQL
135
+ def tb_status_results
136
+ @tb_status_results ||= [::ConceptName.find_by_name('TB Suspected').concept_id,
137
+ ::ConceptName.find_by_name('TB NOT suspected').concept_id].join(',')
138
+ end
139
+
140
+ def tb_status
141
+ @tb_status ||= ::ConceptName.find_by_name('TB status').concept_id
142
+ end
143
+
144
+ def tb_screening_method
145
+ @tb_screening_method ||= ::ConceptName.find_by_name('TB screening method used').concept_id
146
+ end
147
+
148
+ def tb_treatment_start_date
149
+ @tb_treatment_start_date ||= ::ConceptName.find_by_name('TB treatment start date').concept_id
150
+ end
151
+
152
+ def confirmed_tb_on_treatment
153
+ @confirmed_tb_on_treatment ||= ::ConceptName.find_by_name('Confirmed TB on treatment').concept_id
111
154
  end
112
155
 
113
156
  def insert_temp_tb_screened_query
114
157
  <<~SQL
115
- INSERT INTO temp_tb_screened
158
+ INSERT INTO cdr_tb_screened #{current_partition}
116
159
  SELECT
117
- o.person_id as patient_id,
118
- LEFT(current_obs.gender, 1) AS gender, MAX(o.obs_datetime) AS screened_date,
119
- current_obs.earliest_start_date as enrollment_date,
120
- disaggregated_age_group(current_obs.birthdate, DATE('#{end_date.to_date}')) AS age_group,
160
+ tesd.patient_id,
161
+ #{@location} AS site_id,
162
+ LEFT(tesd.gender, 1) AS gender,
163
+ MAX(o.obs_datetime) AS screened_date,
164
+ tesd.earliest_start_date as enrollment_date,
165
+ disaggregated_age_group(tesd.birthdate, DATE('#{end_date.to_date}')) AS age_group,
121
166
  cn.name AS tb_status,
122
167
  GROUP_CONCAT(DISTINCT vcn.name) AS screening_methods
123
- #{@location ? ", #{@location}" : 1} AS site_id
124
- FROM obs #{current_partition} o
125
- INNER JOIN (
126
- SELECT o.person_id, MAX(o.obs_datetime) AS obs_datetime, tesd.earliest_start_date, tesd.gender, tesd.birthdate
127
- FROM obs #{current_partition} o
128
- INNER JOIN cdr_temp_cohort_members tesd ON tesd.patient_id = o.person_id
129
- #{site_manager(operator: 'AND', column: 'tesd.site_id', location: @location)}
130
- WHERE o.concept_id = #{::ConceptName.find_by_name('TB status').concept_id}
131
- AND o.value_coded IN (SELECT concept_id FROM concept_name WHERE name IN ('TB Suspected', 'TB NOT suspected') AND voided = 0)
132
- AND o.voided = 0 AND o.obs_datetime BETWEEN '#{start_date}' AND '#{end_date}'
133
- GROUP BY o.person_id
134
- ) current_obs ON current_obs.person_id = o.person_id AND current_obs.obs_datetime = o.obs_datetime
168
+ FROM cdr_temp_cohort_members #{current_partition} tesd
169
+ INNER JOIN obs #{current_partition} o ON o.person_id = tesd.patient_id
170
+ AND o.voided = 0 AND o.concept_id = #{tb_status}
171
+ AND o.obs_datetime BETWEEN '#{start_date}' AND '#{end_date}'
172
+ AND o.value_coded IN (#{tb_status_results})
135
173
  INNER JOIN concept_name cn ON cn.concept_id = o.value_coded AND cn.voided = 0
136
- LEFT JOIN obs #{current_partition} screen_method ON screen_method.concept_id = #{::ConceptName.find_by_name('TB screening method used').concept_id}
174
+ LEFT JOIN obs #{current_partition} acurr ON acurr.person_id = o.person_id
175
+ AND acurr.voided = 0 AND acurr.concept_id = #{tb_status}
176
+ AND acurr.obs_datetime > o.obs_datetime
177
+ AND acurr.obs_datetime BETWEEN '#{start_date}' AND '#{end_date}'
178
+ AND acurr.value_coded IN (#{tb_status_results})
179
+ LEFT JOIN obs #{current_partition} screen_method ON screen_method.concept_id = #{tb_screening_method}
137
180
  AND screen_method.voided = 0
138
181
  AND screen_method.person_id = o.person_id
139
- AND DATE(screen_method.obs_datetime) = DATE(current_obs.obs_datetime)
182
+ AND DATE(screen_method.obs_datetime) = DATE(o.obs_datetime)
140
183
  LEFT JOIN concept_name vcn ON vcn.concept_id = screen_method.value_coded AND vcn.voided = 0 AND vcn.name IN ('CXR', 'MWRD')
141
- WHERE o.concept_id = #{::ConceptName.find_by_name('TB status').concept_id}
142
- AND o.voided = 0
143
- AND o.value_coded IN (SELECT concept_id FROM concept_name WHERE name IN ('TB Suspected', 'TB NOT suspected') AND voided = 0)
144
- AND o.obs_datetime BETWEEN '#{start_date}' AND '#{end_date}'
145
- GROUP BY o.person_id
184
+ WHERE acurr.person_id IS NULL
185
+ GROUP BY tesd.patient_id
186
+ ON DUPLICATE KEY UPDATE gender = VALUES(gender), screened_date = VALUES(screened_date), age_group = VALUES(age_group), tb_status = VALUES(tb_status), screening_methods = VALUES(screening_methods)
146
187
  SQL
147
188
  end
148
189
 
@@ -152,72 +193,45 @@ module MalawiHivProgramReports
152
193
 
153
194
  def create_temp_earliest_start_date
154
195
  MalawiHivProgramReports::Moh::CumulativeCohort.new(
155
- start_date: start_date,
156
- end_date: end_date,
196
+ start_date:,
197
+ end_date:,
157
198
  locations: [@location],
158
199
  rebuild: rebuild_outcome
159
200
  ).find_report
160
201
  end
161
202
 
162
203
  def process_tb_confirmed_and_on_treatment
163
- execute_action(create_temp_tb_confirmed_query)
164
204
  execute_action(insert_temp_tb_confirmed_query)
165
205
  end
166
206
 
167
- def create_temp_tb_confirmed_query
168
- <<~SQL
169
- CREATE TABLE IF NOT EXISTS temp_tb_confirmed_and_on_treatment(
170
- patient_id INT(11) NOT NULL,
171
- gender VARCHAR(255) NULL,
172
- age_group VARCHAR(255) NOT NULL,
173
- tb_confirmed_date DATE NULL,
174
- has_tb_confirmed_date BOOLEAN NOT NULL,
175
- enrollment_date DATE NULL,
176
- prev_reading DATE,
177
- site_id INT(11) DEFAULT 1,
178
- PRIMARY KEY (patient_id, site_id)
179
- )
180
- SQL
181
- end
182
-
183
207
  def insert_temp_tb_confirmed_query
184
208
  <<~SQL
185
- INSERT INTO temp_tb_confirmed_and_on_treatment
209
+ INSERT INTO cdr_tb_confirmed_and_on_treatment #{current_partition}
186
210
  SELECT
187
211
  o.person_id as patient_id,
188
- LEFT(p.gender, 1) AS gender,
189
- disaggregated_age_group(p.birthdate, DATE('#{end_date.to_date}')) AS age_group,
212
+ #{@location} AS site_id,
213
+ LEFT(tesd.gender, 1) AS gender,
214
+ disaggregated_age_group(tesd.birthdate, DATE('#{end_date.to_date}')) AS age_group,
190
215
  COALESCE(MIN(tcd.value_datetime),MIN(o.obs_datetime)) AS tb_confirmed_date,
191
216
  CASE
192
217
  WHEN COUNT(tcd.value_datetime) > 0 THEN TRUE
193
218
  ELSE FALSE
194
219
  END AS has_tb_confirmed_date,
195
220
  tesd.earliest_start_date as enrollment_date,
196
- prev.tb_confirmed_date prev_reading
197
- #{@location ? ", #{@location}" : ''} AS site_id
221
+ COALESCE(MIN(prev_tcd.value_datetime),MIN(prev.obs_datetime)) AS prev_reading
198
222
  FROM obs #{current_partition} o
199
- INNER JOIN cdr_temp_cohort_members tesd ON tesd.patient_id = o.person_id
200
- #{site_manager(operator: 'AND', column: 'tesd.site_id', location: @location)}
201
- INNER JOIN person #{current_partition} p ON p.person_id = o.person_id AND p.voided = 0
202
- LEFT JOIN obs #{current_partition} tcd ON tcd.concept_id = #{::ConceptName.find_by_name('TB treatment start date').concept_id}
203
- AND tcd.voided = 0 AND tcd.person_id = o.person_id
204
- LEFT JOIN (
205
- SELECT
206
- o.person_id,
207
- COALESCE(MAX(tcd.value_datetime),MAX(o.obs_datetime)) AS tb_confirmed_date
208
- FROM obs #{current_partition} o
209
- LEFT JOIN obs #{current_partition} tcd ON tcd.concept_id = #{::ConceptName.find_by_name('TB treatment start date').concept_id}
210
- AND tcd.voided = 0 AND tcd.person_id = o.person_id
211
- WHERE o.concept_id = #{::ConceptName.find_by_name('TB status').concept_id}
212
- AND o.value_coded = #{::ConceptName.find_by_name('Confirmed TB on treatment').concept_id}
223
+ INNER JOIN cdr_temp_cohort_members #{current_partition} tesd ON tesd.patient_id = o.person_id
224
+ LEFT JOIN obs #{current_partition} tcd ON tcd.concept_id = #{tb_treatment_start_date}
225
+ AND tcd.voided = 0 AND tcd.person_id = o.person_id
226
+ LEFT JOIN obs #{current_partition} prev ON prev.person_id = o.person_id AND prev.voided = 0
227
+ AND prev.concept_id = #{tb_status} AND prev.value_coded = #{confirmed_tb_on_treatment}
228
+ AND prev.obs_datetime < '#{start_date}'
229
+ LEFT JOIN obs #{current_partition} prev_tcd ON prev_tcd.person_id = o.person_id AND prev_tcd.voided = 0
230
+ AND prev_tcd.concept_id = #{tb_treatment_start_date} AND prev_tcd.obs_datetime < '#{start_date}'
231
+ WHERE o.concept_id = #{tb_status}
232
+ AND o.value_coded = #{confirmed_tb_on_treatment}
213
233
  AND o.voided = 0
214
- AND o.obs_datetime <= '#{start_date}'
215
- GROUP BY o.person_id
216
- ) prev ON prev.person_id = o.person_id
217
- WHERE o.concept_id = #{::ConceptName.find_by_name('TB status').concept_id}
218
- AND o.value_coded = #{::ConceptName.find_by_name('Confirmed TB on treatment').concept_id}
219
- AND o.voided = 0
220
- AND o.obs_datetime BETWEEN '#{start_date}' AND '#{end_date}'
234
+ AND o.obs_datetime BETWEEN '#{start_date}' AND '#{end_date}'
221
235
  GROUP BY o.person_id
222
236
  SQL
223
237
  end
@@ -225,8 +239,28 @@ module MalawiHivProgramReports
225
239
  def process_patients_alive_and_on_art
226
240
  find_patients_alive_and_on_art.each do |patient|
227
241
  next unless pepfar_age_groups.include?(patient['age_group'])
242
+ next unless GENDER.include?(patient['gender'])
228
243
 
229
- @report[patient['age_group']][patient['gender'].to_sym][:tx_curr] << patient['patient_id']
244
+ process_aggreggation_rows(patient['age_group'], patient['gender'], :tx_curr, patient['patient_id'],
245
+ patient['maternal_status'])
246
+ end
247
+ end
248
+
249
+ def process_aggreggation_rows(age_group, gender, indicator, patient_id, maternal_status)
250
+ @report[age_group][gender][indicator] << patient_id
251
+
252
+ if gender == 'Male'
253
+ @report['All']['Male'][indicator] << patient_id
254
+ return
255
+ end
256
+
257
+ case maternal_status
258
+ when 'FP'
259
+ @report['All']['FP'][indicator] << patient_id
260
+ when 'FBf'
261
+ @report['All']['FBf'][indicator] << patient_id
262
+ else
263
+ @report['All']['FNP'][indicator] << patient_id
230
264
  end
231
265
  end
232
266
 
@@ -236,11 +270,15 @@ module MalawiHivProgramReports
236
270
 
237
271
  def create_patients_alive_and_on_art_query
238
272
  <<~SQL
239
- SELECT tpo.patient_id, LEFT(tesd.gender, 1) AS gender, disaggregated_age_group(tesd.birthdate, DATE('#{end_date.to_date}')) age_group
273
+ SELECT tpo.patient_id, CASE tesd.gender
274
+ WHEN 'M' THEN 'Male'
275
+ WHEN 'F' THEN 'Female'
276
+ ELSE 'Unknown'
277
+ END gender, ms.maternal_status,
278
+ disaggregated_age_group(tesd.birthdate, DATE('#{end_date.to_date}')) age_group
240
279
  FROM cdr_temp_patient_outcomes #{current_partition} tpo
241
- INNER JOIN cdr_temp_cohort_members tesd ON tesd.patient_id = tpo.patient_id
242
- #{site_manager(operator: 'AND', column: 'tesd.site_id', location: @location)}
243
- #{site_manager(operator: 'AND', column: 'tpo.site_id', location: @location)}
280
+ INNER JOIN cdr_temp_cohort_members #{current_partition} tesd ON tesd.patient_id = tpo.patient_id
281
+ LEFT JOIN cdr_temp_maternal_status #{current_partition} ms ON ms.patient_id = tpo.patient_id
244
282
  WHERE tpo.cum_outcome = 'On antiretrovirals'
245
283
  SQL
246
284
  end
@@ -253,14 +291,15 @@ module MalawiHivProgramReports
253
291
  age_group = patient['age_group']
254
292
  next unless pepfar_age_groups.include?(age_group)
255
293
 
256
- gender = patient['gender'].to_sym
257
- metrics = @report[age_group][gender]
294
+ gender = patient['gender']
258
295
  enrollment_date = patient['enrollment_date']
259
296
  tb_status = patient['tb_status'].downcase
260
- screening_methods = patient['screening_methods']&.split(',')&.map(&:downcase)
297
+ methods = patient['screening_methods']&.split(',')&.map(&:downcase)
261
298
  patient_id = patient['patient_id']
262
- process_method(metrics, screening_methods, patient_id)
263
- process_screening_results(metrics, enrollment_date, tb_status, patient_id)
299
+ maternal_status = patient['maternal_status']
300
+
301
+ process_method(methods:, age_group:, gender:, patient_id:, maternal_status:)
302
+ process_screening_results(enrollment_date:, tb_status:, age_group:, gender:, patient_id:, maternal_status:)
264
303
  end
265
304
  end
266
305
 
@@ -269,34 +308,38 @@ module MalawiHivProgramReports
269
308
  age_group = patient['age_group']
270
309
  next unless pepfar_age_groups.include?(age_group)
271
310
 
272
- gender = patient['gender'].to_sym
273
- metrics = @report[age_group][gender]
311
+ gender = patient['gender']
274
312
  enrollment_date = patient['enrollment_date']
275
313
 
276
314
  if new_on_art(enrollment_date)
277
- metrics[:started_tb_new] << patient['patient_id']
315
+ process_aggreggation_rows(age_group, gender, :started_tb_new, patient['patient_id'], patient['maternal_status'])
278
316
  else
279
- metrics[:started_tb_prev] << patient['patient_id']
317
+ process_aggreggation_rows(age_group, gender, :started_tb_prev, patient['patient_id'], patient['maternal_status'])
280
318
  end
281
319
  end
282
320
  end
283
321
 
284
- def process_screening_results(metrics, enrollment_date, tb_status, patient_id)
322
+ def process_screening_results(enrollment_date:, tb_status:, **kwargs)
285
323
  if new_on_art(enrollment_date)
286
- metrics[:sceen_pos_new] << patient_id if ['tb suspected', 'sup', 'confirmed tb not on treatment', 'norx',
324
+ indicator = :sceen_pos_new if ['tb suspected', 'sup', 'confirmed tb not on treatment', 'norx',
287
325
  'confirmed tb on treatment', 'rx'].include?(tb_status)
288
- metrics[:sceen_neg_new] << patient_id if ['tb not suspected', 'nosup'].include?(tb_status)
326
+ indicator = :sceen_neg_new if ['tb not suspected', 'nosup'].include?(tb_status)
289
327
  else
290
- metrics[:sceen_pos_prev] << patient_id if ['tb suspected', 'sup', 'confirmed tb not on treatment',
328
+ indicator = :sceen_pos_prev if ['tb suspected', 'sup', 'confirmed tb not on treatment',
291
329
  'norx'].include?(tb_status)
292
- metrics[:sceen_neg_prev] << patient_id if ['tb not suspected', 'nosup'].include?(tb_status)
330
+ indicator = :sceen_neg_prev if ['tb not suspected', 'nosup'].include?(tb_status)
293
331
  end
332
+ return unless indicator
333
+
334
+ process_aggreggation_rows(kwargs[:age_group], kwargs[:gender], indicator, kwargs[:patient_id], kwargs[:maternal_status])
294
335
  end
295
336
 
296
- def process_method(metrics, methods, patient_id)
297
- metrics[:symptom_screen_alone] << patient_id if methods.blank?
298
- metrics[:cxr_screen] << patient_id if methods&.include?('cxr') && !methods&.include?('mwrd')
299
- metrics[:mwrd_screen] << patient_id if methods&.include?('mwrd')
337
+ 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')
341
+
342
+ process_aggreggation_rows(kwargs[:age_group], kwargs[:gender], indicator, kwargs[:patient_id], kwargs[:maternal_status])
300
343
  end
301
344
 
302
345
  # rubocop:enable Metrics/AbcSize
@@ -324,18 +367,28 @@ module MalawiHivProgramReports
324
367
 
325
368
  def find_tb_screened_data_query
326
369
  <<~SQL
327
- SELECT tbs.patient_id, tbs.enrollment_date, LEFT(tbs.gender, 1) AS gender, tbs.age_group, tbs.tb_status, tbs.screened_date, tbs.screening_methods
328
- FROM temp_tb_screened tbs
329
- #{site_manager(operator: 'WHERE', column: 'tbs.site_id', location: @location)}
370
+ SELECT tbs.patient_id, tbs.enrollment_date,
371
+ CASE tbs.gender
372
+ WHEN 'M' THEN 'Male'
373
+ WHEN 'F' THEN 'Female'
374
+ ELSE 'Unknown'
375
+ END gender, ms.maternal_status,
376
+ tbs.age_group, tbs.tb_status, tbs.screened_date, tbs.screening_methods
377
+ FROM cdr_tb_screened #{current_partition} tbs
378
+ LEFT JOIN cdr_temp_maternal_status #{current_partition} ms ON ms.patient_id = tbs.patient_id
330
379
  SQL
331
380
  end
332
381
 
333
382
  def find_tb_confirmed_data_query
334
383
  <<~SQL
335
- SELECT t.patient_id, t.gender, t.age_group, t.enrollment_date, t.tb_confirmed_date
336
- FROM temp_tb_confirmed_and_on_treatment t
384
+ SELECT t.patient_id, CASE t.gender
385
+ WHEN 'M' THEN 'Male'
386
+ WHEN 'F' THEN 'Female'
387
+ ELSE 'Unknown'
388
+ END gender, ms.maternal_status, t.age_group, t.enrollment_date, t.tb_confirmed_date
389
+ FROM cdr_tb_confirmed_and_on_treatment #{current_partition} t
390
+ LEFT JOIN cdr_temp_maternal_status #{current_partition} ms ON ms.patient_id = t.patient_id
337
391
  WHERE t.tb_confirmed_date > '#{start_date}'
338
- #{site_manager(operator: 'AND', column: 't.site_id', location: @location)}
339
392
  AND (t.has_tb_confirmed_date = TRUE OR t.prev_reading IS NULL OR TIMESTAMPDIFF(MONTH,t.prev_reading, t.tb_confirmed_date) > 6)
340
393
  SQL
341
394
  end
@@ -35,7 +35,7 @@ module MalawiHivProgramReports
35
35
  'VL_DUE' => MalawiHivProgramReports::Clinic::PatientsDueForViralLoad,
36
36
  'DEFAULTER_LIST' => MalawiHivProgramReports::Pepfar::DefaulterList,
37
37
  'VL_DISAGGREGATED' => MalawiHivProgramReports::Clinic::ViralLoadDisaggregated,
38
- 'TB_PREV' => MalawiHivProgramReports::Pepfar::TbPrev,
38
+ 'TB_PREV' => MalawiHivProgramReports::Pepfar::TbPrev3,
39
39
  'OUTCOME_LIST' => MalawiHivProgramReports::Clinic::OutcomeList,
40
40
  'VIRAL_LOAD' => MalawiHivProgramReports::Clinic::ViralLoad,
41
41
  'VIRAL_LOAD_COVERAGE' => MalawiHivProgramReports::Pepfar::ViralLoadCoverage2,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MalawiHivProgramReports
4
- VERSION = '1.1.16'
4
+ VERSION = '1.1.17'
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.16
4
+ version: 1.1.17
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-07-29 00:00:00.000000000 Z
11
+ date: 2024-09-25 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.6
194
+ rubygems_version: 3.5.17
195
195
  signing_key:
196
196
  specification_version: 4
197
197
  summary: Malawi HIV PROGRAM Reports for Ruby on Rails