Sha256: e964ad6950f18d0d19a1ff773c56cc2849e6ae063abd4682f938157ac3224978

Contents?: true

Size: 1.29 KB

Versions: 117

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/patients"

module Renalware
  module Patients
    class AlertsController < BaseController
      # GET html
      def new
        alert = Alert.new
        authorize alert
        render_form(alert)
      end

      # POST js
      def create
        alert = Alert.new(alert_params.merge!(by: user, patient: patient))
        authorize alert
        if alert.save
          render locals: { patient: patient, alert: alert }
        else
          render_form(alert, status: 422)
        end
      end

      # POST js
      # Idempotent
      def destroy
        alert = find_alert
        if alert.present?
          authorize alert
          alert.destroy
          render locals: { alert: alert }
        else
          skip_authorization
          head :ok
        end
      end

      private

      def find_alert
        Alert.find_by(id: params[:id])
      end

      def render_form(alert, status: 200)
        render :new,
               locals: { patient: patient, alert: alert },
               layout: false,
               status: status
      end

      def user
        @user ||= Renalware::Patients.cast_user(current_user)
      end

      def alert_params
        params.require(:patients_alert).permit(:notes, :urgent)
      end
    end
  end
end

Version data entries

117 entries across 117 versions & 1 rubygems

Version Path
renalware-core-2.0.142 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.141 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.140 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.139 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.138 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.137 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.136 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.135 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.134 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.133 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.132 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.131 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.130 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.129 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.128 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.127 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.126 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.125 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.124 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.123 app/controllers/renalware/patients/alerts_controller.rb