eir_report_interface 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4c2101ad1667578c8d2fee14528de9128b9fdd3d4839fe9e5a89141fc04e11d6
4
+ data.tar.gz: 6ad64f409224db7d3b2be53bc79df2e032699e75e041f01d49b9bcf81fbdd7e6
5
+ SHA512:
6
+ metadata.gz: e90e483171a248a325eacab6fe09268ba84b3d2283c7e5d3e30f119bf253a3521211eb55218fd94dc6d948eaac20667415d26dca442e42104d08049310df5c9f
7
+ data.tar.gz: ffc127e7d399bbb18189afe0cae0f7f0e94abec07bd3b992043e50544ba41365cd400e71a33077b6325914b6ed3fade34486daab17c579a79bacdc62d6d6d9b2
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # EirReportInterface
2
+
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ task default: %i[]
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/eir_report_interface .js
2
+ //= link_directory ../stylesheets/eir_report_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,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ApplicationController serves as the base controller for all controllers
4
+ module EIRReportInterface
5
+ # within the EIRReportInterface module. It inherits from ActionController::Base
6
+ # and includes common configurations and protections for the controllers.
7
+ class ApplicationController < ActionController::Base
8
+ # Protects the application from Cross-Site Request Forgery (CSRF) attacks.
9
+ # Uses the :exception strategy to raise an exception when a CSRF attack is detected.
10
+ protect_from_forgery with: :exception
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ # EIRReportInterface is a module that provides reporting services
4
+ # related to the EIR (Electronic Immunization Registry).
5
+ module EIRReportInterface
6
+ # EIRReportInterfaceController handles requests for generating weeks and months data.
7
+ class EIRReportInterfaceController < ::ApplicationController
8
+ # Generates weeks data and renders it as JSON.
9
+ def weeks_generator
10
+ render json: service.weeks_generator
11
+ end
12
+
13
+ # Generates months data and renders it as JSON.
14
+ def months_generator
15
+ render json: service.months_generator
16
+ end
17
+
18
+ # Provides access to the service object.
19
+ def service
20
+ EIRReportInterface::EIRReportInterfaceService
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EIRReportInterface
4
+ # ApplicationHelper serves as a container for helper methods used across views in the EIRReportInterface module.
5
+ # It is intended to assist with view-related logic and presentation.
6
+ module ApplicationHelper
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EIRReportInterface
4
+ # ApplicationJob serves as the base class for all jobs in the EIRReportInterface module.
5
+ # It inherits from ActiveJob::Base, making it a part of the ActiveJob framework.
6
+ class ApplicationJob < ActiveJob::Base
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EIRReportInterface
4
+ # ApplicationMailer serves as the base class for all mailers in the EIRReportInterface module.
5
+ # It provides default settings and layout configurations for the mailers.
6
+ class ApplicationMailer < ActionMailer::Base
7
+ default from: 'from@example.com'
8
+ layout 'mailer'
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EIRReportInterface
4
+ # ApplicationRecord serves as the abstract base class for all models in the EIRReportInterface module.
5
+ # It inherits from ActiveRecord::Base, making it a part of the ActiveRecord ORM system.
6
+ class ApplicationRecord < ActiveRecord::Base
7
+ self.abstract_class = true
8
+ end
9
+ end
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'csv'
4
+ require 'rest-client'
5
+ require 'json'
6
+
7
+ # EIRReportInterface is a module that provides reporting services
8
+ # related to the EIR (Electronic Immunization Registry).
9
+ module EIRReportInterface
10
+ # EIRReportInterfaceService is a module within EIRReportInterface
11
+ # that provides various service methods for reporting and data disaggregation.
12
+ module EIRReportInterfaceService
13
+ class << self
14
+ # Reads and parses settings from a JSON file.
15
+ # @return [Hash] Parsed JSON configuration
16
+ def settings
17
+ file = File.read(Rails.root.join('db', 'idsr_metadata', 'idsr_ohsp_settings.json'))
18
+ JSON.parse(file)
19
+ end
20
+
21
+ # Reads and parses server configuration from a YAML file.
22
+ # @return [Hash] Parsed YAML configuration
23
+ def server_config
24
+ YAML.load_file("#{Rails.root}/config/application.yml")
25
+ end
26
+
27
+ # Disaggregates data based on the provided criteria.
28
+ # @param disaggregate_key [String] The key for disaggregation (e.g., 'less', 'greater')
29
+ # @param concept_ids [Array<Integer>] The concept IDs to filter by
30
+ # @param start_date [Date] The start date for the date range
31
+ # @param end_date [Date] The end date for the date range
32
+ # @param type [EncounterType] The encounter type
33
+ # @return [Hash] A hash containing the disaggregated data
34
+ def disaggregate(disaggregate_key, concept_ids, start_date, end_date, type)
35
+ data = fetch_data(concept_ids, start_date, end_date, type)
36
+ { 'ids' => filter_data(data, disaggregate_key) }
37
+ end
38
+
39
+ # Fetches data from the database based on the provided criteria.
40
+ # @param concept_ids [Array<Integer>] The concept IDs to filter by
41
+ # @param start_date [Date] The start date for the date range
42
+ # @param end_date [Date] The end date for the date range
43
+ # @param type [EncounterType] The encounter type
44
+ # @return [ActiveRecord::Relation] The fetched data
45
+ def fetch_data(concept_ids, start_date, end_date, type)
46
+ Encounter.where(
47
+ 'encounter_datetime BETWEEN ? AND ? AND encounter_type = ? AND value_coded IN (?) AND concept_id IN (6543, 6542)',
48
+ start_date.to_date.strftime('%Y-%m-%d 00:00:00'),
49
+ end_date.to_date.strftime('%Y-%m-%d 23:59:59'), type.id, concept_ids
50
+ ).joins(
51
+ 'INNER JOIN obs ON obs.encounter_id = encounter.encounter_id
52
+ INNER JOIN person p ON p.person_id = encounter.patient_id'
53
+ ).select('encounter.encounter_type, obs.value_coded, p.*')
54
+ end
55
+
56
+ # Filters data based on the disaggregate key.
57
+ # @param data [ActiveRecord::Relation] The data to filter
58
+ # @param disaggregate_key [String] The key for disaggregation (e.g., 'less', 'greater')
59
+ # @return [Array<Integer>] The filtered IDs
60
+ def filter_data(data, disaggregate_key)
61
+ filtered_data = case disaggregate_key
62
+ when 'less'
63
+ data.select { |record| calculate_age(record['birthdate']) < 5 }
64
+ when 'greater'
65
+ data.select { |record| calculate_age(record['birthdate']) >= 5 }
66
+ else
67
+ []
68
+ end
69
+ filtered_data.collect { |record| record['person_id'] }
70
+ end
71
+
72
+ # Generates a hash of months with their respective date ranges.
73
+ # @return [Array<Array<String>>] An array of month-date range pairs
74
+ def months_generator
75
+ months = {}
76
+ count = 1
77
+ curr_date = Date.today
78
+
79
+ while count < 13
80
+ curr_date -= 1.month
81
+ months[curr_date.strftime('%Y%m')] = [
82
+ curr_date.strftime('%B-%Y'),
83
+ "#{curr_date.beginning_of_month} to #{curr_date.end_of_month}"
84
+ ]
85
+ count += 1
86
+ end
87
+
88
+ months.to_a
89
+ end
90
+
91
+ # Generates a hash of weeks with their respective date ranges.
92
+ # @return [Array<Array<String>>] An array of week-date range pairs
93
+ def weeks_generator
94
+ weeks = {}
95
+ first_day = (Date.today - 11.months).at_beginning_of_month
96
+ add_initial_week(weeks, first_day)
97
+
98
+ first_monday = first_day.next_week(:monday)
99
+
100
+ while first_monday <= Date.today
101
+ add_week(weeks, first_monday)
102
+ first_monday += 7
103
+ end
104
+
105
+ this_wk = "#{Date.today.year}W#{Date.today.cweek}"
106
+ weeks.reject { |key, _| key == this_wk }.to_a
107
+ end
108
+
109
+ # Adds the initial week to the weeks hash.
110
+ # @param weeks [Hash] The hash to add the week to
111
+ # @param first_day [Date] The first day of the initial week
112
+ def add_initial_week(weeks, first_day)
113
+ wk_of_first_day = first_day.cweek
114
+ return unless wk_of_first_day > 1
115
+
116
+ wk = "#{first_day.prev_year.year}W#{wk_of_first_day}"
117
+ dates = "#{first_day - first_day.wday + 1} to #{first_day - first_day.wday + 1 + 6}"
118
+ weeks[wk] = dates
119
+ end
120
+
121
+ # Adds a week to the weeks hash.
122
+ # @param weeks [Hash] The hash to add the week to
123
+ # @param first_monday [Date] The first Monday of the week
124
+ def add_week(weeks, first_monday)
125
+ wk = "#{first_monday.year}W#{first_monday.cweek}"
126
+ dates = "#{first_monday} to #{first_monday + 6}"
127
+ weeks[wk] = dates
128
+ end
129
+
130
+ # Calculates the age based on the date of birth.
131
+ # @param dob [Date] The date of birth
132
+ # @return [Integer] The calculated age
133
+ def calculate_age(dob)
134
+ ((Date.today - dob.to_date).to_i / 365).rescue(0)
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>EIR Report Interface</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "eir_report_interface/application", media: "all" %>
9
+ <%= javascript_include_tag "eir_report_interface/application" %>
10
+ </head>
11
+ <body>
12
+
13
+ <%= yield %>
14
+
15
+ </body>
16
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ EIRReportInterface::Engine.routes.each do
4
+ get '/get_months', to: 'eir_report_interface#months_generator'
5
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EIRReportInterface
4
+ # Engine class for the EIRReportInterface gem.
5
+ #
6
+ # This class is used to integrate the EIRReportInterface functionality into a Rails application.
7
+ # It isolates the namespace for the gem to avoid conflicts with other parts of the application.
8
+ #
9
+ # For more information about configuring and using this engine, see the README file.
10
+ class Engine < ::Rails::Engine
11
+ isolate_namespace EIRReportInterface
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/railtie'
4
+
5
+ module EIRReportInterface
6
+ # Railtie class for the EIRReportInterface gem.
7
+ #
8
+ # This Railtie integrates the EIRReportInterface functionality into a Rails application.
9
+ # It allows you to configure initialization options for the gem within a Rails context.
10
+ #
11
+ # For more information about configuring and using this Railtie, see the README file of the gem.
12
+ class Railtie < Rails::Railtie
13
+ initializer 'eir_report_interface.configure_rails_initialization' do
14
+ # Custom initialization code
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EIRReportInterface
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'eir_report_interface/engine'
4
+
5
+ module EIRReportInterface
6
+ # Example usage of single-quoted string
7
+ MESSAGE = 'Your code goes here...'
8
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eir_report_interface
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - dominickasanga
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-07-23 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: 7.0.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 7.0.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mysql2
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
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'
89
+ description: Write a longer description or delete this line.
90
+ email:
91
+ - dominickasanga@gmail.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - README.md
97
+ - Rakefile
98
+ - app/assets/config/eir_report_interface_manifest.js
99
+ - app/assets/javascripts/eir_report_interface/application.js
100
+ - app/assets/stylesheets/eir_report_interface/application.css
101
+ - app/controllers/eir_report_interface/application_controller.rb
102
+ - app/controllers/eir_report_interface/eir_report_interface_controller.rb
103
+ - app/helpers/eir_report_interface/application_helper.rb
104
+ - app/jobs/eir_report_interface/application_job.rb
105
+ - app/mailers/eir_report_interface/application_mailer.rb
106
+ - app/models/eir_report_interface/application_record.rb
107
+ - app/services/eir_report_interface/eir_report_interface.rb
108
+ - app/views/layouts/eir_report_interface/application.html.erb
109
+ - config/routes.rb
110
+ - lib/eir_report_interface.rb
111
+ - lib/eir_report_interface/engine.rb
112
+ - lib/eir_report_interface/railtie.rb
113
+ - lib/eir_report_interface/version.rb
114
+ homepage: https://github.com/LUKEINTERNATIONAL/eir_report_interface.git
115
+ licenses:
116
+ - MIT
117
+ metadata:
118
+ homepage_uri: https://github.com/LUKEINTERNATIONAL/eir_report_interface.git
119
+ source_code_uri: https://github.com/LUKEINTERNATIONAL/eir_report_interface.git
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: 2.6.0
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubygems_version: 3.4.1
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Write a short summary, because RubyGems requires one.
139
+ test_files: []