lib/fhir_client/sections/crud.rb
def base_create(resource, options, format)
        options = {} if options.nil?
        options[:resource] = resource.class
        options[:format] = format
        reply = post resource_url(options), resource, fhir_headers(options)
        if [200, 201].include? reply.code
          type = reply.response[:headers].detect{|x, _y| x.downcase=='content-type'}.try(:last)
          if !type.nil?
            reply.resource = if type.include?('xml') && !reply.body.empty?
                               FHIR::Xml.from_xml(reply.body)
                             elsif type.include?('json') && !reply.body.empty?
                               FHIR::Json.from_json(reply.body)
                             else
                               resource # just send back the submitted resource
                             end
            resource.id = FHIR::ResourceAddress.pull_out_id(resource.class.name.demodulize, reply.self_link)
          else
            resource.id = FHIR::ResourceAddress.pull_out_id(resource.class.name.demodulize, reply.self_link)
            reply.resource = resource # don't know the content type, so return the resource provided
          end
        else
          resource.id = FHIR::ResourceAddress.pull_out_id(resource.class.name.demodulize, reply.self_link)
          reply.resource = resource # just send back the submitted resource
        end
        reply.resource.client = self
        reply.resource_class = resource.class
        reply
      end
#
# Create a new resource with a server assigned id. Return the newly created
# resource with the id the server assigned.
#
Create a new resource with a server assigned id. Return the newly created
resource with the id the server assigned.
Create a new resource with a server assigned id . Return the newly created resource with the id the server assigned .
def base_create(resource, options, format)
        options = {} if options.nil?
        options[:resource] = resource.class
        options[:format] = format
        reply = post resource_url(options), resource, fhir_headers(options)
        if [200, 201].include? reply.code
          type = reply.response[:headers].detect{|x, _y| x.downcase=='content-type'}.try(:last)
          if !type.nil?
            reply.resource = if type.include?('xml') && !reply.body.empty?
                               FHIR::Xml.from_xml(reply.body)
                             elsif type.include?('json') && !reply.body.empty?
                               FHIR::Json.from_json(reply.body)
                             else
                               resource 
                             end
            resource.id = FHIR::ResourceAddress.pull_out_id(resource.class.name.demodulize, reply.self_link)
          else
            resource.id = FHIR::ResourceAddress.pull_out_id(resource.class.name.demodulize, reply.self_link)
            reply.resource = resource 
          end
        else
          resource.id = FHIR::ResourceAddress.pull_out_id(resource.class.name.demodulize, reply.self_link)
          reply.resource = resource 
        end
        reply.resource.client = self
        reply.resource_class = resource.class
        reply
      end
def base_create ( resource , options , format ) options = { } if options . nil? options [ :resource ] = resource . class options [ :format ] = format reply = post resource_url ( options ) , resource , fhir_headers ( options ) if [ 200 , 201 ] . include? reply . code type = reply . response [ :headers ] . detect { | x , _y | x . downcase == 'content-type' } . try ( :last ) if ! type . nil? reply . resource = if type . include? ( 'xml' ) && ! reply . body . empty? FHIR :: Xml . from_xml ( reply . body ) elsif type . include? ( 'json' ) && ! reply . body . empty? FHIR :: Json . from_json ( reply . body ) else resource end resource . id = FHIR :: ResourceAddress . pull_out_id ( resource . class . name . demodulize , reply . self_link ) else resource . id = FHIR :: ResourceAddress . pull_out_id ( resource . class . name . demodulize , reply . self_link ) reply . resource = resource end else resource . id = FHIR :: ResourceAddress . pull_out_id ( resource . class . name . demodulize , reply . self_link ) reply . resource = resource end reply . resource . client = self reply . resource_class = resource . class reply end
Create a new resource with a server assigned id.
Create a new resource with a server assigned id .
# just send back the submitted resource # don't know the content type, so return the resource provided # just send back the submitted resource
resource
options
format