Ejemplo n.º 1
0
        public void AttributeCSTest()
        {
            bool testResult = false;
            try
            {
                DicomAttributeCS attrib = new DicomAttributeCS(DicomTagDictionary.GetDicomTag(DicomTags.AccessionNumber));
            }
            catch (DicomException)
            {
                testResult = true;
            }
            Assert.AreEqual(testResult, true);

            try
            {
                DicomAttributeCS attrib = new DicomAttributeCS(DicomTagDictionary.GetDicomTag(DicomTags.ImageType));
                testResult = true;
            }
            catch (DicomException)
            {
                testResult = false;
            }
            Assert.AreEqual(testResult, true);


        }
Ejemplo n.º 2
0
        //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();
            }
        }