inferno_core 0.4.18 → 0.4.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9fc795a49145b262a250f35b8653e39c506313af4788f1b82ef274c4c4ea7960
4
- data.tar.gz: 29214802809c59187e4923eaa9f8b1844ebab5f0dffa32738242721de55b4b85
3
+ metadata.gz: a9b06c0f0ce1702d3ba9662e4762e3174eb22527a19a3eb35a5ec0e01dbf57d3
4
+ data.tar.gz: 8c019f778c84c0926ef1705e256e0d3b27fd39a2c6af4f32bd8c4d1ad731ff84
5
5
  SHA512:
6
- metadata.gz: 71c77cd25ddef3ea505359a81b1e979fdcf528e87587ad3b518e5389418a423bacd1965396d7a31f7b7ad3bef3b70465c63654dbb95bd7290e7e35d9f906f7dc
7
- data.tar.gz: fc5abb31735fbc351084ee8ed8d385dbcfab4637bcea8338c58fa79bebcf5bb65314e33cc3e619b96b83b495aadd1225b4cf9f8267ff0c92b0394fad0f2cb57d
6
+ metadata.gz: 39690b392f9e9997081cc5d58ee93c249a15be3eaeecca3927619f4d116e00cd85cdecc8a91693385420bb7b7bc07398b05b636d9be94713b23ad52c99bc9161
7
+ data.tar.gz: f2970277134ae396003da04b2ba09c19cd3dc02f70e513cbdbeaf7a7e014561cbf742a95fc8ed40cec034a23723ad54ed823637989628dd0661fc467b49db11a
@@ -36,7 +36,7 @@ module Inferno
36
36
  command = "rerun \"#{command}\" --background"
37
37
  end
38
38
 
39
- system command
39
+ exec command
40
40
  end
41
41
 
42
42
  desc 'suites', 'List available test suites'
@@ -25,5 +25,13 @@ Inferno::Application.boot(:suites) do
25
25
  end
26
26
 
27
27
  ObjectSpace.each_object(TracePoint, &:disable)
28
+
29
+ Inferno::Entities::TestSuite.descendants.each do |descendant|
30
+ # When ID not assigned in custom test suites, Runnable.id will return default ID
31
+ # equal to the custom test suite's parent class name
32
+ if descendant.id.blank? || descendant.id == 'Inferno::Entities::TestSuite'
33
+ raise StandardError, "Error initializing test suite #{descendant.name}: test suite ID is not set"
34
+ end
35
+ end
28
36
  end
29
37
  end
@@ -116,17 +116,26 @@ module Inferno
116
116
  def resource_is_valid?(resource, profile_url, runnable)
117
117
  profile_url ||= FHIR::Definitions.resource_definition(resource.resourceType).url
118
118
 
119
- outcome = FHIR::OperationOutcome.new(JSON.parse(validate(resource, profile_url)))
119
+ outcome, http_status = validate(resource, profile_url, runnable)
120
120
 
121
- message_hashes = outcome.issue&.map { |issue| message_hash_from_issue(issue, resource) } || []
121
+ message_hashes = message_hashes_from_outcome(outcome, resource, profile_url)
122
122
 
123
- message_hashes.concat(additional_validation_messages(resource, profile_url))
123
+ message_hashes
124
+ .each { |message_hash| runnable.add_message(message_hash[:type], message_hash[:message]) }
124
125
 
125
- filter_messages(message_hashes)
126
+ unless http_status == 200
127
+ raise Inferno::Exceptions::ErrorInValidatorException,
128
+ 'Error occurred in the validator. Review Messages tab or validator service logs for more information.'
129
+ end
126
130
 
127
131
  message_hashes
128
- .each { |message_hash| runnable.add_message(message_hash[:type], message_hash[:message]) }
129
132
  .none? { |message_hash| message_hash[:type] == 'error' }
133
+ rescue Inferno::Exceptions::ErrorInValidatorException
134
+ raise
135
+ rescue StandardError => e
136
+ runnable.add_message('error', e.message)
137
+ raise Inferno::Exceptions::ErrorInValidatorException,
138
+ 'Error occurred in the validator. Review Messages tab or validator service logs for more information.'
130
139
  end
131
140
 
132
141
  # @private
@@ -134,6 +143,17 @@ module Inferno
134
143
  message_hashes.reject! { |message| exclude_message.call(Entities::Message.new(message)) } if exclude_message
135
144
  end
136
145
 
146
+ # @private
147
+ def message_hashes_from_outcome(outcome, resource, profile_url)
148
+ message_hashes = outcome.issue&.map { |issue| message_hash_from_issue(issue, resource) } || []
149
+
150
+ message_hashes.concat(additional_validation_messages(resource, profile_url))
151
+
152
+ filter_messages(message_hashes)
153
+
154
+ message_hashes
155
+ end
156
+
137
157
  # @private
138
158
  def message_hash_from_issue(issue, resource)
139
159
  {
@@ -171,12 +191,33 @@ module Inferno
171
191
  #
172
192
  # @param resource [FHIR::Model]
173
193
  # @param profile_url [String]
174
- # @return [String] the body of the validation response
175
- def validate(resource, profile_url)
176
- Faraday.new(
177
- url,
178
- params: { profile: profile_url }
179
- ).post('validate', resource.source_contents).body
194
+ # @param runnable [Inferno::Entities::Test]
195
+ # @return [[Array(FHIR::OperationOutcome, Number)] the validation response and HTTP status code
196
+ def validate(resource, profile_url, runnable)
197
+ begin
198
+ response = Faraday.new(
199
+ url,
200
+ params: { profile: profile_url }
201
+ ).post('validate', resource.source_contents)
202
+ rescue StandardError => e
203
+ runnable.add_message('error', e.message)
204
+ raise Inferno::Exceptions::ErrorInValidatorException, "Unable to connect to validator at #{url}."
205
+ end
206
+ outcome = operation_outcome_from_validator_response(response.body, runnable)
207
+
208
+ [outcome, response.status]
209
+ end
210
+
211
+ # @private
212
+ def operation_outcome_from_validator_response(response, runnable)
213
+ if response.start_with? '{'
214
+ FHIR::OperationOutcome.new(JSON.parse(response))
215
+ else
216
+ runnable.add_message('error', "Validator Response: #{response}")
217
+ raise Inferno::Exceptions::ErrorInValidatorException,
218
+ 'Validator response was an unexpected format. '\
219
+ 'Review Messages tab or validator service logs for more information.'
220
+ end
180
221
  end
181
222
  end
182
223
 
@@ -39,6 +39,16 @@ module Inferno
39
39
  end
40
40
  end
41
41
 
42
+ class ErrorInValidatorException < TestResultException
43
+ # This extends TestResultException instead of RuntimeError
44
+ # to bypass printing the stack trace in the UI.
45
+ # (The stack trace of this exception may not be useful,
46
+ # instead the message should point to where in the validator an error occurred)
47
+ def result
48
+ 'error'
49
+ end
50
+ end
51
+
42
52
  class ParentNotLoadedException < RuntimeError
43
53
  def initialize(klass, id)
44
54
  super("No #{klass.name.demodulize} found with id '#{id}'")