Class: Renalware::Problems::ProblemsController

Inherits:
BaseController show all
Defined in:
app/controllers/renalware/problems/problems_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#patient

Instance Method Details

#createObject



56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/renalware/problems/problems_controller.rb', line 56

def create
  problem = patient.problems.new(problem_params)
  authorize problem

  if problem.save
    redirect_to patient_problems_url(patient), notice: success_msg_for("problem")
  else
    flash.now[:error] = failed_msg_for("problem")
    render :new, locals: { patient: patient, problem: problem }
  end
end

#destroyObject



68
69
70
71
72
73
74
75
# File 'app/controllers/renalware/problems/problems_controller.rb', line 68

def destroy
  problem = find_problem
  authorize problem
  problem.by = current_user
  problem.save!
  problem.destroy
  redirect_to patient_problems_path(patient), notice: success_msg_for("problem")
end

#editObject



27
28
29
30
31
32
33
34
# File 'app/controllers/renalware/problems/problems_controller.rb', line 27

def edit
  problem = find_problem
  authorize problem
  render locals: {
    patient: patient,
    problem: problem
  }
end

#indexObject



6
7
8
9
10
11
12
13
14
# File 'app/controllers/renalware/problems/problems_controller.rb', line 6

def index
  problems = patient.problems
  authorize problems
  render locals: {
    patient: patient,
    current_problems: problems.current.with_created_by.ordered,
    archived_problems: problems.archived.with_created_by.ordered
  }
end

#newObject



50
51
52
53
54
# File 'app/controllers/renalware/problems/problems_controller.rb', line 50

def new
  problem = patient.problems.build
  authorize problem
  render locals: { patient: patient, problem: problem }
end

#showObject



16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/renalware/problems/problems_controller.rb', line 16

def show
  problem = patient.problems.with_archived.find(params[:id])
  notes = problem.notes.with_updated_by.ordered
  authorize problem
  render locals: {
    patient: patient,
    problem: problem,
    notes: notes
  }
end

#sortObject



77
78
79
80
81
82
# File 'app/controllers/renalware/problems/problems_controller.rb', line 77

def sort
  authorize Problem, :sort?
  ids = params[:problems_problem]
  Problem.sort(ids)
  render json: ids
end

#updateObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/renalware/problems/problems_controller.rb', line 36

def update
  authorize(problem = find_problem)

  if update_problem(problem)
    redirect_to patient_problem_path(patient, problem), notice: success_msg_for("problem")
  else
    flash.now[:error] = failed_msg_for("problem")
    render :edit, locals: {
      patient: patient,
      problem: problem
    }
  end
end