Sha256: fe199e9e05945364ac21987d5cbecc1a7501f54e4415072235758612f0e013e9

Contents?: true

Size: 1.31 KB

Versions: 54

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/hd/base_controller"

module Renalware
  module HD
    # Responsible for rendering an HD Session Form PDF (aka Protocol) which has the patients
    # past 3 sessions on it, and empty rows for their next three sessions.
    class ProtocolsController < BaseController
      # Note that although rendering an individual PDF for a patient here, we use PdfRender
      # which can handles multiple patients, and hence it uses the index.pdf.slim view.
      # The show view is not used.
      def show
        authorize Session, :show?
        respond_to do |format|
          format.html { render html: pdf_renderer.call }
          format.pdf { send_pdf_data_as_inline_file }
        end
      end

      private

      def send_pdf_data_as_inline_file
        send_data(
          pdf_renderer.call,
          filename: pdf_filename,
          type: "application/pdf",
          disposition: "inline"
        )
      end

      def pdf_renderer
        @pdf_renderer ||= begin
          SessionForms::PdfRenderer.new(
            patients: patient,
            output_html_for_debugging: params.key?(:debug)
          )
        end
      end

      def pdf_filename
        "#{patient.family_name}-#{patient.hospital_identifier.id}-protocol".upcase + ".pdf"
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
renalware-core-2.0.127 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.126 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.125 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.124 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.123 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.121 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.120 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.119 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.118 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.117 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.116 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.115 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.113 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.112 app/controllers/renalware/hd/protocols_controller.rb