Class: SubscriptionsTestKit::SubscriptionStatusEndpoint
Constant Summary
SubscriptionsTestKit::SubscriptionsR5BackportR4Client::SubscriptionSimulationUtils::ALLOWED_MIME_TYPES, SubscriptionsTestKit::SubscriptionsR5BackportR4Client::SubscriptionSimulationUtils::DEFAULT_MIME_TYPE
Instance Method Summary
collapse
#actual_mime_type, #client_access_token_input, #derive_event_notification, #derive_handshake_notification, #derive_status_bundle, #determine_event_count, #determine_subscription_status_code, #find_subscription, #notification_bundle_input, #operation_outcome
Instance Method Details
#base_subscription_url ⇒ Object
71
72
73
|
# File 'lib/subscriptions_test_kit/endpoints/subscription_status_endpoint.rb', line 71
def base_subscription_url
request.url.sub(/(#{Regexp.escape(FHIR_SUBSCRIPTION_PATH)}).*/, '\1')
end
|
#find_params(params, name) ⇒ Object
67
68
69
|
# File 'lib/subscriptions_test_kit/endpoints/subscription_status_endpoint.rb', line 67
def find_params(params, name)
params&.parameter&.filter { |p| p.name == name }
end
|
#make_response ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/subscriptions_test_kit/endpoints/subscription_status_endpoint.rb', line 12
def make_response
response.format = :json
subscription = find_subscription(test_run.test_session_id)
unless subscription.present?
not_found
return
end
subscription_id = request.params[:id]
unless subscription_id.present?
begin
params = FHIR.from_contents(request.body.string)
rescue StandardError
response.status = 400
response.body = operation_outcome('error', 'invalid', 'Invalid Parameters in request body').to_json
return
end
unless subscription_params_match?(params)
not_found
return
end
end
notification_json = notification_bundle_input(result)
subscription_url = "#{base_subscription_url}/#{subscription.id}"
status_code = determine_subscription_status_code(subscription_id)
event_count = determine_event_count(test_run.test_session_id)
response.status = 200
response.body = derive_status_bundle(notification_json, subscription_url, status_code, event_count,
request.url).to_json
end
|
#not_found ⇒ Object
62
63
64
65
|
# File 'lib/subscriptions_test_kit/endpoints/subscription_status_endpoint.rb', line 62
def not_found
response.status = 404
response.body = operation_outcome('error', 'not-found').to_json
end
|
#subscription_params_match?(params) ⇒ Boolean
48
49
50
51
52
53
54
55
56
|
# File 'lib/subscriptions_test_kit/endpoints/subscription_status_endpoint.rb', line 48
def subscription_params_match?(params)
id_params = find_params(params, 'id')
return false if id_params&.any? && id_params&.none? { |p| p.valueString == subscription.id }
status_params = find_params(params, 'status')
subscription_status = determine_subscription_status_code(subscription.id)
status_params.nil? || status_params.none? || status_params.any { p.valueString == subscription_status }
end
|
58
59
60
|
# File 'lib/subscriptions_test_kit/endpoints/subscription_status_endpoint.rb', line 58
def tags
[SUBSCRIPTION_STATUS_TAG]
end
|
#test_run_identifier ⇒ Object
8
9
10
|
# File 'lib/subscriptions_test_kit/endpoints/subscription_status_endpoint.rb', line 8
def test_run_identifier
request.['authorization']&.delete_prefix('Bearer ')
end
|