Class: Renalware::HD::SessionForms::BatchesController

Inherits:
BaseController show all
Defined in:
app/controllers/renalware/hd/session_forms/batches_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#patient

Instance Method Details

#createObject



9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/renalware/hd/session_forms/batches_controller.rb', line 9

def create
  batch = create_unprocessed_batch_and_batch_items
  authorize batch
  Delayed::Job.enqueue BatchPrintJob.new(batch.id, current_user.id)

  respond_to do |format|
    format.js {
      render locals: { batch: batch }
    }
  end
end

#showObject

rubocop:disable Metrics/MethodLength



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/renalware/hd/session_forms/batches_controller.rb', line 41

def show
  batch = find_and_authorize_batch
  respond_to do |format|
    format.pdf do
      # Returns the PDF itself using path saved in the Batch - provided status is correct
      send_file(
        batch.filepath,
        type: "application/pdf",
        disposition: "inline",
        filename: "session_forms_batch_#{batch.id}.pdf"
      )
    end
    format.html do
      # Returns a partial with a link to the compiled batch pdf
      render layout: false, locals: { batch: find_and_authorize_batch }
    end
  end
end

#statusObject

rubocop:disable Metrics/MethodLength



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/renalware/hd/session_forms/batches_controller.rb', line 22

def status
  batch = find_and_authorize_batch(params[:batch_id])
  respond_to do |format|
    format.json {
      render(
        status: :ok,
        json: {
          id: batch.id,
          status: batch.status,
          percent_complete: batch.percent_complete
        }
      )
    }
  end
end