inferno_core 0.4.39 → 0.4.40

Sign up to get free protection for your applications and to get access to all the features.
data/lib/inferno/dsl.rb CHANGED
@@ -2,10 +2,12 @@ require_relative 'dsl/assertions'
2
2
  require_relative 'dsl/fhir_client'
3
3
  require_relative 'dsl/fhir_validation'
4
4
  require_relative 'dsl/fhir_resource_validation'
5
+ require_relative 'dsl/fhirpath_evaluation'
5
6
  require_relative 'dsl/http_client'
6
7
  require_relative 'dsl/results'
7
8
  require_relative 'dsl/runnable'
8
9
  require_relative 'dsl/suite_endpoint'
10
+ require_relative 'dsl/messages'
9
11
 
10
12
  module Inferno
11
13
  # The DSL for writing tests.
@@ -16,7 +18,9 @@ module Inferno
16
18
  HTTPClient,
17
19
  Results,
18
20
  FHIRValidation,
19
- FHIRResourceValidation
21
+ FHIRResourceValidation,
22
+ FhirpathEvaluation,
23
+ Messages
20
24
  ].freeze
21
25
 
22
26
  EXTENDABLE_DSL_MODULES = [
@@ -1,6 +1,5 @@
1
1
  require_relative '../dsl'
2
2
  require_relative '../repositories/tests'
3
- require_relative '../utils/markdown_formatter'
4
3
  require 'pry'
5
4
 
6
5
  module Inferno
@@ -8,7 +7,6 @@ module Inferno
8
7
  class Test
9
8
  extend Forwardable
10
9
  include DSL
11
- include Inferno::Utils::MarkdownFormatter
12
10
 
13
11
  def_delegators 'self.class', :title, :id, :block, :inputs, :outputs
14
12
 
@@ -23,20 +21,6 @@ module Inferno
23
21
  @suite_options = params[:suite_options].presence || {}
24
22
  end
25
23
 
26
- # @private
27
- def messages
28
- @messages ||= []
29
- end
30
-
31
- # Add a message to the result.
32
- #
33
- # @param type [String] error, warning, or info
34
- # @param message [String]
35
- # @return [void]
36
- def add_message(type, message)
37
- messages << { type: type.to_s, message: format_markdown(message) }
38
- end
39
-
40
24
  # Set output values. Once set, these values will be available to any
41
25
  # subsequent tests.
42
26
  #
@@ -59,54 +43,6 @@ module Inferno
59
43
  @outputs_to_persist ||= {}
60
44
  end
61
45
 
62
- # Add an informational message to the results of a test. If passed a
63
- # block, a failed assertion will become an info message and test execution
64
- # will continue.
65
- #
66
- # @param message [String]
67
- # @return [void]
68
- # @example
69
- # # Add an info message
70
- # info 'This message will be added to the test results'
71
- #
72
- # # The message for the failed assertion will be treated as an info
73
- # # message. Test exection will continue.
74
- # info { assert false == true }
75
- def info(message = nil)
76
- unless block_given?
77
- add_message('info', message) unless message.nil?
78
- return
79
- end
80
-
81
- yield
82
- rescue Exceptions::AssertionException => e
83
- add_message('info', e.message)
84
- end
85
-
86
- # Add a warning message to the results of a test. If passed a block, a
87
- # failed assertion will become a warning message and test execution will
88
- # continue.
89
- #
90
- # @param message [String]
91
- # @return [void]
92
- # @example
93
- # # Add a warning message
94
- # warning 'This message will be added to the test results'
95
- #
96
- # # The message for the failed assertion will be treated as a warning
97
- # # message. Test exection will continue.
98
- # warning { assert false == true }
99
- def warning(message = nil)
100
- unless block_given?
101
- add_message('warning', message) unless message.nil?
102
- return
103
- end
104
-
105
- yield
106
- rescue Exceptions::AssertionException => e
107
- add_message('warning', e.message)
108
- end
109
-
110
46
  # @private
111
47
  def method_missing(name, *args, &)
112
48
  parent_instance = self.class.parent&.new
@@ -167,18 +103,6 @@ module Inferno
167
103
  Inferno::Repositories::Tests.new
168
104
  end
169
105
 
170
- # Set/Get the block that is executed when a Test is run
171
- #
172
- # @param block [Proc]
173
- # @return [Proc] the block that is executed when a Test is run
174
- def block(&block)
175
- return @block unless block_given?
176
-
177
- @block = block
178
- end
179
-
180
- alias run block
181
-
182
106
  def short_id
183
107
  @short_id ||= begin
184
108
  prefix = parent.respond_to?(:short_id) ? "#{parent.short_id}." : ''
@@ -1,5 +1,6 @@
1
1
  require_relative '../dsl'
2
2
  require_relative '../repositories/test_groups'
3
+ require_relative '../result_collection'
3
4
 
4
5
  module Inferno
5
6
  module Entities
@@ -9,8 +10,19 @@ module Inferno
9
10
  extend DSL::HTTPClient::ClassMethods
10
11
  extend DSL::Runnable
11
12
  include DSL::FHIRValidation
13
+ include DSL::FhirpathEvaluation
14
+ include DSL::Results
15
+ include DSL::Assertions
16
+ include DSL::Messages
12
17
 
13
- def_delegators 'self.class', :title, :id, :groups, :inputs, :outputs, :tests
18
+ def_delegators 'self.class', :title, :id, :block, :groups, :inputs, :outputs, :tests
19
+
20
+ attr_accessor :result_message, :results
21
+
22
+ # @private
23
+ def initialize
24
+ @results = Inferno::ResultCollection.new
25
+ end
14
26
 
15
27
  # @private
16
28
  def method_missing(name, *args, &)
@@ -1,8 +1,10 @@
1
1
  require_relative 'test_group'
2
2
  require_relative '../dsl/runnable'
3
3
  require_relative '../dsl/suite_option'
4
+ require_relative '../dsl/messages'
4
5
  require_relative '../repositories/test_groups'
5
6
  require_relative '../repositories/test_suites'
7
+ require_relative '../result_collection'
6
8
 
7
9
  module Inferno
8
10
  module Entities
@@ -14,6 +16,19 @@ module Inferno
14
16
  extend DSL::HTTPClient::ClassMethods
15
17
  include DSL::FHIRValidation
16
18
  include DSL::FHIRResourceValidation
19
+ include DSL::FhirpathEvaluation
20
+ include DSL::Results
21
+ include DSL::Assertions
22
+ include DSL::Messages
23
+
24
+ def_delegators 'self.class', :block
25
+
26
+ attr_accessor :result_message, :results
27
+
28
+ # @private
29
+ def initialize
30
+ @results = Inferno::ResultCollection.new
31
+ end
17
32
 
18
33
  class << self
19
34
  extend Forwardable
@@ -64,6 +64,25 @@ module Inferno
64
64
  end
65
65
  end
66
66
 
67
+ class FhirpathNotFoundException < RuntimeError
68
+ def initialize(fhirpath_name)
69
+ super("No '#{fhirpath_name}' FHIRPath evaluator found")
70
+ end
71
+ end
72
+
73
+ # ErrorInFhirpathException is used when an exception occurred in
74
+ # calling the FHIRPath service, for example a connection timeout
75
+ # or an unexpected response format.
76
+ # Note: This class extends TestResultException instead of RuntimeError
77
+ # to bypass printing the stack trace in the UI, since
78
+ # the stack trace of this exception is not likely be useful.
79
+ # Instead the message should point to where in the fhirpath evaluator an error occurred.
80
+ class ErrorInFhirpathException < TestResultException
81
+ def result
82
+ 'error'
83
+ end
84
+ end
85
+
67
86
  class RequiredInputsNotFound < RuntimeError
68
87
  def initialize(missing_inputs)
69
88
  super("Missing the following required inputs: #{missing_inputs.join(', ')}")
@@ -1,13 +1,13 @@
1
1
  module FHIR
2
2
  class Client
3
- attr_accessor :oauth_credentials
3
+ attr_accessor :oauth_credentials, :auth_info
4
4
 
5
5
  def need_to_refresh?
6
- oauth_credentials&.need_to_refresh?
6
+ !!(auth_info&.need_to_refresh? || oauth_credentials&.need_to_refresh?)
7
7
  end
8
8
 
9
9
  def able_to_refresh?
10
- oauth_credentials&.able_to_refresh?
10
+ !!(auth_info&.able_to_refresh? || oauth_credentials&.able_to_refresh?)
11
11
  end
12
12
  end
13
13
  end
@@ -8,16 +8,15 @@ module Inferno
8
8
  suite = Inferno::Repositories::TestSuites.new.find suite_id
9
9
  validator = suite.fhir_validators[validator_name.to_sym][validator_index]
10
10
  response_body = validator.validate(FHIR::Patient.new, 'http://hl7.org/fhir/StructureDefinition/Patient')
11
- if response_body.start_with? '{'
12
- res = JSON.parse(response_body)
13
- session_id = res['sessionId']
14
- session_repo = Inferno::Repositories::ValidatorSessions.new
15
- session_repo.save(test_suite_id: suite_id, validator_session_id: session_id,
16
- validator_name:, suite_options: validator.requirements)
17
- validator.session_id = session_id
18
- else
19
- Inferno::Application['logger'].error("InvokeValidatorSession - error from validator: #{response_body}")
20
- end
11
+ res = JSON.parse(response_body)
12
+ session_id = res['sessionId']
13
+ session_repo = Inferno::Repositories::ValidatorSessions.new
14
+ session_repo.save(test_suite_id: suite_id, validator_session_id: session_id,
15
+ validator_name:, suite_options: validator.requirements)
16
+ validator.session_id = session_id
17
+ rescue JSON::ParserError
18
+ Inferno::Application['logger']
19
+ .error("InvokeValidatorSession - error unexpected response format from validator: #{response_body}")
21
20
  end
22
21
  end
23
22
  end