Skip to content

Commit

Permalink
Change include test reference matching to use regex expression and ad…
Browse files Browse the repository at this point in the history
…d check to ensure reference id is in the correct format before running the rest of the test. Also added test to include spec test that ensures test fails when reference id is of the wrong format
  • Loading branch information
emichaud998 committed Oct 16, 2023
1 parent f48affd commit eb4824c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/carin_for_blue_button_test_kit/carin_search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,32 @@ def run_include_search(search_params, param_value)
end
end


def find_included_resource(reference, returned_resources_all)
referenced_resource_id = reference['reference'].split('/')[-1]
referenced_resource_type = reference['reference'].split('/')[-2]
referenced_resource_id = reference['reference']

assert !referenced_resource_id.start_with?('#'), "Reference id is not in the correct format of [ResourceType]/[ResourceID]"

referenced_resource_type = referenced_resource_id.split('/')[-2]

referenced_resources = returned_resources_all.select{|item| item.resourceType == referenced_resource_type}

assert referenced_resources.present?, "No " + referenced_resource_type + " resources were included in the search results"

reference_found = false
referenced_resources.each do |referenced_resource|
reference_found = referenced_resource_id == referenced_resource.id
break if reference_found
reference_found = is_reference_match?(referenced_resource_id, referenced_resource.id)
break if reference_found
end

return reference_found
end

def is_reference_match? (reference, local_reference)
regex_pattern = /^(#{Regexp.escape(local_reference)}|\S+\/#{Regexp.escape(local_reference)}(?:[\/|]\S+)*)$/
reference.match?(regex_pattern)
end

def include_param_paths(param)
case param
when 'ExplanationOfBenefit:patient'
Expand Down
13 changes: 13 additions & 0 deletions spec/carin_for_blue_button/include_test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ def scratch_resources
expect(request).to have_been_made.once
end

it 'fails performing an _include search for ExplanationOfBenefit:patient when reference id is formatted incorrectly' do
# Expect that test fails when Explanation of Benefit patient reference id is in incorrect format
bundle.entry[0].resource.patient.reference = '#Patient1'

request = stub_request(:get, "#{url}/ExplanationOfBenefit?#{search_params_patient}")
.to_return(status: 200, body: bundle.to_json)

result = run(explanation_of_benefit_include_test, search_param: 'ExplanationOfBenefit:patient', c4bb_v200_explanation_of_benefit__id_search_test_param: explanation_of_benefit_id, url: url)
expect(result.result).to eq('fail')
expect(result.result_message).to eq('Reference id is not in the correct format of [ResourceType]/[ResourceID]')
expect(request).to have_been_made.once
end

it 'fails performing an _include search for ExplanationOfBenefit:patient when there is the wrong resource with correct id' do

# Expect that test fails when only organization resource with correct patient id is present in bundle
Expand Down

0 comments on commit eb4824c

Please sign in to comment.