malawi_hiv_program_reports 1.1.18 → 1.1.20

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: 22a3e944fcb8f4a9e0d862b50321ead38c607a3488c002096735853b06922be5
4
- data.tar.gz: fb58caba60b6795e915efaadd08fea81e2817129ef500843da95ba48047028aa
3
+ metadata.gz: 9452090ad1301bd223ba5fe909770f991b280a328a78f291959cc627b3a5445b
4
+ data.tar.gz: 69c727c81ebadf855040d3724dc557d43ef62abb8282c6164eef13a4f10ad4e9
5
5
  SHA512:
6
- metadata.gz: 91ae6c317a44e67d502cc97f3d3d72d54ace89d8def8326f8fc2ea7901e1b4693c0754084b33a1bf9c9d32626dd840b72df1e1c56ee558547ed0ff5056756403
7
- data.tar.gz: 8d52d72581ab43cc207e34bbb20ecf62d942cd104c854e0890c4b1712346d64a609907cd447c9f912298be40b78d0affd36e4be1a8ef123a86f7fd749258a83b
6
+ metadata.gz: 1f8d8117bd8d26f3b98b47d4e165a6cab08ef1f28955328ee4a32b14fe7151f2081b4d52e50f7ac1c8b00e6a57aaa0d540c93f02deaa43712a2a681b8d715a57
7
+ data.tar.gz: 70e3c528f4527b41e5a27daa6b2238342798d8e3b03e2befe51027e88822d138da486e4fc6652f1a9bae4cbc24cce1810277d1e0b258d49501c9d39689f78c4a
@@ -88,6 +88,8 @@ module MalawiHivProgramReports
88
88
  maternal_status = data['maternal_status']
89
89
  # we need to handle regimes that only have one P to become PP. Otherwise if it is already PP or PA we leave
90
90
  # it as is. Regimens are in this format NUMBERLETTERS
91
+
92
+ report[age_group.to_s][gender.to_s][regimen.to_s] << patient_id if regimen.to_s == '15P'
91
93
  regimen = regimen.gsub(/(\d+[A-Za-z]*P)\z/, '\1P') if regimen.match?(/\A\d+[A-Za-z]*[^P]P\z/)
92
94
  gender = data['gender']
93
95
  report[age_group.to_s][gender.to_s][regimen.to_s] << patient_id
@@ -6,7 +6,7 @@ module MalawiHivProgramReports
6
6
  # rubocop:disable Metrics/ClassLength
7
7
  class CohortDisaggregatedAdditions
8
8
  COHORT_REGIMENS = %w[
9
- 0P 2P 4PP 4PA 9PP 9PA 11PP 11PA 12PP 12PA 14PP 14PA 15PP 15PA 16P 17PP 17PA
9
+ 0P 2P 4PP 4PA 9PP 9PA 11PP 11PA 12PP 12PA 14PP 14PA 15P 15PP 15PA 16P 17PP 17PA
10
10
  4A 5A 6A 7A 8A 9A 10A 11A 12A 13A 14A 15A 16A 17A
11
11
  ].freeze
12
12
 
@@ -75,6 +75,7 @@ module MalawiHivProgramReports
75
75
  fourteen_pp: 'Regimen 14PP',
76
76
  fourteen_pa: 'Regimen 14PA',
77
77
  fourteen_a: 'Regimen 14 A',
78
+ fifteen_p: 'Regimen 15P',
78
79
  fifteen_pp: 'Regimen 15PP',
79
80
  fifteen_pa: 'Regimen 15PA',
80
81
  fifteen_a: 'Regimen 15 A',
@@ -31,22 +31,6 @@ module MalawiHivProgramReports
31
31
  load_breast_feeding
32
32
  end
33
33
 
34
- private
35
-
36
- def vl_maternal_status(patient_list)
37
- return { FP: [], FBf: [] } if patient_list.blank?
38
-
39
- pregnant = pregnant_women(patient_list).map { |woman| woman['person_id'].to_i }
40
- return { FP: pregnant, FBf: [] } if (patient_list - pregnant).blank?
41
-
42
- feeding = breast_feeding(patient_list - pregnant).map { |woman| woman['person_id'].to_i }
43
-
44
- {
45
- FP: pregnant,
46
- FBf: feeding
47
- }
48
- end
49
-
50
34
  def pregnant_women(patient_list)
51
35
  ActiveRecord::Base.connection.execute <<~SQL
52
36
  SELECT person_id
@@ -63,6 +47,22 @@ module MalawiHivProgramReports
63
47
  SQL
64
48
  end
65
49
 
50
+ private
51
+
52
+ def vl_maternal_status(patient_list)
53
+ return { FP: [], FBf: [] } if patient_list.blank?
54
+
55
+ pregnant = pregnant_women(patient_list).map { |woman| woman['person_id'].to_i }
56
+ return { FP: pregnant, FBf: [] } if (patient_list - pregnant).blank?
57
+
58
+ feeding = breast_feeding(patient_list - pregnant).map { |woman| woman['person_id'].to_i }
59
+
60
+ {
61
+ FP: pregnant,
62
+ FBf: feeding
63
+ }
64
+ end
65
+
66
66
  def load_pregnant_women
67
67
  ActiveRecord::Base.connection.execute <<~SQL
68
68
  INSERT INTO cdr_temp_maternal_status #{current_partition} (patient_id, site_id, maternal_status)
@@ -118,10 +118,8 @@ module MalawiHivProgramReports
118
118
  end
119
119
 
120
120
  def build_cohort_tables
121
- return unless rebuild_outcome || @occupation.present?
122
-
123
121
  MalawiHivProgramReports::Moh::CumulativeCohort.new(
124
- start_date:,
122
+ start_date: (end_date - 2.months).beginning_of_month,
125
123
  end_date:,
126
124
  locations: [@location.to_s],
127
125
  rebuild: rebuild_outcome
@@ -166,6 +164,8 @@ module MalawiHivProgramReports
166
164
  cn.name AS tb_status,
167
165
  GROUP_CONCAT(DISTINCT vcn.name) AS screening_methods
168
166
  FROM cdr_temp_cohort_members #{current_partition} tesd
167
+ INNER JOIN cdr_temp_patient_outcomes #{current_partition} tpo ON tpo.patient_id = tesd.patient_id
168
+ AND tpo.cum_outcome = 'On antiretrovirals'
169
169
  INNER JOIN obs #{current_partition} o ON o.person_id = tesd.patient_id
170
170
  AND o.voided = 0 AND o.concept_id = #{tb_status}
171
171
  AND o.obs_datetime BETWEEN '#{start_date}' AND '#{end_date}'
@@ -176,6 +176,11 @@ module MalawiHivProgramReports
176
176
  AND acurr.obs_datetime > o.obs_datetime
177
177
  AND acurr.obs_datetime BETWEEN '#{start_date}' AND '#{end_date}'
178
178
  AND acurr.value_coded IN (#{tb_status_results})
179
+ INNER JOIN obs #{current_partition} patient_present ON patient_present.person_id = o.person_id
180
+ AND patient_present.concept_id = #{ConceptName.find_by_name('Patient present').concept_id}
181
+ AND patient_present.value_coded = #{ConceptName.find_by_name('Yes').concept_id}
182
+ AND patient_present.voided = 0
183
+ AND patient_present.obs_datetime BETWEEN '#{start_date}' AND '#{end_date}'
179
184
  LEFT JOIN obs #{current_partition} screen_method ON screen_method.concept_id = #{tb_screening_method}
180
185
  AND screen_method.voided = 0
181
186
  AND screen_method.person_id = o.person_id
@@ -335,9 +340,15 @@ module MalawiHivProgramReports
335
340
  end
336
341
 
337
342
  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')
343
+ indicator = nil
344
+
345
+ if methods.include?('mwrd')
346
+ indicator = :mwrd_screen
347
+ elsif methods.include?('cxr')
348
+ indicator = :cxr_screen
349
+ else
350
+ indicator = :symptom_screen_alone
351
+ end
341
352
 
342
353
  process_aggreggation_rows(kwargs[:age_group], kwargs[:gender], indicator, kwargs[:patient_id], kwargs[:maternal_status])
343
354
  end
@@ -26,7 +26,7 @@ module MalawiHivProgramReports
26
26
  end
27
27
 
28
28
  COHORT_REGIMENS = %w[
29
- 0P 2P 4PP 4PA 9PP 9PA 11PP 11PA 12PP 12PA 14PP 14PA 15PP 15PA 16P 17PP 17PA
29
+ 0P 2P 4PP 4PA 9PP 9PA 11PP 11PA 12PP 12PA 14PP 14PA 15P 15PP 15PA 16P 17PP 17PA
30
30
  4A 5A 6A 7A 8A 9A 10A 11A 12A 13A 14A 15A 16A 17A
31
31
  ].freeze
32
32
 
@@ -36,10 +36,10 @@ module MalawiHivProgramReports
36
36
  def vl_maternal_status(patient_list)
37
37
  return { FP: [], FBf: [] } if patient_list.blank?
38
38
 
39
- pregnant = pregnant_women(patient_list).map { |woman| woman['person_id'].to_i }
39
+ pregnant = maternal_status.pregnant_women(patient_list).map { |woman| woman['patient_id'].to_i }
40
40
  return { FP: pregnant, FBf: [] } if (patient_list - pregnant).blank?
41
41
 
42
- feeding = breast_feeding(patient_list - pregnant).map { |woman| woman['person_id'].to_i }
42
+ feeding = maternal_status.breast_feeding(patient_list - pregnant).map { |woman| woman['patient_id'].to_i }
43
43
 
44
44
  {
45
45
  FP: pregnant,
@@ -120,40 +120,6 @@ module MalawiHivProgramReports
120
120
  true
121
121
  end
122
122
 
123
- def pregnant_women(patient_list)
124
- ActiveRecord::Base.connection.select_all <<~SQL
125
- SELECT o.person_id, o.value_coded
126
- FROM obs #{current_partition} o
127
- LEFT JOIN obs #{current_partition} a ON a.person_id = o.person_id AND a.obs_datetime > o.obs_datetime AND a.concept_id IN (#{pregnant_concepts.to_sql}) AND a.voided = 0
128
- AND a.obs_datetime >= DATE(#{ActiveRecord::Base.connection.quote(start_date)}) AND a.obs_datetime < DATE(#{ActiveRecord::Base.connection.quote(end_date)}) + INTERVAL 1 DAY
129
- WHERE a.obs_id is null
130
- AND o.obs_datetime >= DATE(#{ActiveRecord::Base.connection.quote(start_date)})
131
- AND o.obs_datetime < DATE(#{ActiveRecord::Base.connection.quote(end_date)}) + INTERVAL 1 DAY
132
- AND o.voided = 0
133
- AND o.concept_id in (#{pregnant_concepts.to_sql})
134
- AND o.person_id IN (#{patient_list.join(',')})
135
- AND o.value_coded IN (#{yes_concepts.join(',')})
136
- GROUP BY o.person_id
137
- SQL
138
- end
139
-
140
- def breast_feeding(patient_list)
141
- ActiveRecord::Base.connection.select_all <<~SQL
142
- SELECT o.person_id, o.value_coded
143
- FROM obs #{current_partition} o
144
- LEFT JOIN obs #{current_partition} a ON a.person_id = o.person_id AND a.obs_datetime > o.obs_datetime AND a.concept_id IN (#{breast_feeding_concepts.to_sql}) AND a.voided = 0
145
- AND a.obs_datetime >= DATE(#{ActiveRecord::Base.connection.quote(start_date)}) AND a.obs_datetime < DATE(#{ActiveRecord::Base.connection.quote(end_date)}) + INTERVAL 1 DAY
146
- WHERE a.obs_id is null
147
- AND o.obs_datetime >= DATE(#{ActiveRecord::Base.connection.quote(start_date)})
148
- AND o.obs_datetime < DATE(#{ActiveRecord::Base.connection.quote(end_date)}) + INTERVAL 1 DAY
149
- AND o.voided = 0
150
- AND o.concept_id IN (#{breast_feeding_concepts.to_sql})
151
- AND o.person_id IN (#{patient_list.join(',')})
152
- AND o.value_coded IN (#{yes_concepts.join(',')})
153
- GROUP BY o.person_id
154
- SQL
155
- end
156
-
157
123
  def build_report(report)
158
124
  refresh_outcomes_table
159
125
  load_tx_curr_into_report(report, create_patients_alive_and_on_art_query)
@@ -395,26 +361,18 @@ module MalawiHivProgramReports
395
361
  SQL
396
362
  end
397
363
 
398
- def yes_concepts
399
- @yes_concepts ||= ::ConceptName.where(name: 'Yes').select(:concept_id).map do |record|
400
- record['concept_id'].to_i
401
- end
402
- end
403
-
404
- def pregnant_concepts
405
- @pregnant_concepts ||= ::ConceptName.where(name: ['Is patient pregnant?', 'patient pregnant'])
406
- .select(:concept_id)
407
- end
408
-
409
- def breast_feeding_concepts
410
- @breast_feeding_concepts ||= ::ConceptName.where(name: ['Breast feeding?', 'Breast feeding', 'Breastfeeding'])
411
- .select(:concept_id)
412
- end
413
-
414
364
  def encounter_types
415
365
  @encounter_types ||= ::EncounterType.where(name: ['HIV CLINIC CONSULTATION', 'HIV STAGING'])
416
366
  .select(:encounter_type_id)
417
367
  end
368
+
369
+ def maternal_status
370
+ ArtService::Reports::MaternalStatus.new(
371
+ start_date:,
372
+ end_date:,
373
+ occupation:
374
+ )
375
+ end
418
376
  end
419
377
  end
420
378
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MalawiHivProgramReports
4
- VERSION = '1.1.18'
4
+ VERSION = '1.1.20'
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.18
4
+ version: 1.1.20
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-10-08 00:00:00.000000000 Z
11
+ date: 2025-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails