Class: Renalware::Letters::BatchesController

Inherits:
BaseController show all
Includes:
Concerns::Pageable
Defined in:
app/controllers/renalware/letters/batches_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#patient

Methods inherited from BaseController

#patient

Instance Method Details

#createObject



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

def create
  batch = create_unprocessed_batch_and_batch_items(ids_of_letters_to_batch_print)
  authorize batch
  Printing::BatchPrintJob.perform_later(batch, current_user)
  respond_to do |format|
    format.js {
      render locals: { batch: batch }
    }
  end
end

#indexObject

rubocop:enable Metrics/MethodLength



60
61
62
63
64
# File 'app/controllers/renalware/letters/batches_controller.rb', line 60

def index
  batches = Batch.order(created_at: :desc)
  authorize batches
  render locals: { batches: batches.page(page).per(per_page) }
end

#showObject

rubocop:disable Metrics/MethodLength



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

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: "letter_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/letters/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