Module: FHIR::BundleExtras

Included in:
Bundle, DSTU2::Bundle, STU3::Bundle
Defined in:
lib/fhir_client/ext/bundle.rb

Instance Method Summary collapse

Instance Method Details

#each(&block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fhir_client/ext/bundle.rb', line 30

def each(&block)
  iterator = @entry.map(&:resource).each(&block)
  if next_bundle
    next_iterator = next_bundle.each(&block)
    Enumerator.new do |y|
      iterator.each { |r| y << r }
      next_iterator.each { |r| y << r }
    end
  else
    iterator
  end
end


7
8
9
# File 'lib/fhir_client/ext/bundle.rb', line 7

def first_link
  link.select { |n| n.relation == 'first' }.first
end

#get_by_id(id) ⇒ Object



23
24
25
26
27
28
# File 'lib/fhir_client/ext/bundle.rb', line 23

def get_by_id(id)
  entry.each do |item|
    return item.resource if item.id == id || item.resource.id == id
  end
  nil
end


11
12
13
# File 'lib/fhir_client/ext/bundle.rb', line 11

def last_link
  link.select { |n| n.relation == 'last' }.first
end

#next_bundleObject



43
44
45
46
# File 'lib/fhir_client/ext/bundle.rb', line 43

def next_bundle
  return nil unless client && next_link.try(:url)
  @next_bundle ||= client.parse_reply(self.class, client.default_format, client.raw_read_url(next_link.url))
end


15
16
17
# File 'lib/fhir_client/ext/bundle.rb', line 15

def next_link
  link.select { |n| n.relation == 'next' }.first
end


19
20
21
# File 'lib/fhir_client/ext/bundle.rb', line 19

def previous_link
  link.select { |n| n.relation == 'previous' || n.relation == 'prev' }.first
end


3
4
5
# File 'lib/fhir_client/ext/bundle.rb', line 3

def self_link
  link.select { |n| n.relation == 'self' }.first
end