Skip to content

Commit

Permalink
Fix for DSTU2/STU3 set_client_on_resource (fhir-crucible#144)
Browse files Browse the repository at this point in the history
* fix setting client on dstu2 and stu3 references

* bump version
  • Loading branch information
Jammjammjamm committed Aug 13, 2021
1 parent a69338c commit 42c675d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/fhir_client/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,9 @@ def set_client_on_resource(resource)

resource.client = self
resource.each_element do |element, _, _|
element.client = self if element.is_a?(Reference) || element.respond_to?(:resourceType)
if element.is_a?(Reference) || element.is_a?(STU3::Reference) || element.is_a?(DSTU2::Reference) || element.respond_to?(:resourceType)
element.client = self
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fhir_client/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module FHIR
class Client
VERSION = '5.0.0'.freeze
VERSION = '5.0.1'.freeze
end
end
46 changes: 46 additions & 0 deletions test/unit/set_client_on_resource_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require_relative '../test_helper'

class SetClientOnResourceTest < Test::Unit::TestCase
def client
@client ||= FHIR::Client.new('abc')
end

def test_r4
condition = FHIR::Condition.new(
resourceType: 'Condition',
subject: {
reference: 'Patient/123'
}
)
client.set_client_on_resource(condition)

assert_equal(client, condition.client)
assert_equal(client, condition.subject.client)
end

def test_stu3
condition = FHIR::STU3::Condition.new(
resourceType: 'Condition',
subject: {
reference: 'Patient/123'
}
)
client.set_client_on_resource(condition)

assert_equal(client, condition.client)
assert_equal(client, condition.subject.client)
end

def test_dstu2
condition = FHIR::DSTU2::Condition.new(
resourceType: 'Condition',
patient: {
reference: 'Patient/123'
}
)
client.set_client_on_resource(condition)

assert_equal(client, condition.client)
assert_equal(client, condition.patient.client)
end
end

0 comments on commit 42c675d

Please sign in to comment.