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



20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/renalware/research/study_participants_controller.rb', line 20

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

  if participant.save
    render locals: { study: study, participants: participants }
  else
    render_new(participant)
  end
end

#destroyObject



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

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



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

def edit
  render_edit(find_and_authorise_participant)
end

#indexObject



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

def index
  authorize StudyParticipant, :index?
  render locals: { study: study, participants: participants }
end

#newObject



32
33
34
35
36
# File 'app/controllers/renalware/research/study_participants_controller.rb', line 32

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

#showObject



15
16
17
18
# File 'app/controllers/renalware/research/study_participants_controller.rb', line 15

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.



50
51
52
53
54
55
56
57
# File 'app/controllers/renalware/research/study_participants_controller.rb', line 50

def update
  participant = find_and_authorise_participant
  if participant.update(participant_params_for_update)
    render locals: { study: study, participants: participants }
  else
    render_edit(participant)
  end
end