@@ -114,6 +114,52 @@ def test_process_update_item_status_action(self, storage_instance, listener_payl
114114
115115 storage_instance .update_status .assert_called_once_with ("ACC999999" , "IN PROGRESS" )
116116
117+ def test_process_create_test_item_action_triggers_modality_emulator (self , storage_instance , listener_payload ):
118+ """Process create test item action and trigger modality emulator."""
119+ subject = RelayListener (storage_instance )
120+ payload = dict (listener_payload )
121+ payload ["action_type" ] = "worklist.create_test_item"
122+
123+ with patch .object (subject , "process_with_modality_emulator" ) as mock_emulator :
124+ response = subject .process_action (payload )
125+
126+ assert response == {"action_id" : "action-12345" , "status" : "created" }
127+ mock_emulator .assert_called_once_with (
128+ patient_name = payload ["parameters" ]["worklist_item" ]["participant" ]["name" ]
129+ )
130+
131+ storage_instance .store_worklist_item .assert_called_once_with (
132+ WorklistItem (
133+ accession_number = "ACC999999" ,
134+ patient_id = "999123456" ,
135+ patient_name = "SMITH^JANE" ,
136+ patient_birth_date = "19900202" ,
137+ patient_sex = "F" ,
138+ scheduled_date = "20240615" ,
139+ scheduled_time = "101500" ,
140+ modality = "MG" ,
141+ study_description = "MAMMOGRAPHY" ,
142+ source_message_id = "action-12345" ,
143+ )
144+ )
145+
146+ def test_process_create_test_item_action_without_patient_name_returns_error (
147+ self , storage_instance , listener_payload
148+ ):
149+ """Process create test item action without a patient name returns an error."""
150+ subject = RelayListener (storage_instance )
151+ payload = dict (listener_payload )
152+ payload ["action_type" ] = "worklist.create_test_item"
153+ del payload ["parameters" ]["worklist_item" ]["participant" ]["name" ]
154+
155+ with patch .object (subject , "process_with_modality_emulator" ):
156+ response = subject .process_action (payload )
157+
158+ assert response == {
159+ "status" : "error" ,
160+ "message" : "No patient name provided for ModalityEmulator test item processing" ,
161+ }
162+
117163 def test_process_action_missing_keys (self , storage_instance , listener_payload ):
118164 """Process action missing keys."""
119165 subject = RelayListener (storage_instance )
@@ -132,15 +178,13 @@ def test_process_action_invalid_type(self, storage_instance, listener_payload):
132178
133179 listener_payload ["action_type" ] = "worklist.unknown_action"
134180
135- with pytest .raises (ValueError ):
136- response = subject .process_action (listener_payload )
137- assert response == {
138- "status" : "error" ,
139- "action_id" : "action-12345" ,
140- "error" : "Unknown action type: worklist.unknown_action" ,
141- }
181+ response = subject .process_action (listener_payload )
182+ assert response == {
183+ "status" : "error" ,
184+ "message" : "Unsupported action: worklist.unknown_action" ,
185+ }
142186
143- storage_instance .store_worklist_item .assert_not_called ()
187+ storage_instance .store_worklist_item .assert_not_called ()
144188
145189
146190class TestRelayURIWithDefaultAzureCredential :
0 commit comments