Sha256: 4d19afcc79de1b0b8fbcaa7adf178882d8d1a662e24b1efcb78308a1996f276d

Contents?: true

Size: 1.37 KB

Versions: 11

Compression:

Stored size: 1.37 KB

Contents

module FHIR
  module BundleExtras
    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)
      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

    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
  end
end

module FHIR
  class Bundle
    include FHIR::BundleExtras
  end
end

module FHIR
  module DSTU2
    class Bundle
      include FHIR::BundleExtras
    end
  end
end

module FHIR
  module STU3
    class Bundle
      include FHIR::BundleExtras
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
fhir_client-5.0.3 lib/fhir_client/ext/bundle.rb
fhir_client-5.0.2 lib/fhir_client/ext/bundle.rb
fhir_client-5.0.1 lib/fhir_client/ext/bundle.rb
fhir_client-5.0.0 lib/fhir_client/ext/bundle.rb
fhir_client-4.0.6 lib/fhir_client/ext/bundle.rb
fhir_client-4.0.5 lib/fhir_client/ext/bundle.rb
fhir_client-4.0.4 lib/fhir_client/ext/bundle.rb
fhir_client-4.0.3 lib/fhir_client/ext/bundle.rb
fhir_client-4.0.2 lib/fhir_client/ext/bundle.rb
fhir_client-4.0.1 lib/fhir_client/ext/bundle.rb
fhir_client-4.0.0 lib/fhir_client/ext/bundle.rb