77from typing import Dict , List , Optional
88
99from models import WorklistItem
10- from services .mwl import MWLStatus
10+ from services .mwl import MWLStatusManager
1111
1212logger = logging .getLogger (__name__ )
1313
@@ -285,25 +285,13 @@ class WorklistItemNotFoundError(Exception):
285285 pass
286286
287287
288- class InvalidStatusTransitionError (Exception ):
289- """Raised when a requested status transition is not permitted."""
290-
291- pass
292-
293-
294288class WorklistItemExistsError (Exception ):
295289 """Raised when a worklist item with the same accession number already exists."""
296290
297291 pass
298292
299293
300294class MWLStorage (Storage ):
301- _STATUS_TRANSITIONS : dict [MWLStatus , MWLStatus ] = {
302- MWLStatus .IN_PROGRESS : MWLStatus .SCHEDULED ,
303- MWLStatus .COMPLETED : MWLStatus .IN_PROGRESS ,
304- MWLStatus .DISCONTINUED : MWLStatus .IN_PROGRESS ,
305- }
306-
307295 def __init__ (self , db_path : str = "/var/lib/pacs/worklist.db" ):
308296 """
309297 Initialize Worklist storage.
@@ -481,14 +469,8 @@ def update_status(
481469
482470 Returns:
483471 source_message_id if item was updated, None if not found
484-
485- Raises:
486- InvalidStatusTransitionError: If the transition is not permitted
487472 """
488- target = MWLStatus (status )
489- if target not in self ._STATUS_TRANSITIONS :
490- raise InvalidStatusTransitionError (f"Cannot transition to '{ status } '" )
491- from_status = self ._STATUS_TRANSITIONS [target ]
473+ from_status , to_status = MWLStatusManager .transition_for (status )
492474
493475 with self ._get_connection () as conn :
494476 cursor = conn .execute (
@@ -500,7 +482,7 @@ def update_status(
500482 WHERE accession_number = ?
501483 AND status = ?
502484 """ ,
503- (status , mpps_instance_uid , accession_number , from_status .value ),
485+ (to_status . value , mpps_instance_uid , accession_number , from_status .value ),
504486 )
505487 conn .commit ()
506488
0 commit comments