<commit_before>class ProductTestsController < ApplicationController
  before_action :set_product, only: [:index, :new, :create]
  before_action :set_product_test, except: [:index, :new, :create]
  add_breadcrumb 'Dashboard', :vendors_path

  def index
    @product_tests = @product.product_tests
  end

  def edit
  end

  def update
  end

  def show
    return unless @product_test[:_type] == 'MeasureTest'
    if @product_test.tasks.c1_task
      redirect_to new_task_test_execution_path(@product_test.tasks.c1_task)
    elsif @product_test.tasks.c2_task
      redirect_to new_task_test_execution_path(@product_test.tasks.c2_task)
    end
  end

  def destroy
  end

  # Save and serve up the Records associated with this ProductTest. Filetype is specified by :format
  def download
    format = params[:format] || 'qrda'
    file = Cypress::CreateDownloadZip.create_test_zip(@product_test.id, format)
    file_name = "#{@product_test.cms_id}_#{@product_test.id}.#{format}.zip".tr(' ', '_')
    send_data file.read, type: 'application/zip', disposition: 'attachment', filename: file_name
  end

  private

  def set_product
    @product = Product.find(params[:product_id])
  end

  def set_product_test
    @product_test = ProductTest.find(params[:id])
  end
end<commit_msg>don't re-create the patient qrda zip every download<commit_after>class ProductTestsController < ApplicationController
  before_action :set_product, only: [:index, :new, :create]
  before_action :set_product_test, except: [:index, :new, :create]
  add_breadcrumb 'Dashboard', :vendors_path

  def index
    @product_tests = @product.product_tests
  end

  def edit
  end

  def update
  end

  def show
    return unless @product_test[:_type] == 'MeasureTest'
    if @product_test.tasks.c1_task
      redirect_to new_task_test_execution_path(@product_test.tasks.c1_task)
    elsif @product_test.tasks.c2_task
      redirect_to new_task_test_execution_path(@product_test.tasks.c2_task)
    end
  end

  def destroy
  end

  # Save and serve up the Records associated with this ProductTest. Filetype is specified by :format
  def download
    format = params[:format] || 'qrda'

    file = if format == 'qrda' && @product_test.patient_archive.file
             @product_test.patient_archive.file
           else
             Cypress::CreateDownloadZip.create_test_zip(@product_test.id, format)
           end
    file_name = "#{@product_test.cms_id}_#{@product_test.id}.#{format}.zip".tr(' ', '_')
    send_data file.read, type: 'application/zip', disposition: 'attachment', filename: file_name
  end

  private

  def set_product
    @product = Product.find(params[:product_id])
  end

  def set_product_test
    @product_test = ProductTest.find(params[:id])
  end
end
{'fraction_non_alphanumeric': 0.0998906306963179, 'fraction_numerical': 0.002916514764855997, 'mean_word_length': 4.109869646182496, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2224000', 'n_tokens_mistral': 906, 'n_tokens_neox': 879, 'n_words': 201}