Skip to content

Commit cf05623

Browse files
committed
Updated exec_bcss_timed_events (removed duplicate code) following feedback from Adriano
1 parent ee70d54 commit cf05623

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

utils/oracle/oracle.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,19 @@ def exec_bcss_timed_events(
6060
"""
6161
conn = self.connect_to_db()
6262
try:
63+
subject_ids = []
64+
6365
if nhs_number_df is not None:
64-
for _, row in nhs_number_df.iterrows():
65-
subject_id = self.get_subject_id_from_nhs_number(
66-
row["subject_nhs_number"]
67-
)
68-
try:
69-
logging.info(
70-
f"[ORACLE] Attempting to execute stored procedure: 'bcss_timed_events', [{subject_id}, 'Y']"
71-
)
72-
cursor = conn.cursor()
73-
cursor.callproc("bcss_timed_events", [subject_id, "Y"])
74-
logging.info("Stored procedure execution successful!")
75-
except Exception as spExecutionError:
76-
logging.error(
77-
f"[ORACLE] Failed to execute stored procedure with execution error: {spExecutionError}"
78-
)
66+
subject_ids = [
67+
self.get_subject_id_from_nhs_number(row["subject_nhs_number"])
68+
for _, row in nhs_number_df.iterrows()
69+
]
7970
elif nhs_number is not None:
80-
subject_id = self.get_subject_id_from_nhs_number(nhs_number)
71+
subject_ids = [self.get_subject_id_from_nhs_number(nhs_number)]
72+
else:
73+
raise ValueError("Must provide either nhs_number_df or nhs_number")
74+
75+
for subject_id in subject_ids:
8176
try:
8277
logging.info(
8378
f"[ORACLE] Attempting to execute stored procedure: 'bcss_timed_events', [{subject_id}, 'Y']"
@@ -89,8 +84,7 @@ def exec_bcss_timed_events(
8984
logging.error(
9085
f"[ORACLE] Failed to execute stored procedure with execution error: {spExecutionError}"
9186
)
92-
else:
93-
raise ValueError("Must provide either nhs_number_df or nhs_number")
87+
9488
except Exception as queryExecutionError:
9589
logging.error(
9690
f"[ORACLE] Failed to extract subject ID with error: {queryExecutionError}"

0 commit comments

Comments
 (0)