pythondicompynetdicom

Why my DICOM MWL SCP only sends SUCCESS response without dataset?


I am trying to code a simple DICOM MWL Worklist SCP using pynetdicom. There is no example provided from the documentation besides saying its the same as C-FIND.

Below code only sends the status SUCCESS but the dataset/patient don't appear from list on testing MWL SCU. I am using miele-wl-scu to simulate modality to query the Worklist.

import pydicom

from pydicom.dataset import Dataset

from pydicom.uid import UID
from pynetdicom import AE, evt, debug_logger
from pynetdicom.sop_class import ModalityWorklistInformationFind

debug_logger()

def on_c_find(dataset, context= None, info= None):
    """Handle a C-FIND request event."""
    # Check if ScheduledProcedureStepSequence exists        
    
    # Create the response dataset
    identifier = Dataset()

    identifier.PatientName = 'Hahah'
    identifier.AccessionNumber = 'asa'
    identifier.RequestedProcedureDescription = 'asa'
    identifier.is_little_endian = True
    identifier.is_implicit_VR = True

    # Yield the response dataset
    yield (0x0000, identifier)  # Success        

def main():

    ae = AE()

    # Add supported presentation contexts
    ae.add_supported_context(ModalityWorklistInformationFind) # C FIND
    ae.add_supported_context(UID('1.2.840.10008.1.1')) # ECHO
    
    # Set callback functions
    handlers = [(evt.EVT_C_FIND, on_c_find)]

    print("Starting DICOM Worklist Server...")

    # Start the DICOM server
    ae.start_server(('localhost', 11112), evt_handlers=handlers)
    
if __name__ == "__main__":
    main()

Solution

  • I never used the toolkit but I think following line of code is the problem:

    yield (0x0000, identifier)  # Success
    

    The 0x0000 is SUCCESS which should be sent at the end without any dataset (identifier in your case) attached to it. Before that, with each dataset, your status should be 0xFF00 which is PENDING.

    I am not aware about the syntax of programming language in question; correct me if I am wrong. Your code MAY be something like below:

    yield (0xFF00, identifier)  # Pending
    yield (0x0000, null)  # Success
    

    Please refer to this answer for more details. Following is the quote:

    MWL SCU (in your case - CR) initiates the query with the (optional) filters it suits. As usual, association happens and MWL SCP receives the MWL Request. It then fetch the data from its database matching the filters if any. It then sends one MWL Response for each row fetched from database, status for each response is PENDING. When all the rows are transferred, final SUCCESS response is sent. If no rows were found matching the filter, only final response is sent. If something goes wrong, proper failure response is sent. SCU then, sends the Release Request and on receiving Release Response, it closes the association.