Module: SubscriptionsTestKit::SubscriptionsR5BackportR4Client::SubscriptionSimulationUtils
- Included in:
- Jobs::SendSubscriptionNotifications, SubscriptionsTestKit::SubscriptionCreateEndpoint, SubscriptionsTestKit::SubscriptionReadEndpoint, SubscriptionsTestKit::SubscriptionStatusEndpoint, EventNotificationVerificationTest, HandshakeNotificationVerificationTest, NotificationInputPayloadVerificationTest
- Defined in:
- lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_client/common/subscription_simulation_utils.rb
Constant Summary collapse
- DEFAULT_MIME_TYPE =
Per the IG this should only be application/fhir+xml and application/fhir+json, however, Inferno (server suite) can only handle application/json, so we’ll allow that. Disallow XML for now.
'application/fhir+json'- ALLOWED_MIME_TYPES =
[DEFAULT_MIME_TYPE, 'application/json'].freeze
Instance Method Summary collapse
- #actual_mime_type(subscription) ⇒ Object
- #client_access_token_input(test_result) ⇒ Object
- #derive_event_notification(notification_json, subscription_url, event_count) ⇒ Object
- #derive_handshake_notification(notification_json, subscription_url) ⇒ Object
- #derive_status_bundle(notification_json, subscription_url, status_code, event_count, request_url) ⇒ Object
- #determine_event_count(test_session_id) ⇒ Object
- #determine_subscription_status_code(subscription_id) ⇒ Object
- #find_subscription(test_session_id) ⇒ Object
- #notification_bundle_input(test_result) ⇒ Object
- #operation_outcome(severity, code, text = nil) ⇒ Object
Instance Method Details
#actual_mime_type(subscription) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_client/common/subscription_simulation_utils.rb', line 86 def actual_mime_type(subscription) if ALLOWED_MIME_TYPES.include?(subscription&.channel&.payload) subscription&.channel&.payload else DEFAULT_MIME_TYPE end end |
#client_access_token_input(test_result) ⇒ Object
15 16 17 |
# File 'lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_client/common/subscription_simulation_utils.rb', line 15 def client_access_token_input(test_result) JSON.parse(test_result.input_json).find { |i| i['name'] == 'client_endpoint_access_token' }['value'] end |
#derive_event_notification(notification_json, subscription_url, event_count) ⇒ Object
28 29 30 31 32 |
# File 'lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_client/common/subscription_simulation_utils.rb', line 28 def derive_event_notification(notification_json, subscription_url, event_count) notification_bundle = FHIR.from_contents(notification_json) update_subscription_status(notification_bundle, subscription_url, 'active', event_count, 'event-notification') notification_bundle end |
#derive_handshake_notification(notification_json, subscription_url) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_client/common/subscription_simulation_utils.rb', line 19 def derive_handshake_notification(notification_json, subscription_url) notification_bundle = FHIR.from_contents(notification_json) subscription_status = update_subscription_status(notification_bundle, subscription_url, 'requested', 0, 'handshake') subscription_status.parameter.delete(find_parameter(subscription_status, 'notification-event')) subscription_status.parameter.delete(find_parameter(subscription_status, 'error')) notification_bundle end |
#derive_status_bundle(notification_json, subscription_url, status_code, event_count, request_url) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_client/common/subscription_simulation_utils.rb', line 34 def derive_status_bundle(notification_json, subscription_url, status_code, event_count, request_url) notification_bundle = FHIR.from_contents(notification_json) subscription_status = update_subscription_status(notification_bundle, subscription_url, status_code, event_count, 'query-status') subscription_status.parameter.delete(find_parameter(subscription_status, 'notification-event')) subscription_status_entry = find_subscription_status_entry(notification_bundle) FHIR::Bundle.new( entry: FHIR::Bundle::Entry.new( fullUrl: subscription_status_entry.fullUrl, resource: subscription_status, search: FHIR::Bundle::Entry::Search.new(mode: 'match', score: 1) ), link: FHIR::Bundle::Link.new(relation: 'self', url: request_url), total: 1, type: 'searchset' ) end |
#determine_event_count(test_session_id) ⇒ Object
82 83 84 |
# File 'lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_client/common/subscription_simulation_utils.rb', line 82 def determine_event_count(test_session_id) requests_repo.tagged_requests(test_session_id, [REST_HOOK_EVENT_NOTIFICATION_TAG]).count end |
#determine_subscription_status_code(subscription_id) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_client/common/subscription_simulation_utils.rb', line 69 def determine_subscription_status_code(subscription_id) handshakes = requests_repo.tagged_requests(test_run.test_session_id, [REST_HOOK_HANDSHAKE_NOTIFICATION_TAG]) handshake = handshakes.filter { |h| notification_subscription_id(h.request_body) == subscription_id }.last if handshake.nil? 'requested' elsif handshake.status.between?(200, 299) 'active' else 'error' end end |
#find_subscription(test_session_id) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_client/common/subscription_simulation_utils.rb', line 58 def find_subscription(test_session_id) request = requests_repo.tagged_requests(test_session_id, [SUBSCRIPTION_CREATE_TAG])&.find { |r| r.status == 201 } return unless request begin FHIR.from_contents(request.response_body) rescue StandardError nil end end |
#notification_bundle_input(test_result) ⇒ Object
11 12 13 |
# File 'lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_client/common/subscription_simulation_utils.rb', line 11 def notification_bundle_input(test_result) JSON.parse(test_result.input_json).find { |i| i['name'] == 'notification_bundle' }['value'] end |
#operation_outcome(severity, code, text = nil) ⇒ Object
52 53 54 55 56 |
# File 'lib/subscriptions_test_kit/suites/subscriptions_r5_backport_r4_client/common/subscription_simulation_utils.rb', line 52 def operation_outcome(severity, code, text = nil) oo = FHIR::OperationOutcome.new(issue: FHIR::OperationOutcome::Issue.new(severity:, code:)) oo.issue.first.details = FHIR::CodeableConcept.new(text:) if text.present? oo end |