Пример #1
0
        public void CreateFilmBoxList(PeerNode peer, Core.ICommunicationProxy proxy, List <CardModel> cardList)
        {
            try
            {
                Logger.LogFuncUp();
                var patient = new Patient();
                //Job Info Title
                CurrentPeer = peer;
                var cellModels = FilmPageModel.CellModels.ToList();
                patient.PatientAge  = string.Join(";", cellModels.Select(c => c.PatientAge).Where(s => !string.IsNullOrWhiteSpace(s)).Distinct());
                patient.PatientID   = string.Join(";", cellModels.Select(c => c.PatientId).Where(s => !string.IsNullOrWhiteSpace(s)).Distinct());
                patient.PatientName = string.Join(";", cellModels.Select(c => c.PatientsName).Where(s => !string.IsNullOrWhiteSpace(s)).Distinct());
                patient.PatientSex  = string.Join(";", cellModels.Select(c => c.PatientsSex).Where(s => !string.IsNullOrWhiteSpace(s)).Distinct());
                patient.StudyID     = string.Join(";", cellModels.Select(c => c.StudyId).Where(s => !string.IsNullOrWhiteSpace(s)).Distinct());
                CurrentPatient      = patient;

                //  var printSetting = new PrintSetting();

                PrintSetting.Copies               = uint.Parse(PrinterSettingInfoModel.CurrCopyCount);
                PrintSetting.FilmDestination      = this.PrinterSettingInfoModel.CurrFilmDestination;
                PrintSetting.FilmingDateTime      = DateTime.Now;
                PrintSetting.IfSaveElectronicFilm = bool.Parse(this.PrinterSettingInfoModel.IfSave);
                PrintSetting.MediaType            = this.PrinterSettingInfoModel.CurrMediumType;
                PrintSetting.Priority             = PRINT_PRIORITY.MEDIUM;
                PrintSetting.IfColorPrint         = bool.Parse(this.PrinterSettingInfoModel.IfColorPrint);
                var filmPageModel = FilmPageModel;

                var filmBox = new FilmingPrintJob.Types.FilmBox.Builder();

                var dicomFilePath       = Widget.CreatePrintImageFullPath(0, 0);
                var dicomConvertorProxy = McsfDicomConvertorProxyFactory.Instance().CreateDicomConvertorProxy();

                dicomConvertorProxy.SaveFile(filmPageModel.EFilmModel.DataHeaderForPrint, dicomFilePath, proxy);

                var imageBoxForPrint = new FilmingPrintJob.Types.ImageBox.Builder {
                    ImagePath = dicomFilePath
                };                                                                                              //{ ImagePath = filmPageModel.EFilmModel.EFilmFilePath };
                filmBox.AddImageBox(imageBoxForPrint);
                filmBox.FilmSize         = this.PrinterSettingInfoModel.CurrFilmSize;
                filmBox.Orientation      = this.PrinterSettingInfoModel.CurrOrientation == "0" ? FilmingPrintJob.Types.Orientation.PORTRAIT : FilmingPrintJob.Types.Orientation.LANDSCAPE;
                filmBox.Layout           = "STANDARD\\1,1";
                filmBox.PatientName      = filmPageModel.PageTitleInfoModel.PatientName;
                filmBox.StudyInstanceUid = string.Join(";", filmPageModel.CellModels.Select(c => c.StudyInstanceUid).Where(s => !string.IsNullOrWhiteSpace(s)).Distinct());

                //fill sopinstance list  for print status updating
                var sopInstanceUids = filmPageModel.CellModels.Select(c => c.SopUid).Distinct();

                foreach (var uid in sopInstanceUids)
                {
                    var imageBoxForPrintStatusUpdating = new FilmingPrintJob.Types.ImageBox.Builder {
                        OriginSOPInstanceUID = uid
                    };
                    filmBox.AddImageBox(imageBoxForPrintStatusUpdating);
                }

                //fill seriesUid list for print status updating
                var seriesUids = filmPageModel.CellModels.Select(c => c.SeriesUid).Distinct().Where(s => !string.IsNullOrWhiteSpace(s));
                filmBox.AddRangeSeriesInstanceUidList(seriesUids);

                filmBoxList.Add(filmBox);

                Logger.LogFuncDown();
            }
            catch (Exception ex)
            {
                Logger.LogFuncException(ex.Message + ex.StackTrace);
            }
        }
Пример #2
0
        /// <summary>
        /// after call Set* methods init instance, then call this
        /// function to create a ProtoBuffer serialized object
        /// </summary>
        /// <returns>
        /// a serialized filming job instance
        /// if there is an exception, return null
        /// </returns>
        byte[] CreateFilmingJobInstance(bool withAnnotations)
        {
            Logger.LogFuncUp();
            byte[] serializedJob = null;
            try
            {
                Logger.LogFuncUp("Is AutoFilming : " + withAnnotations.ToString());

                FilmingPrintJob         filmingPrintJob        = new FilmingPrintJob();
                FilmingPrintJob.Builder filmingPrintJobBuilder = new FilmingPrintJob.Builder();

                filmingPrintJobBuilder.SetPrinterAE(_printerAE);
                filmingPrintJobBuilder.SetOurAE(_ourAE);
                filmingPrintJobBuilder.SetPrinterIP(_printerIP);
                filmingPrintJobBuilder.SetPort(_printerPort);

                filmingPrintJobBuilder.SetPrintPriority((FilmingPrintJob.Types.PrintPriority)_printPriority);
                filmingPrintJobBuilder.SetPrintTiming(FilmingPrintJob.Types.PrintTiming.IMMEDIATELY);

                filmingPrintJobBuilder.SetPatientId(_patientID);
                filmingPrintJobBuilder.SetPatientName(_patientName);
                filmingPrintJobBuilder.SetPatientSex(_patientSex);
                filmingPrintJobBuilder.SetPatientAge(_patientAge);
                filmingPrintJobBuilder.SetOperatorName(_operatorName);
                filmingPrintJobBuilder.SetAccessionNo(_accessionNo);
                filmingPrintJobBuilder.SetStudyId(_studyID);

                filmingPrintJobBuilder.SetCopies((int)_copies);

                filmingPrintJobBuilder.SetFilmingDate(DateTime.Now.ToShortDateString());
                filmingPrintJobBuilder.SetFilmingTime(DateTime.Now.ToShortTimeString());

                {//DR Filming : Set Medium Type,  FilmDestination
                    var peerNodes = Printers.Instance.PeerNodes;
                    var peerNode  = peerNodes.FirstOrDefault(node => node.PeerAE == _printerAE);
                    if (peerNode != null)
                    {
                        var mediumType = peerNode.SupportMediumTypeList.FirstOrDefault(m => !string.IsNullOrWhiteSpace(m.ToString()));
                        if (mediumType != null)
                        {
                            filmingPrintJobBuilder.SetMediaType(mediumType.ToString());
                            Logger.Instance.LogDevInfo("[XR Print Parameter][MediumType]" + mediumType.ToString());
                        }

                        var filmDestination =
                            peerNode.SupportFilmDestinationList.FirstOrDefault(
                                m => !string.IsNullOrWhiteSpace(m.ToString()));
                        if (filmDestination != null)
                        {
                            filmingPrintJobBuilder.SetFilmDestination(filmDestination.ToString());
                            Logger.Instance.LogDevInfo("[XR Print Parameter][FilmDestination]" + filmDestination.ToString());
                        }
                    }
                }

                //the total image of per sheet
                int iSheetCount = 0;
                //the total image of this print job
                int iTotalImage = _dicomFilePathList.Count;

                iSheetCount = (int)Math.Ceiling((0.0 + iTotalImage) / _sheetImageCount);

                for (int i = 0, iCurrentIndex = 0; i < iSheetCount; i++)
                {
                    FilmingPrintJob.Types.FilmBox.Builder filmBoxBuilder = new FilmingPrintJob.Types.FilmBox.Builder();
                    if (FilmSize != null)
                    {
                        filmBoxBuilder.SetFilmSize(FilmSize);
                    }

                    if (withAnnotations)
                    {
                        filmBoxBuilder.Orientation = (FilmingPrintJob.Types.Orientation)Printers.Instance.GetDefaultOrientation(_printerAE);
                        var defaultFilmSize = Printers.Instance.GetDefaultFilmSizeOf(_printerAE);
                        if (defaultFilmSize != null)
                        {
                            filmBoxBuilder.SetFilmSize(defaultFilmSize);
                            FilmSize = defaultFilmSize;
                        }

                        //----------------------------new code begin------------------------------------
                        filmImageList.Clear();
                        for (int j = 0; j < _sheetImageCount && iCurrentIndex < iTotalImage; j++, iCurrentIndex++)
                        {
                            filmImageList.Add(_dicomFilePathList[iCurrentIndex]);
                        }

                        _efilmFullPath = Printers.Instance.PrintObjectStoragePath + "/" + DateTime.Now.Millisecond + ".dcm";

                        _dpi  = Printers.Instance.GetMaxDensityOf(_printerAE);
                        _size = ConvertFilmSizeFrom(FilmSize, _dpi);
                        if (_staThread == null)
                        {
                            _staThread = new Thread(new ThreadStart(new Action(() => SaveEFilm(_proxy, _ifSaveEFilm))));
                            _staThread.SetApartmentState(ApartmentState.STA);
                            _staThread.Start();
                        }

                        windowLockEvent.Set();
                        //Console.WriteLine("window lock set");

                        //Console.WriteLine("job lock: wait image burnt");
                        Logger.LogWarning("Waiting for film burning (milliseconds): " + _timeOfWaitingForFilmBurning);
                        lockEvent.WaitOne(millisecondsTimeout: _timeOfWaitingForFilmBurning);                             //first time: 7000, waiting for dll loaded
                        _timeOfWaitingForFilmBurning = MiscellaneousConfigureReader.Instance.TimeOfWaitingForFilmBurning; //later: 3000
                        lockEvent.Reset();
                        //t.Abort();
                        //Console.WriteLine("Job lock reset");

                        //Console.WriteLine("begin print");

                        filmBoxBuilder.SetLayout("STANDARD\\1,1");
                        filmBoxBuilder.SetOrientation((FilmingPrintJob.Types.Orientation)Orientation);

                        FilmingPrintJob.Types.ImageBox.Builder imageBoxBuilder = new FilmingPrintJob.Types.ImageBox.Builder();
                        if (_efilmOriginalSopInstanceUID == string.Empty)
                        {
                            Logger.LogError("can't get sopinstanceUID of image to be print, may be print failed");
                        }
                        imageBoxBuilder.SetOriginSOPInstanceUID(_efilmOriginalSopInstanceUID);
                        imageBoxBuilder.SetImagePath(_efilmFullPath);
                        filmBoxBuilder.AddImageBox(imageBoxBuilder);
                        _studyInstanceUid = _efilmOriginalStudyInstanceUid;
                        //----------------------------new code end------------------------------------
                    }
                    else
                    {
                        //------------------------------------old code begin---------------------------------
                        filmBoxBuilder.SetLayout(_layout);
                        filmBoxBuilder.SetLutFilePath(_lutFile);
                        filmBoxBuilder.SetOrientation((FilmingPrintJob.Types.Orientation)Orientation);

                        for (int j = 0; j < _sheetImageCount && iCurrentIndex < iTotalImage; j++, iCurrentIndex++)
                        {
                            FilmingPrintJob.Types.ImageBox.Builder imageBoxBuilder = new FilmingPrintJob.Types.ImageBox.Builder();
                            imageBoxBuilder.SetImagePath(_dicomFilePathList[iCurrentIndex]);
                            filmBoxBuilder.AddImageBox(imageBoxBuilder);
                        }
                        //------------------------------------old code end---------------------------------
                    }


                    //for update image print status

                    filmBoxBuilder.StudyInstanceUid = _studyInstanceUid;

                    foreach (var imageUID in _originalImageUIDList)
                    {
                        if (string.IsNullOrEmpty(imageUID))
                        {
                            continue;
                        }
                        var originalImageBox = new FilmingPrintJob.Types.ImageBox.Builder();
                        originalImageBox.OriginSOPInstanceUID = imageUID;

                        filmBoxBuilder.AddImageBox(originalImageBox);
                    }

                    filmingPrintJobBuilder.AddFilmBox(filmBoxBuilder);
                }

                FilmingJobStatus.Builder filmingJobStatusBuilder = new FilmingJobStatus.Builder();
                filmingJobStatusBuilder.SetJobStatus(JobStatus.PENDING);
                filmingPrintJobBuilder.SetJobStatus(filmingJobStatusBuilder);

                filmingPrintJob = filmingPrintJobBuilder.Build();

                serializedJob = filmingPrintJob.ToByteArray();

                Logger.LogFuncDown();
            }
            catch (System.Exception ex)
            {
                Logger.LogFuncException(ex.Message + ex.StackTrace);
                serializedJob = null;
                throw;
            }

            return(serializedJob);
        }