emr_ohsp_interface 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6fcec054826eeae6514b895fa86875cabf197b38518c30f85ceba1db894bbced
4
+ data.tar.gz: 1ad95664c8d0f5d5a87069e42f6fa9bfbd8095f70473f5d842e75d2c916fa240
5
+ SHA512:
6
+ metadata.gz: 240a306c8c35d3b2ce53f348afd7f135e8f08fe0c126697cb60fa895632af43335d90112917b16db2a9997eefe5ce421aef61d3bc7690e1a7b15daed07bbdd8e
7
+ data.tar.gz: 37334da676a6c066644e78613b7296ef2c8fc4c0f7cf9c9af6ac9aa9d81bfc6cf7ffd1f8fc3bce642346d0bf1a1441e66d1cdce637ac46190a1d97503ca5c90a
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2021 petroskayange
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # EmrOhspInterface
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'emr_ohsp_interface'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install emr_ohsp_interface
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'EmrOhspInterface'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/emr_ohsp_interface .js
2
+ //= link_directory ../stylesheets/emr_ohsp_interface .css
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require rails-ujs
14
+ //= require activestorage
15
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ module EmrOhspInterface
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ class EmrOHSPInterface::EmrOHSPInterfaceController < ::ApplicationController
2
+ def weeks_generator
3
+ render json: service.weeks_generator();
4
+ end
5
+ def months_generator
6
+ render json: service.months_generator();
7
+ end
8
+
9
+ def service
10
+ EmrOHSPInterface::EmrOHSPInterfaceService
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ module EmrOhspInterface
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module EmrOhspInterface
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module EmrOhspInterface
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module EmrOhspInterface
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,196 @@
1
+ require "emr_OHSP_interface/version"
2
+
3
+ module EmrOHSPInterface
4
+ module EmrOHSPInterfaceService
5
+ class << self
6
+ require 'csv'
7
+ require 'rest-client'
8
+ def settings
9
+ file = File.read(Rails.root.join("db","idsr_metadata","idsr_ohsp_settings.json"))
10
+ config = JSON.parse(file)
11
+ end
12
+
13
+ def get_ohsp_facility_id
14
+ file = File.open(Rails.root.join("db","idsr_metadata","emr_ohsp_facility_map.csv"))
15
+ data = CSV.parse(file,headers: true)
16
+ emr_facility_id = Location.current_health_center.id
17
+ facility = data.select{|row| row["EMR_Facility_ID"].to_i == emr_facility_id}
18
+ ohsp_id = facility[0]["OrgUnit ID"]
19
+ end
20
+
21
+ def get_ohsp_de_ids(de,type)
22
+ #this method returns an array ohsp report line ids
23
+ result = []
24
+ #["waoQ016uOz1", "r1AT49VBKqg", "FPN4D0s6K3m", "zE8k2BtValu"]
25
+ # ds, de_id , <5yrs , >=5yrs
26
+ if type == "weekly"
27
+ file = File.open(Rails.root.join("db","idsr_metadata","idsr_weekly_ohsp_ids.csv"))
28
+ else
29
+ file = File.open(Rails.root.join("db","idsr_metadata","idsr_monthly_ohsp_ids.csv"))
30
+ end
31
+ data = CSV.parse(file,headers: true)
32
+ row = data.select{|row| row["Data Element Name"].strip.downcase.eql?(de.downcase)}
33
+ ohsp_ds_id = row[0]["Data Set ID"]
34
+ result << ohsp_ds_id
35
+ ohsp_de_id = row[0]["UID"]
36
+ result << ohsp_de_id
37
+ option1 = row[0]["<5Yrs"]
38
+ result << option1
39
+ option2 = row[0][">=5Yrs"]
40
+ result << option2
41
+
42
+ return result
43
+ end
44
+
45
+ def get_data_set_id(type)
46
+ if type == "weekly"
47
+ file = File.open(Rails.root.join("db","idsr_metadata","idsr_weekly_ohsp_ids.csv"))
48
+ else
49
+ file = File.open(Rails.root.join("db","idsr_metadata","idsr_monthly_ohsp_ids.csv"))
50
+ end
51
+ data = CSV.parse(file,headers: true)
52
+ data_set_id = data.first["Data Set ID"]
53
+ end
54
+
55
+ def generate_weekly_idsr_report()
56
+
57
+ diag_map = settings["weekly_idsr_map"]
58
+
59
+ 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
62
+
63
+ #pull the data
64
+ type = EncounterType.find_by_name 'Outpatient diagnosis'
65
+ collection = {}
66
+
67
+ diag_map.each do |key,value|
68
+ options = {"<5yrs"=>nil,">=5yrs"=>nil}
69
+ concept_ids = ConceptName.where(name: value).collect{|cn| cn.concept_id}
70
+
71
+ data = Encounter.where('encounter_datetime BETWEEN ? AND ?
72
+ AND encounter_type = ? AND value_coded IN (?)
73
+ AND concept_id IN(6543, 6542)',
74
+ start_date.to_date.strftime('%Y-%m-%d 00:00:00'),
75
+ end_date.to_date.strftime('%Y-%m-%d 23:59:59'),type.id,concept_ids).\
76
+ joins('INNER JOIN obs ON obs.encounter_id = encounter.encounter_id
77
+ INNER JOIN person p ON p.person_id = encounter.patient_id').\
78
+ select('encounter.encounter_type, obs.value_coded, p.*')
79
+
80
+ #under_five
81
+ under_five = data.select{|record| calculate_age(record["birthdate"]) < 5}.\
82
+ collect{|record| record.person_id}
83
+ options["<5yrs"] = under_five
84
+ #above 5 years
85
+ over_five = data.select{|record| calculate_age(record["birthdate"]) >=5 }.\
86
+ collect{|record| record.person_id}
87
+
88
+ options[">=5yrs"] = over_five
89
+
90
+ collection[key] = options
91
+ end
92
+
93
+ response = send_data(collection,"weekly")
94
+ end
95
+
96
+ def generate_monthly_idsr_report()
97
+ end
98
+
99
+ # helper menthod
100
+ def months_generator
101
+ months = Hash.new
102
+ count = 1
103
+ curr_date = Date.today
104
+ while count < 13 do
105
+ curr_date = curr_date - 1.month
106
+ months[curr_date.strftime("%Y%m")] = [curr_date.strftime("%B-%Y"),\
107
+ (curr_date.beginning_of_month.to_s+" to " + curr_date.end_of_month.to_s)]
108
+ count += 1
109
+ end
110
+ return months.to_a
111
+ end
112
+
113
+ # helper menthod
114
+ def weeks_generator
115
+
116
+ weeks = Hash.new
117
+ first_day = ((Date.today.year.to_s)+"-01-01").to_date
118
+ wk_of_first_day = first_day.cweek
119
+
120
+ if wk_of_first_day > 1
121
+ wk = first_day.prev_year.year.to_s+"W"+wk_of_first_day.to_s
122
+ dates = "#{(first_day-first_day.wday+1).to_s} to #{((first_day-first_day.wday+1)+6).to_s}"
123
+ weeks[wk] = dates
124
+ end
125
+
126
+ #get the firt monday of the year
127
+ while !first_day.monday? do
128
+ first_day = first_day+1
129
+ end
130
+ first_monday = first_day
131
+ #generate week numbers and date ranges
132
+
133
+ while first_monday <= Date.today do
134
+ wk = (first_monday.year).to_s+"W"+(first_monday.cweek).to_s
135
+ dates = "#{first_monday.to_s} to #{(first_monday+6).to_s}"
136
+ #add to the hash
137
+ weeks[wk] = dates
138
+ #step by week
139
+ first_monday += 7
140
+ end
141
+ #remove the last week
142
+ this_wk = (Date.today.year).to_s+"W"+(Date.today.cweek).to_s
143
+ weeks = weeks.delete_if{|key,value| key==this_wk}
144
+
145
+ return weeks.to_a
146
+ end
147
+
148
+ #Age calculator
149
+ def calculate_age(dob)
150
+ age = ((Date.today-dob.to_date).to_i)/365 rescue 0
151
+ end
152
+
153
+ def send_data(data,type)
154
+ # method used to post data to the server
155
+ #prepare payload here
156
+ conn = settings["headers"]
157
+ payload = {
158
+ "dataSet" =>get_data_set_id(type),
159
+ "period"=>(type.eql?("weekly") ? weeks_generator.last[0] : months_generator.first[0]),
160
+ "orgUnit"=> get_ohsp_facility_id,
161
+ "dataValues"=> []
162
+ }
163
+
164
+ data.each do |key,value|
165
+ option1 = {"dataElement"=>get_ohsp_de_ids(key,type)[1],
166
+ "categoryOptionCombo"=> get_ohsp_de_ids(key,type)[2],
167
+ "value"=>value["<5yrs"].size }
168
+
169
+ option2 = {"dataElement"=>get_ohsp_de_ids(key,type)[1],
170
+ "categoryOptionCombo"=> get_ohsp_de_ids(key,type)[3],
171
+ "value"=>value[">=5yrs"].size}
172
+
173
+ #fill data values array
174
+ payload["dataValues"] << option1
175
+ payload["dataValues"] << option2
176
+ end
177
+
178
+ puts "now sending these values: #{payload.to_s}"
179
+ url = "#{conn["url"]}/api/dataValueSets"
180
+ puts url
181
+ send = RestClient::Request.execute(method: :post,
182
+ url: url,
183
+ headers:{'Content-Type'=> 'application/json'},
184
+ payload: payload.to_json,
185
+ #headers: {accept: :json},
186
+ user: conn["user"],
187
+ password: conn["pass"])
188
+
189
+ puts send
190
+ end
191
+
192
+ end
193
+ end
194
+
195
+
196
+ end
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Emr ohsp interface</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "emr_ohsp_interface/application", media: "all" %>
9
+ <%= javascript_include_tag "emr_ohsp_interface/application" %>
10
+ </head>
11
+ <body>
12
+
13
+ <%= yield %>
14
+
15
+ </body>
16
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ EmrOhspInterface::Engine.routes.draw do
2
+ resources :radiology, path: 'api/v1/emr_ohsp_interface'
3
+ get '/get_weeks', to: 'emr_ohsp_interface#weeks_generator'
4
+ get '/get_months', to: 'emr_ohsp_interface#months_generator'
5
+ end
@@ -0,0 +1,5 @@
1
+ module EmrOhspInterface
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace EmrOhspInterface
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module EmrOhspInterface
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,5 @@
1
+ require "emr_ohsp_interface/engine"
2
+
3
+ module EmrOhspInterface
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :emr_ohsp_interface do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: emr_ohsp_interface
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Manda
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-09-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.4
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.2.4.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 5.2.4
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.2.4.3
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rest-client
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1'
61
+ - !ruby/object:Gem::Dependency
62
+ name: mysql2
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ description:
76
+ email:
77
+ - justinmandah@gmail.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - MIT-LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - app/assets/config/emr_ohsp_interface_manifest.js
86
+ - app/assets/javascripts/emr_ohsp_interface/application.js
87
+ - app/assets/stylesheets/emr_ohsp_interface/application.css
88
+ - app/controllers/emr_ohsp_interface/application_controller.rb
89
+ - app/controllers/emr_ohsp_interface/emr_OHSP_interface_controller.rb
90
+ - app/helpers/emr_ohsp_interface/application_helper.rb
91
+ - app/jobs/emr_ohsp_interface/application_job.rb
92
+ - app/mailers/emr_ohsp_interface/application_mailer.rb
93
+ - app/models/emr_ohsp_interface/application_record.rb
94
+ - app/services/emr_ohsp_interface/emr_OHSP_interface_service.rb
95
+ - app/views/layouts/emr_ohsp_interface/application.html.erb
96
+ - config/routes.rb
97
+ - lib/emr_ohsp_interface.rb
98
+ - lib/emr_ohsp_interface/engine.rb
99
+ - lib/emr_ohsp_interface/version.rb
100
+ - lib/tasks/emr_ohsp_interface_tasks.rake
101
+ homepage: https://github.com/LUKEINTERNATIONAL/emr_OHSP_interface
102
+ licenses:
103
+ - MIT
104
+ metadata:
105
+ homepage_uri: https://github.com/LUKEINTERNATIONAL/emr_OHSP_interface
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubygems_version: 3.0.8
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: This in a gem that facilitates interfacing of EMR and One Health Surveillance
125
+ Platform
126
+ test_files: []