Module: DaVinciCRDTestKit::ScenarioServiceResponse

Included in:
HookRequestEndpoint
Defined in:
lib/davinci_crd_test_kit/client/endpoints/scenario_service_response.rb

Overview

Serve fixed coverage information responses for hook requests made during scenario groups

Instance Method Summary collapse

Instance Method Details

#add_unknown_action_element(response_body) ⇒ Object

an element that is not part of the CDS Hooks action definition



36
37
38
39
# File 'lib/davinci_crd_test_kit/client/endpoints/scenario_service_response.rb', line 36

def add_unknown_action_element(response_body)
  element_name = random_element_name
  response_body['systemActions'].each { |action| action[element_name] = random_element_name }
end

#add_unknown_extension(response_body) ⇒ Object

a CDS Hooks extension whose key is not defined by CRD or CDS Hooks



42
43
44
# File 'lib/davinci_crd_test_kit/client/endpoints/scenario_service_response.rb', line 42

def add_unknown_extension(response_body)
  response_body['extension'] = { random_element_name => random_element_name }
end

#build_coverage_information_hook_responseObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/davinci_crd_test_kit/client/endpoints/scenario_service_response.rb', line 12

def build_coverage_information_hook_response
  response_body = { 'cards' => [] }
  system_actions = coverage_information_system_actions

  if system_actions.present?
    response_body['systemActions'] = system_actions
  else
    create_missing_coverage_information_message
  end

  response_body
end

#build_unknown_content_hook_responseObject

coverage information carrying content that clients are not expected to recognize



5
6
7
8
9
10
# File 'lib/davinci_crd_test_kit/client/endpoints/scenario_service_response.rb', line 5

def build_unknown_content_hook_response
  response_body = build_coverage_information_hook_response
  add_unknown_action_element(response_body) if response_body['systemActions'].present?
  add_unknown_extension(response_body)
  response_body
end

#coverage_information_system_actionsObject



25
26
27
28
29
# File 'lib/davinci_crd_test_kit/client/endpoints/scenario_service_response.rb', line 25

def coverage_information_system_actions
  return if context.blank? || patient_coverage.blank?

  create_coverage_extension_system_actions(patient_coverage.id)
end

#create_missing_coverage_information_messageObject



46
47
48
49
50
51
52
# File 'lib/davinci_crd_test_kit/client/endpoints/scenario_service_response.rb', line 46

def create_missing_coverage_information_message
  Inferno::Repositories::Messages.new.create(
    result_id: result.id,
    type: 'warning',
    message: %(Unable to return a coverage information system action for the #{requested_hook} hook)
  )
end

#random_element_nameObject



31
32
33
# File 'lib/davinci_crd_test_kit/client/endpoints/scenario_service_response.rb', line 31

def random_element_name
  ('a'..'z').to_a.sample(16).join
end