emr_ohsp_interface 0.5.2 → 1.0.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 615b6608b86d4635ef984daf489d23fd7d2eda027ceba04df262593e03dc8abf
|
4
|
+
data.tar.gz: 3862e0ce3eb31e36b386c1be405fc840f67ed33b57e953d6f4e42d857f86230b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af1d17bb456373feed6325bb5b7168d1f980e8c33fe1b918b638da1b78d229ba564c1623fcc4a9e4ef1ad16feb5d737adf2a38fd93f949763ff18634e082b389
|
7
|
+
data.tar.gz: 9b29acf9e63db3bfec739df4add596c2f4e61f53d6f576d3af1018d80eaaedd749adf17d994c90a2daddadf636c9c0982acebfda1e86cf63891aca99c32e6c4c
|
@@ -5,6 +5,7 @@ module EmrOhspInterface
|
|
5
5
|
class << self
|
6
6
|
require 'csv'
|
7
7
|
require 'rest-client'
|
8
|
+
require 'json'
|
8
9
|
def settings
|
9
10
|
file = File.read(Rails.root.join("db","idsr_metadata","idsr_ohsp_settings.json"))
|
10
11
|
config = JSON.parse(file)
|
@@ -93,10 +94,11 @@ module EmrOhspInterface
|
|
93
94
|
if request == nil
|
94
95
|
response = send_data(collection,"weekly")
|
95
96
|
end
|
97
|
+
|
96
98
|
return collection
|
97
99
|
end
|
98
|
-
#idsr monthly report
|
99
100
|
|
101
|
+
#idsr monthly report
|
100
102
|
def generate_monthly_idsr_report(request=nil,start_date=nil,end_date=nil)
|
101
103
|
diag_map = settings["monthly_idsr_map"]
|
102
104
|
epi_month = months_generator.first.first.strip
|
@@ -105,7 +107,12 @@ module EmrOhspInterface
|
|
105
107
|
type = EncounterType.find_by_name 'Outpatient diagnosis'
|
106
108
|
collection = {}
|
107
109
|
|
108
|
-
special_indicators = ["Malaria in Pregnancy",
|
110
|
+
special_indicators = ["Malaria in Pregnancy",
|
111
|
+
"HIV New Initiated on ART",
|
112
|
+
"Diarrhoea In Under 5",
|
113
|
+
"Malnutrition In Under 5",
|
114
|
+
"Underweight Newborns < 2500g in Under 5 Cases",
|
115
|
+
"Severe Pneumonia in under 5 cases"]
|
109
116
|
|
110
117
|
diag_map.each do |key,value|
|
111
118
|
options = {"<5yrs"=>nil,">=5yrs"=>nil}
|
@@ -172,6 +179,76 @@ module EmrOhspInterface
|
|
172
179
|
|
173
180
|
collection[key] = options
|
174
181
|
end
|
182
|
+
|
183
|
+
if key.eql?("Diarrhoea In Under 5")
|
184
|
+
data = Encounter.where('encounter_datetime BETWEEN ? AND ?
|
185
|
+
AND encounter_type = ? AND value_coded IN (?)
|
186
|
+
AND concept_id IN(6543, 6542)',
|
187
|
+
start_date.to_date.strftime('%Y-%m-%d 00:00:00'),
|
188
|
+
end_date.to_date.strftime('%Y-%m-%d 23:59:59'),type.id,concept_ids).\
|
189
|
+
joins('INNER JOIN obs ON obs.encounter_id = encounter.encounter_id
|
190
|
+
INNER JOIN person p ON p.person_id = encounter.patient_id').\
|
191
|
+
select('encounter.encounter_type, obs.value_coded, p.*')
|
192
|
+
|
193
|
+
#under_five
|
194
|
+
under_five = data.select{|record| calculate_age(record["birthdate"]) < 5}.\
|
195
|
+
collect{|record| record.person_id}
|
196
|
+
options["<5yrs"] = under_five
|
197
|
+
collection[key] = options
|
198
|
+
end
|
199
|
+
|
200
|
+
|
201
|
+
if key.eql?("Malnutrition In Under 5")
|
202
|
+
data = Encounter.where('encounter_datetime BETWEEN ? AND ?
|
203
|
+
AND encounter_type = ? AND value_coded IN (?)
|
204
|
+
AND concept_id IN(6543, 6542)',
|
205
|
+
start_date.to_date.strftime('%Y-%m-%d 00:00:00'),
|
206
|
+
end_date.to_date.strftime('%Y-%m-%d 23:59:59'),type.id,concept_ids).\
|
207
|
+
joins('INNER JOIN obs ON obs.encounter_id = encounter.encounter_id
|
208
|
+
INNER JOIN person p ON p.person_id = encounter.patient_id').\
|
209
|
+
select('encounter.encounter_type, obs.value_coded, p.*')
|
210
|
+
|
211
|
+
#under_five
|
212
|
+
under_five = data.select{|record| calculate_age(record["birthdate"]) < 5}.\
|
213
|
+
collect{|record| record.person_id}
|
214
|
+
options["<5yrs"] = under_five
|
215
|
+
collection[key] = options
|
216
|
+
end
|
217
|
+
|
218
|
+
|
219
|
+
if key.eql?("Underweight Newborns < 2500g in Under 5 Cases")
|
220
|
+
data = Encounter.where('encounter_datetime BETWEEN ? AND ?
|
221
|
+
AND encounter_type = ? AND value_coded IN (?)
|
222
|
+
AND concept_id IN(6543, 6542)',
|
223
|
+
start_date.to_date.strftime('%Y-%m-%d 00:00:00'),
|
224
|
+
end_date.to_date.strftime('%Y-%m-%d 23:59:59'),type.id,concept_ids).\
|
225
|
+
joins('INNER JOIN obs ON obs.encounter_id = encounter.encounter_id
|
226
|
+
INNER JOIN person p ON p.person_id = encounter.patient_id').\
|
227
|
+
select('encounter.encounter_type, obs.value_coded, p.*')
|
228
|
+
|
229
|
+
#under_five
|
230
|
+
under_five = data.select{|record| calculate_age(record["birthdate"]) < 5}.\
|
231
|
+
collect{|record| record.person_id}
|
232
|
+
options["<5yrs"] = under_five
|
233
|
+
collection[key] = options
|
234
|
+
end
|
235
|
+
|
236
|
+
if key.eql?("Severe Pneumonia in under 5 cases")
|
237
|
+
data = Encounter.where('encounter_datetime BETWEEN ? AND ?
|
238
|
+
AND encounter_type = ? AND value_coded IN (?)
|
239
|
+
AND concept_id IN(6543, 6542)',
|
240
|
+
start_date.to_date.strftime('%Y-%m-%d 00:00:00'),
|
241
|
+
end_date.to_date.strftime('%Y-%m-%d 23:59:59'),type.id,concept_ids).\
|
242
|
+
joins('INNER JOIN obs ON obs.encounter_id = encounter.encounter_id
|
243
|
+
INNER JOIN person p ON p.person_id = encounter.patient_id').\
|
244
|
+
select('encounter.encounter_type, obs.value_coded, p.*')
|
245
|
+
|
246
|
+
#under_five
|
247
|
+
under_five = data.select{|record| calculate_age(record["birthdate"]) < 5}.\
|
248
|
+
collect{|record| record.person_id}
|
249
|
+
options["<5yrs"] = under_five
|
250
|
+
collection[key] = options
|
251
|
+
end
|
175
252
|
end
|
176
253
|
end
|
177
254
|
if request == nil
|
@@ -280,6 +357,47 @@ module EmrOhspInterface
|
|
280
357
|
collection
|
281
358
|
end
|
282
359
|
|
360
|
+
def generate_notifiable_disease_conditions_report(start_date=nil,end_date=nil)
|
361
|
+
diag_map = settings["notifiable_disease_conditions"]
|
362
|
+
|
363
|
+
start_date = Date.today.strftime("%Y-%m-%d") if start_date.nil?
|
364
|
+
end_date = Date.today.strftime("%Y-%m-%d") if end_date.nil?
|
365
|
+
|
366
|
+
type = EncounterType.find_by_name 'Outpatient diagnosis'
|
367
|
+
collection = {}
|
368
|
+
concept_name_for_sms_portal = {}
|
369
|
+
|
370
|
+
diag_map.each do |key,value|
|
371
|
+
options = {"<5yrs"=>nil,">=5yrs"=>nil}
|
372
|
+
concept_ids = ConceptName.where(name: value).collect{|cn| cn.concept_id}
|
373
|
+
|
374
|
+
data = Encounter.where('encounter_datetime BETWEEN ? AND ?
|
375
|
+
AND encounter_type = ? AND value_coded IN (?)
|
376
|
+
AND concept_id IN(6543, 6542)',
|
377
|
+
start_date.to_date.strftime('%Y-%m-%d 00:00:00'),
|
378
|
+
end_date.to_date.strftime('%Y-%m-%d 23:59:59'),type.id,concept_ids).\
|
379
|
+
joins('INNER JOIN obs ON obs.encounter_id = encounter.encounter_id
|
380
|
+
INNER JOIN person p ON p.person_id = encounter.patient_id').\
|
381
|
+
select('encounter.encounter_type, obs.value_coded, p.*')
|
382
|
+
|
383
|
+
#under_five
|
384
|
+
under_five = data.select{|record| calculate_age(record["birthdate"]) < 5}.\
|
385
|
+
collect{|record| record.person_id}
|
386
|
+
options["<5yrs"] = under_five
|
387
|
+
#above 5 years
|
388
|
+
over_five = data.select{|record| calculate_age(record["birthdate"]) >=5 }.\
|
389
|
+
collect{|record| record.person_id}
|
390
|
+
|
391
|
+
options[">=5yrs"] = over_five
|
392
|
+
|
393
|
+
collection[key] = options
|
394
|
+
|
395
|
+
concept_name_for_sms_portal[key] = concept_ids
|
396
|
+
end
|
397
|
+
send_data_to_sms_portal(collection, concept_name_for_sms_portal)
|
398
|
+
return collection
|
399
|
+
end
|
400
|
+
|
283
401
|
# helper menthod
|
284
402
|
def months_generator
|
285
403
|
months = Hash.new
|
@@ -351,11 +469,11 @@ module EmrOhspInterface
|
|
351
469
|
if !special.include?(key)
|
352
470
|
option1 = {"dataElement"=>get_ohsp_de_ids(key,type)[1],
|
353
471
|
"categoryOptionCombo"=> get_ohsp_de_ids(key,type)[2],
|
354
|
-
"value"=>value["<5yrs"].size }
|
472
|
+
"value"=>value["<5yrs"].size } rescue {}
|
355
473
|
|
356
474
|
option2 = {"dataElement"=>get_ohsp_de_ids(key,type)[1],
|
357
475
|
"categoryOptionCombo"=> get_ohsp_de_ids(key,type)[3],
|
358
|
-
"value"=>value[">=5yrs"].size}
|
476
|
+
"value"=>value[">=5yrs"].size} rescue {}
|
359
477
|
|
360
478
|
#fill data values array
|
361
479
|
payload["dataValues"] << option1
|
@@ -365,25 +483,25 @@ module EmrOhspInterface
|
|
365
483
|
when special[0]
|
366
484
|
option1 = {"dataElement"=>get_ohsp_de_ids(key,type)[1],
|
367
485
|
"categoryOptionCombo"=> get_ohsp_de_ids(key,type)[2],
|
368
|
-
"value"=>value["<5yrs"].size }
|
486
|
+
"value"=>value["<5yrs"].size } rescue {}
|
369
487
|
|
370
488
|
payload["dataValues"] << option1
|
371
489
|
when special[1]
|
372
490
|
option2 = {"dataElement"=>get_ohsp_de_ids(key,type)[1],
|
373
491
|
"categoryOptionCombo"=> get_ohsp_de_ids(key,type)[3],
|
374
|
-
"value"=>value[">=5yrs"].size }
|
492
|
+
"value"=>value[">=5yrs"].size } rescue {}
|
375
493
|
|
376
494
|
payload["dataValues"] << option2
|
377
495
|
when special[2]
|
378
496
|
option1 = {"dataElement"=>get_ohsp_de_ids(key,type)[1],
|
379
497
|
"categoryOptionCombo"=> get_ohsp_de_ids(key,type)[2],
|
380
|
-
"value"=>value["<5yrs"].size }
|
498
|
+
"value"=>value["<5yrs"].size } rescue {}
|
381
499
|
|
382
500
|
payload["dataValues"] << option1
|
383
501
|
when special[3]
|
384
502
|
option1 = {"dataElement"=>get_ohsp_de_ids(key,type)[1],
|
385
503
|
"categoryOptionCombo"=> get_ohsp_de_ids(key,type)[2],
|
386
|
-
"value"=>value["<5yrs"].size}
|
504
|
+
"value"=>value["<5yrs"].size} rescue {}
|
387
505
|
|
388
506
|
payload["dataValues"] << option1
|
389
507
|
end
|
@@ -405,8 +523,41 @@ module EmrOhspInterface
|
|
405
523
|
puts send
|
406
524
|
end
|
407
525
|
|
526
|
+
def send_data_to_sms_portal(data, concept_name_collection)
|
527
|
+
conn2 = settings["sms_server"]
|
528
|
+
data = data.select {|k,v| v.select {|kk,vv| vv.length > 0}.length > 0}
|
529
|
+
payload = {
|
530
|
+
"email"=> conn2["user"],
|
531
|
+
"password" => conn2["pass"],
|
532
|
+
"emr_facility_id" => Location.current_health_center.id,
|
533
|
+
"emr_facility_name" => Location.current_health_center.name,
|
534
|
+
"payload" => data,
|
535
|
+
"concept_name_collection" => concept_name_collection
|
536
|
+
}
|
537
|
+
|
538
|
+
|
539
|
+
|
540
|
+
begin
|
541
|
+
response = RestClient::Request.execute(method: :post,
|
542
|
+
url: conn2["url"],
|
543
|
+
headers:{'Content-Type'=> 'application/json'},
|
544
|
+
payload: payload.to_json
|
545
|
+
)
|
546
|
+
rescue RestClient::ExceptionWithResponse => res
|
547
|
+
if res.class == RestClient::Forbidden
|
548
|
+
puts "error: #{res.class}"
|
549
|
+
end
|
550
|
+
end
|
551
|
+
|
552
|
+
if response.class != NilClass
|
553
|
+
if response.code == 200
|
554
|
+
puts "success: #{response}"
|
555
|
+
end
|
556
|
+
end
|
557
|
+
|
558
|
+
end
|
559
|
+
|
408
560
|
end
|
409
561
|
end
|
410
562
|
|
411
|
-
|
412
563
|
end
|
data/config/routes.rb
CHANGED
@@ -6,4 +6,12 @@ EmrOhspInterface::Engine.routes.draw do
|
|
6
6
|
get '/generate_weekly_idsr_report', to: 'emr_ohsp_interface#generate_weekly_idsr_report'
|
7
7
|
get '/generate_monthly_idsr_report', to: 'emr_ohsp_interface#generate_monthly_idsr_report'
|
8
8
|
get '/generate_hmis_15_report', to: 'emr_ohsp_interface#generate_hmis_15_report'
|
9
|
+
|
10
|
+
# for the new crossplatform OPD system
|
11
|
+
get 'api/v1/get_lims_user', to: 'emr_lims_interface#get_user_info'
|
12
|
+
get 'api/v1/get_weeks', to: 'emr_ohsp_interface#weeks_generator'
|
13
|
+
get 'api/v1/get_months', to: 'emr_ohsp_interface#months_generator'
|
14
|
+
get 'api/v1/generate_weekly_idsr_report', to: 'emr_ohsp_interface#generate_weekly_idsr_report'
|
15
|
+
get 'api/v1/generate_monthly_idsr_report', to: 'emr_ohsp_interface#generate_monthly_idsr_report'
|
16
|
+
get 'api/v1/generate_hmis_15_report', to: 'emr_ohsp_interface#generate_hmis_15_report'
|
9
17
|
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: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Manda and Petros Kayange
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
- !ruby/object:Gem::Version
|
121
121
|
version: '0'
|
122
122
|
requirements: []
|
123
|
-
rubygems_version: 3.
|
123
|
+
rubygems_version: 3.0.9
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
126
|
summary: This in a gem that facilitates interfacing of EMR, One Health Surveillance
|