Class: Renalware::Research::StudyParticipantsController

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

Instance Method Summary collapse

Methods inherited from BaseController

#patient

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/renalware/research/study_participants_controller.rb', line 22

def create
  participant = study.participants.build(participant_params)
  participant.joined_on ||= Time.zone.today
  authorize participant

  if participant.save
    redirect_to(
      research_study_participants_path(study),
      notice: success_msg_for("participant")
    )
  else
    render_new(participant)
  end
end

#destroyObject



43
44
45
46
47
48
# File 'app/controllers/renalware/research/study_participants_controller.rb', line 43

def destroy
  participant = find_and_authorise_participant
  participant.destroy
  redirect_to research_study_participants_path(study),
              notice: "#{participant.patient} removed from the study"
end

#editObject



50
51
52
# File 'app/controllers/renalware/research/study_participants_controller.rb', line 50

def edit
  render_edit(find_and_authorise_participant)
end

#indexObject



10
11
12
13
14
15
# File 'app/controllers/renalware/research/study_participants_controller.rb', line 10

def index
  authorize StudyParticipant, :index?
  query = StudyParticipantsQuery.new(study: study, options: params[:q])
  participants = query.call.page(page).per(per_page)
  render locals: { study: study, participants: participants, query: query.search }
end

#newObject



37
38
39
40
41
# File 'app/controllers/renalware/research/study_participants_controller.rb', line 37

def new
  participant = study.participants.new(joined_on: Time.zone.today)
  authorize participant
  render_new(participant)
end

#showObject



17
18
19
20
# File 'app/controllers/renalware/research/study_participants_controller.rb', line 17

def show
  authorize StudyParticipant, :show?
  redirect_to research_study_participants_path(study)
end

#updateObject

Don’t update the participant id here (the patient) as that is immutable at this point.



55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/renalware/research/study_participants_controller.rb', line 55

def update
  participant = find_and_authorise_participant
  if participant.update(participant_params_for_update)
    redirect_to(
      research_study_participants_path(study),
      notice: success_msg_for("participant")
    )
  else
    render_edit(participant)
  end
end