Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #582 from onc-healthit/fi-1262-search-string-start…
Browse files Browse the repository at this point in the history
…s-with

change search by string
  • Loading branch information
czh-orz authored Aug 19, 2021
2 parents a502b80 + f3bcb3e commit c9df27e
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 6 deletions.
3 changes: 3 additions & 0 deletions generator/uscore/uscore_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,9 @@ def search_param_match_found_code(type, element)
match_found = values_found.any? do |identifier|
identifier.value == identifier_value && (!value.include?('|') || identifier.system == identifier_system)
end)
when 'string'
%(values = value.downcase.split(/(?<!\\\\),/).each { |str| str.gsub!('\\,', ',') }
match_found = values_found.any? { |value_in_resource| values.any? { |searched_value| value_in_resource.downcase.starts_with? searched_value } })
else
# searching by patient requires special case because we are searching by a resource identifier
# references can also be URL's, so we made need to resolve those url's
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/uscore_v3.1.1/us_core_organization_sequence.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions lib/modules/uscore_v3.1.1/us_core_patient_sequence.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions test/unit/sequence_base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,77 @@ def setup
end
end
end

it 'passes when string value starts with searched value' do
@instance = Inferno::TestingInstance.create!
client = FHIR::Client.new('')
patient_sequence = Inferno::Sequence::USCore311PatientSequence.new(@instance, client, true)
patient_resource = FHIR::Patient.new(
name: [{
family: 'LastName'
}]
)
patient_sequence.validate_resource_item(patient_resource, 'family', 'las')
patient_sequence.validate_resource_item(patient_resource, 'family', 'Las')
patient_sequence.validate_resource_item(patient_resource, 'family', 'LastName')
end

it 'fails when string value does not start with searched value' do
@instance = Inferno::TestingInstance.create!
client = FHIR::Client.new('')
patient_sequence = Inferno::Sequence::USCore311PatientSequence.new(@instance, client, true)
patient_resource = FHIR::Patient.new(
name: [{
family: 'LastName'
}]
)
assert_raises(Inferno::AssertionException) do
patient_sequence.validate_resource_item(patient_resource, 'family', 'something')
end
end

# NOTE: The base FHIR spec says that name search can be fuzzy, but we do not currently support this.
it 'passes for all required name search variants' do
@instance = Inferno::TestingInstance.create!
client = FHIR::Client.new('')
patient_sequence = Inferno::Sequence::USCore311PatientSequence.new(@instance, client, true)
patient_resource = FHIR::Patient.new(
name: [{
given: ['FirstName', 'MiddleName'],
family: 'LastName',
suffix: 'iii',
prefix: 'Mr.',
text: 'Mr. FirstName MiddleName LastName III'
}]
)
patient_sequence.validate_resource_item(patient_resource, 'name', 'LastName')
patient_sequence.validate_resource_item(patient_resource, 'name', 'last')
patient_sequence.validate_resource_item(patient_resource, 'name', 'Last')
patient_sequence.validate_resource_item(patient_resource, 'name', 'FirstName')
patient_sequence.validate_resource_item(patient_resource, 'name', 'first')
patient_sequence.validate_resource_item(patient_resource, 'name', 'MiddleName')
patient_sequence.validate_resource_item(patient_resource, 'name', 'middle')
patient_sequence.validate_resource_item(patient_resource, 'name', 'iii')
patient_sequence.validate_resource_item(patient_resource, 'name', 'Mr. FirstName')
end

it 'fails for all invalid name searches' do
@instance = Inferno::TestingInstance.create!
client = FHIR::Client.new('')
patient_sequence = Inferno::Sequence::USCore311PatientSequence.new(@instance, client, true)
patient_resource = FHIR::Patient.new(
name: [{
given: ['FirstName', 'MiddleName'],
family: 'LastName',
suffix: 'iii',
prefix: 'Mr.',
text: 'Mr. FirstName MiddleName LastName III'
}]
)
assert_raises(Inferno::AssertionException) do
patient_sequence.validate_resource_item(patient_resource, 'name', 'XYZ')
end
end
end

describe '#date_comparator_value' do
Expand Down

0 comments on commit c9df27e

Please sign in to comment.