14
14
when_i_visit_the_import_page
15
15
and_i_upload_import_file ( "pds_extravaganza.csv" )
16
16
then_i_should_see_the_import_page
17
- and_i_should_see_one_new_patient_created
17
+ and_i_should_see_correct_patient_counts
18
18
19
19
# Case 1: Patient with existing NHS number (Albert) - nothing should happen
20
20
and_i_see_the_patient_uploaded_with_nhs_number
21
+ and_parents_are_created_for_albert
21
22
22
23
# Case 2: Existing patient without NHS number (Betty) - should not show duplicate review
23
24
and_i_do_not_see_an_import_review_for_the_first_patient_uploaded_without_nhs_number
24
25
when_i_click_on_the_patient_without_review
25
26
then_i_see_the_new_patient_has_an_nhs_number
27
+ and_betty_has_correct_parent_relationships
26
28
27
29
# Case 3: Existing patient with NHS number (Catherine) - should show duplicate review
28
30
when_i_go_back_to_the_import_page
29
31
then_i_see_an_import_review_for_the_second_patient_uploaded_without_nhs_number
30
32
when_i_click_review
31
33
then_i_see_both_records_have_an_nhs_number
34
+ and_i_see_address_differences_for_review
32
35
when_i_use_duplicate_record_during_merge
33
36
then_the_existing_patient_has_an_nhs_number_in_mavis
37
+ and_catherine_parents_are_handled_correctly
34
38
35
39
# Case 4: New patient without NHS number (Charlie) - should be created with NHS number from PDS
36
40
when_i_go_back_to_the_import_page
37
41
when_i_click_on_new_patient_uploaded_without_an_nhs_number
38
42
then_i_see_the_new_patient_now_has_an_nhs_number
43
+ and_charlie_has_no_parents_as_expected
44
+
45
+ # Case 5: Home educated patient (Emma) - test school move handling
46
+ when_i_go_back_to_the_import_page
47
+ when_i_click_on_home_educated_patient
48
+ then_i_see_home_educated_patient_details
49
+ and_emma_has_correct_parent_data
50
+
51
+ # Case 6: Patient with parent but no relationship specified (Oliver)
52
+ when_i_go_back_to_the_import_page
53
+ when_i_click_on_patient_with_unknown_relationship
54
+ then_i_see_patient_with_unknown_relationship_details
55
+ and_oliver_has_unknown_relationship_parent
56
+
57
+ then_school_moves_are_created_appropriately
58
+
59
+ and_all_parent_relationships_are_established
60
+ and_import_counts_are_correct
39
61
end
40
62
41
63
def given_i_am_signed_in
@@ -52,9 +74,12 @@ def given_i_am_signed_in
52
74
53
75
def and_an_hpv_programme_is_underway
54
76
@school = create ( :school , urn : "123456" , team : @team )
77
+ @clinic = create ( :generic_clinic , team : @team )
55
78
56
79
@session =
57
80
create ( :session , team : @team , location : @school , programmes : [ @programme ] )
81
+ @clinic_session =
82
+ create ( :session , team : @team , location : @clinic , programmes : [ @programme ] )
58
83
end
59
84
60
85
def and_an_existing_patient_record_exists
@@ -91,7 +116,16 @@ def and_an_existing_patient_record_exists
91
116
session : @session
92
117
)
93
118
94
- # Catherine - will have different address, causing review
119
+ @different_school = create ( :school , urn : "456789" , team : @team )
120
+ @different_school_session =
121
+ create (
122
+ :session ,
123
+ team : @team ,
124
+ location : @different_school ,
125
+ programmes : [ @programme ]
126
+ )
127
+
128
+ # Catherine - will have different address and school, causing review, and school move
95
129
@existing_patient_duplicate_review =
96
130
create (
97
131
:patient ,
@@ -104,11 +138,26 @@ def and_an_existing_patient_record_exists
104
138
address_line_2 : "" ,
105
139
address_town : "Birmingham" , # Different from CSV
106
140
address_postcode : "B1 1AA" , # Different from CSV
107
- school : nil ,
108
- session : @session
141
+ school : @different_school ,
142
+ session : @different_school_session
109
143
)
110
144
145
+ @existing_parent =
146
+ create (
147
+ :parent ,
148
+ full_name : "John Tweedle" ,
149
+ email : "john.tweedle@email.com"
150
+ )
151
+ create (
152
+ :parent_relationship ,
153
+ parent : @existing_parent ,
154
+ patient : @existing_patient_uploaded_with_nhs_number ,
155
+ type : "unknown"
156
+ )
157
+
111
158
expect ( Patient . count ) . to eq ( 3 )
159
+ expect ( ParentRelationship . count ) . to eq ( 1 )
160
+ expect ( Parent . count ) . to eq ( 1 )
112
161
end
113
162
114
163
def and_pds_lookup_during_import_is_enabled
@@ -137,6 +186,14 @@ def and_pds_lookup_during_import_is_enabled
137
186
"birthdate" => "eq2011-03-15" ,
138
187
"address-postalcode" => "SW2 2BB"
139
188
)
189
+
190
+ stub_pds_search_to_return_a_patient (
191
+ "9435783309" ,
192
+ "family" => "Homeschool" ,
193
+ "given" => "Emma" ,
194
+ "birthdate" => "eq2010-06-01" ,
195
+ "address-postalcode" => "SW3 3AA"
196
+ )
140
197
end
141
198
142
199
def when_i_visit_the_import_page
@@ -215,11 +272,187 @@ def then_i_see_the_new_patient_now_has_an_nhs_number
215
272
end
216
273
217
274
def then_the_existing_patient_has_an_nhs_number_in_mavis
218
- expect ( Patient . count ) . to eq ( 4 )
275
+ expect ( Patient . count ) . to eq ( 6 )
219
276
patient = Patient . where ( given_name : "Catherine" ) . first
220
277
expect ( patient . nhs_number ) . to eq ( "9876543210" )
221
278
expect ( patient . address_line_1 ) . to eq ( "456 New Street" )
222
279
expect ( patient . address_town ) . to eq ( "London" )
223
280
expect ( patient . address_postcode ) . to eq ( "SW2 2BB" )
224
281
end
282
+
283
+ def and_i_should_see_correct_patient_counts
284
+ perform_enqueued_jobs
285
+ expect ( Patient . count ) . to eq ( 6 )
286
+ end
287
+
288
+ def and_parents_are_created_for_albert
289
+ albert = Patient . find_by ( given_name : "Albert" , family_name : "Tweedle" )
290
+ expect ( albert . parents . count ) . to eq ( 2 )
291
+ expect ( albert . parents . map ( &:full_name ) ) . to contain_exactly (
292
+ "John Tweedle" ,
293
+ "Mary Tweedle"
294
+ )
295
+ expect ( albert . parents . find_by ( full_name : "John Tweedle" ) . email ) . to eq (
296
+ "john.tweedle@email.com"
297
+ )
298
+ end
299
+
300
+ def and_betty_has_correct_parent_relationships
301
+ betty = Patient . find_by ( given_name : "Betty" , family_name : "Samson" )
302
+ expect ( betty . parent_relationships . count ) . to eq ( 2 )
303
+
304
+ dad_relationship =
305
+ betty
306
+ . parent_relationships
307
+ . joins ( :parent )
308
+ . find_by ( parents : { full_name : "Robert Samson" } )
309
+ expect ( dad_relationship . type ) . to eq ( "father" )
310
+
311
+ mum_relationship =
312
+ betty
313
+ . parent_relationships
314
+ . joins ( :parent )
315
+ . find_by ( parents : { full_name : "Linda Samson" } )
316
+ expect ( mum_relationship . type ) . to eq ( "mother" )
317
+
318
+ linda = Parent . find_by ( full_name : "Linda Samson" )
319
+ expect ( linda . phone ) . to be_blank
320
+ expect ( linda . phone_receive_updates ) . to be false
321
+ end
322
+
323
+ def and_i_see_address_differences_for_review
324
+ expect ( page ) . to have_content ( "999 Old Street" ) # Original address
325
+ expect ( page ) . to have_content ( "456 New Street" ) # New address from CSV
326
+ expect ( page ) . to have_content ( "Birmingham" ) # Original town
327
+ expect ( page ) . to have_content ( "London" ) # New town from CSV
328
+ end
329
+
330
+ def and_catherine_parents_are_handled_correctly
331
+ catherine =
332
+ Patient . find_by ( given_name : "Catherine" , family_name : "Williams" )
333
+ expect ( catherine . parents . count ) . to eq ( 2 )
334
+
335
+ guardian = catherine . parents . find_by ( full_name : "David Williams" )
336
+ guardian_relationship =
337
+ catherine . parent_relationships . find_by ( parent : guardian )
338
+ expect ( guardian_relationship . type ) . to eq ( "guardian" )
339
+
340
+ mother = catherine . parents . find_by ( full_name : "Sarah Williams" )
341
+ expect ( mother . phone ) . to be_present
342
+ end
343
+
344
+ def and_charlie_has_no_parents_as_expected
345
+ charlie = Patient . find_by ( given_name : "Charlie" , family_name : "Brown" )
346
+ expect ( charlie . parents . count ) . to eq ( 0 )
347
+ expect ( charlie . parent_relationships . count ) . to eq ( 0 )
348
+ end
349
+
350
+ def when_i_click_on_home_educated_patient
351
+ click_link "HOMESCHOOL, Emma"
352
+ end
353
+
354
+ def then_i_see_home_educated_patient_details
355
+ expect ( page ) . to have_content ( "HOMESCHOOL, Emma" )
356
+ expect ( page ) . to have_content ( "1 June 2010" )
357
+ end
358
+
359
+ def and_emma_has_correct_parent_data
360
+ emma = Patient . find_by ( given_name : "Emma" , family_name : "Homeschool" )
361
+ expect ( emma . parents . count ) . to eq ( 1 )
362
+
363
+ father = emma . parents . first
364
+ expect ( father . full_name ) . to eq ( "Mike HomeDad" )
365
+ expect ( father . email ) . to eq ( "mike@home.com" )
366
+
367
+ relationship = emma . parent_relationships . first
368
+ expect ( relationship . type ) . to eq ( "father" )
369
+ end
370
+
371
+ def then_school_moves_are_created_appropriately
372
+ perform_enqueued_jobs
373
+
374
+ charlie = Patient . find_by ( given_name : "Charlie" )
375
+ charlie_move = SchoolMoveLogEntry . find_by ( patient : charlie )
376
+ expect ( charlie_move ) . to be_present
377
+ expect ( charlie_move . school ) . to eq ( @school )
378
+
379
+ emma = Patient . find_by ( given_name : "Emma" )
380
+ emma_move = SchoolMoveLogEntry . find_by ( patient : emma )
381
+ expect ( emma_move ) . to be_present
382
+ expect ( emma_move . home_educated ) . to be true
383
+ expect ( emma_move . school ) . to be_nil
384
+
385
+ catherine =
386
+ Patient . find_by ( given_name : "Catherine" , family_name : "Williams" )
387
+ catherine_move = SchoolMove . find_by ( patient : catherine , school : @school )
388
+ expect ( catherine_move ) . to be_present
389
+ catherine_log_entry = SchoolMoveLogEntry . find_by ( patient : catherine )
390
+ expect ( catherine_log_entry ) . to be_nil
391
+ expect ( catherine . school ) . to eq ( @different_school )
392
+ end
393
+
394
+ def and_all_parent_relationships_are_established
395
+ expect ( Parent . count ) . to eq ( 8 )
396
+ expect ( ParentRelationship . count ) . to eq ( 8 )
397
+
398
+ father_relationships = ParentRelationship . where ( type : "father" )
399
+ expect ( father_relationships . count ) . to eq ( 3 ) # John Tweedle, Mike HomeDad, Robert Samson
400
+
401
+ mother_relationships = ParentRelationship . where ( type : "mother" )
402
+ expect ( mother_relationships . count ) . to eq ( 3 ) # Mary Tweedle, Linda Samson, Sarah Williams
403
+
404
+ guardian_relationships = ParentRelationship . where ( type : "guardian" )
405
+ expect ( guardian_relationships . count ) . to eq ( 1 ) # David Williams
406
+
407
+ unknown_relationships = ParentRelationship . where ( type : "unknown" )
408
+ expect ( unknown_relationships . count ) . to eq ( 1 ) # Jane Doe
409
+ end
410
+
411
+ def and_import_counts_are_correct
412
+ import = CohortImport . last
413
+ expect ( import . patients . count ) . to eq ( 6 )
414
+ end
415
+
416
+ def when_i_click_on_patient_with_unknown_relationship
417
+ click_link "GREEN, Oliver"
418
+ end
419
+
420
+ def then_i_see_patient_with_unknown_relationship_details
421
+ expect ( page ) . to have_content ( "GREEN, Oliver" )
422
+ expect ( page ) . to have_content ( "15 August 2010" )
423
+ end
424
+
425
+ def and_oliver_has_unknown_relationship_parent
426
+ oliver = Patient . find_by ( given_name : "Oliver" , family_name : "Green" )
427
+ expect ( oliver . parents . count ) . to eq ( 1 )
428
+
429
+ parent = oliver . parents . first
430
+ expect ( parent . full_name ) . to eq ( "Jane Doe" )
431
+ expect ( parent . email ) . to be_blank
432
+
433
+ relationship = oliver . parent_relationships . first
434
+ expect ( relationship . type ) . to eq ( "unknown" )
435
+ expect ( relationship . label ) . to eq ( "Unknown" )
436
+ end
437
+ def when_i_click_on_patient_with_unknown_relationship
438
+ click_link "GREEN, Oliver"
439
+ end
440
+
441
+ def then_i_see_patient_with_unknown_relationship_details
442
+ expect ( page ) . to have_content ( "GREEN, Oliver" )
443
+ expect ( page ) . to have_content ( "15 August 2010" )
444
+ end
445
+
446
+ def and_oliver_has_unknown_relationship_parent
447
+ oliver = Patient . find_by ( given_name : "Oliver" , family_name : "Green" )
448
+ expect ( oliver . parents . count ) . to eq ( 1 )
449
+
450
+ parent = oliver . parents . first
451
+ expect ( parent . full_name ) . to eq ( "Jane Doe" )
452
+ expect ( parent . email ) . to be_blank
453
+
454
+ relationship = oliver . parent_relationships . first
455
+ expect ( relationship . type ) . to eq ( "unknown" )
456
+ expect ( relationship . label ) . to eq ( "Unknown" )
457
+ end
225
458
end
0 commit comments