Sha256: c96c4ad5bb83e229973c9eb6f3cc2411f06f8f4e44bec74709b3b16a2d7429fa

Contents?: true

Size: 1.26 KB

Versions: 27

Compression:

Stored size: 1.26 KB

Contents

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

27 entries across 27 versions & 1 rubygems

Version Path
renalware-core-2.0.16 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.15 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.14 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.13 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.12 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.11 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.9 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.8 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.7 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.5 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.4 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.3 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.2 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.1 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.0 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.0.pre.rc13 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.0.pre.rc11 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.0.pre.rc10 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.0.pre.rc9 app/controllers/renalware/patients/alerts_controller.rb
renalware-core-2.0.0.pre.rc8 app/controllers/renalware/patients/alerts_controller.rb