Module: DaVinciPASTestKit::ResponseGenerator

Instance Method Summary collapse

Instance Method Details

#mock_full_resource_notification_bundle(submit_response, subscription_reference, subscription_topic, decision) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/davinci_pas_test_kit/response_generator.rb', line 10

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

#mock_id_only_notification_bundle(submit_response, subscription_reference, subscription_topic) ⇒ Object



3
4
5
6
7
8
# File 'lib/davinci_pas_test_kit/response_generator.rb', line 3

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

#mock_response_bundle(request_bundle, operation, decision, claim_response_uuid = nil) ⇒ Object



18
19
20
21
# File 'lib/davinci_pas_test_kit/response_generator.rb', line 18

def mock_response_bundle(request_bundle, operation, decision, claim_response_uuid = nil)
  mocked_timestamp = Time.now.utc
  build_mock_response_bundle(request_bundle, operation, decision, mocked_timestamp, claim_response_uuid)&.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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/davinci_pas_test_kit/response_generator.rb', line 49

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) ⇒ 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



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/davinci_pas_test_kit/response_generator.rb', line 28

def update_tester_provided_response(user_inputted_response, claim_full_url)
  response_bundle = FHIR.from_contents(user_inputted_response)
  return user_inputted_response unless response_bundle.present?

  now = Time.now.utc
  response_bundle.timestamp = now.iso8601 if response_bundle&.timestamp.present?
  claim_response_entry = response_bundle&.entry&.find { |e| e&.resource&.resourceType == 'ClaimResponse' }
  if claim_response_entry.present?
    claim_response_entry.resource.created = now.iso8601 if claim_response_entry.resource.created
    if claim_response_entry.resource.request.present? && claim_full_url.present?
      claim_response_entry.resource.request.reference = claim_full_url
    end
  end
  response_bundle.to_json
end