def save(params, session)
      logger.debug { "Scat is saving the specimen with parameters #{params.qp}..." }
      pcl_id = session[:protocol_id] if session[:protocol] == params[:protocol]
      site_id = session[:site_id] if pcl_id
      cpr_id = session[:cpr_id] if pcl_id and session[:mrn] == params[:mrn]
      scg_id = session[:scg_id] if cpr_id and session[:spn] == params[:spn]
      # the caTissue class => { property => value } hash
      ph = @conf.slice(params)
      # the collection protocol
      pcl = to_protocol(ph[CaTissue::CollectionProtocol].merge({:identifier => pcl_id}))
      # the current user
      user = params[:user]
      # the collection site
      site = site_id ? CaTissue::Site.new(:identifier => site_id) : to_site(pcl, user)
      # the patient
      pnt = CaTissue::Participant.new(ph[CaTissue::Participant])
      # the CPR parameters
      reg_params = ph[CaTissue::ParticipantMedicalIdentifier].merge(:participant => pnt, :site => site)
      # the CPR
      reg = to_registration(pcl, reg_params) 
      reg.identifier = cpr_id
      # the specimen parameters
      spc_params = ph[CaTissue::Specimen].merge(ph[CaTissue::SpecimenCharacteristics])
      # The current user is the biobank specimen receiver.
      spc_params.merge!(:receiver => user)
      # the specimen to save
      spc = to_specimen(pcl, spc_params)
      # the SCG parameters
      scg_params = ph[CaTissue::SpecimenCollectionGroup].merge(:participant => pnt, :site => site)
      # the SCG which contains the specimen
      pcl.add_specimens(spc, scg_params)
      # Save the specimen.
      logger.debug { "Scat is saving #{spc} with content:\n#{spc.dump}" }
      spc.save
      # Format the status message.
      session[:status] = "Created the specimen with label #{spc.label}."
      # Capture the params in the session to refresh the form.
      params.each { |a, v| session[a.to_sym] = v }
      # Capture the ids.
      scg = spc.specimen_collection_group
      session[:scg_id] = scg.identifier
      session[:site_id] = site.identifier
      cpr = scg.registration
      session[:cpr_id] = cpr.identifier
      session[:protocol_id] = cpr.protocol.identifier
      logger.debug { "Scat saved #{spc}." }
      spc
    end
def save(params, session)
      logger.debug { "Scat is saving the specimen with parameters #{params.qp}..." }
      pcl_id = session[:protocol_id] if session[:protocol] == params[:protocol]
      site_id = session[:site_id] if pcl_id
      cpr_id = session[:cpr_id] if pcl_id and session[:mrn] == params[:mrn]
      scg_id = session[:scg_id] if cpr_id and session[:spn] == params[:spn]
      # the caTissue class => { property => value } hash
      ph = @conf.slice(params)
      # the collection protocol
      pcl = to_protocol(ph[CaTissue::CollectionProtocol].merge({:identifier => pcl_id}))
      # the current user
      user = params[:user]
      # the collection site
      site = site_id ? CaTissue::Site.new(:identifier => site_id) : to_site(pcl, user)
      # the patient
      pnt = CaTissue::Participant.new(ph[CaTissue::Participant])
      # the CPR parameters
      reg_params = ph[CaTissue::ParticipantMedicalIdentifier].merge(:participant => pnt, :site => site)
      # the CPR
      reg = to_registration(pcl, reg_params) 
      reg.identifier = cpr_id
      # the specimen parameters
      spc_params = ph[CaTissue::Specimen].merge(ph[CaTissue::SpecimenCharacteristics])
      # The current user is the biobank specimen receiver.
      spc_params.merge!(:receiver => user)
      # the specimen to save
      spc = to_specimen(pcl, spc_params)
      # the SCG parameters
      scg_params = ph[CaTissue::SpecimenCollectionGroup].merge(:participant => pnt, :site => site)
      # the SCG which contains the specimen
      pcl.add_specimens(spc, scg_params)
      # Save the specimen.
      logger.debug { "Scat is saving #{spc} with content:\n#{spc.dump}" }
      spc.save
      # Format the status message.
      session[:status] = "Created the specimen with label #{spc.label}."
      # Capture the params in the session to refresh the form.
      params.each { |a, v| session[a.to_sym] = v }
      # Capture the ids.
      scg = spc.specimen_collection_group
      session[:scg_id] = scg.identifier
      session[:site_id] = site.identifier
      cpr = scg.registration
      session[:cpr_id] = cpr.identifier
      session[:protocol_id] = cpr.protocol.identifier
      logger.debug { "Scat saved #{spc}." }
      spc
    end
Saves the +CaTissue::Specimen+ object specified in the request parameters.

 @param [{Symbol => String}] params the request parameters
 @param [{String => String}] session the current Sinatra session
 @return [CaTissue::Specimen] the saved specimen
 @raise [ScatError] if the parameters are insufficient to build a specimen
 @raise [CaRuby::DatabaseError] if the save is unsuccessful