コード例 #1
0
        //string study, string modality, out string seriesUID, bool bSaveEFilm
        private string CreateSeries(EFilmModel eFilmModel)
        {
            var studyInstanceUid = eFilmModel.StudyInstanceUid;

            Series series = DBWrapperHelper.DBWrapper.CreateSeries();

            var uidManager = McsfDatabaseDicomUIDManagerFactory.Instance().CreateUIDManager();

            series.SeriesInstanceUID  = uidManager.CreateSeriesUID("");//eFilmModel.EFilmSeriesUid;
            series.StudyInstanceUIDFk = studyInstanceUid;
            series.Modality           = eFilmModel.EFilmModality;
            // new seriesNumber equals the max seriesNumber of exist series add one
            series.SeriesNumber = Convert.ToInt32(GetSerieNumber(studyInstanceUid)) + 1;
            series.ReconResult  = 2; //代表重建已完成
            if (studyInstanceUid == "****")
            {
                return(string.Empty);                            //FilmingHelper.StarsString) return;
            }
            //check whether disk space is enough
            ICommunicationProxy pCommProxy = Containee.Main.GetCommunicationProxy();
            var target = new SystemResManagerProxy(pCommProxy);

            if (!target.HaveEnoughSpace())
            {
                Logger.LogError("No enough disk space, so Electronic Image Series will not be created");
                Containee.Main.ShowStatusError("UID_Filming_No_Enough_Disk_Space_To_Create_Electronic_Image_Series");
                return(string.Empty);
            }

            series.Save();
            return(series.SeriesInstanceUID);
        }
コード例 #2
0
        public void Print(params DicomAttributeCollection[] dataHeaders)
        {
            try
            {
                this.LogDevInfo("Begin to print DataHeaders");

                var uidManager = McsfDatabaseDicomUIDManagerFactory.Instance().CreateUIDManager();
                var jobID      = uidManager.CreateSeriesUID(string.Empty);

                int dataHeaderIndex = 1;
                int dataHeaderCount = dataHeaders.Length;
                foreach (var dataHeader in dataHeaders)
                {
                    string packetHeader = string.Join(CommunicationCommandID.ParameterListSeparator, jobID,
                                                      dataHeaderIndex.ToString(), dataHeaderCount.ToString());
                    var packetHeaderBytes = Encoding.UTF8.GetBytes(string.Format("{0}{1}{2}", packetHeader, CommunicationCommandID.ParameterListSeparator, CommunicationCommandID.ParameterListSeparator));

                    //dataHeader.InsertElement(PacketHeaderTag, packetHeaderBytes);
                    //dataHeader.InsertElement((uint)Tag.SeriesInstanceUid, jobID);
                    //dataHeader.InsertElement((uint)Tag.InstanceNumber, dataHeaderIndex.ToString());
                    //dataHeader.InsertElement(PacketHeaderTag, dataHeaderCount.ToString());
                    //dataHeader.InsertElement(PacketHeaderTag, packetHeader);

                    byte[] serializedDataheader;
                    if (!dataHeader.Serialize(out serializedDataheader))
                    {
                        this.LogDevError(string.Format("Fail to serialize dataHeader [{0}]", dataHeaderIndex));
                        return;
                    }

                    byte[] serializedObject = MergeByteArray(packetHeaderBytes, serializedDataheader);

                    this.LogDevInfo(string.Format("Succeed to seriealize dataHeader [{0}]", dataHeaderIndex++));
                    _communicator.AsyncSendCommand(CommunicationCommandID.COMMAND_ID_FILMING_DATAHEADERS, CommunicationNode.FilmingService, serializedObject);
                    this.LogDevInfo(string.Format("Command [{0}] sent with a serialized dataHeader", CommunicationCommandID.COMMAND_ID_FILMING_DATAHEADER));
                }
            }
            catch (Exception e)
            {
                this.LogException(e);
            }
        }
コード例 #3
0
ファイル: CardModel.cs プロジェクト: whhub/Filming
        public static PeerNode CurrentPeer      = new PeerNode();                                                                    //当前打印端口
        #endregion



        #region [---Public Methods---]

        public bool DeserializedFromXml(byte[] contentsByte, XmlNode filmPageNode)
        {
            try
            {
                Logger.LogFuncUp();

                string contentsString = Encoding.UTF8.GetString(contentsByte);
                var    xDoc           = new XmlDocument();
                xDoc.LoadXml(contentsString);

                var rootNode = xDoc.DocumentElement;
                if (null == rootNode)
                {
                    Logger.LogWarning("[FilmingSerivceFE]No Card info for print");
                    return(false);
                }

                this.IsPrint = bool.Parse(rootNode.Attributes[OffScreenRenderXmlHelper.OPERATION].Value);

                var printerSettingNode = rootNode.SelectSingleNode(OffScreenRenderXmlHelper.PRINTER_SETTING_INFO);
                this.PrinterSettingInfoModel.DeserializedFromXml(printerSettingNode);

                var filmingPageTitleSettingNode = rootNode.SelectSingleNode(OffScreenRenderXmlHelper.FILMING_PAGE_TITLE_SETTING);
                this.PageTitleConfigInfoModel.DeserializedFromXml(filmingPageTitleSettingNode);

                //PageControl大小
                DisplayedFilmPageHeight = FilmingUtility.DisplayedFilmPageHeight;
                DisplayedFilmPageWidth  = FilmingUtility.DisplayedFilmPageWidth;
                var filmingPageSizeNode = rootNode.SelectSingleNode(OffScreenRenderXmlHelper.FILMING_PAGE_SIZE);
                Double.TryParse(OffScreenRenderXmlHelper.GetChildNodeValue(filmingPageSizeNode, OffScreenRenderXmlHelper.FILMING_PAGE_HEIGHT), out DisplayedFilmPageHeight);
                Double.TryParse(OffScreenRenderXmlHelper.GetChildNodeValue(filmingPageSizeNode, OffScreenRenderXmlHelper.FILMING_PAGE_WIDTH), out DisplayedFilmPageWidth);
                Double.TryParse(OffScreenRenderXmlHelper.GetChildNodeValue(filmingPageSizeNode, OffScreenRenderXmlHelper.FILMING_PAGE_VIEWER_HEIGHT), out DisplayedFilmPageViewerHeight);

                var allFilmPagesNode = rootNode.SelectSingleNode(OffScreenRenderXmlHelper.ALL_FILMING_PAGE_INFO);
                if (allFilmPagesNode == null)
                {
                    Logger.LogWarning("[FilmingSerivceFE]No Common Page info for print");
                    return(false);
                }

                //全局PeerNode
                var ae   = this.PrinterSettingInfoModel.CurrPrinterAE;
                var peer = new PeerNode();

                if (-1 == Printers.Instance.GetPacsNodeParametersByAE(ae, ref peer))
                {
                    Printers.Instance.ReloadPrintersConfig();
                    if (-1 == Printers.Instance.GetPacsNodeParametersByAE(ae, ref peer))
                    {
                        Logger.LogWarning("[FilmingSerivceFE]Can Not Find Printer:" + ae + " in Config File.");
                        if (IsPrint)
                        {
                            return(false);
                        }
                    }
                }
                this.PeerNode = peer;

                //全局SeriesUid
                var uidManager        = McsfDatabaseDicomUIDManagerFactory.Instance().CreateUIDManager();
                var allEFilmSeriesUid = uidManager.CreateSeriesUID("");

                //全局FilmSize
                AllFilmSize = Widget.ConvertFilmSizeFrom(this.PrinterSettingInfoModel.CurrFilmSize,
                                                         int.Parse(this.PrinterSettingInfoModel.CurrPrinterDPI),
                                                         this.PrinterSettingInfoModel.CurrOrientation);
                var lowPrecisionEFilmSize = Widget.ConvertFilmSizeFrom(this.PrinterSettingInfoModel.CurrFilmSize,
                                                                       96,
                                                                       this.PrinterSettingInfoModel.CurrOrientation);
                //全局操作方式
                var ifPrint = IsPrint;
                var ifSave  = !IsPrint || bool.Parse(PrinterSettingInfoModel.IfSave);


                //  foreach (XmlNode filmPageNode in allFilmPagesNode)
                {
                    var filmPage = new PageModel(this.PrinterSettingInfoModel);

                    var eFilmModel = new EFilmModel();
                    filmPage.EFilmModel = eFilmModel;

                    FilmPageModel = filmPage;
                    if (!filmPage.DeserializedFromXml(filmPageNode))
                    {
                        Logger.LogWarning("[FilmingSerivceFE]Fail to get page info of a film page");
                        return(false);
                    }

                    eFilmModel.EFilmSeriesUid        = allEFilmSeriesUid;
                    eFilmModel.FilmSize              = AllFilmSize;
                    eFilmModel.LowPrecisionEFilmSize = lowPrecisionEFilmSize;
                    eFilmModel.PeerNode              = this.PeerNode;
                    eFilmModel.PrintSettings         = this.PrinterSettingInfoModel;
                    eFilmModel.PageTitlePosition     = filmPage.PageTitleInfoModel.DisplayPosition;//  PageTitleConfigInfoModel.DisplayPosition;
                    eFilmModel.IfSaveEFilm           = ifSave;
                    eFilmModel.IfPrint = ifPrint;
                }

                Logger.LogFuncDown();
            }
            catch (Exception ex)
            {
                Logger.LogFuncException(ex.Message + ex.StackTrace);
                return(false);
            }

            return(true);
        }
コード例 #4
0
ファイル: MedViewerWindow.xaml.cs プロジェクト: whhub/Filming
        //public void SaveEfilm(string efilmFullPath, ref string efilmOriginalSopInstanceUID)
        //{
        //    efilmOriginalSopInstanceUID = string.Empty;

        //}

        public void SaveEfilm(string efilmFullPath, ref string efilmOriginalSopInstanceUID, ref string efilmOriginalStudyInstanceUid, bool ifSaveEFilm)
        {
            efilmOriginalSopInstanceUID = string.Empty;

            try
            {
                Logger.LogFuncUp();

                if (_dicomDataHeader == null)
                {
                    return;
                }

                var wrtBmp = RenderControlWriteableBitmap();

                if (wrtBmp == null)
                {
                    throw new ApplicationException("ViewerControl Writeable Bitmap Render failed.");
                }



                byte[] data = ProcessImage(wrtBmp);
                Console.WriteLine(Convert.ToString(wrtBmp.PixelWidth) + " ,,,,," + Convert.ToString(wrtBmp.PixelHeight));

                ////MedViewerLayoutCell layoutCell = medViewerControl.LayoutManager.RootCell;
                ////MedViewerControlCell cell = GetControlCell(layoutCell);


                var pixelHeightTag = new DicomAttributeUS(new DicomTag(Pipeline.Dictionary.Tag.Rows));
                pixelHeightTag.SetUInt16(0, Convert.ToUInt16(wrtBmp.PixelHeight));
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.Rows);
                _dicomDataHeader.AddDicomAttribute(pixelHeightTag);

                var pixelWidthTag = new DicomAttributeUS(new DicomTag(Pipeline.Dictionary.Tag.Columns));
                pixelWidthTag.SetUInt16(0, Convert.ToUInt16(wrtBmp.PixelWidth));
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.Columns);
                _dicomDataHeader.AddDicomAttribute(pixelWidthTag);

                var bitStoredTag = new DicomAttributeUS(new DicomTag(Pipeline.Dictionary.Tag.BitsStored));
                bitStoredTag.SetUInt16(0, 8);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.BitsStored);
                _dicomDataHeader.AddDicomAttribute(bitStoredTag);

                var bitAllocatedTag = new DicomAttributeUS(new DicomTag(Pipeline.Dictionary.Tag.BitsAllocated));
                bitAllocatedTag.SetUInt16(0, 8);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.BitsAllocated);
                _dicomDataHeader.AddDicomAttribute(bitAllocatedTag);

                var hightBitTag = new DicomAttributeUS(new DicomTag(Pipeline.Dictionary.Tag.HighBit));
                hightBitTag.SetUInt16(0, 7);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.HighBit);
                _dicomDataHeader.AddDicomAttribute(hightBitTag);

                var pixelRepresentationTag = new DicomAttributeUS(new DicomTag(Pipeline.Dictionary.Tag.PixelRepresentation));
                pixelRepresentationTag.SetUInt16(0, 0);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.PixelRepresentation);
                _dicomDataHeader.AddDicomAttribute(pixelRepresentationTag);

                var rescaleSlopeTag = new DicomAttributeDS(new DicomTag(Pipeline.Dictionary.Tag.RescaleSlope));
                rescaleSlopeTag.SetString(0, "1");
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.RescaleSlope);
                _dicomDataHeader.AddDicomAttribute(rescaleSlopeTag);

                var rescaleInterceptTag = new DicomAttributeDS(new DicomTag(Pipeline.Dictionary.Tag.RescaleIntercept));
                rescaleInterceptTag.SetString(0, "0");;
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.RescaleIntercept);
                _dicomDataHeader.AddDicomAttribute(rescaleInterceptTag);


                ////insert Photometric Interpretation //maybe can fix inverse problem
                //var photometricInterpretationTag = new DicomAttributeUS(new DicomTag(Pipeline.Dictionary.Tag.PhotometricInterpretation));
                //rescaleInterceptTag.SetString(0, "MONOCHROME2");
                ////_dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.PhotometricInterpretation);
                //_dicomDataHeader.AddDicomAttribute(photometricInterpretationTag);
                //insert Photometric Interpretation
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.PhotometricInterpretation);
                var photometricInterpretationTag = DicomAttribute.CreateAttribute(Pipeline.Dictionary.Tag.PhotometricInterpretation);
                if (!photometricInterpretationTag.SetString(0, "MONOCHROME2"))
                {
                    throw new Exception("Failed to Insert Columns to Data header");
                }
                _dicomDataHeader.AddDicomAttribute(photometricInterpretationTag);

                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.WindowWidth);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.WindowCenter);
                var windowWidthTag = new DicomAttributeDS(new DicomTag(Pipeline.Dictionary.Tag.WindowWidth));
                //var windowWidthTag = DicomAttribute.CreateAttribute(Pipeline.Dictionary.Tag.WindowWidth);
                windowWidthTag.SetString(0, "256");
                _dicomDataHeader.AddDicomAttribute(windowWidthTag);
                var windowCenterTag = new DicomAttributeDS(new DicomTag(Pipeline.Dictionary.Tag.WindowCenter));
                //var windowCenterTag = DicomAttribute.CreateAttribute(Pipeline.Dictionary.Tag.WindowCenter);
                windowCenterTag.SetString(0, "127");
                _dicomDataHeader.AddDicomAttribute(windowCenterTag);

                if (_dicomDataHeader.Contains(Pipeline.Dictionary.Tag.PixelData))
                {
                    _dicomDataHeader[Pipeline.Dictionary.Tag.PixelData].SetBytes(0, data);
                }
                else
                {
                    var pixelTag = new DicomAttributeOW(new DicomTag(Pipeline.Dictionary.Tag.PixelData));
                    pixelTag.SetBytes(0, data);
                    _dicomDataHeader.AddDicomAttribute(pixelTag);
                }
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.ShutterShape);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.ShutterLowerHorizontalEdge);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.ShutterRightVerticalEdge);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.ShutterLeftVerticalEdge);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.ShutterUpperHorizontalEdge);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.ImageHorizontalFlip);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.ImageRotation);
                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.SeriesNumber);
                //_dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.);
                //AssembleTag();

                var uidManager        = McsfDatabaseDicomUIDManagerFactory.Instance().CreateUIDManager();
                var seriesInstanceUid = uidManager.CreateSeriesUID("1", "2", ""); //seriesUID; //
                var imageUid          = uidManager.CreateImageUID("");

                //_dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.SeriesInstanceUid);
                //var seriesInstanceUidTag = new DicomAttributeUI(new DicomTag(Pipeline.Dictionary.Tag.SeriesInstanceUid));
                //seriesInstanceUidTag.SetString(0, seriesInstanceUid);
                //_dicomDataHeader.AddDicomAttribute(seriesInstanceUidTag);

                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.SOPInstanceUID);
                var sopInstanceUidTag = new DicomAttributeUI(new DicomTag(Pipeline.Dictionary.Tag.SOPInstanceUID));
                sopInstanceUidTag.SetString(0, imageUid);
                _dicomDataHeader.AddDicomAttribute(sopInstanceUidTag);

                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.ImageType);
                var imageTypeCollection = ("DERIVED\\SECONDARY\\DISPLAY\\FILMING\\EFILM").Split('\\');
                InsertStringArrayDicomElement(_dicomDataHeader, Pipeline.Dictionary.Tag.ImageType, imageTypeCollection);

                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.ConversionType);
                var cTypeTag = new DicomAttributeCS(new DicomTag(Pipeline.Dictionary.Tag.ConversionType));
                cTypeTag.SetString(0, "WSD");
                _dicomDataHeader.AddDicomAttribute(cTypeTag);

                _dicomDataHeader.RemoveDicomAttribute(Pipeline.Dictionary.Tag.SeriesDescription);
                var seriesDescriptionTag = new DicomAttributeLO(new DicomTag(Pipeline.Dictionary.Tag.SeriesDescription));
                seriesDescriptionTag.SetString(0, "Electronic film_" + DateTime.Now.ToString());
                _dicomDataHeader.AddDicomAttribute(seriesDescriptionTag);

                _dicomConvertorProxy.SaveFile(_dicomDataHeader, efilmFullPath, _proxy);

                var medViewerControlCell = medViewerControl.LayoutManager.ControlCells.FirstOrDefault();
                if (medViewerControlCell != null)
                {
                    var currentPage = medViewerControlCell.Image.CurrentPage;
                    efilmOriginalSopInstanceUID = currentPage.SOPInstanceUID;
                    var dicomHeader = currentPage.ImageHeader.DicomHeader;
                    if (dicomHeader.ContainsKey(ServiceTagName.StudyInstanceUID))
                    {
                        efilmOriginalStudyInstanceUid = dicomHeader[ServiceTagName.StudyInstanceUID];
                    }
                }

                if (!ifSaveEFilm)
                {
                    return;
                }
                CreateSeries(efilmOriginalStudyInstanceUid, seriesInstanceUid);
                SaveEFilmInCommonSave(seriesInstanceUid);

                Logger.LogFuncDown();
            }
            catch (Exception ex)
            {
                Logger.LogFuncException(ex.Message + ex.StackTrace);
            }
            finally
            {
                medViewerControl.RemoveAll();
            }
        }
コード例 #5
0
        //public DicomAttributeCollection AssembleSendData(byte[] imageData, double imageWidth, double imageHeight,
        //                                                 int filmPageIndex, bool ifSaveImageAsGreyScale = true)
        public DicomAttributeCollection AssembleSendData(byte[] imageData, EFilmModel dicomTags)
        {
            try
            {
                Logger.LogFuncUp();

                var dataHeader = new DicomAttributeCollection();

                #region DICOM File Meta Information
                //DICOM File Meta Information
                //string strLen = GetPatientInfo("PatientsBirthTime", string.Empty, string.Empty);
                //UInt32 nLen = Convert.ToUInt32(strLen);
                //DicomElementWidget.InsertUInt32DicomElement(dataHeader, Tag.FileMetaInformationGroupLength, nLen);
                //byte[] btVersion = new byte[1];
                //btVersion[0] = 55;
                //InsertBytesDicomElement(dataHeader, Tag.FileMetaInformationVersion, btVersion);
                //InsertUInt16DicomElement(dataHeader, Tag.MediaStorageSOPClassUID, 0);
                //InsertUInt16DicomElement(dataHeader, Tag.MediaStorageSOPInstanceUID, 0);
                //InsertUInt16DicomElement(dataHeader, Tag.TransferSyntaxUID, 0);//"1.2.840.10008.1.2.1"
                //InsertUInt16DicomElement(dataHeader, Tag.ImplementationClassUID, 0);
                //InsertStringDicomElement(dataHeader, Tag.ImplementationVersionName, string.Empty);
                InsertStringDicomElement(dataHeader, Tag.SpecificCharacterSet, "ISO.IR 192");         //中文字符集
                #endregion



                //Patient Module
                #region Patient Module
                InsertStringDicomElement(dataHeader, Tag.PatientsName, dicomTags.PatientName);              //患者姓名
                InsertStringDicomElement(dataHeader, Tag.PatientID, dicomTags.PatientId);                   //患者ID
                InsertStringDicomElement(dataHeader, Tag.PatientsBirthDate, dicomTags.PatientBirthDate);    //患者出生日期
                InsertStringDicomElement(dataHeader, Tag.PatientsSex, dicomTags.PatientSex);                //患者性别
                InsertStringDicomElement(dataHeader, Tag.PatientsBirthTime, dicomTags.PatientsBirthTime);   //患者出生时间
                InsertStringDicomElement(dataHeader, Tag.PatientComments, dicomTags.PatientComments);       //患者注释
                InsertStringDicomElement(dataHeader, Tag.PatientsAge, dicomTags.PatientsAge);               //患者年龄
                InsertStringDicomElement(dataHeader, Tag.PatientsSize, dicomTags.PatientsSize);             //患者身高
                InsertStringDicomElement(dataHeader, Tag.PatientsWeight, dicomTags.PatientsWeight);         //患者体重
                InsertStringDicomElement(dataHeader, Tag.Occupation, dicomTags.Occupation);                 //患者职业

                #endregion


                //General Study Module

                #region General Study Module
                InsertStringDicomElement(dataHeader, Tag.StudyInstanceUid, dicomTags.StudyInstanceUid);               //检查UID
                InsertStringDicomElement(dataHeader, Tag.StudyDate, dicomTags.StudyDate);                             //检查日期
                InsertStringDicomElement(dataHeader, Tag.StudyTime, dicomTags.StudyTime);                             //检查时间
                InsertStringDicomElement(dataHeader, Tag.ReferringPhysiciansName, dicomTags.ReferringPhysiciansName); //咨询医师姓名
                InsertStringDicomElement(dataHeader, Tag.AccessionNumber, dicomTags.AccessionNumber);                 //检查编号
                //InsertStringDicomElement(dataHeader, Tag.StudyDescription, dicomTags.StudyDescription);
                var now = DateTime.Now;
                InsertStringDicomElement(dataHeader, Tag.AcquisitionDate, now.Date.ToShortDateString());    //获取日期
                InsertStringDicomElement(dataHeader, Tag.AcquisitionTime, now.TimeOfDay.ToString());        //获取时间
                #endregion

                //General Series Module
                #region General Series Module
                InsertStringDicomElement(dataHeader, Tag.SeriesInstanceUid, dicomTags.EFilmSeriesUid);              //系列UID
                InsertStringDicomElement(dataHeader, Tag.SeriesNumber, GetSerieNumber(dicomTags.StudyInstanceUid)); //系列号 ??是否每张都去找数据库算一次??
                InsertStringDicomElement(dataHeader, Tag.SeriesDate, now.Date.ToShortDateString());                 //系列日期
                InsertStringDicomElement(dataHeader, Tag.SeriesTime, now.TimeOfDay.ToString());                     //系列时间

                string descreption = "Electronic film_" + string.Format("{0:yyyyMMddHHmmss}", DateTime.Now);        //系列描述
                InsertStringDicomElement(dataHeader, Tag.SeriesDescription, descreption);
                #endregion

                #region 患者病理相关
                //InsertStringDicomElement(dataHeader, Tag.ProtocolName, dicomTags.ProtocolName);           //协议名称
                InsertStringDicomElement(dataHeader, Tag.BodyPartExamined, dicomTags.BodyPartExamined);     //检查部位
                InsertStringDicomElement(dataHeader, Tag.PatientPosition, dicomTags.PatientPosition);       //病人进入设备体位
                #endregion

                //General Equipment Module
                #region General Equipment Module
                InsertStringDicomElement(dataHeader, Tag.Modality, dicomTags.EFilmModality);          //胶片设备类型
                InsertStringDicomElement(dataHeader, Tag.InstitutionName, dicomTags.InstitutionName); //医院信息
                InsertStringDicomElement(dataHeader, Tag.Manufacturer, dicomTags.Manufacturer);       //原图厂商信息
                #endregion


                #region SC Equipment Module
                //SC Equipment Module
                InsertStringDicomElement(dataHeader, Tag.ConversionType, "WSD");                                //转化类型,WSD:Workstation
                InsertStringDicomElement(dataHeader, Tag.SecondaryCaptureDeviceID,                              //二次获取设备ID
                                         dicomTags.SecondaryCaptureDeviceID);
                InsertStringDicomElement(dataHeader, Tag.SecondaryCaptureDeviceManufacturer,                    //二次获取设备厂商
                                         FilmingUtility.SecondaryCaptureDeviceManufacturer);
                InsertStringDicomElement(dataHeader, Tag.SecondaryCaptureDeviceManufacturersModelName,          //二次获取设备型号
                                         dicomTags.SecondaryCaptureDeviceManufacturersModelName);
                InsertStringDicomElement(dataHeader, Tag.SecondaryCaptureDeviceSoftwareVersions,                //二次获取设备软件版本
                                         dicomTags.SecondaryCaptureDeviceSoftwareVersions);
                var dateOfSecondaryCapture = string.Format("{0:D4}{1:D2}{2:D2}", now.Year, now.Month, now.Day); //二次获取日期
                InsertStringDicomElement(dataHeader, Tag.DateOfSecondaryCapture, dateOfSecondaryCapture);

                var timeOfSecondaryCapture = string.Format("{0:D2}{1:D2}{2:D2}", now.Hour, now.Minute, now.Second); //二次获取时间
                InsertStringDicomElement(dataHeader, Tag.TimeOfSecondaryCapture, timeOfSecondaryCapture);
                #endregion

                //General Image Module
                #region 图片相关

                InsertStringDicomElement(dataHeader, Tag.InstanceNumber, dicomTags.FilmPageIndex); //图片序号
                const string imageType  = FilmingUtility.EFilmImageType;                           //图片类型
                var          imageTypes = imageType.Split('\\');
                InsertStringArrayDicomElement(dataHeader, Tag.ImageType, imageTypes);

                InsertStringDicomElement(dataHeader, Tag.AcquisitionNumber, dicomTags.AcquisitionNumber);     //图片获取号

                InsertStringDicomElement(dataHeader, Tag.ImagesInAcquisition, dicomTags.ImagesInAcquisition); //图片获取总数
                InsertStringDicomElement(dataHeader, Tag.ImageComments, "");                                  //图片注释
                InsertStringDicomElement(dataHeader, Tag.BurnedInAnnotation, dicomTags.BurnedInAnnotation);   //图片烧图注释??

                #endregion


                //Image Pixel Module
                #region 图像像素相关
                if (dicomTags.IfSaveImageAsGrayScale)
                {
                    InsertUInt16DicomElement(dataHeader, Tag.SamplesPerPixel, 1);                       //取样点数
                    InsertStringDicomElement(dataHeader, Tag.PhotometricInterpretation, "MONOCHROME2"); //灰度类型
                }
                else
                {
                    InsertUInt16DicomElement(dataHeader, Tag.SamplesPerPixel, 3);                         //取样点数彩图
                    InsertStringDicomElement(dataHeader, Tag.PhotometricInterpretation, "RGB");           //彩图
                    InsertStringDicomElement(dataHeader, Tag.PlanarConfiguration, "0");                   //彩图依赖
                }
                InsertUInt16DicomElement(dataHeader, Tag.BitsAllocated, dicomTags.BitsAllocated);         //允许存储位数
                InsertUInt16DicomElement(dataHeader, Tag.BitsStored, dicomTags.BitsStored);               //实际存储位数
                InsertUInt16DicomElement(dataHeader, Tag.HighBit, (ushort)(dicomTags.BitsAllocated - 1)); //高位
                InsertUInt16DicomElement(dataHeader, Tag.PixelRepresentation, 0);                         //是否有符号位
                InsertUInt16DicomElement(dataHeader, Tag.Columns, dicomTags.Columns);                     //图片宽
                InsertUInt16DicomElement(dataHeader, Tag.Rows, dicomTags.Rows);                           //图片高

                #endregion

                //SOP Common Module
                #region 图片标识
                var uidManager = McsfDatabaseDicomUIDManagerFactory.Instance().CreateUIDManager();
                var str        = uidManager.CreateImageUID("");
                InsertStringDicomElement(dataHeader, Tag.SOPInstanceUID, str);
                InsertStringDicomElement(dataHeader, Tag.SOPClassUID, "1.2.840.10008.5.1.4.1.1.7");
                InsertStringDicomElement(dataHeader, Tag.SpecificCharacterSet, "127");
                InsertStringDicomElement(dataHeader, Tag.InstanceCreatorUID, "256");
                InsertStringDicomElement(dataHeader, Tag.InstanceNumber, "256");

                #endregion


                #region LUT
                //LUT
                InsertStringDicomElement(dataHeader, Tag.RescaleIntercept, "0");      //截距
                InsertStringDicomElement(dataHeader, Tag.RescaleSlope, "1");          //斜率
                InsertStringDicomElement(dataHeader, Tag.WindowCenter, "127");        //窗位
                InsertStringDicomElement(dataHeader, Tag.WindowWidth, "256");         //窗宽
                #endregion

                #region 插入PixelData
                var element = DicomAttribute.CreateAttribute(Tag.PixelData, VR.OB);
                if (!element.SetBytes(0, imageData))
                {
                    Logger.LogWarning("Failed to Insert NULL  image Data to Data header");
                }
                dataHeader.AddDicomAttribute(element);
                #endregion


                Logger.LogFuncDown();
                return(dataHeader);
            }
            catch (Exception ex)
            {
                Logger.LogFuncException(ex.Message + ex.StackTrace);
                throw;
            }
        }
コード例 #6
0
ファイル: UIDCreatManager.cs プロジェクト: 1059444127/XA
 public UIDCreatManager()
 {
     _dbUidManager = McsfDatabaseDicomUIDManagerFactory.Instance().CreateUIDManager();
 }
コード例 #7
0
ファイル: CellSaveHelper.cs プロジェクト: whhub/Filming
        /// <summary>
        /// Assume that cell is not empty
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static DicomAttributeCollection SaveCellAsDataHeader(MedViewerControlCell cell, int index)
        {
            try
            {
                Logger.LogFuncUp();

                Debug.Assert(cell != null && cell.Image != null && cell.Image.CurrentPage != null);

                var dataHeader = new DicomAttributeCollection();

                var displayData = cell.Image.CurrentPage;
                var dicomHeader = displayData.ImageHeader.DicomHeader;

                var uidManager = McsfDatabaseDicomUIDManagerFactory.Instance().CreateUIDManager();
                if (index == 0)
                {
                    SeriesInstanceUid = uidManager.CreateSeriesUID("1", "2", ""); //seriesUID; //
                    ClearSeries(dicomHeader);
                }

                //if (displayData.PixelData == null) return null;

                var pixelData = displayData.PixelData;
                if (pixelData == null)
                {
                    pixelData = new byte[displayData.ImageDataLength];
                    Marshal.Copy(displayData.ImageDataPtr, pixelData, 0, displayData.ImageDataLength);
                }

                var element = DicomAttribute.CreateAttribute(Tag.PixelData, VR.OB);
                if (!element.SetBytes(0, pixelData))
                {
                    Logger.LogWarning("Failed to Insert NULL  image Data to Data header");
                }
                dataHeader.AddDicomAttribute(element);

                FillTags(dicomHeader, dataHeader);

                //1. need to fill seriesDescription, from configuration, Default value is 3D-1
                FilmingHelper.InsertStringDicomElement(dataHeader, Tag.SeriesDescription, Printers.Instance.NewSeriesDescription);

                //2. remove wrong tag
                dataHeader.RemoveDicomAttribute(Tag.SmallestImagePixelValue);
                dataHeader.RemoveDicomAttribute(Tag.LargestImagePixelValue);

                //3. update some tag
                dataHeader.RemoveDicomAttribute(Tag.InstanceNumber);
                FilmingHelper.InsertStringDicomElement(dataHeader, Tag.InstanceNumber, "" + (index + 1));
                dataHeader.RemoveDicomAttribute(Tag.SeriesNumber);
                FilmingHelper.InsertStringDicomElement(dataHeader, Tag.SeriesNumber, "" + _seriesNumber);
                dataHeader.RemoveDicomAttribute(Tag.SeriesInstanceUid);
                FilmingHelper.InsertStringDicomElement(dataHeader, Tag.SeriesInstanceUid, SeriesInstanceUid);
                dataHeader.RemoveDicomAttribute(Tag.SOPInstanceUID);

                FilmingHelper.InsertStringDicomElement(dataHeader, Tag.SOPInstanceUID, uidManager.CreateImageUID(""));

                var ww = FilmingHelper.GetTagValueFrom(dataHeader, ServiceTagName.WindowWidth);
                dataHeader.RemoveDicomAttribute(Tag.WindowWidth);
                if (dicomHeader.ContainsKey(ServiceTagName.WindowWidth))
                {
                    if (!string.IsNullOrWhiteSpace(ww))
                    {
                        FilmingHelper.InsertStringArrayDicomElement(dataHeader, Tag.WindowWidth, dicomHeader[ServiceTagName.WindowWidth]);
                    }
                }

                var wc = FilmingHelper.GetTagValueFrom(dataHeader, ServiceTagName.WindowCenter);
                dataHeader.RemoveDicomAttribute(Tag.WindowCenter);
                if (dicomHeader.ContainsKey(ServiceTagName.WindowCenter))
                {
                    if (!string.IsNullOrWhiteSpace(wc))
                    {
                        FilmingHelper.InsertStringArrayDicomElement(dataHeader, Tag.WindowCenter, dicomHeader[ServiceTagName.WindowCenter]);
                    }
                }

                if (dicomHeader.ContainsKey(ServiceTagName.ImageType))
                {
                    dataHeader.RemoveDicomAttribute(Tag.ImageType);
                    FilmingHelper.InsertStringArrayDicomElement(dataHeader, Tag.ImageType, dicomHeader[ServiceTagName.ImageType]);
                }

                ////DICOM File Meta Information
                ////FillDicomFileMetaInformationTags(dataHeader);

                ////Patient Module
                //FillPatientModuleTags(dataHeader, dicomHeader);

                ////General Study Module
                //FillGeneralStudyModuleTags(dataHeader, dicomHeader);

                ////Patient Study Module
                //FillPatientStudyModuleTags(dataHeader, dicomHeader);

                ////General Series Module
                //FillGeneralSeriesModuleTags(dataHeader, dicomHeader);

                ////General Equipment Module

                //////SC Equipment Module
                ////FillSCEquipmentModuleTags(dataHeader);

                ////General Image Module
                //FillGeneralImageModuleTags(dataHeader, index, dicomHeader);

                //Image Pixel Module
                //FilmingHelper.AddConstDICOMAttributes(dataHeader);
                //FilmingHelper.InsertUInt16DicomElement(dataHeader, Tag.Columns, (ushort)imageWidth);
                //FilmingHelper.InsertUInt16DicomElement(dataHeader, Tag.Rows, (ushort)imageHeight);


                ////SC Image Module
                ////FillSCImageModuleTags(dataHeader);

                ////VOI LUT Module
                //FillVoilutMacroTags(dataHeader, dicomHeader);

                ////SOP Common Module
                //FillSopCommonModuleTags(dataHeader, dicomHeader);

                Logger.LogFuncDown();
                return(dataHeader);
            }
            catch (Exception ex)
            {
                Logger.LogFuncException(ex.Message + ex.StackTrace);
                return(null);
            }
        }