Sha256: 5dea04dc8ae5dd7e67cc51ae365186e3ed17fed0d2857c0f0274ed54f7f8ae69

Contents?: true

Size: 1.3 KB

Versions: 44

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/hd/base_controller"

module Renalware
  module HD
    class ProtocolsController < BaseController
      before_action :load_patient

      def show
        respond_to do |format|
          format.pdf {
            disposition = params.fetch("disposition", "inline")
            render_pdf(disposition)
          }
        end
      end

      private

      def render_pdf(disposition)
        render(
          pdf_options.merge(
            pdf: pdf_filename,
            disposition: disposition,
            print_media_type: true,
            locals: {
              protocol: ProtocolPresenter.new(patient, view_context)
            }
          )
        )
      end

      # Other options to consider:
      #  viewport_size: '1280x1024'
      #  disable_smart_shrinking: true
      def pdf_options
        {
          page_size: "A4",
          orientation: "Landscape",
          layout: "renalware/layouts/pdf",
          margin: { top: 10, bottom: 10, left: 10, right: 10 },
          footer: {
            font_size: 8
          },
          show_as_html: Rails.env.development? && params.key?("debug")
        }
      end

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

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
renalware-core-2.0.21 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.20 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.18 app/controllers/renalware/hd/protocols_controller.rb
renalware-core-2.0.17 app/controllers/renalware/hd/protocols_controller.rb