Module: Inferno::DSL::FHIRClient
- Defined in:
- lib/inferno/dsl/fhir_client.rb
Overview
This module contains the FHIR DSL available to test writers.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#fhir_client(client = :default) ⇒ FHIR::Client
Return a previously defined FHIR client.
-
#fhir_create(resource, client: :default, name: nil, tags: []) ⇒ Inferno::Entities::Request
Perform a FHIR create interaction.
-
#fhir_delete(resource_type, id, client: :default, name: nil, tags: []) ⇒ Inferno::Entities::Request
Perform a FHIR delete interaction.
-
#fhir_get_capability_statement(client: :default, name: nil, tags: []) ⇒ Inferno::Entities::Request
Fetch the capability statement.
-
#fhir_history(resource_type = nil, id = nil, client: :default, name: nil, tags: []) ⇒ Inferno::Entities::Request
Perform a FHIR history interaction.
-
#fhir_operation(path, body: nil, client: :default, name: nil, headers: {}, operation_method: :post, tags: []) ⇒ Inferno::Entities::Request
Perform a FHIR operation.
-
#fhir_patch(resource_type, id, patchset, client: :default, name: nil, tags: []) ⇒ Inferno::Entities::Request
Perform a FHIR patch interaction.
-
#fhir_read(resource_type, id, client: :default, name: nil, tags: []) ⇒ Inferno::Entities::Request
Perform a FHIR read interaction.
-
#fhir_search(resource_type = nil, client: :default, params: {}, name: nil, search_method: :get, tags: []) ⇒ Inferno::Entities::Request
Perform a FHIR search interaction.
-
#fhir_transaction(bundle = nil, client: :default, name: nil, tags: []) ⇒ Inferno::Entities::Request
Perform a FHIR batch/transaction interaction.
-
#fhir_update(resource, id, client: :default, name: nil, tags: []) ⇒ Inferno::Entities::Request
Perform a FHIR update interaction.
-
#fhir_vread(resource_type, id, version_id, client: :default, name: nil, tags: []) ⇒ Inferno::Entities::Request
Perform a FHIR vread interaction.
Instance Method Details
#fhir_client(client = :default) ⇒ FHIR::Client
Return a previously defined FHIR client
53 54 55 56 |
# File 'lib/inferno/dsl/fhir_client.rb', line 53 def fhir_client(client = :default) fhir_clients[client] ||= FHIRClientBuilder.new.build(self, self.class.fhir_client_definitions[client]) end |
#fhir_create(resource, client: :default, name: nil, tags: []) ⇒ Inferno::Entities::Request
Perform a FHIR create interaction.
158 159 160 161 162 163 164 |
# File 'lib/inferno/dsl/fhir_client.rb', line 158 def fhir_create(resource, client: :default, name: nil, tags: []) store_request_and_refresh_token(fhir_client(client), name, ) do tcp_exception_handler do fhir_client(client).create(resource) end end end |
#fhir_delete(resource_type, id, client: :default, name: nil, tags: []) ⇒ Inferno::Entities::Request
Perform a FHIR delete interaction.
305 306 307 308 309 310 311 |
# File 'lib/inferno/dsl/fhir_client.rb', line 305 def fhir_delete(resource_type, id, client: :default, name: nil, tags: []) store_request('outgoing', name:, tags:) do tcp_exception_handler do fhir_client(client).destroy(fhir_class_from_resource_type(resource_type), id) end end end |
#fhir_get_capability_statement(client: :default, name: nil, tags: []) ⇒ Inferno::Entities::Request
Fetch the capability statement.
141 142 143 144 145 146 147 148 |
# File 'lib/inferno/dsl/fhir_client.rb', line 141 def fhir_get_capability_statement(client: :default, name: nil, tags: []) store_request_and_refresh_token(fhir_client(client), name, ) do tcp_exception_handler do fhir_client(client).conformance_statement fhir_client(client).reply end end end |
#fhir_history(resource_type = nil, id = nil, client: :default, name: nil, tags: []) ⇒ Inferno::Entities::Request
Perform a FHIR history interaction.
245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/inferno/dsl/fhir_client.rb', line 245 def fhir_history(resource_type = nil, id = nil, client: :default, name: nil, tags: []) store_request_and_refresh_token(fhir_client(client), name, ) do tcp_exception_handler do if id fhir_client(client).resource_instance_history(fhir_class_from_resource_type(resource_type), id) elsif resource_type fhir_client(client).resource_history(fhir_class_from_resource_type(resource_type)) else fhir_client(client).all_history end end end end |
#fhir_operation(path, body: nil, client: :default, name: nil, headers: {}, operation_method: :post, tags: []) ⇒ Inferno::Entities::Request
This is a placeholder method until the FHIR::Client supports general operations. Note that while both POST and GET methods are allowed, GET is only allowed when the operation does not affect the server’s state. See https://build.fhir.org/operationdefinition-definitions.html#OperationDefinition.affectsState
Currently does not allow for repeated parameters if using GET
Perform a FHIR operation
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/inferno/dsl/fhir_client.rb', line 106 def fhir_operation( path, body: nil, client: :default, name: nil, headers: {}, operation_method: :post, tags: [] ) store_request_and_refresh_token(fhir_client(client), name, ) do tcp_exception_handler do operation_headers = fhir_client(client).fhir_headers operation_headers.merge!('Content-Type' => 'application/fhir+json') if body.present? operation_headers.merge!(headers) if headers.present? case operation_method when :post fhir_client(client).send(:post, path, body, operation_headers) when :get path = "#{path}?#{body_to_path(body)}" if body.present? fhir_client(client).send(:get, path, operation_headers) else Inferno::Application[:logger].error "Cannot perform #{operation_method} requests, use GET or POST" raise ArgumentError, "Cannot perform #{operation_method} requests, use GET or POST" end end end end |
#fhir_patch(resource_type, id, patchset, client: :default, name: nil, tags: []) ⇒ Inferno::Entities::Request
Perform a FHIR patch interaction.
228 229 230 231 232 233 234 |
# File 'lib/inferno/dsl/fhir_client.rb', line 228 def fhir_patch(resource_type, id, patchset, client: :default, name: nil, tags: []) store_request_and_refresh_token(fhir_client(client), name, ) do tcp_exception_handler do fhir_client(client).partial_update(fhir_class_from_resource_type(resource_type), id, patchset) end end end |
#fhir_read(resource_type, id, client: :default, name: nil, tags: []) ⇒ Inferno::Entities::Request
Perform a FHIR read interaction.
175 176 177 178 179 180 181 |
# File 'lib/inferno/dsl/fhir_client.rb', line 175 def fhir_read(resource_type, id, client: :default, name: nil, tags: []) store_request_and_refresh_token(fhir_client(client), name, ) do tcp_exception_handler do fhir_client(client).read(fhir_class_from_resource_type(resource_type), id) end end end |
#fhir_search(resource_type = nil, client: :default, params: {}, name: nil, search_method: :get, tags: []) ⇒ Inferno::Entities::Request
Perform a FHIR search interaction.
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/inferno/dsl/fhir_client.rb', line 269 def fhir_search( resource_type = nil, client: :default, params: {}, name: nil, search_method: :get, tags: [] ) search = if search_method == :post { body: params } else { parameters: params } end store_request_and_refresh_token(fhir_client(client), name, ) do tcp_exception_handler do if resource_type fhir_client(client) .search(fhir_class_from_resource_type(resource_type), { search: }) else fhir_client(client).search_all({ search: }) end end end end |
#fhir_transaction(bundle = nil, client: :default, name: nil, tags: []) ⇒ Inferno::Entities::Request
Perform a FHIR batch/transaction interaction.
321 322 323 324 325 326 327 328 |
# File 'lib/inferno/dsl/fhir_client.rb', line 321 def fhir_transaction(bundle = nil, client: :default, name: nil, tags: []) store_request('outgoing', name:, tags:) do tcp_exception_handler do fhir_client(client).transaction_bundle = bundle if bundle.present? fhir_client(client).end_transaction end end end |
#fhir_update(resource, id, client: :default, name: nil, tags: []) ⇒ Inferno::Entities::Request
Perform a FHIR update interaction.
210 211 212 213 214 215 216 |
# File 'lib/inferno/dsl/fhir_client.rb', line 210 def fhir_update(resource, id, client: :default, name: nil, tags: []) store_request_and_refresh_token(fhir_client(client), name, ) do tcp_exception_handler do fhir_client(client).update(resource, id) end end end |
#fhir_vread(resource_type, id, version_id, client: :default, name: nil, tags: []) ⇒ Inferno::Entities::Request
Perform a FHIR vread interaction.
193 194 195 196 197 198 199 |
# File 'lib/inferno/dsl/fhir_client.rb', line 193 def fhir_vread(resource_type, id, version_id, client: :default, name: nil, tags: []) store_request_and_refresh_token(fhir_client(client), name, ) do tcp_exception_handler do fhir_client(client).vread(fhir_class_from_resource_type(resource_type), id, version_id) end end end |