Sha256: 1767ba12657a90920f012620aa7b475d3d8254c8ded639ef0171363ea0933be3

Contents?: true

Size: 1.99 KB

Versions: 64

Compression:

Stored size: 1.99 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.includes(:hospital_centre).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

64 entries across 64 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.1.0 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.167 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.166 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.165 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.164 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.163 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.162 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.161 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.160 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.159 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.158 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.157 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.156 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.155 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.153 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.152 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.151 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.149 app/controllers/renalware/hospitals/units_controller.rb
renalware-core-2.0.148 app/controllers/renalware/hospitals/units_controller.rb