Class: Inferno::Terminology::Tasks::CheckBuiltTerminology

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

Constant Summary collapse

NON_UMLS_SYSTEMS =
[
  'http://hl7.org/fhir/ValueSet/mimetypes',
  'urn:ietf:bcp:13',
  'http://hl7.org/fhir/us/core/ValueSet/simple-language',
  'urn:ietf:bcp:47'
].freeze

Instance Method Summary collapse

Instance Method Details

#expected_manifestObject



46
47
48
# File 'lib/inferno/terminology/tasks/check_built_terminology.rb', line 46

def expected_manifest
  YAML.load_file(File.join(__dir__, '..', 'expected_manifest.yml'))
end

#mismatched_value_set_message(expected_value_set) ⇒ Object



86
87
88
89
90
91
# File 'lib/inferno/terminology/tasks/check_built_terminology.rb', line 86

def mismatched_value_set_message(expected_value_set)
  url = expected_value_set[:url]
  actual_value_set = new_value_set(url)

  "#{url}: Expected codes: #{expected_value_set[:count]} Actual codes: #{actual_value_set&.dig(:count) || 0}"
end

#mismatched_value_setsObject



61
62
63
64
65
66
67
# File 'lib/inferno/terminology/tasks/check_built_terminology.rb', line 61

def mismatched_value_sets
  @mismatched_value_sets ||=
    expected_manifest.reject do |expected_value_set|
      url = expected_value_set[:url]
      new_value_set(url) == expected_value_set
    end
end

#new_manifestObject



55
56
57
58
59
# File 'lib/inferno/terminology/tasks/check_built_terminology.rb', line 55

def new_manifest
  return [] unless File.exist? new_manifest_path

  @new_manifest ||= YAML.load_file(new_manifest_path)
end

#new_manifest_pathObject



50
51
52
53
# File 'lib/inferno/terminology/tasks/check_built_terminology.rb', line 50

def new_manifest_path
  @new_manifest_path ||=
    File.join(Dir.pwd, 'resources', 'terminology', 'validators', 'bloom', 'manifest.yml')
end

#new_value_set(url) ⇒ Object



74
75
76
# File 'lib/inferno/terminology/tasks/check_built_terminology.rb', line 74

def new_value_set(url)
  new_manifest.find { |value_set| value_set[:url] == url }
end

#new_value_setsObject



69
70
71
72
# File 'lib/inferno/terminology/tasks/check_built_terminology.rb', line 69

def new_value_sets
  @new_value_sets ||=
    new_manifest.reject { |value_set| old_value_set?(value_set[:url]) }
end

#old_value_set?(url) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/inferno/terminology/tasks/check_built_terminology.rb', line 78

def old_value_set?(url)
  expected_manifest.any? { |value_set| value_set[:url] == url }
end

#only_non_umls_mismatch?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/inferno/terminology/tasks/check_built_terminology.rb', line 82

def only_non_umls_mismatch?
  mismatched_value_sets.all? { |value_set| NON_UMLS_SYSTEMS.include? value_set[:url] }
end

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/inferno/terminology/tasks/check_built_terminology.rb', line 14

def run
  if mismatched_value_sets.blank?
    Inferno.logger.info 'Terminology built successfully.'
    return
  end

  if only_non_umls_mismatch?
    Inferno.logger.info <<~NON_UMLS
      Terminology built successfully.

      Some terminology not based on UMLS did not match, but this can be
      a result of these terminologies having a different update schedule
      than UMLS. As long as the actual number of codes is close to the
      expected number, this does not does not reflect a problem with the
      terminology build.
    NON_UMLS
  else
    Inferno.logger.info 'Terminology build results different than expected.'
  end

  mismatched_value_sets.each do |value_set|
    Inferno.logger.info mismatched_value_set_message(value_set)
  end

  return unless new_value_sets.present?

  Inferno.logger.info("\nThe following unexpected value set validators were created:")
  new_value_sets.each do |value_set|
    Inferno.logger.info("#{value_set[:url]}: #{value_set[:count]} codes")
  end
end