Skip to content

Commit 4e4ed8a

Browse files
committed
Add Programmes::PatientsController
This encapsulates logic related to displaying the patients tab when viewing a programme to reduce the size of the existing ProgrammesController and make the code easier to maintain.
1 parent cad27fc commit 4e4ed8a

7 files changed

Lines changed: 37 additions & 25 deletions

File tree

app/components/app_programme_navigation_component.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def call
2929
)
3030

3131
nav.with_item(
32-
href: patients_programme_path(programme),
33-
text: I18n.t("patients.index.title"),
32+
href: programme_patients_path(programme),
33+
text: I18n.t("programmes.patients.index.title"),
3434
selected: active == :patients
3535
)
3636

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
class Programmes::PatientsController < ApplicationController
4+
include Pagy::Backend
5+
include SearchFormConcern
6+
7+
before_action :set_programme
8+
before_action :set_search_form
9+
10+
layout "full"
11+
12+
def index
13+
scope =
14+
policy_scope(Patient).includes(:vaccination_statuses).in_programmes(
15+
[@programme]
16+
)
17+
18+
@form.programme_types = [@programme.type]
19+
20+
patients = @form.apply(scope)
21+
@pagy, @patients = pagy(patients)
22+
end
23+
24+
private
25+
26+
def set_programme
27+
@programme = policy_scope(Programme).find_by!(type: params[:programme_type])
28+
end
29+
end

app/controllers/programmes_controller.rb

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

3-
require "pagy/extras/array"
4-
53
class ProgrammesController < ApplicationController
6-
include Pagy::Backend
7-
include SearchFormConcern
8-
94
before_action :set_programme, except: :index
10-
before_action :set_search_form, only: :patients
115

126
layout "full"
137

@@ -31,18 +25,6 @@ def sessions
3125
.order("locations.name")
3226
end
3327

34-
def patients
35-
scope =
36-
policy_scope(Patient).includes(:vaccination_statuses).in_programmes(
37-
[@programme]
38-
)
39-
40-
@form.programme_types = [@programme.type]
41-
42-
patients = @form.apply(scope)
43-
@pagy, @patients = pagy(patients)
44-
end
45-
4628
def consent_form
4729
send_file(
4830
"public/consent_forms/#{@programme.type}.pdf",

app/controllers/sessions/register_controller.rb

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

3-
require "pagy/extras/array"
4-
53
class Sessions::RegisterController < ApplicationController
64
include Pagy::Backend
75
include SearchFormConcern

app/views/programmes/patients.html.erb renamed to app/views/programmes/patients/index.html.erb

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

33
<% content_for :before_main do %>
44
<%= render AppBreadcrumbComponent.new(items: [
@@ -20,7 +20,7 @@
2020
<div class="app-grid-column-filters">
2121
<%= render AppSearchComponent.new(
2222
form: @form,
23-
url: patients_programme_path(@programme),
23+
url: programme_patients_path(@programme),
2424
programme_statuses: Patient::VaccinationStatus.statuses.keys,
2525
consent_statuses: Patient::ConsentStatus.statuses.keys,
2626
triage_statuses: %w[required delay_vaccination do_not_vaccinate safe_to_vaccinate],

config/locales/en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,9 @@ en:
586586
title: Cohorts
587587
index:
588588
title: Programmes
589+
patients:
590+
index:
591+
title: Children
589592
sessions:
590593
table_headings:
591594
completed: All sessions completed

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@
168168
resources :programmes, only: %i[index show], param: :type do
169169
member do
170170
get "sessions"
171-
get "patients"
172171

173172
get "consent-form", action: "consent_form"
174173
end
175174

176175
resources :cohorts, only: %i[index show], controller: "programmes/cohorts"
176+
resources :patients, only: :index, controller: "programmes/patients"
177177
resources :reports, only: :create, controller: "programmes/reports"
178178
resources :vaccinations, only: :index, controller: "programmes/vaccinations"
179179
end

0 commit comments

Comments
 (0)