Skip to content

Commit

Permalink
FI-3508 Retrieve primitive value from navigation result (#194)
Browse files Browse the repository at this point in the history
* Retrieve primitive value from navigation result

* fix not returning values_found

* restore accidentaly removed test

---------

Co-authored-by: Yunwei Wang <>
  • Loading branch information
yunwwang authored Sep 4, 2024
1 parent 14dd3bf commit 700bce2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/us_core_test_kit/search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -737,16 +737,19 @@ def resource_matches_param?(resource, search_param_name, escaped_search_value, v

paths.each do |path|
type = metadata.search_definitions[search_param_name.to_sym][:type]
values_found =
resolve_path(resource, path)
.map do |value|
if value.is_a? FHIR::Reference
value.reference
else
value
end

resolve_path(resource, path).each do |value|
values_found <<
if value.is_a? FHIR::Reference
value.reference
elsif value.is_a? USCoreTestKit::PrimitiveType
value.value
else
value
end
end

values_found.compact!
match_found =
case type
when 'Period', 'date', 'instant', 'dateTime'
Expand Down
57 changes: 57 additions & 0 deletions spec/us_core/search_test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1286,4 +1286,61 @@ def scratch_resources
expect(result).to be_falsey
end
end

describe '#resource_matches_param' do
let(:test_class) do
Class.new(USCoreTestKit::USCoreV610::PatientFamilyGenderSearchTest) do
fhir_client { url :url }
input :url
end
end
let(:test) { test_class.new }
let(:patient_gender) { 'male' }
let(:patient_id) { '85' }


it 'matches the primitive value' do
patient = FHIR::Patient.new(
id: patient_id,
gender: patient_gender
)

patient.source_hash['_gender'] = {
'extension' => [
{
'url' => 'http://example.com/extension',
'valueString' => 'value'
}
]
}

values_found = []
match_found = test.resource_matches_param?(patient, 'gender', patient_gender, values_found)

expect(match_found).to be_truthy
expect(values_found.length).to eq(1)
expect(values_found.first).to eq(patient_gender)
end

it 'returns false if only extension exists' do
patient = FHIR::Patient.new(
id: patient_id
)

patient.source_hash['_gender'] = {
'extension' => [
{
'url' => 'http://example.com/extension',
'valueString' => 'value'
}
]
}

values_found = []
match_found = test.resource_matches_param?(patient, 'gender', patient_gender, values_found)

expect(match_found).to be_falsey
expect(values_found.length).to eq(0)
end
end
end

0 comments on commit 700bce2

Please sign in to comment.