Class: Inferno::CLI::Evaluate

Inherits:
Thor::Group
  • Object
show all
Defined in:
lib/inferno/apps/cli/evaluate.rb

Instance Method Summary collapse

Instance Method Details

#check_ig_version(ig) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/inferno/apps/cli/evaluate.rb', line 39

def check_ig_version(ig)
  versions = ig.ig_resource.fhirVersion

  return unless versions.any? { |v| v > '4.0.1' }

  puts '**WARNING** The selected IG targets a FHIR version higher than 4.0.1, which is not supported by Inferno.'
end

#evaluate(ig_path, data_path, _log_level) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/inferno/apps/cli/evaluate.rb', line 11

def evaluate(ig_path, data_path, _log_level)
  validate_args(ig_path, data_path)
  ig = Inferno::Repositories::IGs.new.find_or_load(ig_path)

  check_ig_version(ig)

  data =
    if data_path
      DatasetLoader.from_path(File.join(__dir__, data_path))
    else
      ig.examples
    end

  evaluator = Inferno::DSL::FHIREvaluation::Evaluator.new(ig)

  config = Inferno::DSL::FHIREvaluation::Config.new
  results = evaluator.evaluate(data, config)
  output_results(results, options[:output])
end

#output_results(results, output) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/inferno/apps/cli/evaluate.rb', line 47

def output_results(results, output)
  if output&.end_with?('json')
    oo = FhirEvaluator::EvaluationResult.to_operation_outcome(results)
    File.write(output, oo.to_json)
    puts "Results written to #{output}"
  else
    counts = results.group_by(&:severity).transform_values(&:count)
    print(counts, 'Result Count')
    puts "\n"
    puts results
  end
end

#pad(string, length) ⇒ Object



73
74
75
# File 'lib/inferno/apps/cli/evaluate.rb', line 73

def pad(string, length)
  format("%#{length}.#{length}s", string)
end


60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/inferno/apps/cli/evaluate.rb', line 60

def print(output_fields, title)
  puts("╔══════════════ #{title} ═══════════════╗")
  puts('║ ╭────────────────┬──────────────────────╮ ║')
  output_fields.each_with_index do |(key, value), i|
    field_name = pad(key, 14)
    field_value = pad(value.to_s, 20)
    puts("║ │ #{field_name}#{field_value} │ ║")
    puts('║ ├────────────────┼──────────────────────┤ ║') unless i == output_fields.length - 1
  end
  puts('║ ╰────────────────┴──────────────────────╯ ║')
  puts('╚═══════════════════════════════════════════╝')
end

#validate_args(ig_path, data_path) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/inferno/apps/cli/evaluate.rb', line 31

def validate_args(ig_path, data_path)
  raise 'A path to an IG is required!' unless ig_path

  return unless data_path && (!File.directory? data_path)

  raise "Provided path '#{data_path}' is not a directory"
end