@@ -104,19 +104,14 @@ def process_action(self, payload: dict):
104104 result = CreateWorklistItem (self .storage ).call (payload )
105105 patient_name = payload .get ("parameters" , {}).get ("worklist_item" , {}).get ("participant" , {}).get ("name" )
106106
107- def _run_emulator ():
108- try :
109- self .process_with_modality_emulator (patient_name = patient_name )
110- except Exception :
111- logger .exception ("Modality emulator processing failed" )
107+ if not patient_name :
108+ logger .warning ("No patient name provided for ModalityEmulator test item processing" )
109+ return {
110+ "status" : "error" ,
111+ "message" : "No patient name provided for ModalityEmulator test item processing" ,
112+ }
112113
113- try :
114- loop = asyncio .get_running_loop ()
115- except RuntimeError :
116- # Called outside an event loop (e.g. unit tests)
117- _run_emulator ()
118- else :
119- loop .create_task (asyncio .to_thread (_run_emulator ))
114+ self .process_with_modality_emulator (patient_name = patient_name )
120115
121116 return result
122117 elif action_name == "worklist.update_status" :
@@ -138,7 +133,19 @@ def process_with_modality_emulator(self, patient_name: str | None = None):
138133 ae .add_requested_context (DigitalMammographyXRayImageStorageForPresentation )
139134 ae .add_requested_context (ModalityWorklistInformationFind )
140135
141- ModalityEmulator (self .storage ).process_worklist_items (ae , patient_name = patient_name )
136+ def _run_emulator ():
137+ try :
138+ ModalityEmulator (self .storage ).process_worklist_items (ae , patient_name = patient_name )
139+ except Exception :
140+ logger .exception ("Modality emulator processing failed" )
141+
142+ try :
143+ loop = asyncio .get_running_loop ()
144+ except RuntimeError :
145+ # Called outside an event loop (e.g. unit tests)
146+ _run_emulator ()
147+ else :
148+ loop .create_task (asyncio .to_thread (_run_emulator ))
142149
143150
144151class RelayURI :
0 commit comments