ClearCanvas DICOM 开发系列 一

概述

C#开源的DICOM server.支持影像处理、影像归档、影像管理、影像传输和影像浏览功能。开源代码可学习地方很多。

 

官方网站:http://www.clearcanvas.ca

 

building ImageViewer 的代码,

1、打开ImageViewer.sln/Trunk/ImageViewer 用VS2008编译它.

2、运行ClearCanvas.Desktop.Executable Bin\debug 或Bin\Release下的项目.

 

 

  1. 编译通过ImageServer.sln/Trunk/ImageServer
  2. 修改 connectionStringsImageServer_Shreds_dist.config 的user 和 password 在你安装了ImageServer数据库后.
  3. 编辑/Trunk/ImageServer/Executable/Logging.config 的ConnectionString 的 user 和 password .
  4. 编译通过这个项目
  5. 开启 ClearCanvas.ImageServer.ShredHostService ,运行里面的wcf server,可以在Bin\Log 看到开启后的日志.

结果如下

image

 

运行 ClearCanvas.Desktop.Executable 的结果如下

image

 

 

测试往Server加入.dcm文件的代码如下

[TestFixture]
	public class ScuTests : AbstractTest
	{
		[TestFixtureSetUp]
		public void Init()
		{
			_serverType = TestTypes.Receive;
		}

		[TestFixtureTearDown]
		public void Cleanup()
		{
		}

		TestTypes _serverType;

		public IDicomServerHandler ServerHandlerCreator(DicomServer server, ServerAssociationParameters assoc)
		{
			return new ServerHandler(this, _serverType);
		}

		private StorageScu SetupScu()
		{
			StorageScu scu = new StorageScu("TestAe", "AssocTestServer", "localhost", 104);

			IList<DicomAttributeCollection> list = SetupMRSeries(4, 2, DicomUid.GenerateUid().UID);

			foreach (DicomAttributeCollection collection in list)
			{
				DicomFile file = new DicomFile("test", new DicomAttributeCollection(), collection);
				file.TransferSyntax = TransferSyntax.ExplicitVrLittleEndian;
				file.MediaStorageSopClassUid = SopClass.MrImageStorage.Uid;
				file.MediaStorageSopInstanceUid = collection[DicomTags.SopInstanceUid].ToString();

				scu.AddStorageInstance(new StorageInstance(file));
			}

			return scu;
		}

		[Test]
		public void ScuAbortTest()
		{
			int port = 2112;

			/* Setup the Server */
			ServerAssociationParameters serverParameters = new ServerAssociationParameters("AssocTestServer", new IPEndPoint(IPAddress.Any, port));
			byte pcid = serverParameters.AddPresentationContext(SopClass.MrImageStorage);
			serverParameters.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrLittleEndian);
			serverParameters.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrBigEndian);
			serverParameters.AddTransferSyntax(pcid, TransferSyntax.ImplicitVrLittleEndian);

			_serverType = TestTypes.Receive;
			DicomServer.StartListening(serverParameters, ServerHandlerCreator);

			StorageScu scu = SetupScu();

			IList<DicomAttributeCollection> list = SetupMRSeries(4, 2, DicomUid.GenerateUid().UID);

			foreach (DicomAttributeCollection collection in list)
			{
				DicomFile file = new DicomFile("test",new DicomAttributeCollection(),collection );
				file.TransferSyntax = TransferSyntax.ExplicitVrLittleEndian;
				file.MediaStorageSopClassUid = SopClass.MrImageStorage.Uid;
				file.MediaStorageSopInstanceUid = collection[DicomTags.SopInstanceUid].ToString();

				scu.AddStorageInstance(new StorageInstance(file));
			}

			scu.ImageStoreCompleted += delegate(object o, StorageInstance instance)
			                           	{
											// Test abort
			                           		scu.Abort();
			                           	};

			scu.Send();
			scu.Join();

			Assert.AreEqual(scu.Status, ScuOperationStatus.NetworkError);

			// StopListening
			DicomServer.StopListening(serverParameters);
		}
	}

 

 

 

如果直接是filePath的话也可以这样

 

    public class ImageStoreDAL
    {
        private ConnectModel _connectModel;

        public ImageStoreDAL(ConnectModel connectModel)
        {
            _connectModel = connectModel;
        }

        public ConnectModel ConnectModelInstance
        {
            get { return _connectModel; }
            set { _connectModel = value; }
        }

        private StorageScu SetupScu(string filePath)
        {
            StorageScu scu = new StorageScu(_connectModel.ClientAETitle, _connectModel.RemoteAE, _connectModel.RemoteHost, _connectModel.RemotePort);
            DicomFile file = new DicomFile(filePath);
            scu.AddStorageInstance(new StorageInstance(file));
            return scu;
        }

        public ScuOperationStatus ImageStoreByFilePath(string filePath)
        {
            StorageScu scu = SetupScu(filePath);
            scu.Send();
            return scu.Status;
        }
    }

 

 

欢迎各位参与讨论,如果觉得对你有帮助,请点击image    推荐下,万分谢谢.

作者:spring yang

出处:http://www.cnblogs.com/springyangwc/

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

posted @ 2012-02-28 19:27  spring yang  阅读(9492)  评论(8编辑  收藏  举报