Skip to content

Commit ee3c5ed

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

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/relay_listener.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,27 @@ 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 = (
106+
payload.get("parameters", {})
107+
.get("worklist_item", {})
108+
.get("participant", {})
109+
.get("name")
110+
)
111+
112+
def _run_emulator():
113+
try:
114+
self.process_with_modality_emulator(patient_name=patient_name)
115+
except Exception:
116+
logger.exception("Modality emulator processing failed")
117+
118+
try:
119+
loop = asyncio.get_running_loop()
120+
except RuntimeError:
121+
# Called outside an event loop (e.g. unit tests)
122+
_run_emulator()
123+
else:
124+
loop.create_task(asyncio.to_thread(_run_emulator))
125+
106126
return result
107127
elif action_name == "worklist.update_status":
108128
return UpdateWorklistItemStatus(self.storage).call(payload)

tests/test_relay_listener.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ 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(patient_name=payload["parameters"]["worklist_item"]["participant"]["name"])
128128

129129
storage_instance.store_worklist_item.assert_called_once_with(
130130
WorklistItem(

0 commit comments

Comments
 (0)