emr_ohsp_interface 1.2.0 → 1.2.1

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: 73b9145df1d352e5e6df1cbf8983b7a28a15a3a91cc86ee06341141fb0c0dfee
4
- data.tar.gz: 60069ab8d7ef564129e656e25bd41ba598639cdf07b4f90a317823e8ec9042ba
3
+ metadata.gz: d1e6d6f7ebf7f3796248658b85ab540fdd507feb8d59b502aab9093169b5e80e
4
+ data.tar.gz: fd72dd7ab7ff0887d5abf195d608d45e5e2b103176511ba652455d6166035bb5
5
5
  SHA512:
6
- metadata.gz: 84c0c258dd74dc53322b73b85b88fdef01232cf3fc76f6e989e25e0d141fc7a16a62386465a73471992222d2a7f2f37ce30c34198fb69f4535d9b8159b8b4369
7
- data.tar.gz: 7497b891e1aaa5715457509ed5606baa8af6df7b948a94c51ec855f4d9f0485f10999709b2c9162043ed477e562110565d3f546bb04872f070f3e9adb9004aa7
6
+ metadata.gz: cb9dfa0297d65a8bf726c551e7e206e63f2c1438aa5b36a475e82eb984fea37efd8742f4c3b7e6fe3b06541cb5a43a2f486592136e2776c1554176e4042c61b7
7
+ data.tar.gz: 7c9f18ac0f992341f4567ccb13721ce4a92c467fdcdb94afcc6c43766f1ef9a9f9753c57024286b73ca1922cb79c79af98aad500c4c0997a1017f8ec1295e3a4
@@ -443,13 +443,8 @@ module EmrOhspInterface
443
443
  end
444
444
 
445
445
  def generate_hmis_17_report(start_date=nil,end_date=nil)
446
-
447
446
  diag_map = settings["hmis_17_map"]
448
-
449
- #pull the data
450
- type = EncounterType.find_by_name 'Outpatient diagnosis'
451
447
  collection = {}
452
-
453
448
  special_indicators = [
454
449
  "Referals from other institutions",
455
450
  "OPD total attendance",
@@ -457,124 +452,68 @@ module EmrOhspInterface
457
452
  "Malaria 5 years and older - new",
458
453
  "HIV/AIDS - new"
459
454
  ]
460
-
461
455
  special_under_five_indicators = [
462
456
  "Measles under five years - new",
463
457
  "Pneumonia under 5 years- new",
464
458
  "Dysentery under 5 years - new",
465
459
  "Diarrhoea non - bloody -new cases (under5)",
466
- "Malaria under 5 years - new"
460
+ "Malaria under 5 years - new",
461
+ "Acute respiratory infections U5 - new"
467
462
  ]
468
463
 
469
- diag_map.each do |key,value|
470
- options = {"ids"=>nil}
471
- concept_ids = ConceptName.where(name: value).collect{|cn| cn.concept_id}
472
-
473
- if !special_indicators.include?(key) && !special_under_five_indicators.include?(key)
474
- data = Encounter.where('encounter_datetime BETWEEN ? AND ?
475
- AND encounter_type = ? AND value_coded IN (?)
476
- AND concept_id IN(6543, 6542)',
477
- start_date.to_date.strftime('%Y-%m-%d 00:00:00'),
478
- end_date.to_date.strftime('%Y-%m-%d 23:59:59'),type.id,concept_ids).\
479
- joins('INNER JOIN obs ON obs.encounter_id = encounter.encounter_id
480
- INNER JOIN person p ON p.person_id = encounter.patient_id').\
481
- select('encounter.encounter_type, obs.value_coded, p.*')
482
-
483
- all = data.collect{|record| record.person_id}
484
-
485
-
486
- options["ids"] = all
487
-
488
- collection[key] = options
489
- else
490
- if key.eql?("Referals from other institutions")
491
- _type = EncounterType.find_by_name 'PATIENT REGISTRATION'
492
- visit_type = ConceptName.find_by_name 'Type of visit'
493
-
494
- data = Encounter.where('encounter_datetime BETWEEN ? AND ?
495
- AND encounter_type = ? AND value_coded IS NOT NULL
496
- AND obs.concept_id = ?', start_date.to_date.strftime('%Y-%m-%d 00:00:00'),
497
- end_date.to_date.strftime('%Y-%m-%d 23:59:59'),_type.id, visit_type.concept_id).\
498
- joins('INNER JOIN obs ON obs.encounter_id = encounter.encounter_id
499
- INNER JOIN person p ON p.person_id = encounter.patient_id
500
- INNER JOIN concept_name c ON c.concept_id = 6541').\
501
- select('encounter.encounter_type, obs.value_coded, obs.obs_datetime, p.*, c.name visit_type').\
502
- group('p.person_id, encounter.encounter_id')
503
-
504
- all = data.collect{|record| record.person_id}
505
-
506
- options["ids"] = all
507
-
508
- collection[key] = options
509
- end
510
-
511
- if key.eql?("OPD total attendance")
512
- programID = Program.find_by_name 'OPD Program'
513
- data = Encounter.find_by_sql(
514
- "SELECT patient_id, DATE_FORMAT(encounter_datetime,'%Y-%m-%d') enc_date
515
- FROM encounter e
516
- LEFT OUTER JOIN person p ON p.person_id = e.patient_id
517
- WHERE e.voided = 0 AND encounter_datetime BETWEEN '" + start_date.to_date.strftime('%Y-%m-%d 00:00:00') +"'
518
- AND '" + end_date.to_date.strftime('%Y-%m-%d 23:59:59') + "'
519
- AND program_id ='" + programID.program_id.to_s + "'
520
- GROUP BY enc_date"
521
- ).map{|e| e. patient_id}
522
464
 
523
- options["ids"] = data
524
- collection[key] = options
525
- end
526
-
527
- if key.eql?("Referal to other institutions")
528
- data = Observation.where("obs_datetime BETWEEN ? AND ?
529
- AND concept_id = ?",start_date.to_date.strftime('%Y-%m-%d 00:00:00'),
530
- end_date.to_date.strftime('%Y-%m-%d 23:59:59'),'7414').\
531
- joins('LEFT JOIN location l ON l.location_id = obs.value_text').\
532
- select('obs.person_id').order('obs_datetime DESC')
533
- all = data.collect{|record| record.person_id}
534
- options["ids"] = all
535
- collection[key] = options
536
- end
537
-
538
- if key.eql?("HIV/AIDS - new")
539
- data = ActiveRecord::Base.connection.select_all(
540
- "SELECT * FROM temp_earliest_start_date
541
- WHERE date_enrolled BETWEEN '#{start_date}' AND '#{end_date}'
542
- AND date_enrolled = earliest_start_date
543
- GROUP BY patient_id" ).to_hash
544
- all = data.collect{|record| record["patient_id"]}
545
- options["ids"] = all
546
- collection[key] = options
547
- end
548
-
549
- if key.eql?("Measles under five years - new")
550
- collection[key] = disaggregate('less',concept_ids, start_date, end_date, type)
551
- end
552
-
553
- if key.eql?("Pneumonia under 5 years- new")
554
- collection[key] = disaggregate('less', concept_ids, start_date, end_date, type)
555
- end
556
-
557
- if key.eql?("Malaria under 5 years - new")
558
- collection[key] = disaggregate('less', concept_ids, start_date, end_date, type)
559
- end
560
-
561
- if key.eql?("Malaria 5 years and older - new")
562
- collection[key] = disaggregate('greater',concept_ids, start_date, end_date, type)
563
- end
564
-
565
- if key.eql?("Dysentery under 5 years - new")
566
- collection[key] = disaggregate('less', concept_ids, start_date, end_date, type)
465
+ reg_data = registration_report(start_date,end_date)
466
+
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
567
483
  end
568
-
569
- if key.eql?("Diarrhoea non - bloody -new cases (under5)")
570
- collection[key] = disaggregate('less', concept_ids, start_date, end_date, type)
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
571
497
  end
572
-
573
498
  end
574
- end
575
-
576
- collection
499
+ collection
500
+ end
577
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
578
517
  end
579
518
 
580
519
  def generate_notifiable_disease_conditions_report(start_date=nil,end_date=nil)
@@ -1,3 +1,3 @@
1
1
  module EmrOhspInterface
2
- VERSION = '1.2.0'
2
+ VERSION = '1.2.1'
3
3
  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: 1.2.0
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: 2023-01-15 00:00:00.000000000 Z
11
+ date: 2023-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -72,26 +72,6 @@ dependencies:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
- - !ruby/object:Gem::Dependency
76
- name: sqlite3
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- version: 1.3.6
82
- - - "~>"
83
- - !ruby/object:Gem::Version
84
- version: '1.3'
85
- type: :development
86
- prerelease: false
87
- version_requirements: !ruby/object:Gem::Requirement
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- version: 1.3.6
92
- - - "~>"
93
- - !ruby/object:Gem::Version
94
- version: '1.3'
95
75
  description:
96
76
  email:
97
77
  - justinmandah@gmail.com, kayangepetros@gmail.com, dominickasanga@gmail.com
@@ -140,8 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
120
  - !ruby/object:Gem::Version
141
121
  version: '0'
142
122
  requirements: []
143
- rubyforge_project:
144
- rubygems_version: 2.7.6
123
+ rubygems_version: 3.0.9
145
124
  signing_key:
146
125
  specification_version: 4
147
126
  summary: This in a gem that facilitates interfacing of EMR, One Health Surveillance