Class: Renalware::Medications::PrescriptionsController

Inherits:
BaseController show all
Includes:
PresenterHelper, PrescriptionsHelper
Defined in:
app/controllers/renalware/medications/prescriptions_controller.rb

Instance Method Summary collapse

Methods included from PresenterHelper

#present

Methods included from PrescriptionsHelper

#default_provider, #highlight_validation_fail, #medication_and_route, #new_patient_medications_prescription_termination_path, #new_patient_prescription_path, #patient_medications_prescription_termination_path, #patient_prescriptions_path, #validation_fail

Methods inherited from BaseController

#patient

Instance Method Details

#createObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/renalware/medications/prescriptions_controller.rb', line 29

def create
  @treatable = treatable_class.find(treatable_id)

  prescription = patient.prescriptions.new(
    prescription_params.merge(treatable: @treatable)
  )
  authorize prescription

  if prescription.save
    render_index
  else
    render_form(prescription, url: patient_prescriptions_path(patient, @treatable))
  end
end

#editObject



44
45
46
47
48
49
50
# File 'app/controllers/renalware/medications/prescriptions_controller.rb', line 44

def edit
  prescription = patient.prescriptions.find(params[:id])
  authorize prescription
  @treatable = prescription.treatable

  render_form(prescription, url: patient_prescription_path(patient, prescription))
end

#indexObject



12
13
14
15
16
17
18
19
20
# File 'app/controllers/renalware/medications/prescriptions_controller.rb', line 12

def index
  authorize Prescription, :index?
  @treatable = treatable_class.find(treatable_id)
  respond_to do |format|
    format.html { render_index }
    format.js { render_index }
    format.pdf { render_prescriptions_list_to_hand_to_patient }
  end
end

#newObject



22
23
24
25
26
27
# File 'app/controllers/renalware/medications/prescriptions_controller.rb', line 22

def new
  @treatable = treatable_class.find(treatable_id)
  prescription = build_new_prescription_for(@treatable)
  authorize prescription
  render_form(prescription, url: patient_prescriptions_path(patient, @treatable))
end

#updateObject



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/renalware/medications/prescriptions_controller.rb', line 52

def update
  prescription = patient.prescriptions.find(params[:id])
  authorize prescription
  @treatable = prescription.treatable

  updated = RevisePrescription.new(prescription).call(prescription_params)

  if updated
    render_index
  else
    render_form(prescription, url: patient_prescription_path(patient, prescription))
  end
end