malawi_hiv_program_reports 1.0.1 → 1.0.2
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/README.md +16 -0
- data/app/services/malawi_hiv_program_reports/adapters/moh/custom.rb +199 -0
- data/app/services/malawi_hiv_program_reports/archiving_candidates.rb +130 -0
- data/app/services/malawi_hiv_program_reports/arv_refill_periods.rb +311 -0
- data/app/services/malawi_hiv_program_reports/clinic/README.md +5 -0
- data/app/services/malawi_hiv_program_reports/clinic/appointments_report.rb +317 -0
- data/app/services/malawi_hiv_program_reports/clinic/discrepancy_report.rb +42 -0
- data/app/services/malawi_hiv_program_reports/clinic/docs/hypertension_report.md +31 -0
- data/app/services/malawi_hiv_program_reports/clinic/drug_dispensations.rb +48 -0
- data/app/services/malawi_hiv_program_reports/clinic/external_consultation_clients.rb +69 -0
- data/app/services/malawi_hiv_program_reports/clinic/hypertension_report.rb +223 -0
- data/app/services/malawi_hiv_program_reports/clinic/ipt_coverage.rb +112 -0
- data/app/services/malawi_hiv_program_reports/clinic/ipt_report.rb +69 -0
- data/app/services/malawi_hiv_program_reports/clinic/lims_results.rb +55 -0
- data/app/services/malawi_hiv_program_reports/clinic/outcome_list.rb +127 -0
- data/app/services/malawi_hiv_program_reports/clinic/patients_alive_and_on_treatment.rb +57 -0
- data/app/services/malawi_hiv_program_reports/clinic/patients_due_for_viral_load.rb +39 -0
- data/app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb +44 -0
- data/app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb +36 -0
- data/app/services/malawi_hiv_program_reports/clinic/patients_on_treatment.rb +42 -0
- data/app/services/malawi_hiv_program_reports/clinic/patients_with_outdated_demographics.rb +173 -0
- data/app/services/malawi_hiv_program_reports/clinic/pregnant_patients.rb +91 -0
- data/app/services/malawi_hiv_program_reports/clinic/regimen_dispensation_data.rb +282 -0
- data/app/services/malawi_hiv_program_reports/clinic/regimen_switch.rb +456 -0
- data/app/services/malawi_hiv_program_reports/clinic/regimens_and_formulations.rb +182 -0
- data/app/services/malawi_hiv_program_reports/clinic/regimens_by_weight_and_gender.rb +108 -0
- data/app/services/malawi_hiv_program_reports/clinic/retention.rb +246 -0
- data/app/services/malawi_hiv_program_reports/clinic/stock_card_report.rb +65 -0
- data/app/services/malawi_hiv_program_reports/clinic/tpt_outcome.rb +494 -0
- data/app/services/malawi_hiv_program_reports/clinic/tx_rtt.rb +169 -0
- data/app/services/malawi_hiv_program_reports/clinic/viral_load.rb +292 -0
- data/app/services/malawi_hiv_program_reports/clinic/viral_load_disaggregated.rb +97 -0
- data/app/services/malawi_hiv_program_reports/clinic/viral_load_results.rb +175 -0
- data/app/services/malawi_hiv_program_reports/clinic/visits_report.rb +113 -0
- data/app/services/malawi_hiv_program_reports/clinic/vl_collection.rb +48 -0
- data/app/services/malawi_hiv_program_reports/cohort/outcomes.rb +338 -0
- data/app/services/malawi_hiv_program_reports/cohort/regimens.rb +69 -0
- data/app/services/malawi_hiv_program_reports/cohort/side_effects.rb +141 -0
- data/app/services/malawi_hiv_program_reports/cohort/tpt.rb +172 -0
- data/app/services/malawi_hiv_program_reports/moh/cohort.rb +278 -0
- data/app/services/malawi_hiv_program_reports/moh/cohort_builder.rb +2340 -0
- data/app/services/malawi_hiv_program_reports/moh/cohort_disaggregated.rb +608 -0
- data/app/services/malawi_hiv_program_reports/moh/cohort_disaggregated_additions.rb +208 -0
- data/app/services/malawi_hiv_program_reports/moh/cohort_disaggregated_builder.rb +526 -0
- data/app/services/malawi_hiv_program_reports/moh/cohort_struct.rb +219 -0
- data/app/services/malawi_hiv_program_reports/moh/cohort_survival_analysis.rb +203 -0
- data/app/services/malawi_hiv_program_reports/moh/moh_tpt.rb +223 -0
- data/app/services/malawi_hiv_program_reports/moh/tpt_newly_initiated.rb +235 -0
- data/app/services/malawi_hiv_program_reports/pepfar/defaulter_list.rb +25 -0
- data/app/services/malawi_hiv_program_reports/pepfar/maternal_status.rb +29 -0
- data/app/services/malawi_hiv_program_reports/pepfar/patient_start_vl.rb +45 -0
- data/app/services/malawi_hiv_program_reports/pepfar/regimen_switch.rb +479 -0
- data/app/services/malawi_hiv_program_reports/pepfar/sc_arvdisp.rb +174 -0
- data/app/services/malawi_hiv_program_reports/pepfar/sc_curr.rb +98 -0
- data/app/services/malawi_hiv_program_reports/pepfar/tb_prev.rb +163 -0
- data/app/services/malawi_hiv_program_reports/pepfar/tb_prev2.rb +222 -0
- data/app/services/malawi_hiv_program_reports/pepfar/tb_prev3.rb +421 -0
- data/app/services/malawi_hiv_program_reports/pepfar/tpt_status.rb +181 -0
- data/app/services/malawi_hiv_program_reports/pepfar/tx_ml.rb +181 -0
- data/app/services/malawi_hiv_program_reports/pepfar/tx_new.rb +202 -0
- data/app/services/malawi_hiv_program_reports/pepfar/tx_rtt.rb +288 -0
- data/app/services/malawi_hiv_program_reports/pepfar/tx_tb.rb +283 -0
- data/app/services/malawi_hiv_program_reports/pepfar/utils.rb +141 -0
- data/app/services/malawi_hiv_program_reports/pepfar/viral_load_coverage.rb +414 -0
- data/app/services/malawi_hiv_program_reports/pepfar/viral_load_coverage2.rb +433 -0
- data/app/services/malawi_hiv_program_reports/report_map.rb +56 -0
- data/app/services/malawi_hiv_program_reports/utils/README.md +8 -0
- data/app/services/malawi_hiv_program_reports/utils/common_sql_query_utils.rb +60 -0
- data/app/services/malawi_hiv_program_reports/utils/concurrency_utils.rb +53 -0
- data/app/services/malawi_hiv_program_reports/utils/docs/common_sql_query_utils.md +53 -0
- data/app/services/malawi_hiv_program_reports/utils/model_utils.rb +66 -0
- data/app/services/malawi_hiv_program_reports/utils/parameter_utils.rb +32 -0
- data/app/services/malawi_hiv_program_reports/utils/time_utils.rb +52 -0
- data/lib/malawi_hiv_program_reports/version.rb +1 -1
- metadata +74 -1
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This module contains utility methods for retrieving models
|
4
|
+
module MalawiHivProgramReports
|
5
|
+
module Utils
|
6
|
+
module ModelUtils
|
7
|
+
# Retrieve concept by its name
|
8
|
+
#
|
9
|
+
# Parameters:
|
10
|
+
# name - A string repr of the concept name
|
11
|
+
def concept(name)
|
12
|
+
::Concept.joins(:concept_names).where('LOWER(concept_name.name) = ?', name.downcase).first
|
13
|
+
end
|
14
|
+
|
15
|
+
def concept_name(name)
|
16
|
+
::ConceptName.where('LOWER(name) = ?', name.downcase).first
|
17
|
+
end
|
18
|
+
|
19
|
+
def concept_name_to_id(name)
|
20
|
+
return nil if name.blank?
|
21
|
+
|
22
|
+
concept_name(name)&.concept_id
|
23
|
+
end
|
24
|
+
|
25
|
+
def concept_id_to_name(id)
|
26
|
+
return nil if id.blank?
|
27
|
+
|
28
|
+
concept = ::Concept.find_by_concept_id(id)
|
29
|
+
concept&.fullname
|
30
|
+
end
|
31
|
+
|
32
|
+
def program(name)
|
33
|
+
::Program.where('LOWER(name) = ?', name.downcase).first
|
34
|
+
end
|
35
|
+
|
36
|
+
def encounter_type(name)
|
37
|
+
::EncounterType.where('LOWER(name) = ?', name.downcase).first
|
38
|
+
end
|
39
|
+
|
40
|
+
def global_property(name)
|
41
|
+
::GlobalProperty.where('LOWER(property) = ?', name.downcase).first
|
42
|
+
end
|
43
|
+
|
44
|
+
def user_property(name, user_id: nil)
|
45
|
+
user_id ||= ::User.current.user_id
|
46
|
+
::UserProperty.where('user_id = ? AND LOWER(property) = ?', user_id, name).first
|
47
|
+
end
|
48
|
+
|
49
|
+
def order_type(name)
|
50
|
+
::OrderType.where('LOWER(name) = ?', name.downcase).first
|
51
|
+
end
|
52
|
+
|
53
|
+
def report_type(name)
|
54
|
+
::ReportType.where('LOWER(name) = ?', name.downcase).first
|
55
|
+
end
|
56
|
+
|
57
|
+
def patient_identifier_type(name)
|
58
|
+
::PatientIdentifierType.where('LOWER(name) = ?', name.downcase).first
|
59
|
+
end
|
60
|
+
|
61
|
+
def drug(name)
|
62
|
+
::Drug.where('LOWER(name) = ?', name.downcase).first
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
# Utility methods for dealing with ActiveSupport::Parameters objects.
|
6
|
+
module MalawiHivProgramReports
|
7
|
+
module Utils
|
8
|
+
module ParameterUtils
|
9
|
+
LOGGER = Logger.new($stdout)
|
10
|
+
|
11
|
+
# Fetches field from ActiveSupport::Parameters.
|
12
|
+
#
|
13
|
+
# This method is just a wrapper around the fetch or raise bad request
|
14
|
+
# routine for retrieving parameter values.
|
15
|
+
#
|
16
|
+
# @throws InvalidParameterError - When field is not found in stock_obs
|
17
|
+
def fetch_parameter(parameters, field)
|
18
|
+
parameters.fetch(field)
|
19
|
+
rescue KeyError => e
|
20
|
+
LOGGER.error("Failed to fetch parameter `#{field}` due to #{e}")
|
21
|
+
raise ::InvalidParameterError, "`#{field}` not found in parameters: #{parameters.to_json}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def fetch_parameter_as_date(parameters, field, default = nil)
|
25
|
+
parameters.fetch(field, default)&.to_date
|
26
|
+
rescue ArgumentError => e
|
27
|
+
LOGGER.error("Failed to fetch parameter `#{field}` due to #{e}")
|
28
|
+
raise ::InvalidParameterError, "Could not parse #{field} as date from: #{parameters.to_json}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MalawiHivProgramReports
|
4
|
+
module Utils
|
5
|
+
module TimeUtils
|
6
|
+
class << self
|
7
|
+
def time_epoch
|
8
|
+
Time.now - 120.years
|
9
|
+
end
|
10
|
+
|
11
|
+
def date_epoch
|
12
|
+
Date.today - 120.years
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a 24 hour period (day) containing the date
|
16
|
+
def day_bounds(datetime)
|
17
|
+
datetime = datetime&.to_time || datetime
|
18
|
+
[datetime.strftime('%Y-%m-%d 00:00:00').to_time,
|
19
|
+
datetime.strftime('%Y-%m-%d 23:59:59').to_time]
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Parses and validates start_date and end_date provided by users
|
24
|
+
#
|
25
|
+
# Returns: A pair of Date objects containing the start_date and end_date
|
26
|
+
def parse_date_range(start_date, end_date)
|
27
|
+
raise ::InvalidParameterError, 'start_date is required' if start_date.blank?
|
28
|
+
raise ::InvalidParameterError, 'end_date is required' if end_date.blank?
|
29
|
+
|
30
|
+
start_date = start_date.to_date
|
31
|
+
end_date = end_date.to_date
|
32
|
+
|
33
|
+
raise ::InvalidParameterError, "start_date can't be greater than end_date" if start_date > end_date
|
34
|
+
|
35
|
+
[start_date, end_date]
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns a time object comprising the given date plus the current time.
|
39
|
+
def retro_timestamp(date)
|
40
|
+
return nil unless date
|
41
|
+
|
42
|
+
date = date.to_time
|
43
|
+
"#{date.strftime('%Y-%m-%d')} #{Time.now.strftime('%H:%M:%S')}".to_time
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_person_age(birthdate:)
|
47
|
+
((Time.zone.now - birthdate.to_time) / 1.year.seconds).floor
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
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.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roy Chanunkha
|
@@ -90,6 +90,79 @@ files:
|
|
90
90
|
- MIT-LICENSE
|
91
91
|
- README.md
|
92
92
|
- Rakefile
|
93
|
+
- app/services/malawi_hiv_program_reports/README.md
|
94
|
+
- app/services/malawi_hiv_program_reports/adapters/moh/custom.rb
|
95
|
+
- app/services/malawi_hiv_program_reports/archiving_candidates.rb
|
96
|
+
- app/services/malawi_hiv_program_reports/arv_refill_periods.rb
|
97
|
+
- app/services/malawi_hiv_program_reports/clinic/README.md
|
98
|
+
- app/services/malawi_hiv_program_reports/clinic/appointments_report.rb
|
99
|
+
- app/services/malawi_hiv_program_reports/clinic/discrepancy_report.rb
|
100
|
+
- app/services/malawi_hiv_program_reports/clinic/docs/hypertension_report.md
|
101
|
+
- app/services/malawi_hiv_program_reports/clinic/drug_dispensations.rb
|
102
|
+
- app/services/malawi_hiv_program_reports/clinic/external_consultation_clients.rb
|
103
|
+
- app/services/malawi_hiv_program_reports/clinic/hypertension_report.rb
|
104
|
+
- app/services/malawi_hiv_program_reports/clinic/ipt_coverage.rb
|
105
|
+
- app/services/malawi_hiv_program_reports/clinic/ipt_report.rb
|
106
|
+
- app/services/malawi_hiv_program_reports/clinic/lims_results.rb
|
107
|
+
- app/services/malawi_hiv_program_reports/clinic/outcome_list.rb
|
108
|
+
- app/services/malawi_hiv_program_reports/clinic/patients_alive_and_on_treatment.rb
|
109
|
+
- app/services/malawi_hiv_program_reports/clinic/patients_due_for_viral_load.rb
|
110
|
+
- app/services/malawi_hiv_program_reports/clinic/patients_on_antiretrovirals.rb
|
111
|
+
- app/services/malawi_hiv_program_reports/clinic/patients_on_dtg.rb
|
112
|
+
- app/services/malawi_hiv_program_reports/clinic/patients_on_treatment.rb
|
113
|
+
- app/services/malawi_hiv_program_reports/clinic/patients_with_outdated_demographics.rb
|
114
|
+
- app/services/malawi_hiv_program_reports/clinic/pregnant_patients.rb
|
115
|
+
- app/services/malawi_hiv_program_reports/clinic/regimen_dispensation_data.rb
|
116
|
+
- app/services/malawi_hiv_program_reports/clinic/regimen_switch.rb
|
117
|
+
- app/services/malawi_hiv_program_reports/clinic/regimens_and_formulations.rb
|
118
|
+
- app/services/malawi_hiv_program_reports/clinic/regimens_by_weight_and_gender.rb
|
119
|
+
- app/services/malawi_hiv_program_reports/clinic/retention.rb
|
120
|
+
- app/services/malawi_hiv_program_reports/clinic/stock_card_report.rb
|
121
|
+
- app/services/malawi_hiv_program_reports/clinic/tpt_outcome.rb
|
122
|
+
- app/services/malawi_hiv_program_reports/clinic/tx_rtt.rb
|
123
|
+
- app/services/malawi_hiv_program_reports/clinic/viral_load.rb
|
124
|
+
- app/services/malawi_hiv_program_reports/clinic/viral_load_disaggregated.rb
|
125
|
+
- app/services/malawi_hiv_program_reports/clinic/viral_load_results.rb
|
126
|
+
- app/services/malawi_hiv_program_reports/clinic/visits_report.rb
|
127
|
+
- app/services/malawi_hiv_program_reports/clinic/vl_collection.rb
|
128
|
+
- app/services/malawi_hiv_program_reports/cohort/outcomes.rb
|
129
|
+
- app/services/malawi_hiv_program_reports/cohort/regimens.rb
|
130
|
+
- app/services/malawi_hiv_program_reports/cohort/side_effects.rb
|
131
|
+
- app/services/malawi_hiv_program_reports/cohort/tpt.rb
|
132
|
+
- app/services/malawi_hiv_program_reports/moh/cohort.rb
|
133
|
+
- app/services/malawi_hiv_program_reports/moh/cohort_builder.rb
|
134
|
+
- app/services/malawi_hiv_program_reports/moh/cohort_disaggregated.rb
|
135
|
+
- app/services/malawi_hiv_program_reports/moh/cohort_disaggregated_additions.rb
|
136
|
+
- app/services/malawi_hiv_program_reports/moh/cohort_disaggregated_builder.rb
|
137
|
+
- app/services/malawi_hiv_program_reports/moh/cohort_struct.rb
|
138
|
+
- app/services/malawi_hiv_program_reports/moh/cohort_survival_analysis.rb
|
139
|
+
- app/services/malawi_hiv_program_reports/moh/moh_tpt.rb
|
140
|
+
- app/services/malawi_hiv_program_reports/moh/tpt_newly_initiated.rb
|
141
|
+
- app/services/malawi_hiv_program_reports/pepfar/defaulter_list.rb
|
142
|
+
- app/services/malawi_hiv_program_reports/pepfar/maternal_status.rb
|
143
|
+
- app/services/malawi_hiv_program_reports/pepfar/patient_start_vl.rb
|
144
|
+
- app/services/malawi_hiv_program_reports/pepfar/regimen_switch.rb
|
145
|
+
- app/services/malawi_hiv_program_reports/pepfar/sc_arvdisp.rb
|
146
|
+
- app/services/malawi_hiv_program_reports/pepfar/sc_curr.rb
|
147
|
+
- app/services/malawi_hiv_program_reports/pepfar/tb_prev.rb
|
148
|
+
- app/services/malawi_hiv_program_reports/pepfar/tb_prev2.rb
|
149
|
+
- app/services/malawi_hiv_program_reports/pepfar/tb_prev3.rb
|
150
|
+
- app/services/malawi_hiv_program_reports/pepfar/tpt_status.rb
|
151
|
+
- app/services/malawi_hiv_program_reports/pepfar/tx_ml.rb
|
152
|
+
- app/services/malawi_hiv_program_reports/pepfar/tx_new.rb
|
153
|
+
- app/services/malawi_hiv_program_reports/pepfar/tx_rtt.rb
|
154
|
+
- app/services/malawi_hiv_program_reports/pepfar/tx_tb.rb
|
155
|
+
- app/services/malawi_hiv_program_reports/pepfar/utils.rb
|
156
|
+
- app/services/malawi_hiv_program_reports/pepfar/viral_load_coverage.rb
|
157
|
+
- app/services/malawi_hiv_program_reports/pepfar/viral_load_coverage2.rb
|
158
|
+
- app/services/malawi_hiv_program_reports/report_map.rb
|
159
|
+
- app/services/malawi_hiv_program_reports/utils/README.md
|
160
|
+
- app/services/malawi_hiv_program_reports/utils/common_sql_query_utils.rb
|
161
|
+
- app/services/malawi_hiv_program_reports/utils/concurrency_utils.rb
|
162
|
+
- app/services/malawi_hiv_program_reports/utils/docs/common_sql_query_utils.md
|
163
|
+
- app/services/malawi_hiv_program_reports/utils/model_utils.rb
|
164
|
+
- app/services/malawi_hiv_program_reports/utils/parameter_utils.rb
|
165
|
+
- app/services/malawi_hiv_program_reports/utils/time_utils.rb
|
93
166
|
- lib/malawi_hiv_program_reports.rb
|
94
167
|
- lib/malawi_hiv_program_reports/engine.rb
|
95
168
|
- lib/malawi_hiv_program_reports/version.rb
|