Skip to content

Commit 4ef7752

Browse files
committed
Split VaccinationRecordsController
This splits the controller in to two separate controllers that serve different needs. Programmes::VaccinationsController will exist to render the vaccinations tab in the programme page, and the existing controller will render pages related to viewing and editing vaccination records.
1 parent 893b64f commit 4ef7752

12 files changed

Lines changed: 65 additions & 58 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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def call
3535
)
3636

3737
nav.with_item(
38-
href: programme_vaccination_records_path(programme),
39-
text: I18n.t("vaccination_records.index.title"),
40-
selected: active == :vaccination_records
38+
href: programme_vaccinations_path(programme),
39+
text: I18n.t("programmes.vaccinations.index.title"),
40+
selected: active == :vaccinations
4141
)
4242
end
4343
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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
class Programmes::VaccinationsController < ApplicationController
4+
include Pagy::Backend
5+
6+
before_action :set_programme
7+
8+
layout "full"
9+
10+
def index
11+
scope =
12+
policy_scope(VaccinationRecord)
13+
.where(programme: @programme)
14+
.includes(:patient, :programme)
15+
.order(:performed_at)
16+
17+
@pagy, @vaccination_records = pagy(scope)
18+
end
19+
20+
private
21+
22+
def set_programme
23+
@programme = policy_scope(Programme).find_by!(type: params[:programme_type])
24+
end
25+
end

app/controllers/vaccination_records_controller.rb

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
# frozen_string_literal: true
22

33
class VaccinationRecordsController < ApplicationController
4-
include Pagy::Backend
54
include VaccinationMailerConcern
65

7-
before_action :set_vaccination_record, except: :index
6+
before_action :set_vaccination_record
87
before_action :set_return_to, only: %i[confirm_destroy destroy]
98

10-
def index
11-
@pagy, @vaccination_records = pagy(vaccination_records)
12-
13-
render layout: "full"
14-
end
15-
169
def show
1710
end
1811

@@ -48,31 +41,21 @@ def destroy
4841

4942
private
5043

51-
def programme
52-
@programme ||=
53-
policy_scope(Programme).find_by!(type: params[:programme_type])
54-
end
55-
56-
def vaccination_records
57-
@vaccination_records ||=
58-
policy_scope(VaccinationRecord)
59-
.includes(
60-
:batch,
61-
:immunisation_imports,
62-
:location,
63-
:performed_by_user,
64-
:programme,
65-
patient: [:gp_practice, :school, { parent_relationships: :parent }],
66-
session: %i[session_dates],
67-
vaccine: :programme
68-
)
69-
.where(programme:)
70-
.order(:performed_at)
71-
end
72-
7344
def set_vaccination_record
74-
@vaccination_record = vaccination_records.find(params[:id])
45+
@vaccination_record =
46+
policy_scope(VaccinationRecord).includes(
47+
:batch,
48+
:immunisation_imports,
49+
:location,
50+
:performed_by_user,
51+
:programme,
52+
patient: [:gp_practice, :school, { parent_relationships: :parent }],
53+
session: %i[session_dates],
54+
vaccine: :programme
55+
).find(params[:id])
56+
7557
@patient = @vaccination_record.patient
58+
@programme = @vaccination_record.programme
7659
@session = @vaccination_record.session
7760
end
7861

app/views/vaccination_records/index.html.erb renamed to app/views/programmes/vaccinations/index.html.erb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<% content_for :page_title, "#{@programme.name} – #{t("vaccination_records.index.title")}" %>
1+
<% content_for :page_title, "#{@programme.name} – #{t(".title")}" %>
22

33
<% content_for :before_main do %>
44
<%= render AppBreadcrumbComponent.new(items: [
@@ -10,11 +10,10 @@
1010

1111
<h1 class="nhsuk-heading-l"><%= @programme.name %></h1>
1212

13-
<%= render AppProgrammeNavigationComponent.new(@programme, active: :vaccination_records) %>
13+
<%= render AppProgrammeNavigationComponent.new(@programme, active: :vaccinations) %>
1414

1515
<%= govuk_button_link_to "Import vaccination records", new_immunisation_import_path, secondary: true, class: "nhsuk-u-margin-bottom-0" %>
1616

1717
<%= render AppVaccinationRecordTableComponent.new(@vaccination_records, current_user:, count: @pagy.count) %>
1818

1919
<%= govuk_pagination(pagy: @pagy) %>
20-

app/views/vaccination_records/destroy.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<%= page_title %>
1212
<% end %>
1313

14-
<%= form_with url: programme_vaccination_record_path, method: :delete do |f| %>
14+
<%= form_with url: vaccination_record_path, method: :delete do |f| %>
1515
<%= f.hidden_field :return_to, value: @return_to %>
1616
<div class="app-button-group">
1717
<%= f.govuk_submit "Yes, delete this vaccination record", warning: true %>

app/views/vaccination_records/show.html.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<%= render AppBreadcrumbComponent.new(items: [
33
{ text: t("dashboard.index.title"), href: dashboard_path },
44
{ text: t("programmes.index.title"), href: programmes_path },
5-
{ text: @programme.name, href: programme_vaccination_records_path(@programme) },
6-
{ text: t("vaccination_records.index.title"), href: programme_vaccination_records_path(@programme) },
5+
{ text: @programme.name, href: programme_path(@programme) },
6+
{ text: t("programmes.vaccinations.index.title"), href: programme_vaccinations_path(@programme) },
77
]) %>
88
<% end %>
99

@@ -18,13 +18,13 @@
1818
<div class="app-button-group">
1919
<% if policy(@vaccination_record).edit? %>
2020
<%= govuk_button_to "Edit vaccination record",
21-
programme_vaccination_record_path(@programme, @vaccination_record),
21+
vaccination_record_path(@vaccination_record),
2222
method: :put, secondary: true %>
2323
<% end %>
2424

2525
<% if policy(@vaccination_record).destroy? %>
2626
<%= govuk_link_to "Delete vaccination record",
27-
destroy_programme_vaccination_record_path(@programme, @vaccination_record) %>
27+
destroy_vaccination_record_path(@vaccination_record) %>
2828
<% end %>
2929
</div>
3030
<% end %>

0 commit comments

Comments
 (0)