Skip to content

Commit

Permalink
Remove hipaa identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbeales committed Apr 9, 2018
1 parent 525152c commit 2046b9a
Show file tree
Hide file tree
Showing 22 changed files with 96 additions and 115 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Expand Up @@ -4,6 +4,7 @@ source 'https://rubygems.org'
ruby ENV['CUSTOM_RUBY_VERSION'] || '2.4.4'

gem 'activerecord', '>= 5.1.5' # ORM
gem 'activerecord-delay_touching', '>= 1.0.1' # Batch Touching Calls
gem 'audited', '>= 4.7.0', require: false # adds table auiting support
gem 'bugsnag', '>= 6.6', require: false # online bug reporting
gem 'bundler-audit', '>= 0.6.0', require: false # check gems for security issues
Expand Down Expand Up @@ -56,6 +57,8 @@ end

group :development, :test do
gem 'annotate', '>= 2.7.2', require: false # annotate models
gem 'better_errors', '>= 2.4.0', require: false # better error logging
gem 'binding_of_caller', '>= 0.8.0', require: false # helps better_errors provide more detailed debugging
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', '>= 10.0.2', platforms: %i[mri mingw x64_mingw]
gem 'fasterer', require: false # find slow code
Expand Down
18 changes: 15 additions & 3 deletions Gemfile.lock
Expand Up @@ -7,6 +7,8 @@ GEM
activemodel (= 5.1.6)
activesupport (= 5.1.6)
arel (~> 8.0)
activerecord-delay_touching (1.0.1)
activerecord (>= 4.2)
activesupport (5.1.6)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
Expand All @@ -27,7 +29,13 @@ GEM
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
backports (3.11.1)
bugsnag (6.6.4)
better_errors (2.4.0)
coderay (>= 1.0.0)
erubi (>= 1.0.0)
rack (>= 0.9.0)
binding_of_caller (0.8.0)
debug_inspector (>= 0.0.1)
bugsnag (6.7.0)
concurrent-ruby (~> 1.0)
bundler-audit (0.6.0)
bundler (~> 1.2)
Expand All @@ -49,6 +57,7 @@ GEM
term-ansicolor
thor
database_cleaner (1.6.1)
debug_inspector (0.0.3)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
diff-lcs (1.3)
Expand All @@ -59,6 +68,7 @@ GEM
unf (>= 0.0.5, < 1.0.0)
dotenv (2.2.1)
equalizer (0.0.11)
erubi (1.7.1)
ethon (0.11.0)
ffi (>= 1.3.0)
factory_bot (4.8.2)
Expand Down Expand Up @@ -232,7 +242,7 @@ GEM
rdoc (>= 5.0)
secure_headers (5.0.5)
useragent (>= 0.15.0)
sexp_processor (4.10.1)
sexp_processor (4.11.0)
shellany (0.0.1)
simplecov (0.16.1)
docile (~> 1.1)
Expand Down Expand Up @@ -289,7 +299,6 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.7.5)
unf_ext (0.0.7.5-x64-mingw32)
unicode-display_width (1.3.0)
useragent (0.16.10)
valid_email2 (2.2.2)
Expand All @@ -310,8 +319,11 @@ PLATFORMS

DEPENDENCIES
activerecord (>= 5.1.5)
activerecord-delay_touching (>= 1.0.1)
annotate (>= 2.7.2)
audited (>= 4.7.0)
better_errors (>= 2.4.0)
binding_of_caller (>= 0.8.0)
bugsnag (>= 6.6)
bundler-audit (>= 0.6.0)
byebug (>= 10.0.2)
Expand Down
2 changes: 1 addition & 1 deletion app/models/choice.rb
Expand Up @@ -29,7 +29,7 @@

# Model to represent choices in a rating scale
class Choice < ApplicationRecord
belongs_to :response_scale, inverse_of: :choices
belongs_to :response_scale, inverse_of: :choices, touch: true
has_many :responses, inverse_of: :choice

validates :response_scale, presence: true
Expand Down
29 changes: 0 additions & 29 deletions app/models/hipaa_identifier.rb

This file was deleted.

1 change: 0 additions & 1 deletion app/models/init.rb
Expand Up @@ -12,7 +12,6 @@
require_relative 'assessment_instrument'
require_relative 'choice'
require_relative 'folder'
require_relative 'hipaa_identifier'
require_relative 'instrument'
require_relative 'item'
require_relative 'journal'
Expand Down
1 change: 1 addition & 0 deletions app/models/instrument.rb
Expand Up @@ -4,6 +4,7 @@
# Similar to a survey or questionnaire
class Instrument < ApplicationRecord
include PgSearch
include Discard::Model
multisearchable against: %i[json_content csv_content]
pg_search_scope :search_json, against: :json_content
pg_search_scope :search_csv, against: :csv_content
Expand Down
2 changes: 1 addition & 1 deletion app/models/item.rb
Expand Up @@ -35,7 +35,7 @@
# Represents a psychometric item
# Similar to a question with metadata
class Item < ApplicationRecord
belongs_to :instrument, inverse_of: :items
belongs_to :instrument, inverse_of: :items, touch: true
belongs_to :response_scale, inverse_of: :items, optional: true
has_many :choices, through: :response_scale
validates :name, presence: true
Expand Down
2 changes: 1 addition & 1 deletion app/models/journal_entry.rb
Expand Up @@ -2,7 +2,7 @@

# Model to represent patient journals
class JournalEntry < ApplicationRecord
belongs_to :journal, inverse_of: :journal_entries
belongs_to :journal, inverse_of: :journal_entries, touch: true
validates :entry, exclusion: { in: [nil] } # allow '' but not nil
validates :entry_date, presence: true
validates_uniqueness_of :entry_date, scope: :journal
Expand Down
2 changes: 1 addition & 1 deletion app/models/schedule.rb
Expand Up @@ -2,7 +2,7 @@

# Model to represent visit schedules
class Schedule < ApplicationRecord
belongs_to :study
belongs_to :study, touch: true
has_many :arms, inverse_of: :schedule

validates :name, presence: true
Expand Down
8 changes: 8 additions & 0 deletions config/initializers/00_better_errors_initializer.rb
@@ -0,0 +1,8 @@
# frozen_string_literal: true

require "better_errors"

configure :development, :test do
use BetterErrors::Middleware
BetterErrors.application_root = __dir__
end
12 changes: 0 additions & 12 deletions db/migrate/20180310203617_create_hipaa_identifiers.rb

This file was deleted.

7 changes: 5 additions & 2 deletions db/migrate/20180408205532_add_discard_to_users.rb
@@ -1,9 +1,12 @@
# frozen_string_literal: true

require './lib/shared_migration'

# Add soft delete to users table
class AddDiscardToUsers < ActiveRecord::Migration[5.1]
include SharedMigration

def change
add_column :users, :discarded_at, :datetime
add_index :users, :discarded_at
add_discard table_name: :users
end
end
12 changes: 12 additions & 0 deletions db/migrate/20180409004310_add_discard_to_instruments.rb
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require './lib/shared_migration'

# Add soft delete to users table
class AddDiscardToInstruments < ActiveRecord::Migration[5.1]
include SharedMigration

def change
add_discard table_name: :instruments
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180408205532) do
ActiveRecord::Schema.define(version: 20180409004310) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -106,7 +106,9 @@
t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" }, null: false
t.datetime "updated_at", default: -> { "CURRENT_TIMESTAMP" }, null: false
t.string "tags", default: [], array: true
t.datetime "discarded_at"
t.index ["csv_content"], name: "index_instruments_on_csv_content"
t.index ["discarded_at"], name: "index_instruments_on_discarded_at"
t.index ["json_content"], name: "instrument_json_content", using: :gin
t.index ["name"], name: "index_instruments_on_name"
t.index ["tags"], name: "instrument_tags", using: :gin
Expand Down
22 changes: 0 additions & 22 deletions db/seeds/all.rb
Expand Up @@ -11,25 +11,3 @@
# instrument = InstrumentCsv.new(name: AppConstants::DEFAULT_CSV_INSTRUMENT)
# InstrumentLoader.instance.load(instrument: instrument, type: :csv)
# end

unless HipaaIdentifier.count == 18
HipaaIdentifier.delete_all
HipaaIdentifier.create! name: 'Name'
HipaaIdentifier.create! name: 'Fax number'
HipaaIdentifier.create! name: 'Phone number'
HipaaIdentifier.create! name: 'E-mail address'
HipaaIdentifier.create! name: 'Account numbers'
HipaaIdentifier.create! name: 'Social Security number'
HipaaIdentifier.create! name: 'Medical Record number'
HipaaIdentifier.create! name: 'Health Plan number'
HipaaIdentifier.create! name: 'Certificate/license numbers'
HipaaIdentifier.create! name: 'URL'
HipaaIdentifier.create! name: 'IP address'
HipaaIdentifier.create! name: 'Vehicle identifiers'
HipaaIdentifier.create! name: 'Device ID'
HipaaIdentifier.create! name: 'Biometric ID'
HipaaIdentifier.create! name: 'Full face/identifying photo'
HipaaIdentifier.create! name: 'Other unique identifying number, characteristic, or code'
HipaaIdentifier.create! name: 'Postal address (geographic subdivisions smaller than state)'
HipaaIdentifier.create! name: 'Date precision beyond year'
end
9 changes: 8 additions & 1 deletion lib/custom_exceptions.rb
@@ -1,8 +1,15 @@
# frozen_string_literal: true

# class to implement friendly exception for file not found rather than ErrNoEnt
# class to implement a friendly exception for file not found rather than ErrNoEnt
class FileNotFoundException < StandardError
def to_s
'File not found'
end
end

# class to implement an exception for Missing Table Names in migrations
class MissingTableNameException < StandardError
def to_s
'Missing Table Name'
end
end
9 changes: 9 additions & 0 deletions lib/shared_migration.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require './lib/custom_exceptions'

# Methods to DRY out migrations
module SharedMigration
def create_name_table(table_name:)
Expand All @@ -10,4 +12,11 @@ def create_name_table(table_name:)
tname.timestamps null: false, default: -> { 'CURRENT_TIMESTAMP' }
end
end

def add_discard(table_name:)
raise "Missing Table Name: #{table_name}" if table_name.blank?

add_column table_name, :discarded_at, :datetime
add_index table_name, :discarded_at
end
end
5 changes: 0 additions & 5 deletions spec/factories.rb
Expand Up @@ -46,11 +46,6 @@
initialize_with { Folder.find_or_create_by! name: TestConstants::TEST_FOLDER }
end

factory :test_hipaa_identifier, class: 'HipaaIdentifier' do
name TestConstants::TEST_HIPAA_IDENTIFIER
initialize_with { HipaaIdentifier.find_or_create_by! name: TestConstants::TEST_HIPAA_IDENTIFIER }
end

factory :test_instrument, class: 'Instrument' do
name TestConstants::TEST_INSTRUMENT
initialize_with { Instrument.find_or_create_by! name: TestConstants::TEST_INSTRUMENT }
Expand Down
28 changes: 0 additions & 28 deletions spec/models/hipaa_identifier_spec.rb

This file was deleted.

30 changes: 28 additions & 2 deletions spec/models/instrument_spec.rb
Expand Up @@ -36,15 +36,15 @@
describe '#items' do
context 'has no items' do
it do
ins2 = described_class.find_or_create_by! name: 'Instrument 2'
ins2 = Instrument.find_or_create_by! name: 'Instrument 2'
expect(ins2.items.count).to eq 0
end
end
end

describe '.list_tests' do
it 'should return a list of instrument names' do
expect(described_class.list_tests(limit: 10)).to \
expect(Instrument.list_tests(limit: 10)).to \
include(TestConstants::TEST_INSTRUMENT)
end
end
Expand All @@ -60,4 +60,30 @@
describe '#instructions' do
it { expect(subject.instructions).to include 'felt or behaved' }
end

describe '#discard' do
let!(:ins2) { Instrument.find_or_create_by! name: 'Instrument 2' }
before :each do
ins2.discard
end

context 'does not delete' do
it timecop: :freeze do
expect(ins2.discarded_at.change(usec: 0)).to eq Time.now.change(usec: 0)
end

it do
expect(ins2.discarded?).to eq true
end

it do
discarded = Instrument.discarded.first
expect(discarded.id).to eq ins2.id
end

it do
expect(Instrument.kept.include?(ins2)).to be_falsey
end
end
end
end
1 change: 0 additions & 1 deletion spec/test_constants.rb
Expand Up @@ -6,7 +6,6 @@ module TestConstants
TEST_ARM = 'Test Arm'
TEST_ARM2 = 'Test Arm 2'
TEST_FOLDER = 'Test Folder'
TEST_HIPAA_IDENTIFIER = 'Test Hipaa Identifier'
TEST_INSTRUMENT = 'Cesd-r'
TEST_JOURNAL = 'Test Journal'
TEST_PARTICIPANT_EMAIL = 'test_participant@test.com'
Expand Down

0 comments on commit 2046b9a

Please sign in to comment.