Class: DaVinciCRDTestKit::HookRequestEndpoint

Inherits:
Inferno::DSL::SuiteEndpoint
  • Object
show all
Includes:
MockServiceResponse
Defined in:
lib/davinci_crd_test_kit/routes/hook_request_endpoint.rb

Instance Method Summary collapse

Methods included from MockServiceResponse

#add_basic_cards, #add_coverage_cards, #add_coverage_cards?, #add_coverage_extension, #add_order_hook_cards, #context, #coverage_information_required?, #coverage_information_required_hooks, #create_alternate_request_card, #create_card_response, #create_cards_and_system_actions, #create_companions_prerequisites_card, #create_coverage_extension_system_actions, #create_coverage_resource, #create_form_completion_card, #create_or_update_coverage, #create_system_actions, #create_warning_messages, #current_time, #format_missing_response_types, #get_context_resource, #get_missing_response_types, #get_patient_coverage, #hook_response, #load_json_file, #make_resource_request, #missing_response_type_filter, #request_body, #resource_to_update_field_name, #resource_type_to_update, #update_service_request, #update_specific_hook_card_info

Instance Method Details

#custom_responseObject



14
15
16
17
18
19
# File 'lib/davinci_crd_test_kit/routes/hook_request_endpoint.rb', line 14

def custom_response
  @custom_response ||=
    JSON.parse(result.input_json)
      .find { |input| input['name'].include?('custom_response') }
      &.dig('value')
end

#hook_nameObject



25
26
27
# File 'lib/davinci_crd_test_kit/routes/hook_request_endpoint.rb', line 25

def hook_name
  @hook_name ||= request.params[:hook]
end

#issObject



29
30
31
32
33
34
35
36
37
# File 'lib/davinci_crd_test_kit/routes/hook_request_endpoint.rb', line 29

def iss
  @iss ||=
    begin
      payload, = JWT.decode(token, nil, false)
      payload['iss']
    rescue JWT::DecodeError
      nil
    end
end

#make_responseObject



43
44
45
46
47
48
49
50
51
# File 'lib/davinci_crd_test_kit/routes/hook_request_endpoint.rb', line 43

def make_response
  case hook_name
  when 'appointment-book', 'encounter-start', 'encounter-discharge', 'order-select', 'order-sign', 'order-dispatch'
    hook_response
  else
    response.status = 400
    response.body = 'Invalid Request: Request did not contain a valid hook in the `hook` field.'
  end
end

#nameObject



73
74
75
# File 'lib/davinci_crd_test_kit/routes/hook_request_endpoint.rb', line 73

def name
  hook_name.gsub('-', '_')
end

#selected_response_typesObject



7
8
9
10
11
12
# File 'lib/davinci_crd_test_kit/routes/hook_request_endpoint.rb', line 7

def selected_response_types
  @selected_response_types ||=
    JSON.parse(result.input_json)
      .find { |input| input['name'].include?('selected_response_types') }
      &.dig('value')
end

#tagsObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/davinci_crd_test_kit/routes/hook_request_endpoint.rb', line 53

def tags
  case hook_name
  when 'appointment-book'
    [APPOINTMENT_BOOK_TAG]
  when 'encounter-start'
    [ENCOUNTER_START_TAG]
  when 'encounter-discharge'
    [ENCOUNTER_DISCHARGE_TAG]
  when 'order-select'
    [ORDER_SELECT_TAG]
  when 'order-sign'
    [ORDER_SIGN_TAG]
  when 'order-dispatch'
    [ORDER_DISPATCH_TAG]
  else
    response.status = 400
    response.body = 'Invalid Request: Request did not contain a valid hook in the `hook` field.'
  end
end

#test_run_identifierObject



21
22
23
# File 'lib/davinci_crd_test_kit/routes/hook_request_endpoint.rb', line 21

def test_run_identifier
  "#{hook_name} #{iss}"
end

#tokenObject



39
40
41
# File 'lib/davinci_crd_test_kit/routes/hook_request_endpoint.rb', line 39

def token
  @token ||= request.headers['authorization']&.delete_prefix('Bearer ')
end