Beispiel #1
0
        public void Print(IList <FilmBox> filmBoxList)
        {
            try
            {
                Status = PrintJobStatus.Pending;

                OnStatusUpdate("Preparing films for printing");

                var printJobDir = new System.IO.DirectoryInfo(FullPrintJobFolder);
                if (!printJobDir.Exists)
                {
                    printJobDir.Create();
                }

                DicomFile file;
                int       filmsCount = FilmBoxFolderList.Count;
                for (int i = 0; i < filmBoxList.Count; i++)
                {
                    var filmBox    = filmBoxList[i];
                    var filmBoxDir = printJobDir.CreateSubdirectory(string.Format("F{0:000000}", i + 1 + filmsCount));

                    file = new DicomFile(filmBox.FilmSession);
                    file.Save(string.Format(@"{0}\FilmSession.dcm", filmBoxDir.FullName));

                    FilmBoxFolderList.Add(filmBoxDir.Name);
                    filmBox.Save(filmBoxDir.FullName);
                }

                FilmSessionLabel = filmBoxList.First().FilmSession.FilmSessionLabel;

                var thread = new Thread(new ThreadStart(DoPrint));
                thread.Name         = string.Format("PrintJob {0}", SOPInstanceUID.UID);
                thread.IsBackground = true;
                thread.Start();
            }
            catch (Exception ex)
            {
                Error  = ex;
                Status = PrintJobStatus.Failure;
                OnStatusUpdate("Print failed");
                DeletePrintFolder();
            }
        }
Beispiel #2
0
        private void DoPrint(object arg)
        {
            try
            {
                Status = PrintJobStatus.Printing;
                OnStatusUpdate("Printing Started");

                //PrintThreadParameter printThreadParametr = (PrintThreadParameter)arg;
                IList <FilmBox> filmBoxList = (IList <FilmBox>)arg;

                var printJobDir = new System.IO.DirectoryInfo(FullPrintJobFolder);
                if (!printJobDir.Exists)
                {
                    printJobDir.Create();
                }

                DicomFile     file;
                List <string> autoIDList = new List <string>();
                for (int i = 0; i < filmBoxList.Count; i++)
                {
                    DicomUID autoID  = DicomUID.Generate();
                    var      filmBox = filmBoxList[i];
                    //One Film Box, One Folder
                    //var filmBoxDir = printJobDir.CreateSubdirectory(string.Format("F{0:000000}", i + 1 ));
                    var filmBoxDir = printJobDir.CreateSubdirectory(autoID.UID);

                    //Film Session Relative DICOM Tag
                    file = new DicomFile(filmBox.FilmSession);
                    file.Save(string.Format(@"{0}\FilmSession.dcm", filmBoxDir.FullName));

                    FilmBoxFolderList.Add(filmBoxDir.FullName);
                    List <string> ImageList = filmBox.SaveImage(filmBoxDir.FullName);


                    #region  PrintTask Content
                    PrintTask printTask = new PrintTask();
                    printTask.FilmUID          = autoID.UID;
                    printTask.CallingIPAddress = CallingIPAddress;
                    printTask.CallingAE        = CallingAETitle;
                    printTask.CalledAE         = CalledAETitle;

                    #region  Get Film Session Level DICOM Tag, Save in PrintTag Structure
                    printTask.NumberOfCopies = filmBox.FilmSession.NumberOfCopies;
                    printTask.MediumType     = filmBox.FilmSession.MediumType;
                    #endregion


                    #region  Get Film Box Level DICOM Tag, Save in PrintTag Structure
                    printTask.printUID           = SOPInstanceUID.UID;
                    printTask.BorderDensity      = filmBox.BorderDensity;
                    printTask.ImageDisplayFormat = filmBox.ImageDisplayFormat;
                    printTask.EmptyImageDensity  = filmBox.EmptyImageDensity;
                    printTask.FilmSizeID         = filmBox.FilmSizeID;
                    printTask.FilmOrienation     = filmBox.FilmOrienation;
                    printTask.MagnificationType  = filmBox.MagnificationType;
                    printTask.MaxDensity         = filmBox.MaxDensity;
                    printTask.MinDensity         = filmBox.MinDensity;
                    printTask.SmoothingType      = filmBox.SmoothingType;
                    printTask.Trim            = filmBox.Trim;
                    printTask.PresentationLut = filmBox.PresentationLut == null ? string.Empty : filmBox.PresentationLut.ToString();
                    #endregion

                    #endregion
                    int imageCount = ImageList.Count;
                    for (int imageIndex = 0; imageIndex < imageCount; imageIndex++)
                    {
                        #region PrintImage Content
                        PrintImage printImage = new PrintImage();
                        printImage.FilmUID          = autoID.UID;
                        printImage.ImageBoxPosition = imageIndex;
                        string imagePath = string.Format(@"{0}\I{1:000000}", filmBoxDir.FullName, imageIndex + 1);
                        printImage.DicomFilePath = imagePath + ".dcm";
                        //Save into Table T_PrintTag
                        if (printImage.SaveToDB() == false)
                        {
                            Log.Error("Print Job {0} FAIL: {1}", SOPInstanceUID.UID.Split('.').Last(), "Save PrintImage to DB Failed");
                        }
                        #endregion
                    }

                    int index = 0;
                    foreach (var item in filmBox.BasicImageBoxes)
                    {
                        if (item != null && item.ImageSequence != null && item.ImageSequence.Contains(DicomTag.PixelData))
                        {
                            try
                            {
                                var image = new DicomImage(item.ImageSequence);
                                image.RenderImage().AsBitmap().Save(ImageList[index]);
                                index++;
                            }
                            finally
                            {
                            }
                        }
                    }

                    //Parse DICOM File and render into Memory As image
                    var combineJpgFile = string.Format(@"{0}\{1}" + ".jpg", FilmBoxFolderList[i], autoID.UID);
                    int row = 0, column = 0;
                    GetDisplayFormat(printTask.ImageDisplayFormat, ref row, ref column);
                    CombineImages(ImageList, combineJpgFile, row, column);

                    printTask.JpgFilmPath = combineJpgFile;
                    //Save into Table T_PrintTag
                    if (printTask.SaveToDB() == false)
                    {
                        Log.Error("Print Job {0} FAIL: {1}", SOPInstanceUID.UID.Split('.').Last(), "Save printTask to DB Failed");
                    }

                    autoIDList.Add(autoID.UID);
                }

                Status = PrintJobStatus.Done;
                OnStatusUpdate("Printing Done");

                foreach (var autoIDItem in autoIDList)
                {
                    ClientStart(autoIDItem, this.CallingIPAddress, this.CallingAETitle);
                }
            }
            catch (Exception ex)
            {
                Status = PrintJobStatus.Failure;
                OnStatusUpdate("Printing failed");
                Log.Error("Print Job {0} FAIL: {1}", SOPInstanceUID.UID.Split('.').Last(), ex.Message);
            }
            finally
            {
            }
        }