<commit_before># vi: ts=2:sts=2:et:sw=2  spell:spelllang=en  
require 'lims-laboratory-app/laboratory/tube'
require 'lims-laboratory-app/laboratory/create_labellable_resource_action'

module Lims::LaboratoryApp
  module Laboratory
    class Tube
      class CreateTube
        include CreateLabellableResourceAction

        attribute :aliquots, Array, :default => []
        attribute :type, String, :required => false
        attribute :max_volume, Numeric, :required => false

        def initialize(*args, &block)
          @name = "Create Tube"
          super(*args, &block)
        end

        def create(session)
          tube = Laboratory::Tube.new(:type => type, :max_volume => max_volume)
          session << tube
          count = 1
          if aliquots
            aliquots.each do |aliquot|
              # The sample uuid comes from lims-management-app, 
              # as a result, the sample is not present in the 
              # lims-laboratory-app sample table. The following 
              # creates a new sample with the expected uuid.
              aliquot_ready = aliquot.mash do |k,v|
                case k.to_s
                when "sample_uuid" then 
                  sample = Laboratory::Sample.new(:name => "Sample #{count}")
                  count += 1
                  session << sample
                  uuid_resource = session.new_uuid_resource_for(sample)
                  uuid_resource.send(:uuid=, v)
                  ["sample", sample] 
                else 
                  [k,v]
                end
              end
              tube << Laboratory::Aliquot.new(aliquot_ready)
            end
          end
          {:tube => tube, :uuid => session.uuid_for!(tube)}
        end
      end
    end
  end
  module Laboratory<commit_msg>Use the create sample shared<commit_after># vi: ts=2:sts=2:et:sw=2  spell:spelllang=en  
require 'lims-laboratory-app/laboratory/tube'
require 'lims-laboratory-app/laboratory/create_labellable_resource_action'
require 'lims-laboratory-app/laboratory/sample/create_sample_shared'

module Lims::LaboratoryApp
  module Laboratory
    class Tube
      class CreateTube
        include CreateLabellableResourceAction
        include CreateSampleShared

        attribute :aliquots, Array, :default => []
        attribute :type, String, :required => false
        attribute :max_volume, Numeric, :required => false

        def initialize(*args, &block)
          @name = "Create Tube"
          super(*args, &block)
        end

        def create(session)
          tube = Laboratory::Tube.new(:type => type, :max_volume => max_volume)
          session << tube
          count = 1
          if aliquots
            aliquots.each do |aliquot|
              # The sample uuid comes from lims-management-app, 
              # as a result, the sample is not present in the 
              # lims-laboratory-app sample table. The following 
              # creates a new sample with the expected uuid.
              aliquot_ready = aliquot.mash do |k,v|
                case k.to_s
                when "sample_uuid" then 
                  count += 1
                  ["sample", create_sample(session, "Sample #{count}", v)] 
                else 
                  [k,v]
                end
              end
              tube << Laboratory::Aliquot.new(aliquot_ready)
            end
          end
          {:tube => tube, :uuid => session.uuid_for!(tube)}
        end
      end
    end
  end
  module Laboratory
{'fraction_non_alphanumeric': 0.08750357449242208, 'fraction_numerical': 0.0028595939376608523, 'mean_word_length': 1.7543307086614173, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '672925', 'n_tokens_mistral': 998, 'n_tokens_neox': 943, 'n_words': 254}