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.147 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.146 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.145 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.144 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.143 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.142 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.141 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.140 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.139 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.138 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.137 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.136 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.135 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.134 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.133 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.132 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.131 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.130 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.129 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.128 app/controllers/renalware/hd/protocols_controller.rb