Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FI-3474 Add a check if Reference.reference is empty before processing #212

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/us_core_test_kit/search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,8 @@ def save_delayed_references(resources, containing_resource_type = self.resource_
resources.each do |resource|
references_to_save(containing_resource_type).each do |reference_to_save|
resolve_path(resource, reference_to_save[:path])
.select { |reference| reference.is_a?(FHIR::Reference) && !reference.contained? }
.select { |reference| reference.is_a?(FHIR::Reference) &&
!reference.contained? && reference.reference.present? }
.each do |reference|
resource_type = reference.resource_class.name.demodulize
need_to_save = reference_to_save[:resources].include?(resource_type)
Expand Down
53 changes: 53 additions & 0 deletions spec/us_core/search_test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1343,4 +1343,57 @@ def scratch_resources
expect(values_found.length).to eq(0)
end
end

describe '#save_delayed_references' do
let(:test_class) do
Class.new(USCoreTestKit::USCoreV311::DiagnosticReportLabPatientCategorySearchTest) do
fhir_client { url :url }
input :url
end
end
let(:test) { test_class.new }
let(:patient_id) { '85' }
let(:test_scratch) { {} }
let(:diagnostic_report) do
FHIR::DiagnosticReport.new(
subject: {
reference: "Patient/#{patient_id}"
},
category: [
{
coding: [
{
code: 'abc'
}
]
}
],
performer:[
{
reference: 'Organization/1'
},
{
type: 'Organization',
display: 'Unknown Performing Organization'
}
]
)
end

before do
allow_any_instance_of(test_class)
.to receive(:scratch).and_return(test_scratch)
end

it 'passes with reference not populated' do
test.save_delayed_references([diagnostic_report])

result = test_scratch[:references]
expect(result).not_to be_empty
expect(result['Organization']).not_to be_empty
expect(result['Organization'].count).to be(1)
expect(result['Organization'].first.reference).to eq('Organization/1')
end
end

end
Loading