当前位置: 首页 > 工具软件 > WorkList > 使用案例 >

DICOM学习(3)——python实现worklist获取

淳于昊然
2023-12-01

     这里使用的仍然是pydicom和pynetdicom模块,在使用前需安装。

思路:首先初始化AE作为SCP,并创建数据集dataset,dataset中可以设定具体tag的值,此处可根据需要自行设定。然后和服务端SCU连接,用send_c_find来查询worklist,query_model为“W”表示"1.2.840.10008.5.1.4.31",即 “Modality Worklist Information - FIND”。Worklist 其实就是一个 C-Find 请求,不过这个 C-Find 请求指定了 SOP Class UID 为 【1.2.840.10008.5.1.4.31】。

 

#coding=utf-8
from pydicom.dataset import Dataset
from pydicom.uid import (
ImplicitVRLittleEndian,
ExplicitVRLittleEndian,
ExplicitVRBigEndian)
from pynetdicom import AE
from pynetdicom.sop_class import PatientRootQueryRetrieveInformationModelFind
from pynetdicom.sop_class import BasicWorklistManagementServiceClass
from pynetdicom import AE, BasicWorklistManagementPresentationContexts
# Initialise the Application Entity
ae = AE(ae_title=b'WHTM-116')
#VerificationSOPClas'1.2.840.10008.3.1.1.1'#
ae.add_requested_context('1.2.840.10008.5.1.4.31',
 [ImplicitVRLittleEndian,
  ExplicitVRLittleEndian,
ExplicitVRBigEndian])

# Create our Identifier (query) dataset
ds = Dataset()
ds.PatientName = ''
#ds.PatientID ='2019052700000014'
ds.ScheduledProcedureStepStartDate = "20190526"

print(ds)
# Associate with peer AE at IP 127.0.0.1 and port 11112
assoc = ae.associate('10.3.2.85',3321,ae_title=b'WORKLISTSERVER')

if assoc.is_established:
    # Use the C-FIND service to send the identifier
    responses = assoc.send_c_find(ds , msg_id=1, priority=2,query_model='W')
    for (status, identifier) in responses:
        if status:
            print('C-FIND query status: 0x{0:04x}'.format(status.Status))

            # If the status is 'Pending' then identifier is the C-FIND response
            if status.Status in (0xFF00, 0xFF01):
                print(identifier)
        else:
            print('Connection timed out, was aborted or received invalid response')

     # Release the association
    assoc.release()
else:
    print('Association rejected, aborted or never connected')

 类似资料: