Class: DaVinciCRDTestKit::V221::HookRequestCoverageVerificationTest

Inherits:
Inferno::Test
  • Object
show all
Includes:
MultiRequestMessageHelper, TaggedRequestLoadHelper, ClientURLs
Defined in:
lib/davinci_crd_test_kit/client/v2.2.1/verify_request/hook_request_coverage_verification_test.rb

Constant Summary

Constants included from ClientURLs

ClientURLs::SUITE_ID

Constants included from TaggedRequestLoadHelper

TaggedRequestLoadHelper::ALL_HOOKS

Instance Method Summary collapse

Methods included from ClientURLs

base_url, discovery_url, prefetch_subset_discovery_url, #suite_id

Methods included from ClientBaseURLs

#appointment_book_prefetch_subset_url, #appointment_book_url, #discovery_url, #encounter_discharge_prefetch_subset_url, #encounter_discharge_url, #encounter_start_prefetch_subset_url, #encounter_start_url, #order_dispatch_prefetch_subset_url, #order_dispatch_url, #order_select_prefetch_subset_url, #order_select_url, #order_sign_prefetch_subset_url, #order_sign_url, #prefetch_subset_discovery_url

Methods included from BaseURLs

#inferno_base_url, #resume_fail_url, #resume_pass_url

Methods included from TaggedRequestLoadHelper

#crd_test_group, #hook_name, #load_hook_requests, #requests_to_analyze, #tags_to_load

Methods included from MultiRequestMessageHelper

#add_request_message, #parse_json_request_entity, #request_prefix, #requests_with_errors_prefix

Instance Method Details

#check_payer_request(request_body, request_index, expected_payer_org_id) ⇒ Object



75
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
104
105
# File 'lib/davinci_crd_test_kit/client/v2.2.1/verify_request/hook_request_coverage_verification_test.rb', line 75

def check_payer_request(request_body, request_index, expected_payer_org_id)
  payer_request = load_payer_request_for_hook_request(request_body)
  unless payer_request.present? && payer_request.status.to_s.starts_with?('2')
    add_request_message('error',
                        "Inferno failed to retrieve the Coverage's payer during hook processing.",
                        request_index)
    return
  end

  payer_resource = FHIR.from_contents(payer_request.response_body)
  unless payer_resource.present?
    add_request_message('error', 'Request for payer resource returned invalid FHIR data.', request_index)
    return
  end

  if payer_resource.resourceType != 'Organization'
    add_request_message('error', 'Payer for the Coverage is not an Organization: ' \
                                 "got '#{payer_resource.resourceType}'", request_index)
  end
  if payer_resource.id != expected_payer_org_id
    add_request_message('error', 'Payer for the Coverage has the wrong id: ' \
                                 "expected '#{expected_payer_org_id}', got '#{payer_resource.id}'.",
                        request_index)
  end

  validator_response_details = []
  resource_is_valid?(resource: payer_resource, profile_url: 'http://hl7.org/fhir/us/davinci-crd/StructureDefinition/profile-organization|2.2.1',
                     add_messages_to_runnable: false, validator_response_details:)

  validator_response_details.each { |issue| add_request_message(issue.severity, issue.message, request_index) }
end

#load_payer_request_for_hook_request(request_body) ⇒ Object



70
71
72
73
# File 'lib/davinci_crd_test_kit/client/v2.2.1/verify_request/hook_request_coverage_verification_test.rb', line 70

def load_payer_request_for_hook_request(request_body)
  hook_data_fetch_tag = TagMethods.hook_instance_data_fetch_tag(request_body['hookInstance'])
  load_tagged_requests(PAYER_ORG_FETCH_TAG, hook_data_fetch_tag, DATA_FETCH_TAG).first
end

#payer_org_id_for_request(request) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/davinci_crd_test_kit/client/v2.2.1/verify_request/hook_request_coverage_verification_test.rb', line 62

def payer_org_id_for_request(request)
  if prefetch_target(request) == :subset
    subset_prefetch_service_organization_id
  else
    complete_prefetch_service_organization_id
  end
end

#prefetch_target(request) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/davinci_crd_test_kit/client/v2.2.1/verify_request/hook_request_coverage_verification_test.rb', line 54

def prefetch_target(request)
  if request.url.include?(PREFETCH_SUBSET_PREFIX)
    :subset
  else
    :complete
  end
end

#prefetched_coverage(request_body) ⇒ Object



145
146
147
148
149
# File 'lib/davinci_crd_test_kit/client/v2.2.1/verify_request/hook_request_coverage_verification_test.rb', line 145

def prefetched_coverage(request_body)
  coverage = request_body.dig('prefetch', 'coverage', 'entry', 0, 'resource')
  coverage = request_body.dig('prefetch', 'cov', 'entry', 0, 'resource') unless coverage.present?
  coverage
end