Skip to content

Send Worklist to ultrasound device #909

@Karam897

Description

@Karam897

Hello everyone,
I want to send a worklist to the ultrasound machine, and I prepare my server as C-FIND SCP to respond to the medical device with the worklist, but I want to make sure that the code does not contain any errors and whether it meets all the requirements
@scaramallion
I hope you can help me with this
Thanks to everyone

from pydicom import dcmread
import os
from pydicom.dataset import Dataset
from pynetdicom import AE, evt,debug_logger
from pynetdicom.sop_class import ModalityWorklistInformationFind

debug_logger()

def handle_find(event):
    ds = event.identifier
    fdir = "C:\\Users\\TOPTECH\\Desktop\\dicom"

    # Import stored Worklist Instances
    instances = []
    for fpath in os.listdir(fdir):
        instances.append(dcmread(os.path.join(fdir, fpath)))

    # Check if QueryRetrieveLevel is WORKLIST
    if ds.QueryRetrieveLevel == 'WORKLIST':
        # Filter instances based on Patient ID
        matching = [instance for instance in instances if instance.PatientID == ds.PatientID]
    else:
        yield 0xC000, None
        return

    for instance in matching:
        if event.is_cancelled:
            yield (0xFE00, None)
            return

        identifier = Dataset()

        identifier.PatientName = instance.PatientName
        identifier.PatientID = instance.PatientID
        identifier.PatientAge = instance.PatientAge
        identifier.StudyDate = instance.StudyDate
        identifier.PatientSex = instance.PatientSex
        identifier.InstitutionName = instance.InstitutionName
        identifier.StudyDescription = instance.StudyDescription
        identifier.PerformingPhysicianName = instance.PerformingPhysicianName
        identifier.AccessionNumber = instance.AccessionNumber
        identifier.PatientBirthDate = instance.PatientBirthDate




        identifier.QueryRetrieveLevel = ds.QueryRetrieveLevel

        # Pending
        yield (0xFF00, identifier)

handlers = [(evt.EVT_C_FIND, handle_find)]

ae = AE()

ae.add_supported_context(ModalityWorklistInformationFind)

ae.start_server(("127.0.0.1", 11112), evt_handlers=handlers)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions