Skip to content

Commit

Permalink
Merge pull request fhir-crucible#130 from fhir-crucible/version_searc…
Browse files Browse the repository at this point in the history
…h_options

updated search function to allow user to specify request headers
  • Loading branch information
ashankland authored Apr 1, 2020
2 parents 57cce51 + 3f4c7b5 commit e90b53c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/fhir_client/sections/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,31 @@ module Search
#
# @param klass The type of resource to be searched.
# @param options A hash of options used to construct the search query.
# @param headers A hash of headers used in the http request itself.
# @return FHIR::ClientReply
#
def search(klass, options = {}, format = @default_format)
def search(klass, options = {}, format = @default_format, headers = {})
options[:resource] = klass
options[:format] = format

reply = if options[:search] && options[:search][:flag]
post resource_url(options), nil, fhir_headers({content_type: 'application/x-www-form-urlencoded'})
headers[:content_type] = 'application/x-www-form-urlencoded'
post resource_url(options), nil, fhir_headers(headers)
else
get resource_url(options), fhir_headers
get resource_url(options), fhir_headers(headers)
end
# reply = get resource_url(options), fhir_headers(options)
reply.resource = parse_reply(klass, format, reply)
reply.resource_class = klass
reply
end

def search_existing(klass, id, options = {}, format = @default_format)
def search_existing(klass, id, options = {}, format = @default_format, headers = {})
options.merge!(resource: klass, id: id, format: format)
# if options[:search][:flag]
reply = if options[:search] && options[:search][:flag]
post resource_url(options), nil, fhir_headers({content_type: 'application/x-www-form-urlencoded'})
headers[:content_type] = 'application/x-www-form-urlencoded'
post resource_url(options), nil, fhir_headers(headers)
else
get resource_url(options), fhir_headers
end
Expand All @@ -36,10 +39,11 @@ def search_existing(klass, id, options = {}, format = @default_format)
reply
end

def search_all(options = {}, format = @default_format)
def search_all(options = {}, format = @default_format, headers = {})
options[:format] = format
reply = if options[:search] && options[:search][:flag]
post resource_url(options), nil, fhir_headers({content_type: 'application/x-www-form-urlencoded'})
headers[:content_type] = 'application/x-www-form-urlencoded'
post resource_url(options), nil, fhir_headers(headers)
else
get resource_url(options), fhir_headers
end
Expand Down

0 comments on commit e90b53c

Please sign in to comment.