Sha256: 202799bde5a30ff5ccbe2a71feec22e4bd7b44f49b9a96b42dee4c1d93a7dc6c

Contents?: true

Size: 999 Bytes

Versions: 7

Compression:

Stored size: 999 Bytes

Contents

module FHIR
  class Bundle
    def self_link
      link.select { |n| n.relation == 'self' }.first
    end

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

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

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

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

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

    def each(&block)
      iteration = @entry.map(&:resource).each(&block)
      iteration += next_bundle.each(&block) if next_bundle
      iteration
    end

    def next_bundle
      # TODO: test this
      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
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fhir_client-3.0.2 lib/fhir_client/ext/bundle.rb
fhir_client-3.0.1 lib/fhir_client/ext/bundle.rb
fhir_client-1.8.0 lib/fhir_client/ext/bundle.rb
fhir_client-1.6.10 lib/fhir_client/ext/bundle.rb
fhir_client-1.6.9 lib/fhir_client/ext/bundle.rb
fhir_client-1.6.8 lib/fhir_client/ext/bundle.rb
fhir_client-1.6.7 lib/fhir_client/ext/bundle.rb