leadtools提供了封装后的dicom插件,可以非常方便的开发出dicom 通讯部分的组件,本篇博客讲解如何使用相关的接口进行代码编写,实现Dicom协议中的查询操作。

 

1.用vs2015创建一个winform项目,引用下面的dll,并在代码里引用

using Leadtools;
using Leadtools.Dicom;
using Leadtools.Dicom.Scu.Common;
using Leadtools.Dicom.Scu;
using Leadtools.MedicalViewer;
using System.Net;
using System.IO;

 

2.创建下面的对象

// CFind highlevel 对象
        private QueryRetrieveScu _cfind;
        private DicomScp _server = new DicomScp();
        private TreeNode _currentnode;
        private MedicalViewer _viewer;

 

3.初始化服务器和客户端参数,

本次用的服务器即是开发包中运行pacs服务器设置程序后,创建的L19_PACS_SCP64

在查询过程中主要是使用MatchStudy和MatchSeries事件来获取相应的结果,使用Moved事件来接收传输过来的图片

private void initServer() {
            _server = new DicomScp();
            _server.AETitle = "L19_PACS_SCP64";
            _server.PeerAddress = IPAddress.Parse("10.32.1.75");
            _server.Port = 534;
            _server.Timeout = 30;
        }
private void initCfind()
        {
            _cfind = new QueryRetrieveScu();
            _cfind.AETitle = "L19_CLIENT64";
            _cfind.HostPort = 1030;

            //查询Study
            _cfind.MatchStudy += _cfind_MatchStudy;

            //查询Series
            _cfind.MatchSeries += _cfind_MatchSeries;

            //MOVE
            _cfind.Moved += _cfind_Moved;
        }
private void _cfind_MatchSeries(object sender, MatchEventArgs<Series> e)
        {
            TreeNode seriesnode = new TreeNode(e.Info.Date != null ? e.Info.Date.Value.ToShortDateString() : "未知");
            seriesnode.Tag = e.Info;

            _currentnode.Nodes.Add(seriesnode);
        }

        private void _cfind_MatchStudy(object sender, MatchEventArgs<Study> e)
        {
            TreeNode studynode = new TreeNode(e.Info.Patient.Name.Full);
            studynode.Tag = e.Info;
            querytree.Nodes.Add(studynode);
        }
public delegate void ReceiveFindMovedDelegate(Leadtools.Dicom.Scu.Common.MovedEventArgs e);
        private void _cfind_Moved(object sender, MovedEventArgs e)
        {
            ReceiveFindMoved(e);
        }
        //加载图片
        void ReceiveFindMoved(MovedEventArgs e) {
            if (InvokeRequired)
            {
                Invoke(new ReceiveFindMovedDelegate(ReceiveFindMoved), e);
            }
            else
            {
                ImageInstance instance = e.Instance as ImageInstance;

                int cols = 1;
                int rows = 1;
                RasterImage ri = instance.Images;


                if (instance != null && instance.Images != null)
                {
                    int pageCount = instance.Images.PageCount;
                    if (pageCount > 1)
                    {
                        // Display at most 6 x 6 (36) frames
                        if (pageCount >= 36)
                        {
                            cols = 6;
                            rows = 6;
                        }
                        else
                        {
                            cols = (int)Math.Floor(Math.Sqrt(pageCount));
                            rows = (int)Math.Ceiling((double)pageCount / cols);
                        }
                    }

                    MedicalViewerMultiCell m = GetCell();

                    m.Rows = rows;
                    m.Columns = cols;

                    if (m.Image != null)
                    {
                        for (int pageIndex = 0; pageIndex < instance.Images.PageCount; pageIndex++)
                        {
                            instance.Images.Page = pageIndex + 1;

                            try
                            {
                                m.Image.AddPage(instance.Images);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                        }
                    }
                    else
                    {
                        m.Image = instance.Images;
                    }

                    if (pageCount > 1)
                    {
                        m.SetTag(0, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.Frame);
                        m.ShowTags = true;
                    }
                    m.SetTag(1, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.WindowLevelData);

                    // Give the medical viewer cell the focus
                    if (_viewer.Cells.Count > 0 &&
                          _viewer.Cells[0] is MedicalViewerBaseCell)
                    {
                        (_viewer.Cells[0] as MedicalViewerBaseCell).Selected = true;
                    }

                    m.SetScaleMode(MedicalViewerScaleMode.Fit);
                }
            }

        }

 


初始化完成后即可使用下面的命令来查询

查询study

_cfind.Find(_server, new FindQuery());

 

查询特定study的series

FindQuery query = new FindQuery();
Study study = td.Tag as Study;
query.QueryLevel = QueryLevel.Series;
query.PatientId = study.Patient.Id;
query.StudyInstanceUID = study.InstanceUID;
_cfind.Find(_server, query);

 

用Move方法检索图片,参数依次为服务器对象,客户端aetitle,Study InstanceUID,Series InstanceUID

_cfind.Move(_server, _cfind.AETitle, (e.Node.Parent.Tag as Study).InstanceUID, (e.Node.Tag as Series).InstanceUID);

 

下面是对应的项目代码,Store和Find功能都包含在里面

代码链接