Sha256: 03894894c6d440dbae01cbbae03fc37437f83650c448911399dfe9cadae5426b

Contents?: true

Size: 1.97 KB

Versions: 78

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/hospitals"

module Renalware
  module Hospitals
    class UnitsController < BaseController
      def new
        hospital_unit = Unit.new
        authorize hospital_unit
        render_new(hospital_unit)
      end

      def create
        hospital_unit = Unit.new(hospital_unit_params)
        authorize hospital_unit

        if hospital_unit.save
          redirect_to hospitals_units_path, notice: success_msg_for("hospital unit")
        else
          flash.now[:error] = failed_msg_for("hospital unit")
          render_new(hospital_unit)
        end
      end

      def index
        hospital_units = Unit.all
        authorize hospital_units
        render locals: { hospital_units: hospital_units }
      end

      def edit
        render_edit(find_and_authorize_hospital_unit)
      end

      def update
        hospital_unit = find_and_authorize_hospital_unit
        if hospital_unit.update(hospital_unit_params)
          redirect_to hospitals_units_path, notice: success_msg_for("hospital unit")
        else
          flash.now[:error] = failed_msg_for("hospital unit")
          render_edit(hospital_unit)
        end
      end

      def destroy
        hospital_unit = find_and_authorize_hospital_unit
        hospital_unit.destroy!
        redirect_to hospitals_units_path, notice: success_msg_for("hospital unit")
      end

      private

      def render_new(hospital_unit)
        render :new, locals: { hospital_unit: hospital_unit }
      end

      def render_edit(hospital_unit)
        render :edit, locals: { hospital_unit: hospital_unit }
      end

      def find_and_authorize_hospital_unit
        hospital_unit = Unit.find(params[:id])
        authorize hospital_unit
        hospital_unit
      end

      def hospital_unit_params
        params.require(:hospitals_unit).permit(
          :name, :unit_code, :renal_registry_code, :unit_type, :hospital_centre_id, :is_hd_site
        )
      end
    end
  end
end

Version data entries

78 entries across 78 versions & 1 rubygems

Version Path
renalware-core-2.0.100 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.99 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.98 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.97 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.96 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.95 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.94 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.93 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.92 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.91 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.90 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.89 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.88 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.87 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.86 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.85 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.84 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.83 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.82 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.81 app/controllers/renalware/hospitals/units_controller.rb