Module: DaVinciPASTestKit::ResponseGenerator

Instance Method Summary collapse

Methods included from ParametersHelper

#extract_bundles_from_pas_inquiry_response_parameters

Instance Method Details

#mock_full_resource_notification_bundle(submit_response, subscription_reference, subscription_topic, decision, ig_version = 'v2.0.1') ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/davinci_pas_test_kit/client/response_generator.rb', line 16

def mock_full_resource_notification_bundle(submit_response, subscription_reference, subscription_topic, decision,
                                           ig_version = 'v2.0.1')
  notification_timestamp = Time.now.utc
  mock_notification_bundle = build_mock_notification_bundle(notification_timestamp, subscription_reference,
                                                            subscription_topic, submit_response, 'full-resource',
                                                            decision, ig_version)
  mock_notification_bundle.to_json
end

#mock_id_only_notification_bundle(submit_response, subscription_reference, subscription_topic, ig_version = 'v2.0.1') ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/davinci_pas_test_kit/client/response_generator.rb', line 7

def mock_id_only_notification_bundle(submit_response, subscription_reference, subscription_topic,
                                     ig_version = 'v2.0.1')
  notification_timestamp = Time.now.utc
  mock_notification_bundle = build_mock_notification_bundle(notification_timestamp, subscription_reference,
                                                            subscription_topic, submit_response, 'id-only', nil,
                                                            ig_version)
  mock_notification_bundle.to_json
end

#mock_response_bundle(request_bundle, operation, decision, claim_response_uuid = nil, ig_version = 'v2.0.1') ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/davinci_pas_test_kit/client/response_generator.rb', line 25

def mock_response_bundle(request_bundle, operation, decision, claim_response_uuid = nil, ig_version = 'v2.0.1')
  mocked_timestamp = Time.now.utc
  response = build_mock_response_bundle(request_bundle, operation, decision, mocked_timestamp,
                                        claim_response_uuid, ig_version)
  return nil unless response.present?

  # For v2.2.1 inquire operations, wrap the Bundle in a Parameters resource
  response = wrap_bundle_in_parameters(response) if ig_version == 'v2.2.1' && operation == 'inquire'

  response.to_json
end

#update_tester_provided_notification(user_inputted_notification, generated_claim_response_uuid) ⇒ Object

update things that tester cannot get right themselves

  • reference to the ClaimResponse in the case that it is generated by Inferno. If the tester provided the ClaimResponse, they are responsible for aligning the notification with it.
  • notification timestamps


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/davinci_pas_test_kit/client/response_generator.rb', line 76

def update_tester_provided_notification(user_inputted_notification, generated_claim_response_uuid)
  now = Time.now.utc

  notification_bundle = FHIR.from_contents(user_inputted_notification)
  subscription_status_entry = notification_bundle&.entry&.find { |e| e.resource&.resourceType == 'Parameters' }
  subscription_status_resource = subscription_status_entry&.resource
  event_parameter = subscription_status_resource&.parameter&.find { |p| p.name == 'notification-event' }

  if generated_claim_response_uuid.present?
    claim_response_full_url = "urn:uuid:#{generated_claim_response_uuid}"
    focus_part = event_parameter&.part&.find { |pt| pt.name == 'focus' }
    if focus_part.present?
      existing_claim_response_reference = focus_part.valueReference&.reference
      focus_part.valueReference.reference = claim_response_full_url
      update_tester_provided_notification_claim_response_entry(notification_bundle,
                                                               generated_claim_response_uuid,
                                                               claim_response_full_url,
                                                               existing_claim_response_reference)

    end
  end

  timestamp_part = event_parameter&.part&.find { |pt| pt.name == 'timestamp' }
  timestamp_part.valueInstant = now.iso8601 if timestamp_part.present?
  notification_bundle.timestamp = now.iso8601 if notification_bundle.timestamp.present?

  notification_bundle.to_json
end

#update_tester_provided_response(user_inputted_response, claim_full_url, operation, ig_version = 'v2.0.1') ⇒ Object

update things that tester cannot get right themselves

  • timestamps on the Bundle and ClaimResponse (can't predict the processing time)
  • reference to the submitted Claim (may not have control of created id). NOTE: this is likely incomplete - when the Claim is included, there are other things that need to be in the Bundle that may also not be controlled


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/davinci_pas_test_kit/client/response_generator.rb', line 42

def update_tester_provided_response(user_inputted_response, claim_full_url, operation, ig_version = 'v2.0.1')
  response_resource = FHIR.from_contents(user_inputted_response)
  return user_inputted_response unless response_resource.present?

  # For v2.2.1 inquire responses, wrap user's Bundle in Parameters if needed
  if ig_version == 'v2.2.1' && operation == 'inquire' && response_resource.is_a?(FHIR::Bundle)
    response_resource = wrap_bundle_in_parameters(response_resource)
  end

  # Extract Bundle(s) for updating
  bundles_to_update = []
  is_parameters = response_resource.resourceType == 'Parameters'

  if is_parameters
    bundles_to_update = extract_bundles_from_pas_inquiry_response_parameters(response_resource)
  elsif response_resource.is_a?(FHIR::Bundle)
    bundles_to_update = [response_resource]
  else
    return user_inputted_response
  end

  now = Time.now.utc
  bundles_to_update.each do |response_bundle|
    update_response_bundle(response_bundle, claim_full_url, now, ig_version)
  end

  response_resource.to_json
end