Sha256: c87286f838913306c299aba0fcf6cead06afb7f5adbe86c8bcccbce9be876081

Contents?: true

Size: 1.46 KB

Versions: 6

Compression:

Stored size: 1.46 KB

Contents

require_dependency("renalware/renal")

module Renalware
  module Renal
    class AKIAlertsController < BaseController
      include Renalware::Concerns::Pageable

      def index
        query = search_form.query
        alerts = query.call.page(page).per(per_page)
        authorize alerts
        render locals: {
          alerts: alerts,
          form: search_form,
          search: query.search
        }
      end

      def edit
        authorize alert
        render_edit(alert)
      end

      def update
        authorize alert
        if alert.update_attributes(aki_alert_params.merge(by: current_user))
          redirect_to renal_aki_alerts_path
        else
          render_edit(alert)
        end
      end

      private

      def search_form
        @search_form ||= begin
          options = params.key?(:q) ? search_params : {}
          AKIAlertSearchForm.new(options)
        end
      end

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

      def alert
        @alert ||= AKIAlert.find(params[:id])
      end

      def aki_alert_params
        params
          .require(:renal_aki_alert)
          .permit(
            :notes, :action_id, :hotlist, :hospital_ward_id,
            :max_cre, :cre_date, :max_aki, :aki_date
          )
      end

      def search_params
        params
          .require(:q) {}
          .permit(:term, :on_hotlist, :action, :hospital_unit_id, :hospital_ward_id, :s)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
renalware-core-2.0.5 app/controllers/renalware/renal/aki_alerts_controller.rb
renalware-core-2.0.4 app/controllers/renalware/renal/aki_alerts_controller.rb
renalware-core-2.0.3 app/controllers/renalware/renal/aki_alerts_controller.rb
renalware-core-2.0.2 app/controllers/renalware/renal/aki_alerts_controller.rb
renalware-core-2.0.1 app/controllers/renalware/renal/aki_alerts_controller.rb
renalware-core-2.0.0 app/controllers/renalware/renal/aki_alerts_controller.rb