Class: Renalware::PD::RegimesController

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

Instance Method Summary collapse

Methods inherited from BaseController

#patient

Instance Method Details

#apd_regimesObject



24
25
26
# File 'app/controllers/renalware/pd/regimes_controller.rb', line 24

def apd_regimes
  @apd_regimes ||= APDRegime.for_patient(patient).with_bags.ordered.page(1).per(5)
end

#capd_regimesObject



20
21
22
# File 'app/controllers/renalware/pd/regimes_controller.rb', line 20

def capd_regimes
  @capd_regimes ||= CAPDRegime.for_patient(patient).with_bags.ordered.page(1).per(5)
end

#createObject

rubocop:disable Metrics/AbcSize



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/renalware/pd/regimes_controller.rb', line 38

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



54
55
56
57
58
59
# File 'app/controllers/renalware/pd/regimes_controller.rb', line 54

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

#indexObject



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

def index
  regimes = regime_type_class.for_patient(patient).with_bags.ordered.page(page).per(per_page)
  render locals: {
    patient: patient,
    regimes: regimes,
    pd_type_string: pd_type_string
  }
end

#newObject



28
29
30
31
32
33
34
35
# File 'app/controllers/renalware/pd/regimes_controller.rb', line 28

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



78
79
80
81
82
83
# File 'app/controllers/renalware/pd/regimes_controller.rb', line 78

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

#updateObject

rubocop:disable Metrics/AbcSize



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/renalware/pd/regimes_controller.rb', line 62

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