Skip to content

Commit c95734a

Browse files
committed
Add academic year to programme controllers
This updates all the programme routes and controllers to include the academic year allowing for the pages to be filtered according to the academic year. This has no change to the current design as we will only show the current academic year (as we do currently) but in the future it allows us to show multiple academic years.
1 parent 344b285 commit c95734a

32 files changed

Lines changed: 150 additions & 95 deletions

app/components/app_programme_navigation_component.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# frozen_string_literal: true
22

33
class AppProgrammeNavigationComponent < ViewComponent::Base
4-
def initialize(programme, active:)
4+
def initialize(programme, academic_year, active:)
55
super
66

77
@programme = programme
8+
@academic_year = academic_year
89
@active = active
910
end
1011

@@ -14,7 +15,8 @@ def call
1415
action = section == :overview ? :show : :index
1516

1617
nav.with_item(
17-
href: public_send("programme_#{section}_path", programme),
18+
href:
19+
public_send("programme_#{section}_path", programme, academic_year),
1820
text: I18n.t("title", scope: [:programmes, section, action]),
1921
selected: active == section
2022
)
@@ -24,7 +26,7 @@ def call
2426

2527
private
2628

27-
attr_reader :programme, :active
29+
attr_reader :programme, :active, :academic_year
2830

2931
SECTIONS = %i[overview cohorts sessions patients vaccinations].freeze
3032
end

app/components/app_programme_stats_component.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<div class="nhsuk-grid-row nhsuk-card-group">
22
<div class="nhsuk-grid-column-one-third nhsuk-card-group__item">
3-
<%= render AppCardComponent.new(link_to: programme_cohorts_path(@programme), colour: "reversed", data: true) do |card| %>
3+
<%= render AppCardComponent.new(link_to: programme_cohorts_path(programme, academic_year), colour: "reversed", data: true) do |card| %>
44
<% card.with_heading { "Children" } %>
55
<% card.with_description { patients_count.to_s } %>
66
<% end %>
77
</div>
88

99
<div class="nhsuk-grid-column-one-third nhsuk-card-group__item">
10-
<%= render AppCardComponent.new(link_to: programme_vaccinations_path(@programme), colour: "reversed", data: true) do |card| %>
10+
<%= render AppCardComponent.new(link_to: programme_vaccinations_path(programme, academic_year), colour: "reversed", data: true) do |card| %>
1111
<% card.with_heading { "Vaccinations" } %>
1212
<% card.with_description { vaccinations_count.to_s } %>
1313
<% end %>
Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,38 @@
11
# frozen_string_literal: true
22

33
class AppProgrammeStatsComponent < ViewComponent::Base
4-
def initialize(programme:)
4+
def initialize(programme, academic_year:)
55
super
6+
67
@programme = programme
8+
@academic_year = academic_year
79
end
810

911
def patients_count
10-
helpers.policy_scope(Patient).in_programmes([@programme]).count
12+
helpers
13+
.policy_scope(Patient)
14+
.in_programmes([@programme], academic_year:)
15+
.count
1116
end
1217

1318
def vaccinations_count
14-
helpers.policy_scope(VaccinationRecord).where(programme: @programme).count
19+
helpers
20+
.policy_scope(VaccinationRecord)
21+
.where(programme:, performed_at: academic_year_date_range)
22+
.count
1523
end
1624

1725
def consent_notifications_count
18-
helpers.policy_scope(ConsentNotification).has_programme(@programme).count
26+
helpers
27+
.policy_scope(ConsentNotification)
28+
.has_programme(programme)
29+
.where(sent_at: academic_year_date_range)
30+
.count
1931
end
32+
33+
private
34+
35+
attr_reader :programme, :academic_year
36+
37+
def academic_year_date_range = academic_year.to_academic_year_date_range
2038
end

app/controllers/programmes/base_controller.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
class Programmes::BaseController < ApplicationController
44
before_action :set_programme
5+
before_action :set_academic_year
56

67
layout "full"
78

@@ -10,4 +11,12 @@ class Programmes::BaseController < ApplicationController
1011
def set_programme
1112
@programme = policy_scope(Programme).find_by!(type: params[:programme_type])
1213
end
14+
15+
def set_academic_year
16+
@academic_year = params[:academic_year].to_i
17+
18+
if @academic_year.nil? || @academic_year < 2000 || @academic_year > 2100
19+
raise ActiveRecord::RecordNotFound
20+
end
21+
end
1322
end

app/controllers/programmes/cohorts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def index
88
policy_scope(Location::ProgrammeYearGroup)
99
.where(programme: @programme)
1010
.pluck_year_groups
11-
.map(&:to_birth_academic_year)
11+
.map { it.to_birth_academic_year(academic_year: @academic_year) }
1212

1313
@patient_count_by_birth_academic_year =
1414
patients_in_organisation

app/controllers/programmes/overview_controller.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22

33
class Programmes::OverviewController < Programmes::BaseController
44
def show
5-
patients = policy_scope(Patient).in_programmes([@programme])
5+
patients =
6+
policy_scope(Patient).in_programmes(
7+
[@programme],
8+
academic_year: @academic_year
9+
)
610

711
@consents =
8-
policy_scope(Consent).where(patient: patients, programme: @programme)
12+
policy_scope(Consent).where(
13+
patient: patients,
14+
programme: @programme,
15+
submitted_at: @academic_year.to_academic_year_date_range
16+
)
917
end
1018
end

app/controllers/programmes/patients_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def index
1414

1515
scope =
1616
policy_scope(Patient).includes(:vaccination_statuses).in_programmes(
17-
[@programme]
17+
[@programme],
18+
academic_year: @academic_year
1819
)
1920

2021
@form.programme_types = [@programme.type]

app/controllers/programmes/reports_controller.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ def create
66
VaccinationReport.new(request_session: session, current_user:)
77

88
vaccination_report.reset!
9-
vaccination_report.update!(programme: @programme)
9+
vaccination_report.update!(
10+
programme: @programme,
11+
academic_year: @academic_year
12+
)
1013

1114
redirect_to vaccination_report_path(Wicked::FIRST_STEP)
1215
end

app/controllers/programmes/sessions_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def index
55
@sessions =
66
policy_scope(Session)
77
.has_programme(@programme)
8-
.for_current_academic_year
8+
.for_academic_year(@academic_year)
99
.includes(:location, :session_dates)
1010
.order("locations.name")
1111
end

app/controllers/programmes/vaccinations_controller.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ class Programmes::VaccinationsController < Programmes::BaseController
66
def index
77
scope =
88
policy_scope(VaccinationRecord)
9-
.where(programme: @programme)
9+
.where(
10+
programme: @programme,
11+
performed_at: @academic_year.to_academic_year_date_range
12+
)
1013
.includes(:patient, :programme)
1114
.order(:performed_at)
1215

0 commit comments

Comments
 (0)