@@ -27,13 +27,7 @@ def exec_bcss_timed_events(self, nhs_number_df): # Executes bcss_timed_events w
2727 conn = self .connect_to_db ()
2828 try :
2929 for index , row in nhs_number_df .iterrows ():
30- logging .info (f"Attempting to get subject_id from nhs number: { row ["subject_nhs_number" ]} " )
31- cursor = conn .cursor ()
32- cursor .execute (
33- f"SELECT SCREENING_SUBJECT_ID FROM SCREENING_SUBJECT_T WHERE SUBJECT_NHS_NUMBER = { int (row ["subject_nhs_number" ])} " )
34- result = cursor .fetchall ()
35- subject_id = result [0 ][0 ]
36- logging .info (f"Able to extract subject ID: { subject_id } " )
30+ subject_id = self .get_subject_id_from_nhs_number (row ["subject_nhs_number" ])
3731 try :
3832 logging .info (
3933 f"Attempting to execute stored procedure: { f"'bcss_timed_events', [{ subject_id } ,'Y']" } " )
@@ -49,6 +43,17 @@ def exec_bcss_timed_events(self, nhs_number_df): # Executes bcss_timed_events w
4943 conn .close ()
5044 logging .info ("Connection closed" )
5145
46+ def get_subject_id_from_nhs_number (self , nhs_number ) -> str :
47+ conn = self .connect_to_db ()
48+ logging .info (f"Attempting to get subject_id from nhs number: { nhs_number } " )
49+ cursor = conn .cursor ()
50+ cursor .execute (
51+ f"SELECT SCREENING_SUBJECT_ID FROM SCREENING_SUBJECT_T WHERE SUBJECT_NHS_NUMBER = { int (nhs_number )} " )
52+ result = cursor .fetchall ()
53+ subject_id = result [0 ][0 ]
54+ logging .info (f"Able to extract subject ID: { subject_id } " )
55+ return subject_id
56+
5257 def populate_ui_approved_users_table (self , user : str ): # To add users to the UI_APPROVED_USERS table
5358 conn = self .connect_to_db ()
5459 try :
@@ -93,7 +98,7 @@ def execute_query(self, query: str) -> pd.DataFrame: # To use when "select xxxx
9398 if conn is not None :
9499 conn .close ()
95100 logging .info ("Connection Closed - Returning results" )
96- return df
101+ return df
97102
98103 def execute_stored_procedure (self , procedure : str ): # To use when "exec xxxx" (stored procedures)
99104 conn = self .connect_to_db ()
0 commit comments