Class: Renalware::PD::RegimesController

Inherits:
BaseController show all
Defined in:
app/controllers/renalware/pd/regimes_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#patient

Instance Method Details

#createObject

rubocop:disable Metrics/AbcSize



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/renalware/pd/regimes_controller.rb', line 20

def create
  result = CreateRegime.new(patient: patient)
                       .call(by: current_user, params: pd_regime_params)

  if result.success?
    redirect_to patient_pd_dashboard_path(patient), notice: success_msg_for("PD regime")
  else
    flash.now[:error] = failed_msg_for("PD Regime")
    render :new, locals: {
      regime: result.object,
      patient: patient
    }
  end
end

#editObject

rubocop:enable Metrics/AbcSize



36
37
38
39
40
41
# File 'app/controllers/renalware/pd/regimes_controller.rb', line 36

def edit
  render :edit, locals: {
    regime: pd_regime,
    patient: patient
  }
end

#newObject



10
11
12
13
14
15
16
17
# File 'app/controllers/renalware/pd/regimes_controller.rb', line 10

def new
  regime = cloned_last_known_regime_of_type || patient.pd_regimes.new(type: regime_type)

  render :new, locals: {
    regime: regime,
    patient: patient
  }
end

#showObject

rubocop:enable Metrics/AbcSize



60
61
62
63
64
65
# File 'app/controllers/renalware/pd/regimes_controller.rb', line 60

def show
  render :show, locals: {
    regime: pd_regime,
    patient: patient
  }
end

#updateObject

rubocop:disable Metrics/AbcSize



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/renalware/pd/regimes_controller.rb', line 44

def update
  result = ReviseRegime.new(pd_regime).call(by: current_user, params: pd_regime_params)

  if result.success?
    redirect_to patient_pd_dashboard_path(patient),
      notice: t(".success", model_name: "PD regime")
  else
    flash.now[:error] = t(".failed", model_name: "PD regime")
    render :edit, locals: {
      regime: result.object,
      patient: patient
    }
  end
end