Beispiel #1
0
        //CMOVE
        public DicomFilesResult CMoveImage(string StudyInstanceUID, string SeriesInstanceUID, string SOPInstanceUID)
        {
            var sb = new StringBuilder();

            if (SOPInstanceUID != null && SOPInstanceUID != "")
            {
                sb.Append(DicomDic.Find("QueryRetrieveLevel").ToString("({Tag}) {VR} [IMAGE]\n"));
                sb.Append(DicomDic.Find("StudyInstanceUID").ToString("({Tag}) {VR} [{0}]\n", StudyInstanceUID));
                sb.Append(DicomDic.Find("SeriesInstanceUID").ToString("({Tag}) {VR} [{0}]\n", SeriesInstanceUID));
                sb.Append(DicomDic.Find("SOPInstanceUID").ToString("({Tag}) {VR} [{0}]\n", SOPInstanceUID));
            }
            else if (SeriesInstanceUID != null && SeriesInstanceUID != "")
            {
                sb.Append(DicomDic.Find("QueryRetrieveLevel").ToString("({Tag}) {VR} [SERIES]\n"));
                sb.Append(DicomDic.Find("StudyInstanceUID").ToString("({Tag}) {VR} [{0}]\n", StudyInstanceUID));
                sb.Append(DicomDic.Find("SeriesInstanceUID").ToString("({Tag}) {VR} [{0}]\n", SeriesInstanceUID));
            }
            else
            {
                sb.Append(DicomDic.Find("QueryRetrieveLevel").ToString("({Tag}) {VR} [STUDY]\n"));
                sb.Append(DicomDic.Find("StudyInstanceUID").ToString("({Tag}) {VR} [{0}]\n", StudyInstanceUID));
            }

            return(CMove(sb.ToString()));
        }
Beispiel #2
0
        //CFIND(IMAGE)
        public DicomTagsResult CFindImage(string StudyInstanceUID, string SeriesInstanceUID)
        {
            var sb = new StringBuilder();

            sb.Append(DicomDic.Find("QueryRetrieveLevel").ToString("({Tag}) {VR} [IMAGE]\n"));
            sb.Append(DicomDic.Find("StudyInstanceUID").ToString("({Tag}) {VR} [{0}]\n", StudyInstanceUID));
            sb.Append(DicomDic.Find("SeriesInstanceUID").ToString("({Tag}) {VR} [{0}]\n", SeriesInstanceUID));
            sb.Append(DicomDic.Find("SOPInstanceUID").ToString("({Tag}) {VR}\n"));
            sb.Append(DicomDic.Find("InstanceNumber").ToString("({Tag}) {VR}\n"));

            return(CFind(sb.ToString()));
        }
Beispiel #3
0
        //CFIND(SERIES)
        public DicomTagsResult CFindSeries(string StudyInstanceUID)
        {
            var sb = new StringBuilder();

            sb.Append(DicomDic.Find("QueryRetrieveLevel").ToString("({Tag}) {VR} [SERIES]\n"));
            sb.Append(DicomDic.Find("StudyInstanceUID").ToString("({Tag}) {VR} [{0}]\n", StudyInstanceUID));
            sb.Append(DicomDic.Find("SeriesInstanceUID").ToString("({Tag}) {VR}\n"));
            sb.Append(DicomDic.Find("Modality").ToString("({Tag}) {VR}\n"));
            sb.Append(DicomDic.Find("SeriesNumber").ToString("({Tag}) {VR}\n"));

            sb.Append(DicomDic.Find("NumberOfSeriesRelatedInstances").ToString("({Tag}) {VR}\n"));
            sb.Append(DicomDic.Find("SeriesDescription").ToString("({Tag}) {VR}\n"));

            return(CFind(sb.ToString()));
        }
Beispiel #4
0
        //CFIND(STUDY)
        public DicomTagsResult CFindStudy(FindParam prm)
        {
            var sb = new StringBuilder();

            sb.Append(DicomDic.Find("QueryRetrieveLevel").ToString("({Tag}) {VR} [STUDY]\n"));
            sb.Append(DicomDic.Find("StudyInstanceUID").ToString("({Tag}) {VR} [{0}]\n", prm.StudyInstanceUID ?? ""));
            sb.Append(DicomDic.Find("StudyDate").ToString("({Tag}) {VR} [{0}]\n", prm.StudyDate ?? ""));
            sb.Append(DicomDic.Find("StudyTime").ToString("({Tag}) {VR}\n"));
            sb.Append(DicomDic.Find("AccessionNumber").ToString("({Tag}) {VR} [{0}]\n", prm.AccessionNumber ?? ""));
            sb.Append(DicomDic.Find("PatientsName").ToString("({Tag}) {VR} [{0}]\n", prm.PatientName ?? ""));
            sb.Append(DicomDic.Find("PatientID").ToString("({Tag}) {VR} [{0}]\n", prm.PatientID ?? ""));
            sb.Append(DicomDic.Find("StudyID").ToString("({Tag}) {VR}\n"));

            sb.Append(DicomDic.Find("ModalitiesInStudy").ToString("({Tag}) {VR} [{0}]\n", prm.Modality ?? ""));
            sb.Append(DicomDic.Find("StudyDescription").ToString("({Tag}) {VR}\n"));
            sb.Append(DicomDic.Find("PatientsBirthDate").ToString("({Tag}) {VR}\n"));
            sb.Append(DicomDic.Find("PatientsSex").ToString("({Tag}) {VR}\n"));
            sb.Append(DicomDic.Find("PatientsAge").ToString("({Tag}) {VR}\n"));
            sb.Append(DicomDic.Find("NumberOfStudyRelatedInstances").ToString("({Tag}) {VR}\n"));

            return(CFind(sb.ToString()));
        }
Beispiel #5
0
        //スタディ一覧の取得 (過去検査)
        public static void GetStudyList_Kako(string patientid, StudyKey key, out List <StudyTag> tags)
        {
            tags = new List <StudyTag>();

            using (var pc = new PacsComm())
            {
                var prm2 = new PacsComm.FindParam();
                if (patientid.Trim() == "")
                {
                    prm2.StudyInstanceUID = key.StudyInstanceUID;
                }
                else
                {
                    prm2.PatientID = patientid;
                }

                DicomTagsResult ret = pc.CFindStudy(prm2);
                if (!ret.IsSuccess)
                {
                    LogUtil.Error("CFINDに失敗しました。");
                    return;
                }

                foreach (var dcmTag in ret.Tags)
                {
                    var stkey = new StudyKey()
                    {
                        StudyInstanceUID = dcmTag.GetTagValue(DicomDic.Find("StudyInstanceUID").Tag),
                        IsPacsSearch     = true
                    };

                    var tag = new StudyTag();
                    tag.StudyKey = ConvertUtil.Serialize(stkey);

                    tag.StudyDate       = dcmTag.GetTagValue(DicomDic.Find("StudyDate").Tag);
                    tag.StudyTime       = dcmTag.GetTagValue(DicomDic.Find("StudyTime").Tag);
                    tag.AccessionNumber = dcmTag.GetTagValue(DicomDic.Find("AccessionNumber").Tag);
                    tag.PatientName     = dcmTag.GetTagValue(DicomDic.Find("PatientsName").Tag);
                    tag.PatientID       = dcmTag.GetTagValue(DicomDic.Find("PatientID").Tag);

                    tag.Modality         = dcmTag.GetTagValue(DicomDic.Find("ModalitiesInStudy").Tag);
                    tag.StudyDescription = dcmTag.GetTagValue(DicomDic.Find("StudyDescription").Tag);
                    tag.PatientBirthDate = dcmTag.GetTagValue(DicomDic.Find("PatientsBirthDate").Tag);
                    tag.PatientSex       = dcmTag.GetTagValue(DicomDic.Find("PatientsSex").Tag);
                    tag.PatientAge       = dcmTag.GetTagValue(DicomDic.Find("PatientsAge").Tag);
                    Int32.TryParse(dcmTag.GetTagValue(DicomDic.Find("NumberOfStudyRelatedInstances").Tag), out tag.NumberOfImages);

                    //メモ有無
                    using (var db = new TryDbConnection(LCL.settings))
                    {
                        using (var cmd = db.CreateCommand())
                        {
                            cmd.CommandText = "SELECT COUNT(*) cnt FROM T_StudyMemo WHERE StudyInstanceUID=@0";
                            cmd.Add(stkey.StudyInstanceUID);

                            using (var dr = cmd.ExecuteReader())
                            {
                                if (dr.Read())
                                {
                                    tag.StudyMemoUmu = Convert.ToInt32(dr["cnt"]);
                                }
                            }
                        }
                    }

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

                    tags.Add(tag);
                }
            }

            //ソート
            tags.Sort(new StudyTagComparer());
        }
Beispiel #6
0
        //画像一覧の取得
        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;
            }
        }
Beispiel #7
0
        //シリーズ一覧の取得
        public static void GetSeriesList(StudyKey key, out List <SeriesTag> seTags)
        {
            seTags = new List <SeriesTag>();
            var tags = new List <SeriesTag>();

            using (var pc = new PacsComm())
            {
                DicomTagsResult ret = pc.CFindSeries(key.StudyInstanceUID);
                if (!ret.IsSuccess)
                {
                    LogUtil.Error("CFINDに失敗しました。");
                    return;
                }

                foreach (var dcmTag in ret.Tags)
                {
                    string mod = dcmTag.GetTagValue(DicomDic.Find("Modality").Tag);

                    //無視するモダリティ
                    if (Array.IndexOf(AppUtil.SkipModality, mod) >= 0)
                    {
                        continue;
                    }

                    var sekey = new SeriesKey()
                    {
                        StudyInstanceUID  = key.StudyInstanceUID,
                        SeriesInstanceUID = dcmTag.GetTagValue(DicomDic.Find("SeriesInstanceUID").Tag),
                        IsImage           = false,
                        IsPacsSearch      = true
                    };

                    var tag = new SeriesTag();
                    tag.SeriesKey = ConvertUtil.Serialize(sekey);
                    tag.Modality  = mod;
                    Int64.TryParse(dcmTag.GetTagValue(DicomDic.Find("SeriesNumber").Tag), out tag.SeriesNumber);
                    Int32.TryParse(dcmTag.GetTagValue(DicomDic.Find("NumberOfSeriesRelatedInstances").Tag), out tag.NumberOfImages);
                    tag.SeriesDescription = dcmTag.GetTagValue(DicomDic.Find("SeriesDescription").Tag);

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

                    tags.Add(tag);
                }
            }

            //ソート
            tags.Sort(new SeriesTagComparer());

            //重複チェック
            foreach (var tag in tags)
            {
                var sekey = ConvertUtil.Deserialize <SeriesKey>(tag.SeriesKey);

                bool chk = true;
                foreach (var setag in seTags)
                {
                    var sekey2 = ConvertUtil.Deserialize <SeriesKey>(setag.SeriesKey);

                    if (sekey.StudyInstanceUID == sekey2.StudyInstanceUID && sekey.SeriesInstanceUID == sekey2.SeriesInstanceUID)
                    {
                        chk = false;
                        break;
                    }
                }

                if (chk)
                {
                    seTags.Add(tag);
                }
            }
        }
Beispiel #8
0
        //スタディの取得 (URLコール用)
        public static bool GetStudyKey(FindParam prm, out string patientid, out List <string> studykey)
        {
            patientid = "";
            studykey  = new List <string>();

            var tags = new List <StudyTag>();

            using (var pc = new PacsComm())
            {
                var prm2 = new PacsComm.FindParam();
                prm2.SetStudyDate(prm.StudyDateFrom, prm.StudyDateTo);
                prm2.AccessionNumber = prm.AccessionNumber;
                prm2.PatientName     = prm.PatientName;
                prm2.PatientID       = prm.PatientID;
                prm2.Modality        = prm.Modality;

                DicomTagsResult ret = pc.CFindStudy(prm2);
                if (!ret.IsSuccess)
                {
                    LogUtil.Error("CFINDに失敗しました。");
                    return(true);
                }

                foreach (var dcmTag in ret.Tags)
                {
                    var tag = new StudyTag();
                    tag.StudyDate = dcmTag.GetTagValue(DicomDic.Find("StudyDate").Tag);
                    tag.StudyTime = dcmTag.GetTagValue(DicomDic.Find("StudyTime").Tag);
                    tag.PatientID = dcmTag.GetTagValue(DicomDic.Find("PatientID").Tag);

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

                    tags.Add(tag);
                }
            }

            if (tags.Count == 0)
            {
                return(true);
            }

            //ソート
            tags.Sort(new StudyTagComparer());

            foreach (var tag in tags)
            {
                var key = new StudyKey()
                {
                    StudyInstanceUID = tag.StudyInstanceUID,
                    IsPacsSearch     = true
                };
                studykey.Add(ConvertUtil.Serialize(key));

                if (studykey.Count == 1)
                {
                    patientid = tag.PatientID;
                }
                else
                {
                    if (patientid != tag.PatientID)
                    {
                        patientid = null;
                        studykey  = null;
                        return(false);
                    }
                }
            }

            return(true);
        }
Beispiel #9
0
        //サムネイルの作成
        public static void GetThumbnail(SeriesKey key, out byte[] thumb)
        {
            thumb = null;

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

                    var tags = new List <Tuple <string, long> >();

                    foreach (var dcmTag in ret.Tags)
                    {
                        long InstanceNumber = 0;
                        Int64.TryParse(dcmTag.GetTagValue(DicomDic.Find("InstanceNumber").Tag), out InstanceNumber);

                        var tag = Tuple.Create(dcmTag.GetTagValue(DicomDic.Find("SOPInstanceUID").Tag), InstanceNumber);
                        tags.Add(tag);
                    }

                    //ソート
                    tags = tags.OrderBy(n => n.Item2).ToList();

                    if (tags.Count > 0)
                    {
                        key.SOPInstanceUID = tags[0].Item1;
                    }
                }
            }

            if (key.SOPInstanceUID != null && key.SOPInstanceUID != "")
            {
                //DICOMがある
                {
                    LCL.GetImageStorageID(ref key);
                    if (key.StorageID != null && key.StorageID != "")
                    {
                        var sto = DbCacheUtil.GetStorage(key.StorageID);
                        using (var imp = new Impersonate(sto.LogonUsername, sto.LogonPassword))
                        {
                            var file = FileUtil.GetDicomFile(key);
                            if (File.Exists(file))
                            {
                                DicomUtil.DicomToThumb(file, out thumb);
                                if (thumb != null)
                                {
                                    return;
                                }
                            }
                        }
                    }
                }

                //DICOMがない
                using (var pc = new PacsComm())
                {
                    //画像取得
                    DicomFilesResult ret = pc.CMoveImage(key.StudyInstanceUID, key.SeriesInstanceUID, key.SOPInstanceUID);
                    if (!ret.IsSuccess)
                    {
                        LogUtil.Error("CMoveImage");
                        return;
                    }

                    if (ret.Files.Length == 0)
                    {
                        LogUtil.Error("CMoveImage [File=0]");
                        return;
                    }

                    LogUtil.Debug1("CMoveImage [File={0}]", ret.Files.Length.ToString());

                    foreach (DicomFile dcmfile in ret.Files)
                    {
                        var file = dcmfile.FileName.Trim();
                        if (!File.Exists(file))
                        {
                            continue;
                        }

                        DicomUtil.DicomToThumb(file, out thumb);

                        if (thumb != null)
                        {
                            return;
                        }
                    }
                }
            }
        }