Class: Inferno::Terminology::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/inferno/terminology/validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metadata) ⇒ Validator

Returns a new instance of Validator.



8
9
10
11
12
13
14
15
# File 'lib/inferno/terminology/validator.rb', line 8

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_filterObject (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_systemsObject (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_countObject (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_nameObject (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

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/inferno/terminology/validator.rb', line 6

def type
  @type
end

#urlObject (readonly)

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_systemsObject



40
41
42
43
# File 'lib/inferno/terminology/validator.rb', line 40

def allowed_systems
  @allowed_systems ||=
    code_systems.select { |system| TerminologyConfiguration.system_allowed?(system) }
end

#code_in_allowed_system?(code) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/inferno/terminology/validator.rb', line 45

def code_in_allowed_system?(code)
  code_in_systems?(code, allowed_systems)
end

#code_in_any_system?(code) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/inferno/terminology/validator.rb', line 49

def code_in_any_system?(code)
  code_in_systems?(code, code_systems)
end

#code_in_systems?(code, possible_systems) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
# File 'lib/inferno/terminology/validator.rb', line 53

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

Returns:

  • (Boolean)


59
60
61
# File 'lib/inferno/terminology/validator.rb', line 59

def coding_in_filter?(code:, system:)
  bloom_filter.include? "#{system}|#{code}"
end

#contains_prohibited_systems?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/inferno/terminology/validator.rb', line 31

def contains_prohibited_systems?
  prohibited_systems.present?
end

#prohibited_systemsObject



35
36
37
38
# File 'lib/inferno/terminology/validator.rb', line 35

def prohibited_systems
  @prohibited_systems ||=
    code_systems.select { |system| TerminologyConfiguration.system_prohibited?(system) }
end

#validate(code:, system: nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/inferno/terminology/validator.rb', line 17

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