@@ -400,3 +400,197 @@ def the_report_is_downloaded_successfully(shared_data, nhs_number):
400
400
)
401
401
402
402
logger .info (f"Vaccination date '{ vaccination_date } ' is correctly not present in the report." )
403
+
404
+ @when ('I click the today date range button and click continue' )
405
+ def I_click_today_date_range_and_click_continue (shared_data ):
406
+ click_today_radio_button ()
407
+ attach_screenshot ("clicked_today_radio_button" )
408
+ logging .info ("clicked_today_radio_button" )
409
+ click_continue_to_reports_select_vaccine_button ()
410
+ attach_screenshot ("clicked_continue_to_reports_select_vaccine_button" )
411
+ logging .info ("clicked_continue_to_reports_select_vaccine_button" )
412
+
413
+ @when (parse ('I select the vaccine type {vaccineType} and click continue' ))
414
+ def I_select_vaccinetype_and_click_continue (shared_data , vaccineType ):
415
+ click_vaccine_check_box_on_reports_page (vaccineType )
416
+ attach_screenshot ("clicked_" + vaccineType .lower () + "_check_box_on_reports_page" )
417
+ logging .info ("clicked_" + vaccineType .lower () + "_check_box_on_reports_page" )
418
+ click_continue_to_reports_select_site_button ()
419
+ attach_screenshot ("clicked_continue_to_reports_select_site_button" )
420
+ logging .info ("clicked_continue_to_reports_select_site_button" )
421
+
422
+ @then ("the choose sites page should be displayed" )
423
+ def the_choose_sites_page_should_be_displayed ():
424
+ assert check_site_check_box_exists ("ALBERT HOUSE" ) == True
425
+ attach_screenshot ("check_choose_sites_page_is_displayed" )
426
+ logging .info ("check_choose_sites_page_is_displayed" )
427
+
428
+ @when (parse ('I select the site {site} and click continue' ))
429
+ def I_select_vaccinetype_and_click_continue (shared_data , site ):
430
+ check_site_check_box (site )
431
+ attach_screenshot ("clicked_" + site .lower () + "_check_box_on_reports_page" )
432
+ logging .info ("clicked_" + site .lower () + "_check_box_on_reports_page" )
433
+ click_continue_to_reports_select_data_button ()
434
+ attach_screenshot ("clicked_continue_to_reports_select_data_button" )
435
+ logging .info ("clicked_continue_to_reports_select_data_button" )
436
+
437
+ @then ("the choose data page should be displayed and all data options should be checked by default" )
438
+ def the_choose_data_page_should_be_displayed ():
439
+ assert check_reports_data_check_box_exists ("Patients" ) == True
440
+ assert check_reports_data_check_box_checked ("Patients" ) == True
441
+ assert check_reports_data_check_box_checked ("Staff" ) == True
442
+ assert check_reports_data_check_box_checked ("Site or delivery team" ) == True
443
+ assert check_reports_data_check_box_checked ("Assessment and consent" ) == True
444
+ assert check_reports_data_check_box_checked ("Vaccination" ) == True
445
+ attach_screenshot ("check_choose_data_pages_reports_exists" )
446
+ logging .info ("check_choose_data_pages_reports_exists" )
447
+
448
+ @when (parse ('I click continue on the data page' ))
449
+ def I_select_data_and_click_continue (shared_data ):
450
+ click_continue_to_reports_select_data_button ()
451
+ attach_screenshot ("clicked_continue_to_reports_select_data_button" )
452
+ logging .info ("clicked_continue_to_reports_select_data_button" )
453
+
454
+ @then ("the check and confirm page should be displayed" )
455
+ def the_check_and_confirm_page_should_be_displayed ():
456
+ assert check_reports_change_data_button_exists () == True
457
+ attach_screenshot ("check_reports_change_data_pages_reports_exists" )
458
+ logging .info ("check_reports_change_data_pages_reports_exists" )
459
+
460
+ @when ('I click Confirm and create report button in the check and confirm page' )
461
+ def I_click_confirm_to_generate_report (shared_data ):
462
+ click_continue_to_confirm_and_create_report_button ()
463
+ attach_screenshot ("clicked_continue_to_confirm_and_create_report_button" )
464
+ logging .info ("clicked_continue_to_confirm_and_create_report_button" )
465
+
466
+ @then ("Creating your page element should be displayed and Download Report button should be visible" )
467
+ def the_check_and_confirm_page_should_be_displayed ():
468
+ assert check_reports_download_report_button_exists () == True
469
+ attach_screenshot ("check_reports_change_data_pages_reports_exists" )
470
+ logging .info ("check_reports_change_data_pages_reports_exists" )
471
+
472
+ @when ('I click download report button' )
473
+ def I_click_confirm_to_generate_report (shared_data ):
474
+ shared_data ['report_download_path' ] = click_reports_download_report_button ()
475
+ attach_screenshot ("clicked_reports_download_report_button" )
476
+ logging .info ("clicked_reports_download_report_button" )
477
+
478
+ @then ("the report is downloaded successfully" )
479
+ def the_report_is_downloaded_successfully (shared_data ):
480
+ assert os .path .exists (shared_data ['report_download_path' ]), f"Downloaded file not found: { shared_data ['report_download_path' ]} "
481
+ attach_screenshot ("check_report_downloaded" )
482
+ logger .info ("check_report_downloaded_to_" + str (shared_data ['report_download_path' ]))
483
+ expected_headers = [
484
+ "NhsNumber" , "PatientName" , "Gender" , "DateOfBirth" , "Address" , "Postcode" ,
485
+ "SiteName" , "SiteODS" , "OrganisationName" , "OrganisationODS" , "CareModel" ,
486
+ "Vaccinated" , "NoVaccinationReason" , "AssessmentDate" , "Consented" , "ConsentType" ,
487
+ "ConsentingPersonName" , "ConsentingPersonRelationship" , "EligibilityType" , "StaffType" ,
488
+ "AssessmentComments" , "VaccinationDate" , "Vaccine" , "VaccineProduct" , "DoseAmount" ,
489
+ "VaccineRoute" , "PrescribingMethod" , "BatchNumber" , "BatchExpiryDate" , "AuditType" ,
490
+ "DateEntered" , "UserEnteringData" , "VaccinationComments" , "AssessingClinician" ,
491
+ "VaccinatingClinician" , "ConsentingClinician"
492
+ ]
493
+ is_valid , _ = validate_report_headers (shared_data ['report_download_path' ], expected_headers )
494
+ assert is_valid , "Report headers are invalid. See logs for details."
495
+
496
+ @then (parse ("the report is downloaded successfully and contains the vaccine record for {nhs_number}" ))
497
+ def the_report_is_downloaded_successfully (shared_data , nhs_number ):
498
+ assert os .path .exists (shared_data ['report_download_path' ]), f"Downloaded file not found: { shared_data ['report_download_path' ]} "
499
+ attach_screenshot ("check_report_downloaded" )
500
+ logger .info ("check_report_downloaded_to_" + str (shared_data ['report_download_path' ]))
501
+ expected_headers = [
502
+ "NhsNumber" , "PatientName" , "Gender" , "DateOfBirth" , "Address" , "Postcode" ,
503
+ "SiteName" , "SiteODS" , "OrganisationName" , "OrganisationODS" , "CareModel" ,
504
+ "Vaccinated" , "NoVaccinationReason" , "AssessmentDate" , "Consented" , "ConsentType" ,
505
+ "ConsentingPersonName" , "ConsentingPersonRelationship" , "EligibilityType" , "StaffType" ,
506
+ "AssessmentComments" , "VaccinationDate" , "Vaccine" , "VaccineProduct" , "DoseAmount" ,
507
+ "VaccineRoute" , "PrescribingMethod" , "BatchNumber" , "BatchExpiryDate" , "AuditType" ,
508
+ "DateEntered" , "UserEnteringData" , "VaccinationComments" , "AssessingClinician" ,
509
+ "VaccinatingClinician" , "ConsentingClinician"
510
+ ]
511
+ is_valid , _ = validate_report_headers (shared_data ['report_download_path' ], expected_headers )
512
+ assert is_valid , "Report headers are invalid. See logs for details."
513
+
514
+ vaccination_date = shared_data .get ("vaccination_date" )
515
+ vaccinated_decision = shared_data ["vaccinated_decision" ]
516
+ consent_given_by = shared_data ['consent_given_by' ]
517
+ eligibility_type = shared_data ['eligibility_type' ]
518
+
519
+ if vaccination_date :
520
+ # Convert the vaccination date from shared_data to a datetime object
521
+ vaccination_date_obj = datetime .strptime (vaccination_date , "%d/%m/%Y" ) # Adjust format as needed
522
+ current_date = datetime .now ()
523
+ date_diff = (current_date - vaccination_date_obj ).days
524
+
525
+ if 0 <= date_diff <= 31 :
526
+ # If vaccination date is within the last 31 days, ensure all columns have values
527
+ logger .info (f"Vaccination date '{ vaccination_date } ' is within the last 31 days. Verifying all columns have values..." )
528
+
529
+ with open (shared_data ['report_download_path' ], mode = "r" , newline = "" , encoding = "utf-8" ) as file :
530
+ reader = csv .DictReader (file )
531
+ for row in reader :
532
+ # For each row, ensure that all columns have non-empty values
533
+ for header in expected_headers :
534
+ if header == "NoVaccinationReason" :
535
+ # If vaccinated_decision is "yes", NoVaccinationReason should be empty
536
+ if vaccinated_decision .lower () == "yes" :
537
+ assert not row [header ], f"Column 'NoVaccinationReason' should be empty for NHS number { shared_data ['nhs_number' ]} as vaccinated_decision is 'yes'."
538
+ else :
539
+ assert row [header ], f"Missing value in column '{ header } ' for NHS number { shared_data ['nhs_number' ]} ."
540
+ elif header == "ConsentingPersonName" or header == "ConsentingPersonRelationship" :
541
+ if consent_given_by == "Patient (informed consent)" :
542
+ assert not row [header ], f"Column 'ConsentingPersonName' and 'ConsentingPersonRelationship' should be empty for NHS number { shared_data ['nhs_number' ]} as consent given by patient (informed consent)"
543
+ else :
544
+ assert row [header ], f"Missing value in column '{ header } ' for NHS number { shared_data ['nhs_number' ]} ."
545
+ elif header == "StaffType" :
546
+ if eligibility_type == "Healthcare workers" :
547
+ assert row [header ], f"Column 'StaffType' should not be empty for NHS number { shared_data ['nhs_number' ]} as eligibility_type is 'Healthcare workers'."
548
+ else :
549
+ assert not row [header ], f"Column 'StaffType' should be empty for NHS number { shared_data ['nhs_number' ]} as eligibility_type is not 'Healthcare workers'."
550
+ else :
551
+ # For other columns, ensure they are not empty
552
+ assert row [header ], f"Missing value in column '{ header } ' for NHS number { shared_data ['nhs_number' ]} ."
553
+
554
+ # Validate the presence of the vaccination date in the report
555
+ is_vaccination_date_present = validate_value_in_header (
556
+ shared_data ['report_download_path' ],
557
+ "VaccinationDate" ,
558
+ vaccination_date
559
+ )
560
+ assert is_vaccination_date_present , (
561
+ f"Value '{ vaccination_date } ' not found under header 'VaccinationDate' in the report."
562
+ )
563
+
564
+ # Validate the presence of the NHS number only if the vaccination date is within the last 31 days
565
+ is_nhsNumber_present = validate_value_in_header (shared_data ['report_download_path' ], "NhsNumber" , shared_data ["nhs_number" ])
566
+ assert is_nhsNumber_present , f"Value '{ shared_data ['nhs_number' ]} ' not found under header 'NhsNumber' in the report."
567
+
568
+ else :
569
+ # If vaccination date is more than 31 days old, ensure no rows for that date
570
+ logger .info (f"Vaccination date '{ vaccination_date } ' is more than 31 days old. Ensuring no rows exist with this date in the report." )
571
+
572
+ with open (shared_data ['report_download_path' ], mode = "r" , newline = "" , encoding = "utf-8" ) as file :
573
+ reader = csv .DictReader (file )
574
+ found_invalid_row = False
575
+ for row in reader :
576
+ if row ["VaccinationDate" ] == vaccination_date :
577
+ found_invalid_row = True
578
+ break
579
+
580
+ assert not found_invalid_row , (
581
+ f"Row with vaccination date '{ vaccination_date } ' found in the report, but it should not be present since it's older than 31 days."
582
+ )
583
+
584
+ logger .info (f"Vaccination date '{ vaccination_date } ' is correctly not present in the report." )
585
+ attach_screenshot ("click_" + site .lower () + "_check_box_on_reports_page" )
586
+ logging .info ("click_" + site .lower () + "_check_box_on_reports_page" )
587
+ click_continue_to_reports_select_data_button ()
588
+ attach_screenshot ("click_continue_to_reports_select_data_button" )
589
+ logging .info ("click_continue_to_reports_select_data_button" )
590
+
591
+ @then ("the choose data page should be displayed" )
592
+ def the_choose_data_page_should_be_displayed ():
593
+ assert check_data_check_box_exists ("Patients" ) == True
594
+ attach_screenshot ("check_choose_data_pages_reports_exists" )
595
+ logging .info ("check_choose_data_pages_reports_exists" )
596
+
0 commit comments