rubocop:enbale Metrics/MethodLength, Metrics/AbcSize
180586
def seed_pathology_for(local_patient_id:)
      patient = Patient.find_by(local_patient_id: local_patient_id)
      pathology_patient = Pathology.cast_patient(patient)
      seed_pathology_requests_for(patient: pathology_patient)
      seed_pathology_observations_for(patient: pathology_patient)
    end
182789
def [](key, src = name.to_sym)
      attr =
        if count_index[key].equal?(1)
          name_index[key]
        else
          source_index[src][key]
        end

      unless attr
        raise(KeyError, "#{key.inspect} attribute doesn't exist in #{src} schema")
      end

      attr
    end
392899
def method_missing mtd, *args
      if mtd.to_s.chars.to_a.last == '='
        raise ArgumentError, "Invalid number of arguments (#{args.length} for 1)" if args.length != 1
        attributes[mtd.to_s.slice(0,mtd.to_s.length-1)] = args.first
      else
        raise ArgumentError, "Invalid number of arguments (#{args.length} for 0)" if args.length != 0
        attributes[mtd.to_s]
      end
    end
1167072
def load
      @comments = self.build
      max_size = @comments.values.max_by(&:size).try(:size)
      
      load_comments(Rails.root.join('app', 'controllers').to_s, max_size) do |file, line|
        if get_finder === line
          found_method = $1
          
          comments = build_comments(found_method, line.chomp.match(/^(\s*)[^\s]*/)[1])
          file.write(comments.join) unless file.trailing?(comments)
          
          @comments.delete(found_method)
          get_finder(true)
        end
        
        file.write(line)
      end
    end
663345
def method_missing(meth, *args, &block)
      meth_str = meth.to_s

      if /^(\w+)\=$/.match(meth_str)
        _set($1, *args, &block)
      elsif args.length > 0 || block_given?
        _add(meth, *args, &block)
      elsif /^(\w+)\?$/.match(meth_str)
        !!_get($1)
      else
        _get_or_create_namespace(meth)
      end
    end
326336
def size=(size)
      unless size.nil?
        case size
        when String
          width, height = size.split('x')
        when Array
          width, height = size
        when Hash
          width = size[:width]
          height = size[:height]
        else
          raise "Don't know how to set size from #{size.class}!"
        end

        self.width = width if width
        self.height = height if height
      end
    end
113689
def parse_attributes!
      self.attributes = (attributes || []).map do |key_value|
        name, type, index, default = key_value.split(/:/)
        opts = {}
        if default
          opts[:default] = default
        end
        if index
          index_type, constraint = index.split(/,/)
          if constraint == 'not_null'
            opts[:null] = false
          end
        end
        create_attribute(name, type, index_type, opts)
      end
    end
821573
def [](new_size)
      if new_size.is_a? Directive
        tags.merge! new_size.tags_for_sized_directive
      else
        tags[:size] = new_size
      end

      self
    end
329177
def map_gems_to_specs(gems)
      gems.map.with_index do |gemfile, index|
        # rubocop:disable Metrics/LineLength
        Utils.logger.info("[#{index + 1}/#{gems.size}]: Processing #{gemfile.split('/')[-1]}")
        # rubocop:enable Metrics/LineLength

        if File.size(gemfile).zero?
          Utils.logger.warn("Skipping zero-length gem: #{gemfile}")
          next
        end

        begin
          spec = if ::Gem::Package.respond_to? :open
                   ::Gem::Package
                     .open(File.open(gemfile, 'rb'), 'r', &:metadata)
                 else
                   ::Gem::Package.new(gemfile).spec
                 end

          spec.loaded_from = gemfile

          # HACK: fuck this shit - borks all tests that use pl1
          if File.basename(gemfile, '.gem') != spec.original_name
            exp = spec.full_name
            exp << " (#{spec.original_name})" if
              spec.original_name != spec.full_name
            msg = "Skipping misnamed gem: #{gemfile} should be named #{exp}"
            Utils.logger.warn(msg)
            next
          end

          version = spec.version.version
          unless version =~ /^\d+\.\d+\.\d+.*/
            msg = "Skipping gem #{spec.full_name} - invalid version #{version}"
            Utils.logger.warn(msg)
            next
          end

          if ::Gem::VERSION >= '2.5.0'
            spec.abbreviate
            spec.sanitize
          else
            abbreviate spec
            sanitize spec
          end

          spec
        rescue SignalException
          msg = 'Received signal, exiting'
          Utils.logger.error(msg)
          raise
        rescue StandardError => e
          msg = ["Unable to process #{gemfile}",
                 "#{e.message} (#{e.class})",
                 "\t#{e.backtrace.join "\n\t"}"].join("\n")
          Utils.logger.debug(msg)
        end
      end.compact
    end
521963
def execute!
      begin
        options   = Options.new(argv)

        generator = ErbGenerator.new(Data.new(options.data_sources))
        generator.compile(options.source, options.destination)

        exitstatus = 0
      rescue Interrupt
        Filegen::Ui.warning 'You told me to stop command execution.'
        exitstatus = 2
      rescue Exceptions::ErbTemplateHasSyntaxErrors => e
        Filegen::Ui.error "Syntax error in ERB-Template: \n" + e.message
        exitstatus = 3
      rescue Exceptions::YamlFileNotFound => e
        Filegen::Ui.error "Yaml-file \"#{JSON.parse(e.message)['file']}\" not found."
        exitstatus = 4
      rescue StandardError => e
        Filegen::Ui.error "#{e.class} - #{e.message}"
        exitstatus = 99
      end

      @kernel.exit(exitstatus)
    end
182657
def method_missing(method, *args, &code)
    success = false
    result  = nil

    if method.to_s.match(/^set\_([a-z].*)$/)
      name = $1.to_sym

      if @types.has_key?(name) && args.length > 2
        @types[name].set([ args[0], args[1] ], args[2]) if args.length > 2
        success = true
      end

    elsif method.to_s.match(/^remove\_([a-z].*)$/)
      name = $1.to_sym

      if @types.has_key?(name) && args.length > 0
        @types[name].delete([ args[0], args[1] ])
        success = true
      end

    else
      name = @plurals[method.to_sym]

      if name && @types.has_key?(name)
        result  = @types[name]
        success = true
      end
    end
    super unless success # Raise NoMethodError
    result
  end
32575
def run
        raise Lupa::SearchAttributesError, "You need to specify search attributes." unless search_attributes

        search_attributes.each do |method_name, value|
          new_scope         = scope_class.public_send(method_name)
          scope_class.scope = new_scope unless new_scope.nil?
        end

        scope_class.scope
      end
1232820
def method_missing(name, *args, &block)
      return attributes[name.to_sym] if attributes.include?(name.to_sym)
      return super
    end
456525
def method_missing(name, *arguments)
      value = arguments[0]
      name = name.to_s
      if name[-1, 1] == '='
        key = name[/(.+)\s?=/, 1]
        @data[key.to_sym] = value unless instance_variables.include? "@#{key}".to_sym
      else
        @data[name.to_sym]
      end
    end
934320
def method_missing(name, *args, &block)
      return attr(name[0..-2], args[0]) if args.size == 1 and name[-1] == '='
    end
336415
def method_missing(method, *args)
      unless args.size == 1 && [Hash, Array].include?(args[0].class)
        raise 'Expected 1 Hash or Array argument'
      end

      call_remote method, args[0]
    end
840196
def call(env)
      # remove the callback and _ parameters BEFORE calling the backend, so
      # that caching middleware does not store a copy for each value of the
      # callback parameter
      request = Rack::Request.new(env)
      callback = request.params.delete(@callback_param)
      timestamp = request.params.delete(@timestamp_param)
      env['QUERY_STRING'] = env['QUERY_STRING'].split("&").delete_if{|param|
        param =~ /^(#{@timestamp_param}|#{@callback_param})=/
      }.join("&")
      env['rack.jsonp.callback'] = callback
      env['rack.jsonp.timestamp'] = timestamp

      status, headers, response = @app.call(env)

      if callback && headers['Content-Type'] =~ /json/i
        response = pad(callback, response)
        headers['Content-Length'] = response.first.bytesize.to_s
        headers['Content-Type'] = 'application/javascript'
      elsif @carriage_return && headers['Content-Type'] =~ /json/i
        # add a \n after the response if this is a json (not JSONP) response
        response = carriage_return(response)
        headers['Content-Length'] = response.first.bytesize.to_s
      end

      [status, headers, response]
    end