Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions lib/fhir_client/sections/search.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

module FHIR
module Sections
module Search
Expand All @@ -6,42 +7,46 @@ 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
get resource_url(options), fhir_headers(headers)
end
reply.resource = parse_reply(klass, format, reply)
reply.resource_class = klass
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
get resource_url(options), fhir_headers(headers)
end
reply.resource = parse_reply(nil, format, reply)
reply.resource_class = nil
Expand Down