@@ -283,6 +283,49 @@ def test_find_worklist_items_with_filters(self, mock_db, tmp_dir):
283283 ["MG" , "20240101" , "999123456" ],
284284 )
285285
286+ mock_connection .reset_mock ()
287+ subject .find_worklist_items (patient_name = "Smith*" )
288+
289+ mock_connection .execute .assert_called_once_with (
290+ (
291+ "SELECT accession_number, modality, patient_birth_date, patient_id, "
292+ "patient_name, patient_sex, procedure_code, scheduled_date, scheduled_time, "
293+ "source_message_id, study_description, study_instance_uid, status, mpps_instance_uid "
294+ "FROM worklist_items WHERE UPPER(patient_name) LIKE UPPER(?) ORDER BY scheduled_date, scheduled_time"
295+ ),
296+ ["Smith%" ],
297+ )
298+
299+ @pytest .mark .parametrize (
300+ "dicom_pattern, sql_pattern" ,
301+ [
302+ ("Smith*" , "Smith%" ), # trailing wildcard
303+ ("*Smith*" , "%Smith%" ), # leading and trailing wildcard
304+ ("Sm?th*" , "Sm_th%" ), # single-character wildcard combined with trailing
305+ ("Smith^Jane" , "Smith^Jane" ), # exact name, no wildcards
306+ ],
307+ )
308+ def test_find_worklist_items_patient_name_wildcard_conversion (self , mock_db , tmp_dir , dicom_pattern , sql_pattern ):
309+ mock_cursor = MagicMock ()
310+ mock_cursor .fetchall .return_value = []
311+ mock_connection = MagicMock ()
312+ mock_connection .execute .return_value = mock_cursor
313+ mock_db .connect .return_value = mock_connection
314+ subject = MWLStorage (tmp_dir )
315+ mock_connection .reset_mock ()
316+
317+ subject .find_worklist_items (patient_name = dicom_pattern )
318+
319+ mock_connection .execute .assert_called_once_with (
320+ (
321+ "SELECT accession_number, modality, patient_birth_date, patient_id, "
322+ "patient_name, patient_sex, procedure_code, scheduled_date, scheduled_time, "
323+ "source_message_id, study_description, study_instance_uid, status, mpps_instance_uid "
324+ "FROM worklist_items WHERE UPPER(patient_name) LIKE UPPER(?) ORDER BY scheduled_date, scheduled_time"
325+ ),
326+ [sql_pattern ],
327+ )
328+
286329 def test_get_worklist_item (self , mock_db , tmp_dir , result ):
287330 mock_cursor = MagicMock ()
288331 mock_cursor .fetchone .return_value = result
0 commit comments