inferno_core 0.4.17 → 0.4.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77e9c5d39c29db85f07321f5456cebad0fb4e285f0143533984d36500248fbd7
4
- data.tar.gz: e22a7589dbb1bc4edd54ad3305526fdfeae4358fd992b2b23f5d69a8a8fa139c
3
+ metadata.gz: a9b06c0f0ce1702d3ba9662e4762e3174eb22527a19a3eb35a5ec0e01dbf57d3
4
+ data.tar.gz: 8c019f778c84c0926ef1705e256e0d3b27fd39a2c6af4f32bd8c4d1ad731ff84
5
5
  SHA512:
6
- metadata.gz: 642da73f8db4428c210e80919567a7fe5586a93fa4f485e6dfaff117c1d796936a263dcb82d8bb69c309266a0b150846e93a51825e4b8bab0eaffe237ec23f20
7
- data.tar.gz: 2f68462dee18ced89167e7327a3dd5fbb7d250adef866604e4590d5c891fcb695761127b46804125c9d165de859d0777dc74ccf4772ba5a1b9f2865f0dcda6f3
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
@@ -130,6 +130,78 @@ module Inferno
130
130
  end
131
131
  end
132
132
 
133
+ # Perform a FHIR vread interaction.
134
+ #
135
+ # @param resource_type [String, Symbol, Class]
136
+ # @param id [String]
137
+ # @param version_id [String]
138
+ # @param client [Symbol]
139
+ # @param name [Symbol] Name for this request to allow it to be used by
140
+ # other tests
141
+ # @return [Inferno::Entities::Request]
142
+ def fhir_vread(resource_type, id, version_id, client: :default, name: nil)
143
+ store_request_and_refresh_token(fhir_client(client), name) do
144
+ tcp_exception_handler do
145
+ fhir_client(client).vread(fhir_class_from_resource_type(resource_type), id, version_id)
146
+ end
147
+ end
148
+ end
149
+
150
+ # Perform a FHIR update interaction.
151
+ #
152
+ # @param resource [FHIR::Model]
153
+ # @param id [String]
154
+ # @param client [Symbol]
155
+ # @param name [Symbol] Name for this request to allow it to be used by
156
+ # other tests
157
+ # @return [Inferno::Entities::Request]
158
+ def fhir_update(resource, id, client: :default, name: nil)
159
+ store_request_and_refresh_token(fhir_client(client), name) do
160
+ tcp_exception_handler do
161
+ fhir_client(client).update(resource, id)
162
+ end
163
+ end
164
+ end
165
+
166
+ # Perform a FHIR patch interaction.
167
+ #
168
+ # @param resource_type [String, Symbol, Class]
169
+ # @param id [String]
170
+ # @param patchset [Array]
171
+ # @param client [Symbol]
172
+ # @param name [Symbol] Name for this request to allow it to be used by
173
+ # other tests
174
+ # @return [Inferno::Entities::Request]
175
+ def fhir_patch(resource_type, id, patchset, client: :default, name: nil)
176
+ store_request_and_refresh_token(fhir_client(client), name) do
177
+ tcp_exception_handler do
178
+ fhir_client(client).partial_update(fhir_class_from_resource_type(resource_type), id, patchset)
179
+ end
180
+ end
181
+ end
182
+
183
+ # Perform a FHIR history interaction.
184
+ #
185
+ # @param resource_type [String, Symbol, Class]
186
+ # @param id [String]
187
+ # @param client [Symbol]
188
+ # @param name [Symbol] Name for this request to allow it to be used by
189
+ # other tests
190
+ # @return [Inferno::Entities::Request]
191
+ def fhir_history(resource_type = nil, id = nil, client: :default, name: nil)
192
+ store_request_and_refresh_token(fhir_client(client), name) do
193
+ tcp_exception_handler do
194
+ if id
195
+ fhir_client(client).resource_instance_history(fhir_class_from_resource_type(resource_type), id)
196
+ elsif resource_type
197
+ fhir_client(client).resource_history(fhir_class_from_resource_type(resource_type))
198
+ else
199
+ fhir_client(client).all_history
200
+ end
201
+ end
202
+ end
203
+ end
204
+
133
205
  # Perform a FHIR search interaction.
134
206
  #
135
207
  # @param resource_type [String, Symbol, Class]
@@ -139,7 +211,7 @@ module Inferno
139
211
  # other tests
140
212
  # @param search_method [Symbol] Use `:post` to search via POST
141
213
  # @return [Inferno::Entities::Request]
142
- def fhir_search(resource_type, client: :default, params: {}, name: nil, search_method: :get)
214
+ def fhir_search(resource_type = nil, client: :default, params: {}, name: nil, search_method: :get)
143
215
  search =
144
216
  if search_method == :post
145
217
  { body: params }
@@ -149,8 +221,12 @@ module Inferno
149
221
 
150
222
  store_request_and_refresh_token(fhir_client(client), name) do
151
223
  tcp_exception_handler do
152
- fhir_client(client)
153
- .search(fhir_class_from_resource_type(resource_type), { search: })
224
+ if resource_type
225
+ fhir_client(client)
226
+ .search(fhir_class_from_resource_type(resource_type), { search: })
227
+ else
228
+ fhir_client(client).search_all({ search: })
229
+ end
154
230
  end
155
231
  end
156
232
  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}'")