Skip to content

Commit

Permalink
Merge pull request #93 from honestica/partial_update
Browse files Browse the repository at this point in the history
Add the partial_update method to crud methods
  • Loading branch information
arscan authored Jun 21, 2018
2 parents b73c1e3 + de99205 commit 5b1325d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/fhir_client/ext/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def handle_response(response)
end

module ClassMethods

def client
FHIR::Model.client
end
Expand Down Expand Up @@ -107,6 +107,10 @@ def conditional_create(model, params, client = self.client)
handle_response client.conditional_create(model, params)
end

def partial_update(id, patchset, options = {})
handle_response client.partial_update(self, id, patchset, options)
end

def all(client = self.client)
handle_response client.read_feed(self)
end
Expand Down
26 changes: 26 additions & 0 deletions test/unit/client_interface_sections/update_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require_relative '../../test_helper'

class ClientInterfaceUpdateTest < Test::Unit::TestCase
def client
@client ||= FHIR::Client.new('update-test')
end

def test_class_partial_update
patient = FHIR::Patient.new({'id' => 'foo', 'active'=>true})
patchset = [
{
op: "replace",
path: "/active/",
value: "false"
}
]

outcome = FHIR::OperationOutcome.new({'issue'=>[{'code'=>'informational', 'severity'=>'information', 'diagnostics'=>'Successfully updated "Patient/foo" in 0 ms'}]})

stub_request(:patch, /Patient\/foo/).with(body: "[{\"op\":\"replace\",\"path\":\"/active/\",\"value\":\"false\"}]").to_return(status: 200, body: outcome.to_json, headers: {'Content-Type'=>'application/fhir+json', 'Location'=>'http://update-test/Patient/foo/_history/0', 'ETag'=>'W/"foo"', 'Last-Modified'=>Time.now.strftime("%a, %e %b %Y %T %Z")})
reply = FHIR::Patient.partial_update(patient.id, patchset)

assert reply.is_a?(FHIR::DSTU2::OperationOutcome)
end

end

0 comments on commit 5b1325d

Please sign in to comment.