emr_ohsp_interface 0.2.0 → 0.3.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f6553499e58adb8f290bfa2ff597f0c57ca58412b1b7430d2ab8d33494c89b0
|
4
|
+
data.tar.gz: c603ea2729e987c6a85a091f0bd9eaf63b2671e20b9218ebac5edfb706c42ad5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 837e42141f3d58d61da5780a4693f834edfbcb40715717ffa858ee20feac78a4e762f2d2265f1b0b7f0c588222d95e2ddaf392cb06c0cdd9555c69fc43227551
|
7
|
+
data.tar.gz: 3e15c6d814d1277208b96ee5084562016cad88ce995f6434c0644a42925dc7620ffec7dfc0e8db285d479b0e97670a8fc0f6f1e54cf66f537eb659e308004b11
|
@@ -2,8 +2,17 @@ class EmrOhspInterface::EmrOhspInterfaceController < ::ApplicationController
|
|
2
2
|
def weeks_generator
|
3
3
|
render json: service.weeks_generator();
|
4
4
|
end
|
5
|
+
|
5
6
|
def months_generator
|
6
7
|
render json: service.months_generator();
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_weekly_idsr_report
|
11
|
+
render json: service.generate_weekly_idsr_report(params[:request],params[:start_date],params[:end_date]);
|
12
|
+
end
|
13
|
+
|
14
|
+
def generate_monthly_idsr_report
|
15
|
+
render json: service.generate_monthly_idsr_report(params[:request],params[:start_date],params[:end_date]);
|
7
16
|
end
|
8
17
|
|
9
18
|
def service
|
@@ -23,13 +23,14 @@ module EmrOhspInterface
|
|
23
23
|
result = []
|
24
24
|
#["waoQ016uOz1", "r1AT49VBKqg", "FPN4D0s6K3m", "zE8k2BtValu"]
|
25
25
|
# ds, de_id , <5yrs , >=5yrs
|
26
|
+
puts de
|
26
27
|
if type == "weekly"
|
27
28
|
file = File.open(Rails.root.join("db","idsr_metadata","idsr_weekly_ohsp_ids.csv"))
|
28
29
|
else
|
29
30
|
file = File.open(Rails.root.join("db","idsr_metadata","idsr_monthly_ohsp_ids.csv"))
|
30
31
|
end
|
31
32
|
data = CSV.parse(file,headers: true)
|
32
|
-
row = data.select{|row| row["Data Element Name"].strip.downcase.eql?(de.downcase)}
|
33
|
+
row = data.select{|row| row["Data Element Name"].strip.downcase.eql?(de.downcase.strip)}
|
33
34
|
ohsp_ds_id = row[0]["Data Set ID"]
|
34
35
|
result << ohsp_ds_id
|
35
36
|
ohsp_de_id = row[0]["UID"]
|
@@ -52,13 +53,13 @@ module EmrOhspInterface
|
|
52
53
|
data_set_id = data.first["Data Set ID"]
|
53
54
|
end
|
54
55
|
|
55
|
-
def generate_weekly_idsr_report()
|
56
|
+
def generate_weekly_idsr_report(request=nil,start_date=nil,end_date=nil)
|
56
57
|
|
57
58
|
diag_map = settings["weekly_idsr_map"]
|
58
59
|
|
59
60
|
epi_week = weeks_generator.last.first.strip
|
60
|
-
start_date = weeks_generator.last.last.split("to")[0].strip
|
61
|
-
end_date = weeks_generator.last.last.split("to")[1].strip
|
61
|
+
start_date = weeks_generator.last.last.split("to")[0].strip if start_date.nil?
|
62
|
+
end_date = weeks_generator.last.last.split("to")[1].strip if end_date.nil?
|
62
63
|
|
63
64
|
#pull the data
|
64
65
|
type = EncounterType.find_by_name 'Outpatient diagnosis'
|
@@ -89,11 +90,94 @@ module EmrOhspInterface
|
|
89
90
|
|
90
91
|
collection[key] = options
|
91
92
|
end
|
92
|
-
|
93
|
-
|
93
|
+
if request == nil
|
94
|
+
response = send_data(collection,"weekly")
|
95
|
+
end
|
96
|
+
return collection
|
94
97
|
end
|
98
|
+
#idsr monthly report
|
99
|
+
|
100
|
+
def generate_monthly_idsr_report(request=nil,start_date=nil,end_date=nil)
|
101
|
+
diag_map = settings["monthly_idsr_map"]
|
102
|
+
epi_month = months_generator.first.first.strip
|
103
|
+
start_date = months_generator.first.last[1].split("to").first.strip if start_date.nil?
|
104
|
+
end_date = months_generator.first.last[1].split("to").last.strip if end_date.nil?
|
105
|
+
type = EncounterType.find_by_name 'Outpatient diagnosis'
|
106
|
+
collection = {}
|
107
|
+
|
108
|
+
special_indicators = ["Malaria in Pregnancy","HIV New Initiated on ART"]
|
95
109
|
|
96
|
-
|
110
|
+
diag_map.each do |key,value|
|
111
|
+
options = {"<5yrs"=>nil,">=5yrs"=>nil}
|
112
|
+
concept_ids = ConceptName.where(name: value).collect{|cn| cn.concept_id}
|
113
|
+
if !special_indicators.include?(key)
|
114
|
+
data = Encounter.where('encounter_datetime BETWEEN ? AND ?
|
115
|
+
AND encounter_type = ? AND value_coded IN (?)
|
116
|
+
AND concept_id IN(6543, 6542)',
|
117
|
+
start_date.to_date.strftime('%Y-%m-%d 00:00:00'),
|
118
|
+
end_date.to_date.strftime('%Y-%m-%d 23:59:59'),type.id,concept_ids).\
|
119
|
+
joins('INNER JOIN obs ON obs.encounter_id = encounter.encounter_id
|
120
|
+
INNER JOIN person p ON p.person_id = encounter.patient_id').\
|
121
|
+
select('encounter.encounter_type, obs.value_coded, p.*')
|
122
|
+
|
123
|
+
#under_five
|
124
|
+
under_five = data.select{|record| calculate_age(record["birthdate"]) < 5}.\
|
125
|
+
collect{|record| record.person_id}
|
126
|
+
options["<5yrs"] = under_five
|
127
|
+
#above 5 years
|
128
|
+
over_five = data.select{|record| calculate_age(record["birthdate"]) >=5 }.\
|
129
|
+
collect{|record| record.person_id}
|
130
|
+
|
131
|
+
options[">=5yrs"] = over_five
|
132
|
+
|
133
|
+
collection[key] = options
|
134
|
+
else
|
135
|
+
if key.eql?("Malaria in Pregnancy")
|
136
|
+
mal_patient_id = Encounter.where('encounter_datetime BETWEEN ? AND ?
|
137
|
+
AND encounter_type = ? AND value_coded IN (?)
|
138
|
+
AND concept_id IN(6543, 6542)',
|
139
|
+
start_date.to_date.strftime('%Y-%m-%d 00:00:00'),
|
140
|
+
end_date.to_date.strftime('%Y-%m-%d 23:59:59'),type.id,concept_ids).\
|
141
|
+
joins('INNER JOIN obs ON obs.encounter_id = encounter.encounter_id
|
142
|
+
INNER JOIN person p ON p.person_id = encounter.patient_id').\
|
143
|
+
select('encounter.encounter_type, obs.value_coded, p.*')
|
144
|
+
|
145
|
+
mal_patient_id= mal_patient_id.collect{|record| record.person_id}
|
146
|
+
#find those that are pregnant
|
147
|
+
preg = Observation.where(["concept_id = 6131 AND obs_datetime
|
148
|
+
BETWEEN ? AND ? AND person_id IN(?)
|
149
|
+
AND value_coded =1065",
|
150
|
+
start_date.to_date.strftime('%Y-%m-%d 00:00:00'),
|
151
|
+
end_date.to_date.strftime('%Y-%m-%d 23:59:59'),mal_patient_id ])
|
152
|
+
|
153
|
+
options[">=5yrs"] = preg.collect{|record| record.person_id} rescue 0
|
154
|
+
collection[key] = options
|
155
|
+
end
|
156
|
+
|
157
|
+
if key.eql?("HIV New Initiated on ART")
|
158
|
+
data = ActiveRecord::Base.connection.select_all(
|
159
|
+
"SELECT * FROM temp_earliest_start_date
|
160
|
+
WHERE date_enrolled BETWEEN '#{start_date}' AND '#{end_date}'
|
161
|
+
AND date_enrolled = earliest_start_date
|
162
|
+
GROUP BY patient_id" ).to_hash
|
163
|
+
|
164
|
+
under_five = data.select{|record| calculate_age(record["birthdate"]) < 5 }.\
|
165
|
+
collect{|record| record["patient_id"]}
|
166
|
+
|
167
|
+
over_five = data.select{|record| calculate_age(record["birthdate"]) >=5 }.\
|
168
|
+
collect{|record| record["patient_id"]}
|
169
|
+
|
170
|
+
options["<5yrs"] = under_five
|
171
|
+
options[">=5yrs"] = over_five
|
172
|
+
|
173
|
+
collection[key] = options
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
if request == nil
|
178
|
+
response = send_data(collection,"monthly")
|
179
|
+
end
|
180
|
+
return collection
|
97
181
|
end
|
98
182
|
|
99
183
|
# helper menthod
|
@@ -160,24 +244,56 @@ module EmrOhspInterface
|
|
160
244
|
"orgUnit"=> get_ohsp_facility_id,
|
161
245
|
"dataValues"=> []
|
162
246
|
}
|
247
|
+
special = ["Severe Pneumonia in under 5 cases","Malaria in Pregnancy",
|
248
|
+
"Underweight Newborns < 2500g in Under 5 Cases","Diarrhoea In Under 5"]
|
163
249
|
|
164
250
|
data.each do |key,value|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
251
|
+
if !special.include?(key)
|
252
|
+
option1 = {"dataElement"=>get_ohsp_de_ids(key,type)[1],
|
253
|
+
"categoryOptionCombo"=> get_ohsp_de_ids(key,type)[2],
|
254
|
+
"value"=>value["<5yrs"].size }
|
255
|
+
|
256
|
+
option2 = {"dataElement"=>get_ohsp_de_ids(key,type)[1],
|
257
|
+
"categoryOptionCombo"=> get_ohsp_de_ids(key,type)[3],
|
258
|
+
"value"=>value[">=5yrs"].size}
|
259
|
+
|
260
|
+
#fill data values array
|
261
|
+
payload["dataValues"] << option1
|
262
|
+
payload["dataValues"] << option2
|
263
|
+
else
|
264
|
+
case key
|
265
|
+
when special[0]
|
266
|
+
option1 = {"dataElement"=>get_ohsp_de_ids(key,type)[1],
|
267
|
+
"categoryOptionCombo"=> get_ohsp_de_ids(key,type)[2],
|
268
|
+
"value"=>value["<5yrs"].size }
|
269
|
+
|
270
|
+
payload["dataValues"] << option1
|
271
|
+
when special[1]
|
272
|
+
option2 = {"dataElement"=>get_ohsp_de_ids(key,type)[1],
|
273
|
+
"categoryOptionCombo"=> get_ohsp_de_ids(key,type)[3],
|
274
|
+
"value"=>value[">=5yrs"].size }
|
275
|
+
|
276
|
+
payload["dataValues"] << option2
|
277
|
+
when special[2]
|
278
|
+
option1 = {"dataElement"=>get_ohsp_de_ids(key,type)[1],
|
279
|
+
"categoryOptionCombo"=> get_ohsp_de_ids(key,type)[2],
|
280
|
+
"value"=>value["<5yrs"].size }
|
281
|
+
|
282
|
+
payload["dataValues"] << option1
|
283
|
+
when special[3]
|
284
|
+
option1 = {"dataElement"=>get_ohsp_de_ids(key,type)[1],
|
285
|
+
"categoryOptionCombo"=> get_ohsp_de_ids(key,type)[2],
|
286
|
+
"value"=>value["<5yrs"].size}
|
287
|
+
|
288
|
+
payload["dataValues"] << option1
|
289
|
+
end
|
290
|
+
end
|
176
291
|
end
|
177
292
|
|
178
|
-
puts "now sending these values: #{payload.
|
293
|
+
puts "now sending these values: #{payload.to_json}"
|
179
294
|
url = "#{conn["url"]}/api/dataValueSets"
|
180
295
|
puts url
|
296
|
+
puts "pushing #{type} IDSR Reports"
|
181
297
|
send = RestClient::Request.execute(method: :post,
|
182
298
|
url: url,
|
183
299
|
headers:{'Content-Type'=> 'application/json'},
|
data/config/routes.rb
CHANGED
@@ -2,4 +2,6 @@ EmrOhspInterface::Engine.routes.draw do
|
|
2
2
|
resources :radiology, path: 'api/v1/emr_ohsp_interface'
|
3
3
|
get '/get_weeks', to: 'emr_ohsp_interface#weeks_generator'
|
4
4
|
get '/get_months', to: 'emr_ohsp_interface#months_generator'
|
5
|
+
get '/generate_weekly_idsr_report', to: 'emr_ohsp_interface#generate_weekly_idsr_report'
|
6
|
+
get '/generate_monthly_idsr_report', to: 'emr_ohsp_interface#generate_monthly_idsr_report'
|
5
7
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emr_ohsp_interface
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Manda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|