emr_ohsp_interface 1.2.2 → 2.2.0

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: be2ba0df688b91d1575492fa6baaf5c9e89a80f6b364eb92e100268e717260fb
4
- data.tar.gz: 70ea97490458b7f611e558a59000dbf9c7987154cdadb581bf1f2935e7adf5c2
3
+ metadata.gz: 1c906580f753b4ecd4247310a6e86515ba23ac8f34a022d17c2d133eb8e35ce8
4
+ data.tar.gz: 0343e303c83d845d8e6764797157e056fdc4a34d3060e28d0978b80c32ed292a
5
5
  SHA512:
6
- metadata.gz: 963c904f3a7e1cdaa64ac8c9df78a3ff0746c272796871bfde4e525084d4698ceb1c9fc8c36b2fca009f0784f534da87fa24077c66f095d9662047c90ee3d07e
7
- data.tar.gz: 6d33652b469e327a19c3b3fa28ad7837598f62470d3baef1c6007d30574ad2fb25045a2cbba6e76980f97de726bbffd25d48307536070a870903942e410a4b1a
6
+ metadata.gz: 363dcd8068deb4bab8a6ce38463a173e7e32ea958eb0699fae6c9f8a9685ade0d5248227fd7584a3d562462941e6c270a40585aab5621faa7efee3b04191a8df
7
+ data.tar.gz: 447c8cbb8205eac3365d78b7105674829888ae55c8de36dbf4e4fdb917735ec0263db733d601ec5c10f55237b92b45c52f8f2fee5a956355ddca7473d7baea17
@@ -443,8 +443,13 @@ module EmrOhspInterface
443
443
  end
444
444
 
445
445
  def generate_hmis_17_report(start_date=nil,end_date=nil)
446
+
446
447
  diag_map = settings["hmis_17_map"]
448
+
449
+ #pull the data
450
+ type = EncounterType.find_by_name 'Outpatient diagnosis'
447
451
  collection = {}
452
+
448
453
  special_indicators = [
449
454
  "Referals from other institutions",
450
455
  "OPD total attendance",
@@ -452,68 +457,124 @@ module EmrOhspInterface
452
457
  "Malaria 5 years and older - new",
453
458
  "HIV/AIDS - new"
454
459
  ]
460
+
455
461
  special_under_five_indicators = [
456
462
  "Measles under five years - new",
457
463
  "Pneumonia under 5 years- new",
458
464
  "Dysentery under 5 years - new",
459
465
  "Diarrhoea non - bloody -new cases (under5)",
460
- "Malaria under 5 years - new",
461
- "Acute respiratory infections U5 - new"
466
+ "Malaria under 5 years - new"
462
467
  ]
463
468
 
464
-
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" => [] }
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
+
476
511
  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
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
+
523
+ options["ids"] = data
524
+ collection[key] = options
483
525
  end
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
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)
567
+ end
568
+
569
+ if key.eql?("Diarrhoea non - bloody -new cases (under5)")
570
+ collection[key] = disaggregate('less', concept_ids, start_date, end_date, type)
497
571
  end
572
+
498
573
  end
499
- collection
500
- end
574
+ end
575
+
576
+ collection
501
577
 
502
- def registration_report(start_date=nil,end_date=nil)
503
- ActiveRecord::Base.connection.select_all <<~SQL
504
- SELECT
505
- MIN(IFNULL(c.name, 'Unidentified')) 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
517
578
  end
518
579
 
519
580
  def generate_notifiable_disease_conditions_report(start_date=nil,end_date=nil)
@@ -1,3 +1,3 @@
1
1
  module EmrOhspInterface
2
- VERSION = '1.2.2'
2
+ VERSION = '2.2.0'
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.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Justin Manda, Petros Kayange, and Dominic Kasanga
7
+ - Justin Manda, Petros Kayange, Dominic Kasanga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-25 00:00:00.000000000 Z
11
+ date: 2023-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 5.2.4
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 5.2.4.3
19
+ version: 7.0.6
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: 5.2.4
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 5.2.4.3
26
+ version: 7.0.6
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: rspec
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -50,14 +44,14 @@ dependencies:
50
44
  requirements:
51
45
  - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: '1'
47
+ version: '2.1'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
52
  - - "~>"
59
53
  - !ruby/object:Gem::Version
60
- version: '1'
54
+ version: '2.1'
61
55
  - !ruby/object:Gem::Dependency
62
56
  name: mysql2
63
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,6 +66,26 @@ dependencies:
72
66
  - - "~>"
73
67
  - !ruby/object:Gem::Version
74
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.3.6
76
+ - - "~>"
77
+ - !ruby/object:Gem::Version
78
+ version: '1.3'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 1.3.6
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '1.3'
75
89
  description:
76
90
  email:
77
91
  - justinmandah@gmail.com, kayangepetros@gmail.com, dominickasanga@gmail.com
@@ -120,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
134
  - !ruby/object:Gem::Version
121
135
  version: '0'
122
136
  requirements: []
123
- rubygems_version: 3.0.9
137
+ rubygems_version: 3.4.10
124
138
  signing_key:
125
139
  specification_version: 4
126
140
  summary: This in a gem that facilitates interfacing of EMR, One Health Surveillance