@@ -510,7 +510,7 @@ def extract_patient_data(
510510 if not valid_cols :
511511 if close_wb :
512512 workbook .close ()
513- logger .warning (f"No valid headers found in sheet '{ sheet_name } '" )
513+ logger .bind ( error_code = "invalid_tracker" ). warning (f"No valid headers found in sheet '{ sheet_name } '" )
514514 return pl .DataFrame ()
515515
516516 data = read_patient_rows (ws , data_start_row , len (headers ))
@@ -689,21 +689,21 @@ def read_all_patient_sheets(
689689 df_sheet = extract_patient_data (tracker_file , sheet_name , year , mapper = mapper , workbook = wb )
690690
691691 if df_sheet .is_empty ():
692- logger .warning (f"Sheet '{ sheet_name } ' has no data, skipping" )
692+ logger .bind ( error_code = "invalid_tracker" ). warning (f"Sheet '{ sheet_name } ' has no data, skipping" )
693693 continue
694694
695695 df_sheet = harmonize_patient_data_columns (df_sheet , mapper = mapper , strict = False )
696696
697697 if "patient_id" not in df_sheet .columns :
698- logger .warning (
698+ logger .bind ( error_code = "invalid_tracker" ). warning (
699699 f"Sheet '{ sheet_name } ' has no 'patient_id' column after harmonization, skipping"
700700 )
701701 continue
702702
703703 try :
704704 month_num = extract_tracker_month (sheet_name )
705705 except ValueError as e :
706- logger .warning (f"Could not extract month from '{ sheet_name } ': { e } , skipping" )
706+ logger .bind ( error_code = "invalid_tracker" ). warning (f"Could not extract month from '{ sheet_name } ': { e } , skipping" )
707707 continue
708708
709709 # Derived metadata (year, month) use Int64; text metadata (sheet_name, etc.) use String
@@ -735,7 +735,7 @@ def read_all_patient_sheets(
735735 missing_count = len (missing_patient_id_rows )
736736
737737 if missing_count > 0 :
738- logger .error (
738+ logger .bind ( error_code = "invalid_value" ). error (
739739 f"Found { missing_count } rows with missing patient_id in { tracker_file .name } - "
740740 f"these rows will be excluded from processing"
741741 )
@@ -837,13 +837,13 @@ def read_all_patient_sheets(
837837 )
838838 logger .info (f"Joined { len (patient_list )} Patient List records" )
839839 else :
840- logger .warning (
840+ logger .bind ( error_code = "invalid_tracker" ). warning (
841841 "Patient List sheet has no 'patient_id' column after harmonization"
842842 )
843843 else :
844- logger .warning ("Patient List sheet is empty" )
844+ logger .bind ( error_code = "invalid_tracker" ). warning ("Patient List sheet is empty" )
845845 except Exception as e :
846- logger .warning (f"Could not process Patient List sheet: { e } " )
846+ logger .bind ( error_code = "invalid_tracker" ). warning (f"Could not process Patient List sheet: { e } " )
847847
848848 # Process Annual sheet if it exists (R: lines 132-160)
849849 if "Annual" in all_sheets :
@@ -884,11 +884,11 @@ def read_all_patient_sheets(
884884 )
885885 logger .info (f"Joined { len (annual_data )} Annual records" )
886886 else :
887- logger .warning ("Annual sheet has no 'patient_id' column after harmonization" )
887+ logger .bind ( error_code = "invalid_tracker" ). warning ("Annual sheet has no 'patient_id' column after harmonization" )
888888 else :
889- logger .warning ("Annual sheet is empty" )
889+ logger .bind ( error_code = "invalid_tracker" ). warning ("Annual sheet is empty" )
890890 except Exception as e :
891- logger .warning (f"Could not process Annual sheet: { e } " )
891+ logger .bind ( error_code = "invalid_tracker" ). warning (f"Could not process Annual sheet: { e } " )
892892
893893 # Close workbook after all processing
894894 wb .close ()
0 commit comments