emr_ohsp_interface 1.1.0 → 1.2.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: d1e6d6f7ebf7f3796248658b85ab540fdd507feb8d59b502aab9093169b5e80e
|
4
|
+
data.tar.gz: fd72dd7ab7ff0887d5abf195d608d45e5e2b103176511ba652455d6166035bb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb9dfa0297d65a8bf726c551e7e206e63f2c1438aa5b36a475e82eb984fea37efd8742f4c3b7e6fe3b06541cb5a43a2f486592136e2776c1554176e4042c61b7
|
7
|
+
data.tar.gz: 7c9f18ac0f992341f4567ccb13721ce4a92c467fdcdb94afcc6c43766f1ef9a9f9753c57024286b73ca1922cb79c79af98aad500c4c0997a1017f8ec1295e3a4
|
@@ -11,6 +11,10 @@ module EmrOhspInterface
|
|
11
11
|
config = JSON.parse(file)
|
12
12
|
end
|
13
13
|
|
14
|
+
def server_config
|
15
|
+
config =YAML.load_file("#{Rails.root}/config/application.yml")
|
16
|
+
end
|
17
|
+
|
14
18
|
def get_ohsp_facility_id
|
15
19
|
file = File.open(Rails.root.join("db","idsr_metadata","emr_ohsp_facility_map.csv"))
|
16
20
|
data = CSV.parse(file,headers: true)
|
@@ -129,11 +133,11 @@ module EmrOhspInterface
|
|
129
133
|
|
130
134
|
#under_five
|
131
135
|
under_five = data.select{|record| calculate_age(record["birthdate"]) < 5}.\
|
132
|
-
collect{|record| record.person_id}
|
136
|
+
collect{|record| record.person_id}.uniq
|
133
137
|
options["<5yrs"] = under_five
|
134
138
|
#above 5 years
|
135
139
|
over_five = data.select{|record| calculate_age(record["birthdate"]) >=5 }.\
|
136
|
-
collect{|record| record.person_id}
|
140
|
+
collect{|record| record.person_id}.uniq
|
137
141
|
|
138
142
|
options[">=5yrs"] = over_five
|
139
143
|
|
@@ -439,138 +443,77 @@ module EmrOhspInterface
|
|
439
443
|
end
|
440
444
|
|
441
445
|
def generate_hmis_17_report(start_date=nil,end_date=nil)
|
442
|
-
|
443
446
|
diag_map = settings["hmis_17_map"]
|
444
|
-
|
445
|
-
#pull the data
|
446
|
-
type = EncounterType.find_by_name 'Outpatient diagnosis'
|
447
447
|
collection = {}
|
448
|
-
|
449
448
|
special_indicators = [
|
450
449
|
"Referals from other institutions",
|
451
450
|
"OPD total attendance",
|
452
451
|
"Referal to other institutions",
|
453
|
-
"Malaria 5 years and older - new"
|
452
|
+
"Malaria 5 years and older - new",
|
453
|
+
"HIV/AIDS - new"
|
454
454
|
]
|
455
|
-
|
456
455
|
special_under_five_indicators = [
|
457
456
|
"Measles under five years - new",
|
458
457
|
"Pneumonia under 5 years- new",
|
459
458
|
"Dysentery under 5 years - new",
|
460
459
|
"Diarrhoea non - bloody -new cases (under5)",
|
461
|
-
"Malaria under 5 years - new"
|
460
|
+
"Malaria under 5 years - new",
|
461
|
+
"Acute respiratory infections U5 - new"
|
462
462
|
]
|
463
463
|
|
464
|
-
|
465
|
-
|
466
|
-
concept_ids = ConceptName.where(name: value).collect{|cn| cn.concept_id}
|
467
|
-
|
468
|
-
if !special_indicators.include?(key) && !special_under_five_indicators.include?(key)
|
469
|
-
data = Encounter.where('encounter_datetime BETWEEN ? AND ?
|
470
|
-
AND encounter_type = ? AND value_coded IN (?)
|
471
|
-
AND concept_id IN(6543, 6542)',
|
472
|
-
start_date.to_date.strftime('%Y-%m-%d 00:00:00'),
|
473
|
-
end_date.to_date.strftime('%Y-%m-%d 23:59:59'),type.id,concept_ids).\
|
474
|
-
joins('INNER JOIN obs ON obs.encounter_id = encounter.encounter_id
|
475
|
-
INNER JOIN person p ON p.person_id = encounter.patient_id').\
|
476
|
-
select('encounter.encounter_type, obs.value_coded, p.*')
|
477
|
-
|
478
|
-
all = data.collect{|record| record.person_id}
|
479
|
-
|
480
|
-
|
481
|
-
options["ids"] = all
|
482
|
-
|
483
|
-
collection[key] = options
|
484
|
-
else
|
485
|
-
if key.eql?("Referals from other institutions")
|
486
|
-
_type = EncounterType.find_by_name 'PATIENT REGISTRATION'
|
487
|
-
visit_type = ConceptName.find_by_name 'Type of visit'
|
488
|
-
|
489
|
-
data = Encounter.where('encounter_datetime BETWEEN ? AND ?
|
490
|
-
AND encounter_type = ? AND value_coded IS NOT NULL
|
491
|
-
AND obs.concept_id = ?', start_date.to_date.strftime('%Y-%m-%d 00:00:00'),
|
492
|
-
end_date.to_date.strftime('%Y-%m-%d 23:59:59'),_type.id, visit_type.concept_id).\
|
493
|
-
joins('INNER JOIN obs ON obs.encounter_id = encounter.encounter_id
|
494
|
-
INNER JOIN person p ON p.person_id = encounter.patient_id
|
495
|
-
INNER JOIN concept_name c ON c.concept_id = 6541').\
|
496
|
-
select('encounter.encounter_type, obs.value_coded, obs.obs_datetime, p.*, c.name visit_type').\
|
497
|
-
group('p.person_id, encounter.encounter_id')
|
498
|
-
|
499
|
-
all = data.collect{|record| record.person_id}
|
500
|
-
|
501
|
-
options["ids"] = all
|
502
|
-
|
503
|
-
collection[key] = options
|
504
|
-
end
|
505
|
-
|
506
|
-
if key.eql?("OPD total attendance")
|
507
|
-
_type = EncounterType.find_by_name 'PATIENT REGISTRATION'
|
508
|
-
visit_type = ConceptName.find_by_name 'Type of visit'
|
464
|
+
|
465
|
+
reg_data = registration_report(start_date,end_date)
|
509
466
|
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
options["ids"] = all
|
527
|
-
|
528
|
-
collection[key] = options
|
529
|
-
end
|
530
|
-
|
531
|
-
if key.eql?("Referal to other institutions")
|
532
|
-
data = Observation.where("obs_datetime BETWEEN ? AND ?
|
533
|
-
AND concept_id = ?",start_date.to_date.strftime('%Y-%m-%d 00:00:00'),
|
534
|
-
end_date.to_date.strftime('%Y-%m-%d 23:59:59'),'7414').\
|
535
|
-
joins('LEFT JOIN location l ON l.location_id = obs.value_text').\
|
536
|
-
select('obs.person_id').order('obs_datetime DESC')
|
537
|
-
|
538
|
-
all = data.collect{|record| record.person_id}
|
539
|
-
|
540
|
-
options["ids"] = all
|
541
|
-
|
542
|
-
collection[key] = options
|
543
|
-
end
|
544
|
-
|
545
|
-
if key.eql?("Measles under five years - new")
|
546
|
-
collection[key] = disaggregate('less',concept_ids, start_date, end_date, type)
|
547
|
-
end
|
548
|
-
|
549
|
-
if key.eql?("Pneumonia under 5 years- new")
|
550
|
-
collection[key] = disaggregate('less', concept_ids, start_date, end_date, type)
|
551
|
-
end
|
552
|
-
|
553
|
-
if key.eql?("Malaria under 5 years - new")
|
554
|
-
collection[key] = disaggregate('less', concept_ids, start_date, end_date, type)
|
555
|
-
end
|
556
|
-
|
557
|
-
if key.eql?("Malaria 5 years and older - new")
|
558
|
-
collection[key] = disaggregate('greater',concept_ids, start_date, end_date, type)
|
559
|
-
end
|
560
|
-
|
561
|
-
if key.eql?("Dysentery under 5 years - new")
|
562
|
-
collection[key] = disaggregate('less', concept_ids, start_date, end_date, type)
|
467
|
+
data =Observation.where("obs_datetime BETWEEN ? AND ? AND c.voided = ? AND obs.concept_id IN (?) ",
|
468
|
+
start_date.to_date.strftime('%Y-%m-%d 00:00:00'), end_date.to_date.strftime('%Y-%m-%d 23:59:59'),0, [6543, 6542]).\
|
469
|
+
joins('INNER JOIN concept_name c ON c.concept_id = obs.value_coded
|
470
|
+
INNER JOIN person p ON p.person_id = obs.person_id').\
|
471
|
+
pluck("c.name, CASE WHEN (SELECT timestampdiff(year, birthdate, '#{end_date.to_date.strftime('%Y-%m-%d')}')) >= 5 THEN 'more_than_5'
|
472
|
+
ELSE 'less_than_5' END AS age_group,p.person_id").group_by(&:shift)
|
473
|
+
|
474
|
+
diag_map.each do |key, value|
|
475
|
+
collection[key] = { "ids" => [] }
|
476
|
+
if key.eql?("OPD total attendance")
|
477
|
+
collection[key]["ids"] = reg_data.map { |item| item[1] }
|
478
|
+
else
|
479
|
+
if key.eql?("Referals from other institutions")
|
480
|
+
reg_data = reg_data.rows.group_by(&:shift)
|
481
|
+
collection[key]["ids"]= reg_data['Referral'].flatten
|
482
|
+
end
|
563
483
|
end
|
564
|
-
|
565
|
-
|
566
|
-
|
484
|
+
data.each do |phrase, counts|
|
485
|
+
next unless value.include?(phrase)
|
486
|
+
|
487
|
+
counts.each do |label, count|
|
488
|
+
if !key.eql?("Malaria 5 years and older - new") && !special_under_five_indicators.include?(key)
|
489
|
+
collection[key]["ids"] << count
|
490
|
+
else
|
491
|
+
if ((special_under_five_indicators.include?(key) && label.eql?("less_than_5")) ||
|
492
|
+
(key.eql?("Malaria 5 years and older - new") && label.eql?("more_than_5")))
|
493
|
+
collection[key]["ids"] << count
|
494
|
+
end
|
495
|
+
end
|
496
|
+
end
|
567
497
|
end
|
568
|
-
|
569
498
|
end
|
570
|
-
|
571
|
-
|
572
|
-
collection
|
499
|
+
collection
|
500
|
+
end
|
573
501
|
|
502
|
+
def registration_report(start_date=nil,end_date=nil)
|
503
|
+
ActiveRecord::Base.connection.select_all <<~SQL
|
504
|
+
SELECT
|
505
|
+
c.name AS visit_type,
|
506
|
+
obs.person_id
|
507
|
+
FROM `encounter`
|
508
|
+
LEFT JOIN obs ON obs.encounter_id = encounter.encounter_id AND obs.voided = 0
|
509
|
+
LEFT JOIN concept_name c ON c.concept_id = obs.value_coded
|
510
|
+
AND c.name IN ('New patient','Revisiting','Referral') AND c.voided = 0
|
511
|
+
WHERE
|
512
|
+
encounter.voided = 0
|
513
|
+
AND DATE(encounter_datetime) BETWEEN '#{start_date}' AND '#{end_date}'
|
514
|
+
AND encounter.program_id = 14 -- OPD program
|
515
|
+
GROUP BY encounter.patient_id, DATE(encounter_datetime);
|
516
|
+
SQL
|
574
517
|
end
|
575
518
|
|
576
519
|
def generate_notifiable_disease_conditions_report(start_date=nil,end_date=nil)
|
@@ -632,7 +575,7 @@ module EmrOhspInterface
|
|
632
575
|
def weeks_generator
|
633
576
|
|
634
577
|
weeks = Hash.new
|
635
|
-
first_day = (
|
578
|
+
first_day = (Date.today - (11).month).at_beginning_of_month
|
636
579
|
wk_of_first_day = first_day.cweek
|
637
580
|
|
638
581
|
if wk_of_first_day > 1
|
@@ -671,7 +614,7 @@ module EmrOhspInterface
|
|
671
614
|
def send_data(data,type)
|
672
615
|
# method used to post data to the server
|
673
616
|
#prepare payload here
|
674
|
-
conn =
|
617
|
+
conn = server_config['ohsp']
|
675
618
|
payload = {
|
676
619
|
"dataSet" =>get_data_set_id(type),
|
677
620
|
"period"=>(type.eql?("weekly") ? weeks_generator.last[0] : months_generator.first[0]),
|
@@ -733,18 +676,18 @@ module EmrOhspInterface
|
|
733
676
|
headers:{'Content-Type'=> 'application/json'},
|
734
677
|
payload: payload.to_json,
|
735
678
|
#headers: {accept: :json},
|
736
|
-
user: conn["
|
737
|
-
password: conn["
|
679
|
+
user: conn["username"],
|
680
|
+
password: conn["password"])
|
738
681
|
|
739
682
|
puts send
|
740
683
|
end
|
741
684
|
|
742
685
|
def send_data_to_sms_portal(data, concept_name_collection)
|
743
|
-
conn2 =
|
686
|
+
conn2 = server_config['idsr_sms']
|
744
687
|
data = data.select {|k,v| v.select {|kk,vv| vv.length > 0}.length > 0}
|
745
688
|
payload = {
|
746
|
-
"email"=> conn2["
|
747
|
-
"password" => conn2["
|
689
|
+
"email"=> conn2["username"],
|
690
|
+
"password" => conn2["password"],
|
748
691
|
"emr_facility_id" => Location.current_health_center.id,
|
749
692
|
"emr_facility_name" => Location.current_health_center.name,
|
750
693
|
"payload" => data,
|
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: 1.1
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Manda, Petros Kayange, and Dominic Kasanga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|