Class: Inferno::CLI::Evaluate
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Inferno::CLI::Evaluate
show all
- Includes:
- Utils::IgDownloader, Thor::Actions
- Defined in:
- lib/inferno/apps/cli/evaluate.rb
Constant Summary
Utils::IgDownloader::FHIR_PACKAGE_NAME_REG_EX, Utils::IgDownloader::FILE_URI_REG_EX, Utils::IgDownloader::HTTP_URI_END_REG_EX, Utils::IgDownloader::HTTP_URI_REG_EX
Instance Method Summary
collapse
#ig_file, #ig_http_url, #ig_path, #ig_registry_url, #load_ig
Instance Method Details
#evaluate(ig_path, data_path, _log_level) ⇒ Object
[View source]
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/inferno/apps/cli/evaluate.rb', line 13
def evaluate(ig_path, data_path, _log_level)
validate_args(ig_path, data_path)
_ig = get_ig(ig_path)
end
|
#get_ig(ig_path) ⇒ Object
[View source]
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/inferno/apps/cli/evaluate.rb', line 40
def get_ig(ig_path)
if File.exist?(ig_path)
ig = Inferno::Entities::IG.from_file(ig_path)
elsif in_user_package_cache?(ig_path.sub('@', '#'))
cache_directory = File.join(user_package_cache, ig_path.sub('@', '#'))
ig = Inferno::Entities::IG.from_file(cache_directory)
else
Tempfile.create('package.tgz') do |temp_file|
load_ig(ig_path, nil, { force: true }, temp_file.path)
ig = Inferno::Entities::IG.from_file(temp_file.path)
end
end
ig.add_self_to_repository
ig
end
|
#in_user_package_cache?(ig_identifier) ⇒ Boolean
[View source]
62
63
64
|
# File 'lib/inferno/apps/cli/evaluate.rb', line 62
def in_user_package_cache?(ig_identifier)
File.directory?(File.join(user_package_cache, ig_identifier))
end
|
#output_results(results, output) ⇒ Object
[View source]
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/inferno/apps/cli/evaluate.rb', line 66
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
[View source]
92
93
94
|
# File 'lib/inferno/apps/cli/evaluate.rb', line 92
def pad(string, length)
format("%#{length}.#{length}s", string)
end
|
#print(output_fields, title) ⇒ Object
[View source]
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/inferno/apps/cli/evaluate.rb', line 79
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
|
#user_package_cache ⇒ Object
[View source]
58
59
60
|
# File 'lib/inferno/apps/cli/evaluate.rb', line 58
def user_package_cache
File.join(Dir.home, '.fhir', 'packages')
end
|
#validate_args(ig_path, data_path) ⇒ Object
[View source]
32
33
34
35
36
37
38
|
# File 'lib/inferno/apps/cli/evaluate.rb', line 32
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
|