1
1
# frozen_string_literal: true
2
2
3
3
describe "Import child records" do
4
- scenario "PDS lookup extravaganza" do
5
- skip "Feature is completely disabled temporarily"
4
+ let ( :today ) { Time . zone . local ( 2025 , 9 , 1 , 12 , 0 , 0 ) }
6
5
6
+ around { |example | travel_to ( today ) { example . run } }
7
+
8
+ scenario "PDS lookup extravaganza with multiple patient scenarios" do
7
9
given_i_am_signed_in
8
10
and_an_hpv_programme_is_underway
9
11
and_an_existing_patient_record_exists
10
12
and_pds_lookup_during_import_is_enabled
11
13
12
14
when_i_visit_the_import_page
13
- and_i_upload_the_pds_extravaganza_import_file
15
+ and_i_upload_import_file ( "pds_extravaganza.csv" )
14
16
then_i_should_see_the_import_page
15
- and_i_should_see_the_existing_patient_as_imported
16
-
17
- when_i_click_on_the_invalidated_patient
18
- then_i_should_see_invalidated_patient_record
17
+ and_i_should_see_one_new_patient_created
18
+
19
+ # Case 1: Patient with existing NHS number (Albert) - nothing should happen
20
+ and_i_see_the_patient_uploaded_with_nhs_number
21
+
22
+ # Case 2: Existing patient without NHS number (Betty) - should not show duplicate review
23
+ and_i_do_not_see_an_import_review_for_the_first_patient_uploaded_without_nhs_number
24
+ when_i_click_on_the_patient_without_review
25
+ then_i_see_the_new_patient_has_an_nhs_number
26
+
27
+ # Case 3: Existing patient with NHS number (Catherine) - should show duplicate review
28
+ when_i_go_back_to_the_import_page
29
+ then_i_see_an_import_review_for_the_second_patient_uploaded_without_nhs_number
30
+ when_i_click_review
31
+ then_i_see_both_records_have_an_nhs_number
32
+ when_i_use_duplicate_record_during_merge
33
+ then_the_existing_patient_has_an_nhs_number_in_mavis
34
+
35
+ # Case 4: New patient without NHS number (Charlie) - should be created with NHS number from PDS
36
+ when_i_go_back_to_the_import_page
37
+ when_i_click_on_new_patient_uploaded_without_an_nhs_number
38
+ then_i_see_the_new_patient_now_has_an_nhs_number
19
39
end
20
40
21
41
def given_i_am_signed_in
@@ -38,7 +58,7 @@ def and_an_hpv_programme_is_underway
38
58
end
39
59
40
60
def and_an_existing_patient_record_exists
41
- @existing_patient =
61
+ @existing_patient_uploaded_with_nhs_number =
42
62
create (
43
63
:patient ,
44
64
given_name : "Albert" ,
@@ -50,40 +70,72 @@ def and_an_existing_patient_record_exists
50
70
address_line_2 : "" ,
51
71
address_town : "London" ,
52
72
address_postcode : "SW11 1EH" ,
53
- school : nil , # Unknown school, should be silently updated
73
+ school : nil ,
54
74
session : @session
55
75
)
56
- @invalidated_patient =
76
+
77
+ # Betty - will match exactly except NHS number (no review needed)
78
+ @existing_patient_uploaded_without_nhs_number =
57
79
create (
58
80
:patient ,
59
81
given_name : "Betty" ,
60
82
family_name : "Samson" ,
61
- nhs_number : "9993524689" ,
83
+ nhs_number : nil ,
62
84
date_of_birth : Date . new ( 2010 , 1 , 1 ) ,
63
85
gender_code : :female ,
64
- address_line_1 : "10 Downing Street" ,
86
+ address_line_1 : "123 High Street" ,
65
87
address_line_2 : "" ,
66
88
address_town : "London" ,
67
- address_postcode : "SW11 1AA" ,
68
- school : nil , # Unknown school, should be silently updated
89
+ address_postcode : "SW1A 1AA" ,
90
+ school : nil ,
91
+ session : @session
92
+ )
93
+
94
+ # Catherine - will have different address, causing review
95
+ @existing_patient_duplicate_review =
96
+ create (
97
+ :patient ,
98
+ given_name : "Catherine" ,
99
+ family_name : "Williams" ,
100
+ nhs_number : "9876543210" ,
101
+ date_of_birth : Date . new ( 2010 , 5 , 15 ) ,
102
+ gender_code : :female ,
103
+ address_line_1 : "999 Old Street" , # Different from CSV
104
+ address_line_2 : "" ,
105
+ address_town : "Birmingham" , # Different from CSV
106
+ address_postcode : "B1 1AA" , # Different from CSV
107
+ school : nil ,
69
108
session : @session
70
109
)
110
+
111
+ expect ( Patient . count ) . to eq ( 3 )
71
112
end
72
113
73
114
def and_pds_lookup_during_import_is_enabled
74
115
Flipper . enable ( :pds_lookup_during_import )
75
116
76
- stub_pds_get_nhs_number_to_return_a_patient ( @existing_patient . nhs_number )
117
+ stub_pds_search_to_return_a_patient (
118
+ "9449306168" ,
119
+ "family" => "Samson" ,
120
+ "given" => "Betty" ,
121
+ "birthdate" => "eq2010-01-01" ,
122
+ "address-postalcode" => "SW1A 1AA"
123
+ )
77
124
78
- stub_pds_search_to_return_no_patients (
79
- "family" => @invalidated_patient . family_name ,
80
- "given" => @invalidated_patient . given_name ,
81
- "birthdate" => "eq#{ @invalidated_patient . date_of_birth } " ,
82
- "address-postalcode" => @invalidated_patient . address_postcode
125
+ stub_pds_search_to_return_a_patient (
126
+ "9876543210" ,
127
+ "family" => "Williams" ,
128
+ "given" => "Catherine" ,
129
+ "birthdate" => "eq2009-05-15" ,
130
+ "address-postalcode" => "SW2 2BB"
83
131
)
84
132
85
- stub_pds_get_nhs_number_to_return_an_invalidated_patient (
86
- @invalidated_patient . nhs_number
133
+ stub_pds_search_to_return_a_patient (
134
+ "4491459835" ,
135
+ "family" => "Brown" ,
136
+ "given" => "Charlie" ,
137
+ "birthdate" => "eq2011-03-15" ,
138
+ "address-postalcode" => "SW2 2BB"
87
139
)
88
140
end
89
141
@@ -92,35 +144,82 @@ def when_i_visit_the_import_page
92
144
click_link "Import" , match : :first
93
145
end
94
146
95
- def and_i_upload_the_pds_extravaganza_import_file
147
+ def when_i_go_back_to_the_import_page
148
+ visit "/imports"
149
+ click_link "1 September 2025 at 12:00pm"
150
+ end
151
+
152
+ def when_i_click_review
153
+ click_link "Review"
154
+ end
155
+
156
+ def and_i_upload_import_file ( filename )
96
157
click_button "Import records"
97
158
choose "Child records"
98
159
click_button "Continue"
99
- attach_file (
100
- "cohort_import[csv]" ,
101
- "spec/fixtures/cohort_import/pds_extravaganza.csv"
102
- )
160
+ attach_file ( "cohort_import[csv]" , "spec/fixtures/cohort_import/#{ filename } " )
103
161
click_on "Continue"
104
162
end
105
163
164
+ def and_i_do_not_see_an_import_review_for_the_first_patient_uploaded_without_nhs_number
165
+ expect ( page ) . not_to have_content ( "Actions Review SAMSON, Betty" )
166
+ end
167
+
168
+ def when_i_click_on_the_patient_without_review
169
+ click_link "SAMSON, Betty"
170
+ end
171
+
172
+ def then_i_see_an_import_review_for_the_second_patient_uploaded_without_nhs_number
173
+ expect ( page ) . to have_content ( "Actions Review WILLIAMS, Catherine" )
174
+ end
175
+
176
+ def when_i_click_on_new_patient_uploaded_without_an_nhs_number
177
+ click_link "BROWN, Charlie"
178
+ end
179
+
180
+ def when_i_use_duplicate_record_during_merge
181
+ choose "Use duplicate record"
182
+ click_on "Resolve duplicate"
183
+ end
184
+
106
185
def then_i_should_see_the_import_page
107
186
expect ( page ) . to have_content ( "Imported on" )
108
187
expect ( page ) . to have_content ( "Imported byUSER, Test" )
109
188
end
110
189
111
- def and_i_should_see_the_existing_patient_as_imported
112
- expect ( page ) . not_to have_content ( "Actions Review TWEEDLE, Albert" )
190
+ def and_i_should_see_one_new_patient_created
191
+ perform_enqueued_jobs
192
+ expect ( Patient . count ) . to eq ( 4 )
113
193
end
114
194
115
- def when_i_click_on_the_invalidated_patient
116
- click_link "SAMSON, Betty"
195
+ def and_i_see_the_patient_uploaded_with_nhs_number
196
+ expect ( page ) . to have_content (
197
+ "Name and NHS number TWEEDLE, Albert 999 907 5320"
198
+ )
117
199
end
118
200
119
- def then_i_should_see_invalidated_patient_record
120
- expect ( page ) . to have_content ( "Record flagged as invalid " )
201
+ def then_i_see_the_new_patient_has_an_nhs_number
202
+ expect ( page ) . to have_content ( "944 930 6168 " )
121
203
expect ( page ) . to have_content ( "SAMSON, Betty" )
122
- expect ( page ) . to have_content ( "NHS number999 352 4689" )
123
- expect ( page ) . to have_content ( "Date of birth1 January 2010 (aged 15)" )
124
- expect ( page ) . to have_content ( "SW11 1AA" )
204
+ expect ( page ) . to have_content ( "1 January 2010 (aged 15)" )
205
+ end
206
+
207
+ def then_i_see_both_records_have_an_nhs_number
208
+ expect ( page ) . to have_text ( "987 654 3210" , count : 2 )
209
+ end
210
+
211
+ def then_i_see_the_new_patient_now_has_an_nhs_number
212
+ expect ( page ) . to have_content ( "NHS number449 145 9835" )
213
+ expect ( page ) . to have_content ( "Full nameBROWN, Charlie" )
214
+ expect ( page ) . to have_content ( "Date of birth15 March 2011 (aged 14)" )
215
+ end
216
+
217
+ def then_the_existing_patient_has_an_nhs_number_in_mavis
218
+ expect ( Patient . count ) . to eq ( 4 )
219
+ patient = Patient . where ( given_name : "Catherine" ) . first
220
+ expect ( patient . nhs_number ) . to eq ( "9876543210" )
221
+ expect ( patient . address_line_1 ) . to eq ( "456 New Street" )
222
+ expect ( patient . address_town ) . to eq ( "London" )
223
+ expect ( patient . address_postcode ) . to eq ( "SW2 2BB" )
125
224
end
126
225
end
0 commit comments