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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b8fed6ebe30ff7bc1f0573f0b560d33796ee13af2ff4de885c694dd023fbfc7
4
- data.tar.gz: 59b5f6b719c14f0eb297ee1ff9e8aabf54e69ffa7ab97cda0f803aa4414f1a01
3
+ metadata.gz: 9c6bffbef9d85fec441ab368a631e8e730446a87ed8722d2a60d348c68ecf969
4
+ data.tar.gz: dfd3ba0bfe3a2fc65ca948d3dd2bee21c9f8bb4f7c42ade37623f46c6fb8aefb
5
5
  SHA512:
6
- metadata.gz: 47261e1116d8d96465267866238b02402bddc68c6ff4385590fdf1e3347abebdbbe003250b313a993ae443cff4d9803d408f95a7199e14e4569c3aa335ce3ff8
7
- data.tar.gz: a32981a2ab869c4bd28de08625eca90cd3b93bdb267604bc3ebbf9197cb5489dd59728406c035529c513f55832bba41c296e0df10adabeeba6c1039256652582
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
- cdr_other_patient_types location
82
- external_clients location
83
- transfer_ins location
84
- min_drug_orders location
85
- potential_cohort_members location
86
- reason_for_starting_art location
87
- cohort_members location
88
- outcome = MalawiHivProgramReports::Moh::CumulativeOutcome.new(end_date:, location:, definition:, rebuild:, start_date:)
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:, end_date:, definition: 'pepfar', 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)
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
- pat['gender'].first.upcase
36
- rescue StandardError
37
- 'Unknown'
38
- end
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
- SELECT
74
- e.patient_id,
75
- e.birthdate,
76
- e.gender,
77
- e.date_enrolled,
78
- e.earliest_start_date,
79
- o.outcome_date,
80
- TIMESTAMPDIFF(MONTH, DATE(e.earliest_start_date), DATE(o.outcome_date)) months,
81
- disaggregated_age_group(e.birthdate, DATE('#{end_date}')) age_group,
82
- o.cum_outcome outcome
83
- FROM cdr_temp_cohort_members #{current_partition} e
84
- 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')
85
- WHERE e.patient_id IN (SELECT patient_id FROM cdr_temp_patient_outcomes_start #{current_partition} WHERE cum_outcome = 'On antiretrovirals')
86
- AND DATE(e.date_enrolled) < '#{start_date.to_date}'
87
- GROUP BY e.patient_id
88
- SQL
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
- SELECT
94
- e.patient_id,
95
- e.birthdate,
96
- e.gender,
97
- e.date_enrolled,
98
- e.earliest_start_date,
99
- o.outcome_date,
100
- TIMESTAMPDIFF(MONTH, DATE(e.earliest_start_date), DATE(o.outcome_date)) months,
101
- disaggregated_age_group(e.birthdate, DATE('#{end_date}')) age_group,
102
- o.cum_outcome outcome
103
- FROM cdr_temp_cohort_members #{current_partition} e
104
- 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')
105
- WHERE e.date_enrolled BETWEEN DATE('#{start_date}') AND DATE('#{end_date}')
106
- GROUP BY e.patient_id
107
- SQL
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
- (#{tx_ml_clients})
113
- UNION
114
- (#{tx_ml_clients_new})
115
- SQL
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:, end_date:, definition: 'pepfar', locations: location.to_s, rebuild: true)
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['cd4_less_than_200'.to_sym],
124
- cd4_greater_than_equal_to_200: age_group_report['cd4_greater_than_equal_to_200'.to_sym],
125
- cd4_unknown_or_not_done: age_group_report['cd4_unknown_or_not_done'.to_sym],
126
- transfer_in: age_group_report['transfer_in'.to_sym]
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
- SELECT
155
- e.patient_id,
156
- e.gender,
157
- disaggregated_age_group(e.birthdate, DATE('#{end_date}')) age_group,
158
- CASE
159
- WHEN o.value_numeric < 200 THEN 'cd4_less_than_200'
160
- WHEN o.value_numeric = 200 AND o.value_modifier = '=' THEN 'cd4_greater_than_equal_to_200'
161
- WHEN o.value_numeric = 200 AND o.value_modifier = '<' THEN 'cd4_less_than_200'
162
- WHEN o.value_numeric = 200 AND o.value_modifier = '>' THEN 'cd4_greater_than_equal_to_200'
163
- WHEN o.value_numeric > 200 THEN 'cd4_greater_than_equal_to_200'
164
- ELSE 'cd4_unknown_or_not_done'
165
- END cd4_count_group,
166
- CASE
167
- WHEN e.recorded_start_date IS NULL THEN 1
168
- ELSE 0
169
- END new_patient,
170
- e.date_enrolled,
171
- e.earliest_start_date,
172
- preg_or_breast.name AS maternal_status,
173
- DATE(MIN(pregnant_or_breastfeeding.obs_datetime)) AS maternal_status_date
174
- FROM cdr_temp_cohort_members #{current_partition} e
175
- LEFT JOIN (
176
- SELECT max(o.obs_datetime) AS obs_datetime, o.person_id
177
- FROM obs #{current_partition} o
178
- INNER JOIN concept_name cn ON cn.concept_id = o.concept_id AND cn.name = 'CD4 count' AND cn.voided = 0
179
- INNER JOIN patient_program #{current_partition} pp ON pp.patient_id = o.person_id
180
- AND pp.program_id = #{program('HIV PROGRAM').id}
181
- AND pp.voided = 0
182
- 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}')
183
- WHERE o.concept_id = #{concept_name('CD4 count').concept_id} AND o.voided = 0
184
- AND o.obs_datetime <= '#{end_date}' AND o.obs_datetime >= '#{start_date}'
185
- GROUP BY o.person_id
186
- ) current_cd4 ON current_cd4.person_id = e.patient_id
187
- 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
188
- LEFT JOIN obs #{current_partition} pregnant_or_breastfeeding ON pregnant_or_breastfeeding.person_id = e.patient_id
189
- 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)
190
- AND pregnant_or_breastfeeding.voided = 0
191
- AND pregnant_or_breastfeeding.value_coded = #{concept_name('Yes').concept_id}
192
- LEFT JOIN concept_name preg_or_breast ON preg_or_breast.concept_id = pregnant_or_breastfeeding.concept_id AND preg_or_breast.voided = 0
193
- WHERE e.date_enrolled <= '#{end_date}' AND e.date_enrolled >= '#{start_date}'
194
- GROUP BY e.patient_id
195
- SQL
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:, end_date:, definition: 'pepfar',
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:, end_date:, definition: 'pepfar',
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MalawiHivProgramReports
4
- VERSION = '1.0.27'
4
+ VERSION = '1.1.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: malawi_hiv_program_reports
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.27
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roy Chanunkha