Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.03.01
Implementing a C-STORE AddIn
  1. Start Visual Studio 2005.
  2. Choose File->New->Project from the menu.
  3. In the New Project dialog box, choose either "Visual C#" or "Visual Basic" in the Projects Type List, and choose " Class Library" in the Templates List.
  4. Type the project name as "SampleAddIn" in the Project Name field, and then choose OK. If desired, type a new location for your project or select a directory using the Browse button, and then choose OK.
  5. In the "Solution Explorer" window right-click on the "References" folder, and select "Add Reference..." from the context menu. In the "Add Reference" dialog box, select the "Browse" tab and browse to the Leadtools for .NET "\LEAD Technologies\LEADTOOLS 16\Bin\DotNet\Win32" folder and select the following DLLS:
  6. [Showing a C# code example]

    
    Leadtools.dll
    Leadtools.Dicom.dll
    Leadtools.Dicom.AddIn.dll
    Microsoft.Practices.Unity
    
    Press the OK button to add the above DLLs to the application.
  7. In the "Solution Explorer" window right-click "SampleAddIn" and select Add->Class from the context menu. In the "Add New Item" dialog, type Module.cs in the "Name" field. Click "Add" to add the class to the project.
  8. Open the Module.cs file and add the following using statements:
  9. 
    using Leadtools.Dicom.AddIn;
    using Leadtools.Dicom.AddIn.Attributes;
    using System.IO;
    
  10. Define the module class as listed below;
  11. 
    public class Module : ModuleInit
    {
        private static string _ImageDirectory = string.Empty;
        public static string ImageDirectory
        {
            get
            {
                return _ImageDirectory;
            }
        }
    
    public override void Load(string ServiceDirectory, string DisplayName)
            {
                string dir = ServiceDirectory + @"\Images\";
    
                 if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                _ImageDirectory = dir;
            }
    }	
    
    When this addin loads, the Load function is called by the LEADTOOLS PACS Framework. This class checks for the Images directory. If the directory does not exist it is created by the addin.
  12. In the "Solution Explorer" window right-click Class1.cs and select Rename from the context menu. Type CStoreAddIn.cs and press Enter.
  13. Open the CStoreAddIn.cs file and add the following using statements;
  14. 
    using Leadtools.Dicom;
    using Leadtools.Dicom.AddIn;
    using Leadtools.Dicom.AddIn.Interfaces;
    using Microsoft.Practices.Unity;
    
  15. Add IProcessCStore to the CStoreAddIn class derivation list. Your class should look like the following;
  16. 
    public class CStoreAddIn : IProcessCStore
    {
    }	
    
  17. Right-click on IProcessCStore and select "Implement Inteface->Implement Interface" from the context menu. Your class should now look as follows;
  18. 
    [DicomAddInAttribute("CStore","1.0.0.0",Description="DICOM Storage",Author="")]
    public class CStoreAddIn : IProcessCStore
    {
        #region IProcessCStore Members
    
        public DicomCommandStatusType OnStore(DicomClient Client, byte PresentationId, 
        int MessageId, 
        string AffectedClass, 
        string Instance, 
        DicomCommandPriorityType Priority, 
        string MoveAE, 
        int MoveMessageId, 
    	 DicomDataSet Request)
        {
            throw new NotImplementedException();
        }
    
        #endregion
    
        #region IProcessBreak Members
    
        public void Break(BreakType type)
        {
            throw new NotImplementedException();
        }
    
        #endregion
    }
    
    
  19. Add the following to the top of the CStoreAddIn class.
  20. 
    private IServiceLog _ServiceLog;
    [Dependency]
    public IServiceLog ServiceLog
    {
        set
        {
            _ServiceLog = value;
        }
    }	
    
    This code automatically adds the IServiceLog implementation to your class when it is created. This allows you to log any error to the service log.
  21. To tell the server what we are interested in, we need to specify PresentationContextAttributes for the OnStore method. This will allow the server to build an association for use when a client connections. For this example we will only store CT images. Thus we need to enter the following attributes for the OnStore method:
  22. 
    [PresentationContext(DicomUidType.CTImageStorage, 
    DicomUidType.ImplicitVRLittleEndian,
    DicomUidType.JPEG2000,
    DicomUidType.JPEG2000LosslessOnly,
    DicomUidType.JPEGBaseline1,
    DicomUidType.JPEGExtended2_4,
    DicomUidType.ExplicitVRBigEndian,
    DicomUidType.ExplicitVRLittleEndian,
    DicomUidType.JPEGLosslessNonhier14,                                                 
    DicomUidType.JPEGLosslessNonhier14B)]
    
    public DicomCommandStatusType OnStore(DicomClient Client, 
    byte PresentationId,
    int MessageId, 
    string AffectedClass, 
    string Instance, 
    DicomCommandPriorityType Priority, 
    string MoveAE,
    int MoveMessageId, 
    DicomDataSet Request)
    
    This makes it possible to store CT images with the above transfer syntaxes.
  23. Add the code to the OnStore method to save the image to disk. Your OnStore method should look like the following:
  24. 
    public DicomCommandStatusType OnStore(DicomClient Client, byte PresentationId, 
    int MessageId, 
    string AffectedClass, 
    string Instance,
    DicomCommandPriorityType Priority, 
    string MoveAE,
    int MoveMessageId, 
    DicomDataSet Request)
    {
        DicomCommandStatusType status = DicomCommandStatusType.Success;
        try
        {
            if(Request!=null)
            {
                string sop = Request.GetValue(DicomTag.SOPInstanceUID, string.Empty);
                if (string.IsNullOrEmpty(sop))
                    status = DicomCommandStatusType.ProcessingFailure;
                else
                {
                    string file = string.Format("{0}{1}.dic", Module.ImageDirectory,sop);
                    Request.Save(file, DicomDataSetSaveFlags.None);
                }
            }
         }
         catch (Exception e)
         {
              _ServiceLog.Error(e.Message);
              status = DicomCommandStatusType.ProcessingFailure;
         }
         return status;
    }	
    
  25. Build the class library and take the output and put it in the AddIn directory of your previously created server.
  26. If the server is running stop it. Start the server.
  27. Connect and store a CT Image.
Leadtools.Dicom.Scu requires a Medical toolkit license and unlock key. For more information, refer to: Imaging Pro/Document/Medical Features