Module: FHIR::Sections::Transactions
- Included in:
- Client
- Defined in:
- lib/sections/transactions.rb
Instance Attribute Summary collapse
-
#transaction_bundle ⇒ Object
Returns the value of attribute transaction_bundle.
Instance Method Summary collapse
- #add_batch_request(method, url, resource = nil, if_none_exist = nil) ⇒ Object
-
#add_transaction_request(method, url, resource = nil, if_none_exist = nil) ⇒ Object
syntactic sugar for add_batch_request.
- #begin_batch ⇒ Object
- #begin_transaction ⇒ Object
-
#end_batch(format = @default_format) ⇒ Object
submit the batch/transaction to the server.
-
#end_transaction(format = @default_format) ⇒ Object
syntactic sugar for end_batch.
Instance Attribute Details
#transaction_bundle ⇒ Object
Returns the value of attribute transaction_bundle.
5 6 7 |
# File 'lib/sections/transactions.rb', line 5 def transaction_bundle @transaction_bundle end |
Instance Method Details
#add_batch_request(method, url, resource = nil, if_none_exist = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sections/transactions.rb', line 29 def add_batch_request(method, url, resource=nil, if_none_exist=nil) request = FHIR::Bundle::Entry::Request.new if FHIR::Bundle::Entry::Request::METADATA['method']['valid_codes'].values.first.include?(method.upcase) request.local_method = method.upcase else request.local_method = 'POST' end request.ifNoneExist = if_none_exist if !if_none_exist.nil? if url.nil? && !resource.nil? = Hash.new [:resource] = resource.class [:id] = resource.id if request.local_method != 'POST' request.url = resource_url() request.url = request.url[1..-1] if request.url.starts_with?('/') else request.url = url end entry = FHIR::Bundle::Entry.new entry.resource = resource entry.request = request @transaction_bundle.entry << entry entry end |
#add_transaction_request(method, url, resource = nil, if_none_exist = nil) ⇒ Object
syntactic sugar for add_batch_request
25 26 27 |
# File 'lib/sections/transactions.rb', line 25 def add_transaction_request(method, url, resource=nil, if_none_exist=nil) add_batch_request(method, url, resource, if_none_exist) end |
#begin_batch ⇒ Object
14 15 16 17 18 19 |
# File 'lib/sections/transactions.rb', line 14 def begin_batch @transaction_bundle = FHIR::Bundle.new @transaction_bundle.type = 'batch' @transaction_bundle.entry ||= [] @transaction_bundle end |
#begin_transaction ⇒ Object
7 8 9 10 11 12 |
# File 'lib/sections/transactions.rb', line 7 def begin_transaction @transaction_bundle = FHIR::Bundle.new @transaction_bundle.type = 'transaction' @transaction_bundle.entry ||= [] @transaction_bundle end |
#end_batch(format = @default_format) ⇒ Object
submit the batch/transaction to the server
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/sections/transactions.rb', line 64 def end_batch(format=@default_format) = { format: format, 'Prefer' => 'return=representation' } reply = post resource_url(), @transaction_bundle, fhir_headers() begin if(format.downcase.include?('xml')) reply.resource = FHIR::Xml.from_xml(reply.body) else reply.resource = FHIR::Json.from_json(reply.body) end rescue Exception => e reply.resource = nil end reply.resource_class = reply.resource.class reply end |
#end_transaction(format = @default_format) ⇒ Object
syntactic sugar for end_batch
56 57 58 |
# File 'lib/sections/transactions.rb', line 56 def end_transaction(format=@default_format) end_batch(format) end |