コード例 #1
0
ファイル: DCM_T.cs プロジェクト: k-matsuda-85/dev-private
        //画像一覧の取得(横展開したシリーズ用)
        public static void GetImageList(ImageKey[] keys, out List <ImageTag> tags)
        {
            tags = new List <ImageTag>();

            //タグの取得
            foreach (var key in keys)
            {
                var sto = DbCacheUtil.GetStorage(key.StorageID);
                using (var imp = new Impersonate(sto.LogonUsername, sto.LogonPassword))
                {
                    var file = FileUtil.GetDicomFile(key);
                    if (File.Exists(file))
                    {
                        ImageTag tag;
                        DicomUtil.GetImageTag(file, out tag);
                        tag.ImageKey = ConvertUtil.Serialize(key);

                        tags.Add(tag);
                    }
                }
            }
        }
コード例 #2
0
ファイル: DCM_T.cs プロジェクト: k-matsuda-85/dev-private
        //画像一覧の取得
        public static void GetImageList(LoginItem login, SeriesKey key, out List <ImageTag> imTags, out List <SeriesTag> seTags)
        {
            imTags = null;
            seTags = null;
            var tags = new List <ImageTag>();

            if (key.IsImage)
            {
                var imkey = new ImageKey()
                {
                    StudyInstanceUID  = key.StudyInstanceUID,
                    SeriesInstanceUID = key.SeriesInstanceUID,
                    SOPInstanceUID    = key.SOPInstanceUID,
                    StorageID         = login.StorageID
                };

                var tag = new ImageTag();
                tag.ImageKey = ConvertUtil.Serialize(imkey);

                tags.Add(tag);
            }
            else
            {
                using (var pc = new PacsComm())
                {
                    DicomTagsResult ret = pc.CFindImage(key.StudyInstanceUID, key.SeriesInstanceUID);
                    if (!ret.IsSuccess)
                    {
                        LogUtil.Error("CFINDに失敗しました。");
                        return;
                    }

                    foreach (var dcmTag in ret.Tags)
                    {
                        var imkey = new ImageKey()
                        {
                            StudyInstanceUID  = key.StudyInstanceUID,
                            SeriesInstanceUID = key.SeriesInstanceUID,
                            SOPInstanceUID    = dcmTag.GetTagValue(DicomDic.Find("SOPInstanceUID").Tag),
                            StorageID         = login.StorageID
                        };

                        var tag = new ImageTag();
                        tag.ImageKey = ConvertUtil.Serialize(imkey);
                        Int64.TryParse(dcmTag.GetTagValue(DicomDic.Find("InstanceNumber").Tag), out tag.InstanceNumber);

                        //ソート用
                        tag.SOPInstanceUID = dcmTag.GetTagValue(DicomDic.Find("SOPInstanceUID").Tag);

                        tags.Add(tag);
                    }
                }

                //ソート
                tags.Sort(new ImageTagComparer());
            }

            //DICOMファイルの取得
            int cnt = 0;

            foreach (var tag in tags)
            {
                var imkey = ConvertUtil.Deserialize <ImageKey>(tag.ImageKey);

                var sto = DbCacheUtil.GetStorage(imkey.StorageID);
                using (var imp = new Impersonate(sto.LogonUsername, sto.LogonPassword))
                {
                    var dcmfile = FileUtil.GetDicomFile(imkey);
                    if (!File.Exists(dcmfile))
                    {
                        cnt++;
                    }
                }
            }
            if (cnt > 0)
            {
                DCM.GetImage(login, key);
            }

            int MultiCount = 0;

            //タグの取得
            foreach (var tag in tags)
            {
                var imkey = ConvertUtil.Deserialize <ImageKey>(tag.ImageKey);

                var sto = DbCacheUtil.GetStorage(imkey.StorageID);
                using (var imp = new Impersonate(sto.LogonUsername, sto.LogonPassword))
                {
                    var dcmfile = FileUtil.GetDicomFile(imkey);
                    if (File.Exists(dcmfile))
                    {
                        ImageTag tmp = null;
                        DicomUtil.GetImageTag(dcmfile, out tmp);

                        tag.InstanceNumber          = tmp.InstanceNumber;
                        tag.SliceThickness          = tmp.SliceThickness;
                        tag.ImagePositionPatient    = tmp.ImagePositionPatient;
                        tag.ImageOrientationPatient = tmp.ImageOrientationPatient;
                        tag.SliceLocation           = tmp.SliceLocation;
                        tag.Rows           = tmp.Rows;
                        tag.Columns        = tmp.Columns;
                        tag.PixelSpacing   = tmp.PixelSpacing;
                        tag.WindowCenter   = tmp.WindowCenter;
                        tag.WindowWidth    = tmp.WindowWidth;
                        tag.NumberOfFrames = tmp.NumberOfFrames;

                        if (tag.IsMultiframe)
                        {
                            MultiCount += 1;
                        }
                    }
                }
            }

            if (key.IsImage)
            {
                var sto = DbCacheUtil.GetStorage(key.StorageID);
                using (var imp = new Impersonate(sto.LogonUsername, sto.LogonPassword))
                {
                    var dcmfile = FileUtil.GetDicomFile(key);
                    if (File.Exists(dcmfile))
                    {
                        imTags = new List <ImageTag>();

                        ImageTag tmp = tags[0];
                        if (tmp.IsMultiframe)
                        {
                            for (var i = 0; i < tmp.NumberOfFrames; i++)
                            {
                                var imkey = new ImageKey()
                                {
                                    StudyInstanceUID  = key.StudyInstanceUID,
                                    SeriesInstanceUID = key.SeriesInstanceUID,
                                    SOPInstanceUID    = key.SOPInstanceUID,
                                    FrameNumber       = i,
                                };

                                var tag = new ImageTag();
                                tag.ImageKey                = ConvertUtil.Serialize(imkey);
                                tag.InstanceNumber          = i;
                                tag.SliceThickness          = tmp.SliceThickness;
                                tag.ImagePositionPatient    = tmp.ImagePositionPatient;
                                tag.ImageOrientationPatient = tmp.ImageOrientationPatient;
                                tag.SliceLocation           = tmp.SliceLocation;
                                tag.Rows           = tmp.Rows;
                                tag.Columns        = tmp.Columns;
                                tag.PixelSpacing   = tmp.PixelSpacing;
                                tag.WindowCenter   = tmp.WindowCenter;
                                tag.WindowWidth    = tmp.WindowWidth;
                                tag.NumberOfFrames = tmp.NumberOfFrames;

                                imTags.Add(tag);
                            }
                        }
                        else
                        {
                            imTags.Add(tmp);
                        }
                    }
                }
            }
            else if (MultiCount >= 1)
            {
                //マルチフレームがある場合はシリーズで返す
                seTags = new List <SeriesTag>();

                foreach (var tag in tags)
                {
                    var imkey = ConvertUtil.Deserialize <ImageKey>(tag.ImageKey);

                    var sto = DbCacheUtil.GetStorage(imkey.StorageID);
                    using (var imp = new Impersonate(sto.LogonUsername, sto.LogonPassword))
                    {
                        var dcmfile = FileUtil.GetDicomFile(imkey);
                        if (File.Exists(dcmfile))
                        {
                            SeriesTag tmp;
                            DicomUtil.GetSeriesTag(dcmfile, out tmp);

                            var sekey = new SeriesKey()
                            {
                                StudyInstanceUID  = imkey.StudyInstanceUID,
                                SeriesInstanceUID = imkey.SeriesInstanceUID,
                                SOPInstanceUID    = imkey.SOPInstanceUID,
                                StorageID         = login.StorageID,
                                IsImage           = true,
                                IsPacsSearch      = key.IsPacsSearch
                            };

                            tmp.SeriesKey = ConvertUtil.Serialize(sekey);

                            seTags.Add(tmp);
                        }
                    }
                }

                //ソート
                seTags = seTags.OrderBy(n => n.SeriesNumber).ToList();
            }
            else
            {
                imTags = tags;
            }
        }