provider_taxonomy 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
+ SHA1:
3
+ metadata.gz: 7aa24a84bc11e3ddd1420bbd05f2f268dbc0e5e9
4
+ data.tar.gz: 780867722314029ccbaf64f4840caa09981f2690
5
+ SHA512:
6
+ metadata.gz: 985d7ed6421585a44eb1e9d9e47496c5e04f39698e283b6d3109877c26bb4143d420085bd8da3daae23587ca9b7e3d6197158e27363813f606e91c047bad50e1
7
+ data.tar.gz: 33ebd9e61820d1ada8e66ace7df30fb6f84f02a031db8de8d45b6879aa5856cc34893e7a635b482e8fe77ef501cae426bf5da0a30342d4acaa0fb3c3645ab34c
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 ClydeDroid
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
+ # ProviderTaxonomy
2
+ A gem to add a database table containing the NUCC Health Care Provider Taxonomy.
3
+
4
+ ## Usage
5
+ Once installed, your Rails app will have a TaxonomyItem database table, from which you can access all healthcare provider specialties.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'provider_taxonomy'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle install
17
+ ```
18
+
19
+ Finally, run the migration and rake task:
20
+ ```bash
21
+ $ rake db:migrate
22
+ ```
23
+ ```bash
24
+ $ rake provider_taxonomy:import
25
+ ```
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,24 @@
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 = 'ProviderTaxonomy'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+
22
+
23
+ require 'bundler/gem_tasks'
24
+
@@ -0,0 +1,3 @@
1
+ class TaxonomyItem < ActiveRecord::Base
2
+ belongs_to :parent, foreign_key: :parent_id, class_name: TaxonomyItem, optional: true
3
+ end
@@ -0,0 +1,15 @@
1
+ class CreateTaxonomyItems < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :taxonomy_items do |t|
4
+ t.string :name, null: false
5
+ t.integer :parent_id
6
+ t.integer :depth
7
+ t.string :category
8
+ t.string :taxonomy_code
9
+ t.string :sub_category
10
+ t.string :definition
11
+ t.string :notes
12
+ end
13
+ add_index :taxonomy_items, :parent_id
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ require "provider_taxonomy/engine"
2
+
3
+ module ProviderTaxonomy
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,11 @@
1
+ module ProviderTaxonomy
2
+ class Engine < ::Rails::Engine
3
+ initializer :append_migrations do |app|
4
+ unless app.root.to_s.match root.to_s
5
+ config.paths["db/migrate"].expanded.each do |expanded_path|
6
+ app.config.paths["db/migrate"] << expanded_path
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module ProviderTaxonomy
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,110 @@
1
+ namespace :provider_taxonomy do
2
+ desc 'Import data representing provider specialties taxonomy. Result is db table with parent ids and depth for each entry.'
3
+ task import: :environment do
4
+ require 'csv'
5
+ require 'open-uri'
6
+
7
+ def download(url, dest)
8
+ open(url) do |u|
9
+ File.open(dest, 'wb') { |f| f.write(u.read) }
10
+ end
11
+ end
12
+
13
+ table = 'taxonomy_items'
14
+ $stdout.sync = true
15
+ print "Truncating and resetting the " + table + " table\n"
16
+ ActiveRecord::Base.connection.execute("TRUNCATE " + table + " RESTART IDENTITY;")
17
+
18
+ today = Date.today
19
+ if today.month < 7
20
+ current_version = today.year.to_s[2, 2] + "0"
21
+ previous_version = (today.year - 1).to_s[2, 2] + "1"
22
+ else
23
+ current_version = today.year.to_s[2, 2] + "1"
24
+ previous_version = today.year.to_s[2, 2] + "0"
25
+ end
26
+
27
+ begin
28
+ if Dir.exists?('db/provider_taxonomy')
29
+ old_file = Dir['db/provider_taxonomy/nucc_taxonomy_*.csv'][0]
30
+ File.delete(old_file) if old_file
31
+ else
32
+ FileUtils.mkdir_p 'db/provider_taxonomy'
33
+ end
34
+ taxonomy_file = "db/provider_taxonomy/nucc_taxonomy_#{current_version}.csv"
35
+ download("http://nucc.org/images/stories/CSV/nucc_taxonomy_#{current_version}.csv", taxonomy_file)
36
+ if File.exist?(taxonomy_file)
37
+ puts "Taxonomy file downloaded: Version #{current_version}."
38
+ end
39
+ rescue OpenURI::HTTPError
40
+ taxonomy_file = "db/rawdata/CMS_Taxonomy_Hierarchy/nucc_taxonomy_#{previous_version}.csv"
41
+ download("http://nucc.org/images/stories/CSV/nucc_taxonomy_#{previous_version}.csv", taxonomy_file)
42
+ if File.exist?(taxonomy_file)
43
+ puts "Taxonomy file downloaded: Version #{previous_version}."
44
+ end
45
+ end
46
+
47
+ csv_text = File.read(taxonomy_file).scrub
48
+ csv = CSV.parse(csv_text, headers: true)
49
+
50
+ print "Importing provider taxonomy\n"
51
+ csv.each_with_index do |row, i|
52
+ print "\n" if (i % 80).zero?
53
+ print "."
54
+
55
+ grouping = TaxonomyItem.where(name: row['Grouping'], depth: 1).first
56
+ if !grouping
57
+ grouping = TaxonomyItem.create!(
58
+ name: row['Grouping'],
59
+ depth: 1,
60
+ parent_id: nil,
61
+ taxonomy_code: nil
62
+ )
63
+ end
64
+
65
+ if row['Specialization'].blank?
66
+ classification = TaxonomyItem.where(name: row['Classification'], depth: 2, parent_id: grouping.id).first
67
+ if classification
68
+ classification.update_attributes(
69
+ taxonomy_code: row['Code'],
70
+ definition: row['Definition'],
71
+ notes: row['Notes']
72
+ )
73
+ else
74
+ TaxonomyItem.create!(
75
+ name: row['Classification'],
76
+ depth: 2,
77
+ parent_id: grouping.id,
78
+ taxonomy_code: row['Code'],
79
+ definition: row['Definition'],
80
+ notes: row['Notes']
81
+ )
82
+ end
83
+ else
84
+ classification = TaxonomyItem.where(name: row['Classification'], parent_id: grouping.id, depth: 2).first
85
+ if !classification
86
+ classification = TaxonomyItem.create!(
87
+ name: row['Classification'],
88
+ depth: 2,
89
+ parent_id: grouping.id,
90
+ taxonomy_code: nil,
91
+ definition: nil,
92
+ notes: nil
93
+ )
94
+ end
95
+
96
+ TaxonomyItem.create!(
97
+ name: row['Specialization'],
98
+ depth: 3,
99
+ parent_id: classification.id,
100
+ taxonomy_code: row['Code'],
101
+ definition: row['Definition'],
102
+ notes: row['Notes']
103
+ ).id
104
+ end
105
+ end
106
+ print "\n"
107
+ puts 'Provider taxonomy imported.'
108
+ FileUtils.rm_rf 'db/provider_taxonomy'
109
+ end
110
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: provider_taxonomy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ClydeDroid
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-09 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.0.0
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.0.0.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 5.0.0
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.0.0.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: pg
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ description: A gem to add a database table containing the NUCC Health Care Provider
48
+ Taxonomy
49
+ email:
50
+ - clydedroid@gmail.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - MIT-LICENSE
56
+ - README.md
57
+ - Rakefile
58
+ - app/models/taxonomy_item.rb
59
+ - db/migrate/20160909180325_create_taxonomy_items.rb
60
+ - lib/provider_taxonomy.rb
61
+ - lib/provider_taxonomy/engine.rb
62
+ - lib/provider_taxonomy/version.rb
63
+ - lib/tasks/import.rake
64
+ homepage: https://github.com/adhocteam/provider-taxonomy
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.5.1
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: A gem to add a database table containing the NUCC Provider Taxonomy
88
+ test_files: []