Skip to content

Commit d361221

Browse files
authored
Merge pull request #3983 from nhsuk/refactor-programme-controllers
Refactor programme controllers
2 parents 59fd87e + dce0624 commit d361221

29 files changed

Lines changed: 180 additions & 184 deletions

app/components/app_patient_vaccination_table_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<% row.with_cell do %>
1818
<span class="nhsuk-table-responsive__heading">Vaccination date</span>
1919
<%= link_to vaccination_record.performed_at.to_date.to_fs(:long),
20-
programme_vaccination_record_path(vaccination_record.programme, vaccination_record) %>
20+
vaccination_record_path(vaccination_record) %>
2121
<% end %>
2222

2323
<% row.with_cell do %>

app/components/app_programme_navigation_component.rb

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,21 @@ def initialize(programme, active:)
1010

1111
def call
1212
render AppSecondaryNavigationComponent.new do |nav|
13-
nav.with_item(
14-
href: programme_path(programme),
15-
text: "Overview",
16-
selected: active == :overview
17-
)
18-
19-
nav.with_item(
20-
href: programme_cohorts_path(programme),
21-
text: I18n.t("cohorts.index.title"),
22-
selected: active == :cohorts
23-
)
24-
25-
nav.with_item(
26-
href: sessions_programme_path(programme),
27-
text: I18n.t("sessions.index.title"),
28-
selected: active == :sessions
29-
)
30-
31-
nav.with_item(
32-
href: patients_programme_path(programme),
33-
text: I18n.t("patients.index.title"),
34-
selected: active == :patients
35-
)
36-
37-
nav.with_item(
38-
href: programme_vaccination_records_path(programme),
39-
text: I18n.t("vaccination_records.index.title"),
40-
selected: active == :vaccination_records
41-
)
13+
SECTIONS.each do |section|
14+
action = section == :overview ? :show : :index
15+
16+
nav.with_item(
17+
href: public_send("programme_#{section}_path", programme),
18+
text: I18n.t("title", scope: [:programmes, section, action]),
19+
selected: active == section
20+
)
21+
end
4222
end
4323
end
4424

4525
private
4626

4727
attr_reader :programme, :active
28+
29+
SECTIONS = %i[overview cohorts sessions patients vaccinations].freeze
4830
end

app/components/app_programme_stats_component.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</div>
88

99
<div class="nhsuk-grid-column-one-third nhsuk-card-group__item">
10-
<%= render AppCardComponent.new(link_to: programme_vaccination_records_path(@programme), colour: "reversed", data: true) do |card| %>
10+
<%= render AppCardComponent.new(link_to: programme_vaccinations_path(@programme), colour: "reversed", data: true) do |card| %>
1111
<% card.with_heading { "Vaccinations" } %>
1212
<% card.with_description { vaccinations_count.to_s } %>
1313
<% end %>
@@ -19,4 +19,4 @@
1919
<% card.with_description { consent_notifications_count.to_s } %>
2020
<% end %>
2121
</div>
22-
</div>
22+
</div>

app/components/app_vaccination_record_table_component.html.erb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
<span class="nhsuk-table-responsive__heading">Full name</span>
1919

2020
<% if can_link_to?(vaccination_record) %>
21-
<%= link_to vaccination_record.patient.full_name,
22-
programme_vaccination_record_path(vaccination_record.programme, vaccination_record) %>
21+
<%= link_to vaccination_record.patient.full_name, vaccination_record_path(vaccination_record) %>
2322
<% else %>
2423
<%= vaccination_record.patient.full_name %>
2524
<% end %>

app/controllers/draft_vaccination_records_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def finish_wizard_path
143143
return_to: "record"
144144
)
145145
else
146-
programme_vaccination_record_path(@programme, @vaccination_record)
146+
vaccination_record_path(@vaccination_record)
147147
end
148148
end
149149

@@ -231,7 +231,7 @@ def set_back_link_path
231231
@back_link_path =
232232
if @draft_vaccination_record.editing?
233233
if current_step == :confirm
234-
programme_vaccination_record_path(@programme, @vaccination_record)
234+
vaccination_record_path(@vaccination_record)
235235
else
236236
wizard_path("confirm")
237237
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
class Programmes::BaseController < ApplicationController
4+
before_action :set_programme
5+
6+
layout "full"
7+
8+
private
9+
10+
def set_programme
11+
@programme = policy_scope(Programme).find_by!(type: params[:programme_type])
12+
end
13+
end

app/controllers/cohorts_controller.rb renamed to app/controllers/programmes/cohorts_controller.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
# frozen_string_literal: true
22

3-
class CohortsController < ApplicationController
3+
class Programmes::CohortsController < Programmes::BaseController
44
include Pagy::Backend
55

6-
before_action :set_programme
7-
8-
layout "full"
9-
106
def index
117
birth_academic_years = @programme.birth_academic_years
128

@@ -35,10 +31,6 @@ def show
3531

3632
private
3733

38-
def set_programme
39-
@programme = policy_scope(Programme).find_by!(type: params[:programme_type])
40-
end
41-
4234
def patients_in_organisation
4335
current_user.selected_organisation.patients
4436
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
class Programmes::OverviewController < Programmes::BaseController
4+
def show
5+
patients = policy_scope(Patient).in_programmes([@programme])
6+
7+
@consents =
8+
policy_scope(Consent).where(patient: patients, programme: @programme)
9+
end
10+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
class Programmes::PatientsController < Programmes::BaseController
4+
include Pagy::Backend
5+
include SearchFormConcern
6+
7+
before_action :set_search_form
8+
9+
def index
10+
scope =
11+
policy_scope(Patient).includes(:vaccination_statuses).in_programmes(
12+
[@programme]
13+
)
14+
15+
@form.programme_types = [@programme.type]
16+
17+
patients = @form.apply(scope)
18+
@pagy, @patients = pagy(patients)
19+
end
20+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
class Programmes::ReportsController < Programmes::BaseController
4+
def create
5+
vaccination_report =
6+
VaccinationReport.new(request_session: session, current_user:)
7+
8+
vaccination_report.reset!
9+
vaccination_report.update!(programme: @programme)
10+
11+
redirect_to vaccination_report_path(Wicked::FIRST_STEP)
12+
end
13+
end

0 commit comments

Comments
 (0)