44import logging
55
66
7+
78def process_kit_data ():
89 # Get test data for compartment 3
910 kit_id_df = get_kit_id_logged_from_db ()
1011
1112 # Split dataframe into two different dataframes, normal and abnormal
1213 normal_fit_kit_df , abnormal_fit_kit_df = split_fit_kits (kit_id_df )
1314
15+ # Prepare a list to store device IDs and their respective flags
16+ device_ids = []
17+
1418 # Process normal kits (only 1)
1519 if not normal_fit_kit_df .empty :
1620 device_id = normal_fit_kit_df ["device_id" ].iloc [0 ]
1721 logging .info (f"Processing normal kit with Device ID: { device_id } " ) # Logging normal device_id
18- update_kit_service_management_entity ( device_id , True )
22+ device_ids . append (( device_id , True )) # Add to the list with normal flag
1923 else :
2024 logging .warning ("No normal kits found for processing." ) # Log warning
2125
22- # Process abnormal kits (multiple, loop through)
26+ # Process abnormal kits (multiple, loop through)
2327 if not abnormal_fit_kit_df .empty :
2428 for index , row in abnormal_fit_kit_df .iterrows ():
2529 device_id = row ["device_id" ]
2630 logging .info (f"Processing abnormal kit with Device ID: { device_id } " ) # Logging abnormal device_id
27- update_kit_service_management_entity ( device_id , False )
31+ device_ids . append (( device_id , False )) # Add to the list with abnormal flag
2832 else :
2933 logging .warning ("No abnormal kits found for processing." ) # Log warning
3034
35+ return device_ids
36+
3137
3238def get_kit_id_logged_from_db ():
3339 kit_id_df = OracleDB ().execute_query ("""SELECT tk.kitid,tk.device_id,tk.screening_subject_id
@@ -101,6 +107,9 @@ def execute_stored_procedures():
101107
102108def update_kit_service_management_entity (device_id , normal ):
103109 get_service_management_df = get_service_management_by_device_id (device_id )
110+
111+ # Extract the NHS number from the DataFrame
112+ subject_nhs_number = get_service_management_df ["subject_nhs_number" ].iloc [0 ]
104113 test_kit_name = get_service_management_df ["test_kit_name" ].iloc [0 ]
105114 test_kit_type = get_service_management_df ["test_kit_type" ].iloc [0 ]
106115 logged_by_hub = get_service_management_df ["logged_by_hub" ].iloc [0 ]
@@ -127,7 +136,7 @@ def update_kit_service_management_entity(device_id, normal):
127136 kq.test_result = :test_result,
128137 kq.calculated_result = :calculated_result,
129138 kq.error_code = NULL,
130- kq.analyser_code = 'HMJackalt1 ',
139+ kq.analyser_code = '3Wjvy ',
131140 kq.date_time_authorised = TO_TIMESTAMP(:date_time_authorised, 'DD-Mon-YY HH24.MI.SS.FF9'),
132141 kq.authoriser_user_code = 'AUTO1',
133142 kq.post_response = :post_response,
@@ -147,8 +156,8 @@ def update_kit_service_management_entity(device_id, normal):
147156 "test_result" : int (test_result ),
148157 "calculated_result" : calculated_result ,
149158 "date_time_authorised" : str (date_time_authorised ),
150- "post_response" : int (post_response ),
151- "post_attempts" : int (post_attempts ),
159+ "post_response" :int (post_response )if post_response is not None else 0 ,
160+ "post_attempts" :int (post_attempts )if post_attempts is not None else 0 ,
152161 "put_response" : put_response ,
153162 "put_attempts" : put_attempts ,
154163 "device_id" : device_id
@@ -158,10 +167,8 @@ def update_kit_service_management_entity(device_id, normal):
158167 print ("Parameters before execution:" , params )
159168 rows_affected = OracleDB ().update_or_insert_data_to_table (update_query , params )
160169 print (f"Rows affected: { rows_affected } " )
170+ # Return the subject NHS number
171+ return subject_nhs_number
172+
161173
162174
163- def get_nhs_number_from_subject_id (subject_ids , df ):
164- temp_df = OracleDB ().execute_query (
165- f"SELECT SCREENING_SUBJECT_ID, SUBJECT_NHS_NUMBER FROM SCREENING_SUBJECT_T WHERE SCREENING_SUBJECT_ID = { subject_ids } " )
166- df = df .merge (temp_df [["screening_subject_id" , "subject_nhs_number" ]], on = "screening_subject_id" , how = "left" )
167- return df
0 commit comments