Skip to content

Commit d38fcef

Browse files
Delegate to update_status
1 parent 1bd5b6b commit d38fcef

3 files changed

Lines changed: 14 additions & 16 deletions

File tree

src/services/storage.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -493,23 +493,14 @@ def update_status(
493493

494494
def mark_in_progress(self, accession_number: str) -> bool:
495495
"""
496-
Transition worklist item from SCHEDULED to IN_PROGRESS.
496+
Transition worklist item from SCHEDULED to IN PROGRESS.
497497
498498
Returns True if the status was updated, False if not found or already past SCHEDULED.
499499
"""
500-
with self._get_connection() as conn:
501-
cursor = conn.execute(
502-
"""
503-
UPDATE worklist_items
504-
SET status = 'IN PROGRESS',
505-
updated_at = CURRENT_TIMESTAMP
506-
WHERE accession_number = ?
507-
AND status = 'SCHEDULED'
508-
""",
509-
(accession_number,),
510-
)
511-
conn.commit()
512-
return cursor.rowcount > 0
500+
item = self.get_worklist_item(accession_number)
501+
if item is None or item.status != "SCHEDULED":
502+
return False
503+
return self.update_status(accession_number, "IN PROGRESS") is not None
513504

514505
def update_study_instance_uid(self, accession_number: str, study_instance_uid: str) -> bool:
515506
"""

tests/services/dicom/test_c_store.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ def test_mark_in_progress_not_called_on_failure(self, mock_storage, mock_event):
141141

142142
mock_mwl.mark_in_progress.assert_not_called()
143143

144+
def test_mark_in_progress_error_does_not_fail_store(self, mock_storage, mock_event):
145+
mock_mwl = Mock(spec=MWLStorage)
146+
mock_mwl.mark_in_progress.side_effect = Exception("db error")
147+
subject = CStore(mock_storage, mwl_storage=mock_mwl)
148+
149+
assert subject.call(mock_event) == SUCCESS
150+
144151
def test_validation_failure_accession_not_in_mwl(self, mock_storage, mock_event):
145152
"""When accession is not in MWL, validation failure returns FAILURE without calling notify."""
146153
mock_validator = Mock(spec=DicomValidator)

tests/services/test_storage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ def test_mark_in_progress(self, mwl_storage, result):
322322

323323
def test_mark_in_progress_is_idempotent(self, mwl_storage, result):
324324
item = self._insert_item(mwl_storage, result)
325-
mwl_storage.mark_in_progress(item.accession_number) # now IN_PROGRESS
325+
mwl_storage.update_status(item.accession_number, "IN PROGRESS")
326326

327-
assert mwl_storage.mark_in_progress(item.accession_number) is False # no-op
327+
assert mwl_storage.mark_in_progress(item.accession_number) is False
328328

329329
def test_mark_in_progress_returns_false_when_not_found(self, mwl_storage):
330330
assert mwl_storage.mark_in_progress("DOES_NOT_EXIST") is False

0 commit comments

Comments
 (0)