Skip to content
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## [Unreleased]

## 0.3.1 / 2026-03-05
### Fixed
* Strip whitespace from IDs in FHIR Base.find to prevent bad URI errors
* Handle ApiError/InvalidURIError gracefully in Organisation.find

## 0.3.0 / 2026-02-26
### Added
* Added specific error classes (InvalidURIError, UnauthorizedError) for granular error handling
Expand Down
5 changes: 3 additions & 2 deletions lib/ndr_lookup/fhir/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ def sync
# Finds a specific FHIR resource by type and ID
# @return [Hash] Parsed FHIR resource
def find(resource_type, id)
with_error_handling("#{resource_type} with ID '#{id}' not found") do
response = connection.get("#{endpoint}/#{resource_type}/#{id}", headers)
sanitized_id = id.to_s.strip
with_error_handling("#{resource_type} with ID '#{sanitized_id}' not found") do
response = connection.get("#{endpoint}/#{resource_type}/#{sanitized_id}", headers)
JSON.parse(response.body)
end
end
Expand Down
3 changes: 3 additions & 0 deletions lib/ndr_lookup/fhir/odt/organisation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def find(id)
rescue Client::ResourceNotFound => e
logger.info("Organization not found: #{e.message}")
nil
rescue Client::ApiError, Client::InvalidURIError => e
logger.warn("Organization lookup failed for '#{id}': #{e.message}")
nil
end

# ActiveRecord subs .all in to /all which then becomes like finding the id 'all'
Expand Down
2 changes: 1 addition & 1 deletion lib/ndr_lookup/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module NdrLookup
VERSION = '0.3.0'.freeze
VERSION = '0.3.1'.freeze
end
12 changes: 12 additions & 0 deletions test/fhir/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ def test_should_raise_api_error_on_timeout
TestClient.find('Organization', 'X26')
end
end

def test_find_strips_whitespace_from_id
url = "#{ODT_ENDPOINT}/Organization/7A3C4"
file = File.new("#{RESPONSES_DIR}/fhir/organisation_find_success_response.txt")
stub_request(:get, url).to_return(file)

response = TestClient.find('Organization', ' 7A3C4 ')

# WebMock would raise an error if the id is not sanitized
assert_kind_of(Hash, response)
assert_requested(:get, url)
end
end

class TestClient < Fhir::Base
Expand Down
20 changes: 20 additions & 0 deletions test/fhir/odt/organisation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ def test_sync_handles_api_error_gracefully

assert_equal [], orgs
end

def test_find_handles_api_error_gracefully
url = "#{ODT_ENDPOINT}/Organization/X26"
stub_request(:get, url).to_timeout

org = Organisation.find('X26')

assert_nil org
end

def test_find_strips_whitespace_from_id
url = "#{ODT_ENDPOINT}/Organization/7A3C4"
file = File.new("#{RESPONSES_DIR}/fhir/organisation_find_success_response.txt")
stub_request(:get, url).to_return(file)

Organisation.find('7A3C4 ')

# WebMock would raise an error if the id is not sanitized
assert_requested(:get, url)
end
end
end
end
Expand Down