1+ import copy
12import json
23import random
34import uuid
@@ -329,7 +330,8 @@ def validate_etag_in_header(context):
329330@when ("I subsequently update the vaccination details of the original immunization event" )
330331def send_update_for_vaccination_detail (context ):
331332 get_update_url_header (context , str (context .expected_version ))
332- context .update_object = convert_to_update (context .immunization_object , context .ImmsID )
333+ context .update_object = copy .deepcopy (context .immunization_object )
334+ context .update_object = convert_to_update (context .update_object , context .ImmsID )
333335 context .update_object .extension = [build_vaccine_procedure_extension (context .vaccine_type .upper ())]
334336 vaccine_details = get_vaccine_details (context .vaccine_type .upper ())
335337 context .update_object .vaccineCode = vaccine_details ["vaccine_code" ]
@@ -341,7 +343,8 @@ def send_update_for_vaccination_detail(context):
341343@when ("I update the address of the original immunization event" )
342344def send_update_for_immunization_event (context ):
343345 get_update_url_header (context , str (context .expected_version ))
344- context .update_object = convert_to_update (context .immunization_object , context .ImmsID )
346+ context .update_object = copy .deepcopy (context .immunization_object )
347+ context .update_object = convert_to_update (context .update_object , context .ImmsID )
345348 context .update_object .contained [1 ].address [0 ].city = "Updated City"
346349 context .update_object .contained [1 ].address [0 ].state = "Updated State"
347350 trigger_the_updated_request (context )
@@ -395,14 +398,7 @@ def mns_event_will_not_be_triggered_for_the_event(context):
395398
396399@then ("MNS event will not be triggered for the update event" )
397400def validate_mns_event_not_triggered_for_updated_event (context ):
398- message_body = read_message (
399- context ,
400- queue_type = "notification" ,
401- wait_time_seconds = 5 ,
402- max_total_wait_seconds = 20 ,
403- )
404- print ("no MNS update event is created" )
405- assert message_body is None , "Not expected a message but queue returned a message"
401+ mns_event_will_not_be_triggered_for_the_event (context )
406402
407403
408404def trigger_the_updated_request (context ):
@@ -482,10 +478,11 @@ def validate_sqs_message(context, message_body, action):
482478 f"msn event for { action } Filtering is missing in the message body" ,
483479 )
484480
485- check .is_true (
486- normalize (message_body .filtering .generalpractitioner ) == normalize (context .gp_code ),
487- f"msn event for { action } GP code mismatch: expected { context .gp_code } , got { message_body .filtering .generalpractitioner } " ,
488- )
481+ if context .gp_code :
482+ check .is_true (
483+ normalize (message_body .filtering .generalpractitioner ) == normalize (context .gp_code ),
484+ f"msn event for { action } GP code mismatch: expected { context .gp_code } , got { message_body .filtering .generalpractitioner } " ,
485+ )
489486
490487 expected_org = context .immunization_object .performer [1 ].actor .identifier .value
491488 check .is_true (
@@ -498,10 +495,11 @@ def validate_sqs_message(context, message_body, action):
498495 f"msn event for { action } Source application mismatch: expected { context .supplier_name } , got { message_body .filtering .sourceapplication } " ,
499496 )
500497
501- check .is_true (
502- message_body .filtering .subjectage == context .patient_age ,
503- f"msn event for { action } Age mismatch: expected { context .patient_age } , got { message_body .filtering .subjectage } " ,
504- )
498+ if context .patient_age :
499+ check .is_true (
500+ message_body .filtering .subjectage == context .patient_age ,
501+ f"msn event for { action } Age mismatch: expected { context .patient_age } , got { message_body .filtering .subjectage } " ,
502+ )
505503
506504 check .is_true (
507505 message_body .filtering .immunisationtype == context .vaccine_type .upper (),
@@ -544,7 +542,12 @@ def mns_event_will_be_triggered_with_correct_data(context, action):
544542 print (f"Read { action } d message from SQS: { message_body } " )
545543 assert message_body is not None , f"Expected a { action } message but queue returned empty"
546544 context .gp_code = get_gp_code_by_nhs_number (context .patient .identifier [0 ].value )
547- context .patient_age = calculate_age (context .patient .birthDate , context .immunization_object .occurrenceDateTime )
545+ patient_DOB = (
546+ context .immunization_object .contained [1 ].birthDate
547+ if action .upper () == "CREATE"
548+ else context .update_object .contained [1 ].birthDate
549+ )
550+ context .patient_age = calculate_age (patient_DOB , context .immunization_object .occurrenceDateTime )
548551 validate_sqs_message (context , message_body , action )
549552 else :
550553 print (
0 commit comments