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.



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_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) 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_systemsObject



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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


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

def contains_prohibited_systems?
  prohibited_systems.present?
end

#prohibited_systemsObject



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