module Inferno::DSL::FHIRClient

This module contains the FHIR DSL available to test writers.

@example

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 Inferno::FHIRClientBuilder Documentation for the client

configuration DSL

Public Class Methods

included(klass) click to toggle source

@api private

# File lib/inferno/dsl/fhir_client.rb, line 39
def self.included(klass)
  klass.extend ClassMethods
  klass.extend Forwardable
  klass.include RequestStorage

  klass.def_delegators 'self.class', :profile_url, :validator_url
end

Public Instance Methods

fhir_class_from_resource_type(resource_type) click to toggle source

@todo Make this a FHIR class method? Something like

FHIR.class_for(resource_type)

@api private

# File lib/inferno/dsl/fhir_client.rb, line 130
def fhir_class_from_resource_type(resource_type)
  FHIR.const_get(resource_type.to_s.camelize)
end
fhir_client(client = :default) click to toggle source

Return a previously defined FHIR client

@param client [Symbol] the name of the client @return [FHIR::Client] @see Inferno::FHIRClientBuilder

# File lib/inferno/dsl/fhir_client.rb, line 52
def fhir_client(client = :default)
  fhir_clients[client] ||=
    FHIRClientBuilder.new.build(self, self.class.fhir_client_definitions[client])
end
fhir_clients() click to toggle source

@api private

# File lib/inferno/dsl/fhir_client.rb, line 58
def fhir_clients
  @fhir_clients ||= {}
end
fhir_get_capability_statement(client: :default, name: nil, **_options) click to toggle source

Fetch the capability statement.

@param client [Symbol] @param name [Symbol] Name for this request to allow it to be used by

other tests

@param _options [Hash] TODO @return [Inferno::Entities::Request]

# File lib/inferno/dsl/fhir_client.rb, line 89
def fhir_get_capability_statement(client: :default, name: nil, **_options)
  store_request('outgoing', name) do
    fhir_client(client).conformance_statement
    fhir_client(client).reply
  end
end
fhir_operation(path, body: nil, client: :default, name: nil, **_options) click to toggle source

Perform a FHIR operation

@note This is a placeholder method until the FHIR::Client supports

general operations

@param path [String] @param body [FHIR::Parameters] @param client [Symbol] @param name [Symbol] Name for this request to allow it to be used by

other tests

@param _options [Hash] TODO @return [Inferno::Entities::Request]

# File lib/inferno/dsl/fhir_client.rb, line 74
def fhir_operation(path, body: nil, client: :default, name: nil, **_options)
  store_request('outgoing', name) do
    headers = fhir_client(client).fhir_headers
    headers.merge!('Content-Type' => 'application/fhir+json') if body.present?
    fhir_client(client).send(:post, path, body, headers)
  end
end
fhir_read(resource_type, id, client: :default, name: nil, **_options) click to toggle source

Perform a FHIR read interaction.

@param resource_type [String, Symbol, Class] @param id [String] @param client [Symbol] @param name [Symbol] Name for this request to allow it to be used by

other tests

@param _options [Hash] TODO @return [Inferno::Entities::Request]

# File lib/inferno/dsl/fhir_client.rb, line 105
def fhir_read(resource_type, id, client: :default, name: nil, **_options)
  store_request('outgoing', name) do
    fhir_client(client).read(fhir_class_from_resource_type(resource_type), id)
  end
end