Module: SubscriptionsTestKit::SubscriptionConformanceVerification
Instance Method Summary
collapse
Methods included from URLs
#base_url, #fhir_subscription_url, #resume_fail_url, #resume_pass_url, #subscription_channel_url, #suite_id
Instance Method Details
#channel_field_matches?(subscription_channel, field_name, expected_entry) ⇒ Boolean
11
12
13
|
# File 'lib/subscriptions_test_kit/common/subscription_conformance_verification.rb', line 11
def channel_field_matches?(subscription_channel, field_name, expected_entry)
subscription_channel[field_name].present? && subscription_channel[field_name] == expected_entry
end
|
#check_extension(extensions) ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/subscriptions_test_kit/common/subscription_conformance_verification.rb', line 19
def check_extension(extensions)
extensions.each do |extension|
next unless cross_version_extension?(extension['url'])
add_message('warning', %(
Cross-version extensions SHOULD NOT be used on R4 subscriptions to describe any elements also described by
this guide, but found the #{extension['url']} extension on the Subscription resource
))
end
end
|
#cross_version_extension?(url) ⇒ Boolean
15
16
17
|
# File 'lib/subscriptions_test_kit/common/subscription_conformance_verification.rb', line 15
def cross_version_extension?(url)
url.match?(%r{http://hl7\.org/fhir/[0-9]+\.[0-9]+/StructureDefinition/extension-Subscription\..+})
end
|
#cross_version_extension_check(subscription) ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/subscriptions_test_kit/common/subscription_conformance_verification.rb', line 30
def cross_version_extension_check(subscription)
subscription.each do |key, value|
if value.is_a?(Array) && key == 'extension'
check_extension(value)
elsif value.is_a?(Hash) || value.is_a?(Array)
cross_version_extension_check(value)
end
end
end
|
#no_error_verification(message) ⇒ Object
7
8
9
|
# File 'lib/subscriptions_test_kit/common/subscription_conformance_verification.rb', line 7
def no_error_verification(message)
assert messages.none? { |msg| msg[:type] == 'error' }, message
end
|
#server_check_channel(subscription, access_token) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/subscriptions_test_kit/common/subscription_conformance_verification.rb', line 58
def server_check_channel(subscription, access_token)
subscription_channel = subscription['channel']
unless channel_field_matches?(subscription_channel, 'endpoint', subscription_channel_url)
add_message('warning', %(
The subscription url was changed from #{subscription_channel['endpoint']} to
#{subscription_channel_url}))
subscription_channel['endpoint'] = subscription_channel_url
end
unless channel_field_matches?(subscription_channel, 'payload', 'application/json')
add_message('warning', %(
The `type` field on the Subscription resource should be set to `application/json`. Inferno will only accept
resources in requests with this content type.
))
end
unless subscription_channel['header'].present? &&
subscription_channel['header'].include?("Authorization: Bearer #{access_token}")
add_message('warning', %(
Added the Authorization header field with a Bearer token set to #{access_token} to the `header` field on the
Subscription resource in order to connect successfully with the Inferno subscription channel.
))
subscription['header'] = [] unless subscription['header'].present?
subscription['header'].append("Authorization: Bearer #{access_token}")
end
subscription['channel'] = subscription_channel
subscription
end
|
#subscription_verification(subscription_resource) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/subscriptions_test_kit/common/subscription_conformance_verification.rb', line 40
def subscription_verification(subscription_resource)
assert_valid_json(subscription_resource)
subscription = JSON.parse(subscription_resource)
subscription_channel = subscription['channel']
assert(channel_field_matches?(subscription_channel, 'type', 'rest-hook'), %(
The `type` field on the Subscription resource must be set to `rest-hook`, the `#{subscription_channel['type']}`
channel type is unsupported.))
subscription_resource = FHIR.from_contents(subscription.to_json)
assert_resource_type('Subscription', resource: subscription_resource)
assert_valid_resource(resource: subscription_resource,
profile_url: 'http://hl7.org/fhir/uv/subscriptions-backport/StructureDefinition/backport-subscription')
cross_version_extension_check(subscription)
subscription
end
|