Module: DaVinciPASTestKit::UserInputResponse

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



3
4
5
# File 'lib/davinci_pas_test_kit/client/user_input_response.rb', line 3

def self.included(klass)
  klass.extend ClassMethods
end

.read_input(result, input_name) ⇒ Object

Reads an arbitrary input value by name from result.input_json.



8
9
10
11
12
# File 'lib/davinci_pas_test_kit/client/user_input_response.rb', line 8

def self.read_input(result, input_name)
  JSON.parse(result.input_json)&.find { |i| i['name'] == input_name.to_s }&.dig('value')
rescue JSON::ParserError
  nil
end

.response_candidates(result, operation) ⇒ Object

Returns the tester-provided response candidates for the must support workflow as a list of parsed JSON hashes. The input value may be a single entry or a JSON array of entries, where each entry is either a bare FHIR Bundle or a wrapper object holding the response Bundle under "bundle" alongside optional selection "criteria". Returns nil if the input is not present, not parseable, or malformed.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/davinci_pas_test_kit/client/user_input_response.rb', line 28

def self.response_candidates(result, operation)
  input_name = operation == 'submit' ? 'ms_submit_responses' : 'ms_inquire_responses'
  input_value = JSON.parse(result.input_json)&.find { |i| i['name'] == input_name }&.dig('value')
  return unless input_value.present?

  candidates = JSON.parse(input_value)
  candidates = [candidates] unless candidates.is_a?(Array)
  candidates if candidates.all? { |candidate| valid_candidate?(candidate) }
rescue JSON::ParserError
  nil
end

.user_inputted_response(configurable, operation, result) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/davinci_pas_test_kit/client/user_input_response.rb', line 14

def self.user_inputted_response(configurable, operation, result)
  config_key = operation == 'submit' ? :submit_respond_with : :inquire_respond_with
  input_key = configurable.config.options[config_key]
  return unless input_key.present?

  read_input(result, input_key)
end

.valid_candidate?(candidate) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/davinci_pas_test_kit/client/user_input_response.rb', line 40

def self.valid_candidate?(candidate)
  return false unless candidate.is_a?(Hash)

  candidate['resourceType'] == 'Bundle' || candidate['bundle'].is_a?(Hash)
end

Instance Method Details

#input_title(input_key) ⇒ Object



50
51
52
# File 'lib/davinci_pas_test_kit/client/user_input_response.rb', line 50

def input_title(input_key)
  config.inputs[input_key]&.title || config.inputs[input_key]&.name
end

#user_inputted_response?(input_key) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/davinci_pas_test_kit/client/user_input_response.rb', line 46

def user_inputted_response?(input_key)
  input_key.present? && send(input_key).present?
end