Module: FHIR::Sections::Transactions

Included in:
Client
Defined in:
lib/sections/transactions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#transaction_bundleObject

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::['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?
    options = Hash.new
    options[:resource] = resource.class
    options[:id] = resource.id if request.local_method != 'POST'
    request.url = resource_url(options)
    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

Parameters:

  • method

    one of [‘GET’,‘POST’,‘PUT’,‘DELETE’]

  • url

    relative path, such as ‘Patient/123’. Do not include the [base]

  • resource (defaults to: nil)

    The resource if a POST or PUT



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_batchObject



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_transactionObject



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

Parameters:

  • format (defaults to: @default_format)

Returns:

  • FHIR::ClientReply



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)
  options = { format: format, 'Prefer' => 'return=representation' }
  reply = post resource_url(options), @transaction_bundle, fhir_headers(options)
  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