Class: BulkDataTestKit::BulkDataV200Client::Endpoints::KickOff

Inherits:
Inferno::DSL::SuiteEndpoint
  • Object
show all
Includes:
ServerProxy, URLs
Defined in:
lib/bulk_data_test_kit/v2.0.0_client/endpoints/kick_off.rb

Instance Method Summary collapse

Methods included from ServerProxy

#proxy_client, #request_headers, #rewrite_url_base

Methods included from URLs

#base_url, #fhir_url, #output_url, #resume_pass_url, #status_url, #suite_id

Instance Method Details

#group_idObject



72
73
74
# File 'lib/bulk_data_test_kit/v2.0.0_client/endpoints/kick_off.rb', line 72

def group_id
  request.params[:group_id]
end

#job_id(url) ⇒ Object



76
77
78
# File 'lib/bulk_data_test_kit/v2.0.0_client/endpoints/kick_off.rb', line 76

def job_id(url)
  CGI.parse(URI.parse(url).query)['_jobId']&.first
end

#make_responseObject

Proxy the request to the reference server, and re-use the returned ‘_jobId’ as the identifier we’ll return to the user for our own ‘content-location` header.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bulk_data_test_kit/v2.0.0_client/endpoints/kick_off.rb', line 21

def make_response
  server_response = proxy_kickoff
  case server_response.status
  when 202
    server_status_url = server_response.headers['content-location']
    response.status = 202
    response.headers['content-location'] = status_url.gsub(':job_id', job_id(server_status_url))
  else
    response.status = server_response.status
    response.body = server_response.body
  end
end

#proxy_kickoffObject



45
46
47
48
49
50
51
52
53
54
# File 'lib/bulk_data_test_kit/v2.0.0_client/endpoints/kick_off.rb', line 45

def proxy_kickoff
  case request_type
  when PATIENT_EXPORT_TYPE
    proxy_client.get('$export', request_params)
  when GROUP_EXPORT_TYPE
    proxy_client.get("#{request_type}/#{group_id}/$export", request_params)
  when SYSTEM_EXPORT_TYPE
    proxy_client.get('$export', request_params)
  end
end

#request_paramsObject

Collect request params to forward to the reference server



57
58
59
# File 'lib/bulk_data_test_kit/v2.0.0_client/endpoints/kick_off.rb', line 57

def request_params
  request.params.to_h.stringify_keys
end

#request_typeObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/bulk_data_test_kit/v2.0.0_client/endpoints/kick_off.rb', line 61

def request_type
  path_component_before_export = request.path_info.split('/')[-2].downcase
  if path_component_before_export == 'fhir'
    SYSTEM_EXPORT_TYPE
  elsif path_component_before_export == 'patient'
    PATIENT_EXPORT_TYPE
  else
    GROUP_EXPORT_TYPE
  end
end

#tagsObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/bulk_data_test_kit/v2.0.0_client/endpoints/kick_off.rb', line 34

def tags
  case request_type
  when PATIENT_EXPORT_TYPE
    [KICKOFF_TAG, PATIENT_KICKOFF_TAG]
  when GROUP_EXPORT_TYPE
    [KICKOFF_TAG, GROUP_KICKOFF_TAG]
  when SYSTEM_EXPORT_TYPE
    [KICKOFF_TAG, SYSTEM_KICKOFF_TAG]
  end
end

#test_run_identifierObject



11
12
13
14
15
16
17
# File 'lib/bulk_data_test_kit/v2.0.0_client/endpoints/kick_off.rb', line 11

def test_run_identifier
  return request.params[:session_path] if request.params[:session_path].present?

  SMARTAppLaunch::MockSMARTServer.issued_token_to_client_id(
    request.headers['authorization']&.delete_prefix('Bearer ')
  )
end