malawi_hiv_program_reports 1.0.2 → 1.0.3

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: aac7cd1e88a85ad8992b57e4bdd77351d194ca17fe74fcadf1d181c1e2500ae1
4
- data.tar.gz: 7aa0b9e69decce733bb9c1e345d3e3b1e4a436d97be2db28d533a7d8f844db99
3
+ metadata.gz: f760361da4c9737b3c6e1a656bc241a2b00b293bb55a8ea87140b80b17791944
4
+ data.tar.gz: 38d1370e27a37f4cf05c1693aeb2520cededf24def54ff9dc9aacc2a37058b54
5
5
  SHA512:
6
- metadata.gz: 289ad98c3a4c178e959e80da3265d25c159637896ab363336995d795c10c139bc13fe70f1677993156b5348c381e32dbdf077c8e1ec644b3d6229bbd9f8228a7
7
- data.tar.gz: 5e71a3c4a72ff1e11cc6e9ae39180270bc4d083cef408d96f42997e71a52019bf826107ceb6dadd39a9eece0f47e8feccaab6fe1aa1c0f6807eac88993293721
6
+ metadata.gz: 44185581748db309173379260ff86ad76c64dcae1689c7e4d306b4930d80e0f6e0f670382fdc931c171da06bc18debd657ce149ebc848aa455aa5edfb3a758ca
7
+ data.tar.gz: 19693969f34e6401039883a0c4974d2426e77262420b465db8123293a5f0ba086e91798b5cc06d14ef6263aaccb4df9b3c4c982cb1187ebbeb8d69fd876c37f2
@@ -25,7 +25,7 @@ module MalawiHivProgramReports
25
25
  # with various outcomes.
26
26
  def refresh_outcomes_table
27
27
  logger.debug('Initialising cohort temporary tables...')
28
- MalawiHivProgramReports::Moh::CohortBuilder.new(outcomes_definition: @outcomes_definition, location:@location)
28
+ MalawiHivProgramReports::Moh::CohortBuilder.new(outcomes_definition: @outcomes_definition, location: @location)
29
29
  .init_temporary_tables(@start_date, @end_date, @occupation)
30
30
  end
31
31
 
@@ -871,7 +871,7 @@ module MalawiHivProgramReports
871
871
  SQL
872
872
  end
873
873
 
874
- def create_temp_register_start_date_table(_end_date)
874
+ def create_temp_register_start_date_table(end_date)
875
875
  type_of_patient_concept = concept('Type of patient').concept_id
876
876
  new_patient_concept = concept('New patient').concept_id
877
877
  exe_temp_register_start_date_table(adapter: @adapter)
@@ -879,14 +879,11 @@ module MalawiHivProgramReports
879
879
  INSERT INTO temp_register_start_date (patient_id, start_date, site_id)
880
880
  SELECT pp.patient_id as patient_id, MIN(o.obs_datetime) AS start_date, pp.site_id as site_id
881
881
  FROM patient_program pp
882
- INNER JOIN temp_other_patient_types tmp ON tmp.patient_id = pp.patient_id
883
- #{site_manager(operator: 'AND', column: 'pp.site_id', location: @location)}
884
- INNER JOIN obs o ON pp.patient_id = o.person_id AND o.concept_id = #{type_of_patient_concept}
885
- #{site_manager(operator: 'AND', column: 'o.site_id', location: @location)}
882
+ INNER JOIN temp_other_patient_types tmp ON tmp.patient_id = pp.patient_id #{site_manager(operator: 'AND', column: 'pp.site_id', location: @location)}
883
+ INNER JOIN obs o ON pp.patient_id = o.person_id AND o.concept_id = #{type_of_patient_concept} #{site_manager(operator: 'AND', column: 'o.site_id', location: @location)}
886
884
  AND o.value_coded = #{new_patient_concept}
887
- AND o.voided = 0
888
- WHERE pp.program_id = 1
889
- #{site_manager(operator: 'AND', column: 'pp.site_id', location: @location)}
885
+ AND o.voided = 0 AND o.obs_datetime < DATE(#{end_date}) + INTERVAL 1 DAY
886
+ WHERE pp.program_id = 1 #{site_manager(operator: 'AND', column: 'pp.site_id', location: @location)}
890
887
  GROUP BY pp.patient_id #{@adapter == 'mysql2' ? '' : ', pp.site_id'}
891
888
  SQL
892
889
  end
@@ -130,7 +130,7 @@ module MalawiHivProgramReports
130
130
  AND pe.person_id NOT IN (#{drug_refills_and_external_consultation_list})
131
131
  GROUP BY p.patient_id
132
132
  HAVING date_enrolled IS NOT NULL AND DATE(date_enrolled) < '#{start_date.to_date}';
133
- SQL
133
+ SQL
134
134
  end
135
135
 
136
136
  def new_potential_tx_ml_clients
@@ -153,7 +153,7 @@ module MalawiHivProgramReports
153
153
  #{site_manager(operator: 'AND', column: 'p.site_id', location: @location)}
154
154
  GROUP BY p.patient_id
155
155
  HAVING date_enrolled IS NOT NULL AND date_enrolled BETWEEN DATE('#{start_date}') AND DATE('#{end_date}');
156
- SQL
156
+ SQL
157
157
  end
158
158
 
159
159
  def defaulter_period(patient_id, earliest_start_date)
@@ -8,7 +8,7 @@ module MalawiHivProgramReports
8
8
  include MalawiHivProgramReports::Utils::ModelUtils
9
9
  include Pepfar::Utils
10
10
  include MalawiHivProgramReports::Adapters::Moh::Custom
11
-
11
+
12
12
  attr_reader :start_date, :end_date, :rebuild, :location
13
13
 
14
14
  def initialize(start_date:, end_date:, **kwargs)
@@ -22,7 +22,10 @@ module MalawiHivProgramReports
22
22
  def find_report
23
23
  report = init_report
24
24
  addittional_groups report
25
- MalawiHivProgramReports::Moh::CohortBuilder.new(location: @location).init_temporary_tables(start_date, end_date, '') if rebuild
25
+ if rebuild
26
+ MalawiHivProgramReports::Moh::CohortBuilder.new(location: @location).init_temporary_tables(start_date,
27
+ end_date, '')
28
+ end
26
29
  process_data report
27
30
  flatten_the_report report
28
31
  rescue StandardError => e
@@ -35,7 +38,7 @@ module MalawiHivProgramReports
35
38
  private
36
39
 
37
40
  GENDER = %w[M F].freeze
38
-
41
+
39
42
  def init_report
40
43
  pepfar_age_groups.each_with_object({}) do |age_group, report|
41
44
  report[age_group] = GENDER.each_with_object({}) do |gender, age_group_report|
@@ -78,13 +81,14 @@ module MalawiHivProgramReports
78
81
  indicator = new_patient.positive? ? cd4_count_group : 'transfer_in'
79
82
 
80
83
  if new_patient.positive? && earliest_start_date.to_date >= start_date.to_date
81
- report[age_group.to_s][gender.to_s][indicator.to_sym] << patient_id
84
+ report[age_group.to_s][gender.to_s][indicator.to_sym] << patient_id
82
85
  elsif new_patient.zero?
83
86
  report[age_group.to_s][gender.to_s][indicator.to_sym] << patient_id
84
87
  else
85
88
  next
86
89
  end
87
- process_aggreggation_rows(report: report, gender: gender, indicator: indicator, start_date: date_enrolled, patient_id: patient_id, maternal_status: row['maternal_status'], maternal_status_date: row['maternal_status_date'])
90
+ process_aggreggation_rows(report:, gender:, indicator:, start_date: date_enrolled,
91
+ patient_id:, maternal_status: row['maternal_status'], maternal_status_date: row['maternal_status_date'])
88
92
  end
89
93
  end
90
94
 
@@ -94,9 +98,9 @@ module MalawiHivProgramReports
94
98
 
95
99
  if gender == 'M'
96
100
  report['All']['Male'][indicator.to_sym] << kwargs[:patient_id]
97
- elsif maternal_status&.match?(/pregnant/i) && maternal_status_date&.to_date <= start_date.to_date
101
+ elsif maternal_status&.match?(/pregnant/i) && (maternal_status_date&.to_date&.<= start_date.to_date)
98
102
  report['All']['FP'][indicator.to_sym] << kwargs[:patient_id]
99
- elsif maternal_status&.match?(/breast/i) && maternal_status_date&.to_date <= start_date.to_date
103
+ elsif maternal_status&.match?(/breast/i) && (maternal_status_date&.to_date&.<= start_date.to_date)
100
104
  report['All']['FBf'][indicator.to_sym] << kwargs[:patient_id]
101
105
  else
102
106
  report['All']['FNP'][indicator.to_sym] << kwargs[:patient_id]
@@ -105,16 +109,16 @@ module MalawiHivProgramReports
105
109
 
106
110
  def process_age_group_report(age_group, gender, age_group_report)
107
111
  {
108
- age_group: age_group,
112
+ age_group:,
109
113
  gender: if gender == 'F'
110
114
  'Female'
111
115
  else
112
116
  (gender == 'M' ? 'Male' : gender)
113
117
  end,
114
- cd4_less_than_200: age_group_report['cd4_less_than_200'.to_sym],
115
- cd4_greater_than_equal_to_200: age_group_report['cd4_greater_than_equal_to_200'.to_sym],
116
- cd4_unknown_or_not_done: age_group_report['cd4_unknown_or_not_done'.to_sym],
117
- transfer_in: age_group_report['transfer_in'.to_sym]
118
+ cd4_less_than_200: age_group_report[:cd4_less_than_200],
119
+ cd4_greater_than_equal_to_200: age_group_report[:cd4_greater_than_equal_to_200],
120
+ cd4_unknown_or_not_done: age_group_report[:cd4_unknown_or_not_done],
121
+ transfer_in: age_group_report[:transfer_in]
118
122
  }
119
123
  end
120
124
 
@@ -138,7 +142,6 @@ module MalawiHivProgramReports
138
142
  result_scores.reject { |item| item[:age_group].match?(/unknown/i) }
139
143
  end
140
144
 
141
-
142
145
  def data
143
146
  ActiveRecord::Base.connection.select_all <<~SQL
144
147
  SELECT
@@ -173,7 +176,7 @@ module MalawiHivProgramReports
173
176
  AND pp.voided = 0
174
177
  INNER JOIN patient_state 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}')
175
178
  WHERE o.concept_id = #{concept_name('CD4 count').concept_id} AND o.voided = 0
176
- #{site_manager(operator: 'AND', column: 'o.site_id', location: @location)}
179
+ #{site_manager(operator: 'AND', column: 'o.site_id', location: @location)}#{' '}
177
180
  AND o.obs_datetime <= '#{end_date}' AND o.obs_datetime >= '#{start_date}'
178
181
  GROUP BY o.person_id
179
182
  ) current_cd4 ON current_cd4.person_id = pp.patient_id
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MalawiHivProgramReports
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.3'
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.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roy Chanunkha