Skip to content

Commit 51480a0

Browse files
steventuxCopilot
andcommitted
Fix patient name lookup from payload
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 1ad5b3e commit 51480a0

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/relay_listener.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,22 @@ def process_action(self, payload: dict):
102102
return CreateWorklistItem(self.storage).call(payload)
103103
elif action_name == "worklist.create_test_item":
104104
result = CreateWorklistItem(self.storage).call(payload)
105-
self.process_with_modality_emulator(patient_name=payload.get("patient_name"))
105+
patient_name = payload.get("parameters", {}).get("worklist_item", {}).get("participant", {}).get("name")
106+
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")
112+
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))
120+
106121
return result
107122
elif action_name == "worklist.update_status":
108123
return UpdateWorklistItemStatus(self.storage).call(payload)

tests/test_relay_listener.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ def test_process_create_test_item_action_triggers_modality_emulator(self, storag
124124
response = subject.process_action(payload)
125125

126126
assert response == {"action_id": "action-12345", "status": "created"}
127-
mock_emulator.assert_called_once_with(patient_name=payload.get("patient_name"))
127+
mock_emulator.assert_called_once_with(
128+
patient_name=payload["parameters"]["worklist_item"]["participant"]["name"]
129+
)
128130

129131
storage_instance.store_worklist_item.assert_called_once_with(
130132
WorklistItem(

0 commit comments

Comments
 (0)