Skip to content

Commit 85a288b

Browse files
committed
Add filtering patients by date of birth
This makes it possible to filter patients by their date of birth when looking at the patients page for a particular programme.
1 parent 444050c commit 85a288b

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

app/components/app_session_patient_table_component.html.erb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
"data-turbo-permanent": "true" %>
2626
<% end %>
2727

28+
<% if @columns.include?(:dob) %>
29+
<%= f.govuk_text_field :dob, label: { text: "Date of birth" },
30+
hint: {
31+
text: "e.g. 2005 or 01/03/2014",
32+
class: "nhsuk-u-font-size-16",
33+
},
34+
value: params[:dob],
35+
"data-autosubmit-target": "field",
36+
"data-action": "autosubmit#submit",
37+
"data-turbo-permanent": "true" %>
38+
<% end %>
39+
2840
<% if @columns.include?(:year_group) %>
2941
<%= f.govuk_check_boxes_fieldset :year_groups, legend: { text: "Year group", size: "s" } do %>
3042
<% year_groups.each do |year_group| %>

app/controllers/concerns/patient_sorting_concern.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ def filter_patients!(patients_or_patient_sessions)
5252
end
5353
end
5454

55+
if (date_of_birth = params[:dob]).present?
56+
patients_or_patient_sessions.select! do
57+
value = _1.try(:date_of_birth) || _1.patient.date_of_birth
58+
value.to_fs(:uk_short).include?(date_of_birth)
59+
end
60+
end
61+
5562
if (year_groups = params[:year_groups]).present?
5663
patients_or_patient_sessions.select! do
5764
value = _1.try(:year_group) || _1.patient.year_group

spec/components/app_session_patient_table_component_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,11 @@ def have_column(text)
156156

157157
it { should have_column("Status") }
158158
end
159+
160+
context "includes date of birth" do
161+
let(:columns) { %i[name dob] }
162+
163+
it { should have_column("Date of birth") }
164+
end
159165
end
160166
end

spec/features/patient_sorting_filtering_spec.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@
5050
then_i_see_patients_ordered_by_name_desc
5151
end
5252

53+
scenario "Users can sort and filter date of birth" do
54+
given_that_i_am_signed_in
55+
when_i_visit_the_programme_patients_page
56+
then_i_see_patients_ordered_by_name_asc # Initial server load is name asc
57+
58+
when_i_click_on_the_dob_header
59+
then_i_see_patients_ordered_by_dob_asc
60+
61+
when_i_click_on_the_dob_header
62+
then_i_see_patients_ordered_by_dob_desc
63+
64+
when_i_filter_by_dob
65+
and_i_click_filter
66+
then_i_see_patients_with_dob
67+
end
68+
5369
def given_that_i_am_signed_in
5470
@programme = create(:programme, :hpv)
5571
@organisation =
@@ -83,6 +99,10 @@ def when_i_visit_the_consents_page
8399
visit session_consents_path(@session)
84100
end
85101

102+
def when_i_visit_the_programme_patients_page
103+
visit patients_programme_path(@programme)
104+
end
105+
86106
def when_i_click_on_the_name_header
87107
click_link "Full name"
88108
sleep 0.1
@@ -156,4 +176,27 @@ def when_i_reset_filters
156176
expect(page).to have_button "Reset filters", disabled: false
157177
click_button "Reset filters"
158178
end
179+
180+
def when_i_click_on_the_dob_header
181+
click_link "Date of birth"
182+
end
183+
184+
def then_i_see_patients_ordered_by_dob_asc
185+
expect(page).to have_selector("tr:nth-child(4)", text: "Alex")
186+
expect(page).to have_selector("tr:nth-child(3)", text: "Blair")
187+
end
188+
189+
def then_i_see_patients_ordered_by_dob_desc
190+
expect(page).to have_selector("tr:nth-child(1)", text: "Alex")
191+
expect(page).to have_selector("tr:nth-child(2)", text: "Blair")
192+
end
193+
194+
def when_i_filter_by_dob
195+
fill_in "Date of birth", with: "2011"
196+
end
197+
198+
def then_i_see_patients_with_dob
199+
expect(page).not_to have_selector("tr:nth-child(2)")
200+
expect(page).to have_selector("tr:nth-child(1)", text: "Alex")
201+
end
159202
end

0 commit comments

Comments
 (0)