Class: Inferno::Terminology::Validator
- Inherits:
-
Object
- Object
- Inferno::Terminology::Validator
- Defined in:
- lib/inferno/terminology/validator.rb
Instance Attribute Summary collapse
-
#bloom_filter ⇒ Object
readonly
Returns the value of attribute bloom_filter.
-
#code_systems ⇒ Object
readonly
Returns the value of attribute code_systems.
-
#concept_count ⇒ Object
readonly
Returns the value of attribute concept_count.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#url ⇒ Object
(also: #id)
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #allowed_systems ⇒ Object
- #code_in_allowed_system?(code) ⇒ Boolean
- #code_in_any_system?(code) ⇒ Boolean
- #code_in_systems?(code, possible_systems) ⇒ Boolean
- #coding_in_filter?(code:, system:) ⇒ Boolean
- #contains_prohibited_systems? ⇒ Boolean
-
#initialize(metadata) ⇒ Validator
constructor
A new instance of Validator.
- #prohibited_systems ⇒ Object
- #validate(code:, system: nil) ⇒ Object
Constructor Details
#initialize(metadata) ⇒ Validator
Returns a new instance of Validator.
9 10 11 12 13 14 15 16 |
# File 'lib/inferno/terminology/validator.rb', line 9 def initialize() @url = [:url] @concept_count = [:count] @type = [:type] @code_systems = [:code_systems] @file_name = [:file] @bloom_filter = [:bloom_filter] end |
Instance Attribute Details
#bloom_filter ⇒ Object (readonly)
Returns the value of attribute bloom_filter.
6 7 8 |
# File 'lib/inferno/terminology/validator.rb', line 6 def bloom_filter @bloom_filter end |
#code_systems ⇒ Object (readonly)
Returns the value of attribute code_systems.
6 7 8 |
# File 'lib/inferno/terminology/validator.rb', line 6 def code_systems @code_systems end |
#concept_count ⇒ Object (readonly)
Returns the value of attribute concept_count.
6 7 8 |
# File 'lib/inferno/terminology/validator.rb', line 6 def concept_count @concept_count end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
6 7 8 |
# File 'lib/inferno/terminology/validator.rb', line 6 def file_name @file_name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/inferno/terminology/validator.rb', line 6 def type @type end |
#url ⇒ Object (readonly) Also known as: id
Returns the value of attribute url.
6 7 8 |
# File 'lib/inferno/terminology/validator.rb', line 6 def url @url end |
Instance Method Details
#allowed_systems ⇒ Object
41 42 43 44 |
# File 'lib/inferno/terminology/validator.rb', line 41 def allowed_systems @allowed_systems ||= code_systems.select { |system| TerminologyConfiguration.system_allowed?(system) } end |
#code_in_allowed_system?(code) ⇒ Boolean
46 47 48 |
# File 'lib/inferno/terminology/validator.rb', line 46 def code_in_allowed_system?(code) code_in_systems?(code, allowed_systems) end |
#code_in_any_system?(code) ⇒ Boolean
50 51 52 |
# File 'lib/inferno/terminology/validator.rb', line 50 def code_in_any_system?(code) code_in_systems?(code, code_systems) end |
#code_in_systems?(code, possible_systems) ⇒ Boolean
54 55 56 57 58 |
# File 'lib/inferno/terminology/validator.rb', line 54 def code_in_systems?(code, possible_systems) possible_systems.any? do |possible_system| coding_in_filter?(code:, system: possible_system) end end |
#coding_in_filter?(code:, system:) ⇒ Boolean
60 61 62 |
# File 'lib/inferno/terminology/validator.rb', line 60 def coding_in_filter?(code:, system:) bloom_filter.include? "#{system}|#{code}" end |
#contains_prohibited_systems? ⇒ Boolean
32 33 34 |
# File 'lib/inferno/terminology/validator.rb', line 32 def contains_prohibited_systems? prohibited_systems.present? end |
#prohibited_systems ⇒ Object
36 37 38 39 |
# File 'lib/inferno/terminology/validator.rb', line 36 def prohibited_systems @prohibited_systems ||= code_systems.select { |system| TerminologyConfiguration.system_prohibited?(system) } end |
#validate(code:, system: nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/inferno/terminology/validator.rb', line 18 def validate(code:, system: nil) if system raise ProhibitedSystemException, system if TerminologyConfiguration.system_prohibited?(system) coding_in_filter?(code:, system:) elsif contains_prohibited_systems? raise ProhibitedSystemException, prohibited_systems.join(', ') unless code_in_allowed_system?(code) true else code_in_any_system?(code) end end |