-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathprogrammes_controller.rb
More file actions
57 lines (44 loc) · 1.27 KB
/
programmes_controller.rb
File metadata and controls
57 lines (44 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true
require "pagy/extras/array"
class ProgrammesController < ApplicationController
include Pagy::Backend
include SearchFormConcern
before_action :set_programme, except: :index
before_action :set_search_form, only: :patients
layout "full"
def index
@programmes = policy_scope(Programme).includes(:active_vaccines)
end
def show
patients = policy_scope(Patient).in_programmes([@programme])
@consents =
policy_scope(Consent).where(patient: patients, programme: @programme)
end
def sessions
@sessions =
policy_scope(Session)
.has_programme(@programme)
.for_current_academic_year
.includes(:location, :session_dates)
.order("locations.name")
end
def patients
scope =
policy_scope(Patient).includes(:vaccination_statuses).in_programmes(
[@programme]
)
patients = @form.apply(scope, programme: @programme)
@pagy, @patients = pagy(patients)
end
def consent_form
send_file(
"public/consent_forms/#{@programme.type}.pdf",
filename: "#{@programme.name} Consent Form.pdf",
disposition: "attachment"
)
end
private
def set_programme
@programme = authorize policy_scope(Programme).find_by!(type: params[:type])
end
end