Skip to content

Commit

Permalink
Merge pull request #226 from hl7au/225-fix-search-by-reference
Browse files Browse the repository at this point in the history
Fix reference search by ID
  • Loading branch information
projkov authored Dec 2, 2024
2 parents 814d5e9 + e238536 commit 7694615
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ down:
rubocop:
$(compose) $(inferno) rubocop

rubocop-fix:
$(compose) $(inferno) rubocop -A

migrate:
$(compose) $(inferno) bundle exec rake db:migrate

Expand Down
9 changes: 8 additions & 1 deletion lib/au_core_test_kit/search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require_relative 'search_test_properties'
require_relative 'read_test'
require_relative 'assert_helpers'
require_relative 'search_test_helpers'

module AUCoreTestKit
module SearchTest
Expand Down Expand Up @@ -160,6 +161,11 @@ def perform_search(params, patient_id)
search_params = is_count_available_for_resource_type?(resource_type, params) == false ? params : params.merge({ _count: 10 })
fhir_search(resource_type, params: search_params)

if SearchTestHelpers.search_by_reference?(search_params)
search_params = SearchTestHelpers.replace_full_reference_search_param_to_id(search_params)
fhir_search(resource_type, params: search_params)
end

perform_search_with_status(params, patient_id) if response[:status] == 400 && possible_status_search?

check_search_response
Expand Down Expand Up @@ -193,6 +199,7 @@ def perform_search(params, patient_id)
test_include_param(resources_returned, params, patient_id, include_param)
end
end

perform_reference_with_type_search(params, resources_returned.count) if test_reference_variants?
perform_search_with_system(params, patient_id) if token_search_params.present?

Expand Down Expand Up @@ -525,7 +532,7 @@ def test_include_param(base_resources, params, patient_id, include_param, keep_s
search_params = params.merge(_include: include_param['parameter'])

search_and_check_response(search_params)

puts "fetch_all_bundled_resources #{fetch_all_bundled_resources}"

resources = fetch_all_bundled_resources.select { |resource| resource.resourceType == target_resource_type }
Expand Down
21 changes: 21 additions & 0 deletions lib/au_core_test_kit/search_test_helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module SearchTestHelpers
def self.search_by_reference?(search_param)
search_param = search_param.transform_keys(&:to_s)
search_param.keys.map { |key| search_param_is_reference?(search_param[key]) }.include?(true)
end

def self.replace_full_reference_search_param_to_id(search_param)
search_param = search_param.transform_keys(&:to_s)
search_param.each_key do |key|
search_param[key] = search_param[key].split('/').last if search_param_is_reference?(search_param[key])
end
search_param
end

def self.search_param_is_reference?(single_search_param)
single_search_param = single_search_param.to_s
single_search_param.include?('/') && single_search_param.split('/').length == 2
end
end
40 changes: 40 additions & 0 deletions spec/au_core/search_test_helpers_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

require 'rspec'
require_relative '../../lib/au_core_test_kit/search_test_helpers'

RSpec.describe 'search_by_reference? method' do
it 'SHOULD return false if there is no references in the search params hash' do
expect(
SearchTestHelpers.search_by_reference?(
{ 'patient' => 'baratz-toni', :_count => 10 }
)
).to eq(false)
end

it 'SHOULD return true if there is references in the search params hash' do
expect(
SearchTestHelpers.search_by_reference?(
{ 'patient' => 'Patient/baratz-toni', :_count => 10 }
)
).to eq(true)
end
end

RSpec.describe 'replace_full_reference_search_param_to_id method' do
it 'SHOULD return correctly formatted hash without resourceType when resourceType is exists in original search param' do
expect(
SearchTestHelpers.replace_full_reference_search_param_to_id(
{ 'patient' => 'Patient/baratz-toni', :_count => 10 }
)
).to eq({ 'patient' => 'baratz-toni', '_count' => 10 })
end

it 'SHOULD return correctly formatted hash without resourceType when resourceType is not exists in original search param' do
expect(
SearchTestHelpers.replace_full_reference_search_param_to_id(
{ 'patient' => 'baratz-toni', :_count => 10 }
)
).to eq({ 'patient' => 'baratz-toni', '_count' => 10 })
end
end

0 comments on commit 7694615

Please sign in to comment.