Module: Inferno::DSL::FHIRClient

Defined in:
lib/inferno/dsl/fhir_client.rb

Overview

This module contains the FHIR DSL available to test writers.

Examples:

class MyTestGroup < Inferno::TestGroup
  # create a "default" client for a group
  fhir_client do
    url 'https://example.com/fhir'
  end

  # create a named client for a group
  fhir_client :with_custom_header do
    url 'https://example.com/fhir'
    headers { 'X-my-custom-header': 'ABC123' }
  end

  test :some_test do
    run do
      # uses the default client
      fhir_read('Patient', 5)

      # uses a named client
      fhir_read('Patient', 5, client: :with_custom_header)

      request  # the most recent request
      response # the most recent response
      resource # the resource from the most recent response
      requests # all of the requests which have been made in this test
    end
  end
end

See Also:

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#fhir_client(client = :default) ⇒ FHIR::Client

Return a previously defined FHIR client

Parameters:

  • client (Symbol) (defaults to: :default)

    the name of the client

Returns:

See Also:



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) ⇒ Inferno::Entities::Request

Perform a FHIR create interaction.

Parameters:

  • resource (FHIR::Model)
  • client (Symbol) (defaults to: :default)
  • name (Symbol) (defaults to: nil)

    Name for this request to allow it to be used by other tests

Returns:



109
110
111
112
113
114
115
# File 'lib/inferno/dsl/fhir_client.rb', line 109

def fhir_create(resource, client: :default, name: nil)
  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) ⇒ Inferno::Entities::Request

Perform a FHIR delete interaction.

Parameters:

  • resource_type (String, Symbol, Class)
  • id (String)
  • client (Symbol) (defaults to: :default)
  • name (Symbol) (defaults to: nil)

    Name for this request to allow it to be used by other tests

Returns:



166
167
168
169
170
171
172
# File 'lib/inferno/dsl/fhir_client.rb', line 166

def fhir_delete(resource_type, id, client: :default, name: nil)
  store_request('outgoing', name) 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) ⇒ Inferno::Entities::Request

Fetch the capability statement.

Parameters:

  • client (Symbol) (defaults to: :default)
  • name (Symbol) (defaults to: nil)

    Name for this request to allow it to be used by other tests

Returns:



93
94
95
96
97
98
99
100
# File 'lib/inferno/dsl/fhir_client.rb', line 93

def fhir_get_capability_statement(client: :default, name: nil)
  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_operation(path, body: nil, client: :default, name: nil, headers: {}) ⇒ Inferno::Entities::Request

Note:

This is a placeholder method until the FHIR::Client supports general operations

Perform a FHIR operation

Parameters:

  • path (String)
  • body (FHIR::Parameters) (defaults to: nil)
  • client (Symbol) (defaults to: :default)
  • name (Symbol) (defaults to: nil)

    Name for this request to allow it to be used by other tests

  • headers (Hash) (defaults to: {})

    custom headers for this operation

Returns:



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/inferno/dsl/fhir_client.rb', line 75

def fhir_operation(path, body: nil, client: :default, name: nil, headers: {})
  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?

      fhir_client(client).send(:post, path, body, operation_headers)
    end
  end
end

#fhir_read(resource_type, id, client: :default, name: nil) ⇒ Inferno::Entities::Request

Perform a FHIR read interaction.

Parameters:

  • resource_type (String, Symbol, Class)
  • id (String)
  • client (Symbol) (defaults to: :default)
  • name (Symbol) (defaults to: nil)

    Name for this request to allow it to be used by other tests

Returns:



125
126
127
128
129
130
131
# File 'lib/inferno/dsl/fhir_client.rb', line 125

def fhir_read(resource_type, id, client: :default, name: nil)
  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, client: :default, params: {}, name: nil, search_method: :get) ⇒ Inferno::Entities::Request

Perform a FHIR search interaction.

Parameters:

  • resource_type (String, Symbol, Class)
  • client (Symbol) (defaults to: :default)
  • params (Hash) (defaults to: {})

    the search params

  • name (Symbol) (defaults to: nil)

    Name for this request to allow it to be used by other tests

  • search_method (Symbol) (defaults to: :get)

    Use :post to search via POST

Returns:



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/inferno/dsl/fhir_client.rb', line 142

def fhir_search(resource_type, client: :default, params: {}, name: nil, search_method: :get)
  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
      fhir_client(client)
        .search(fhir_class_from_resource_type(resource_type), { search: })
    end
  end
end

#fhir_transaction(bundle = nil, client: :default, name: nil) ⇒ Inferno::Entities::Request

Perform a FHIR batch/transaction interaction.

Parameters:

  • bundle (FHIR::Bundle) (defaults to: nil)

    the FHIR batch/transaction Bundle

  • client (Symbol) (defaults to: :default)
  • name (Symbol) (defaults to: nil)

    Name for this request to allow it to be used by other tests

Returns:



181
182
183
184
185
186
187
188
# File 'lib/inferno/dsl/fhir_client.rb', line 181

def fhir_transaction(bundle = nil, client: :default, name: nil)
  store_request('outgoing', name) do
    tcp_exception_handler do
      fhir_client(client).transaction_bundle = bundle if bundle.present?
      fhir_client(client).end_transaction
    end
  end
end