Ejemplo n.º 1
0
        //画像一覧の取得(横展開したシリーズ用)
        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);
                    }
                }
            }
        }
Ejemplo n.º 2
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());
        }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
                }
            }
        }
Ejemplo n.º 6
0
        //シリーズ一覧の取得
        public static void GetSeriesList(StudyKey key, out List <SeriesTag> tags)
        {
            tags = new List <SeriesTag>();

            using (var db = new TryDbConnection(settings))
            {
                using (var cmd = db.CreateCommand())
                {
                    var sb = new StringBuilder();
                    sb.Append("SELECT SeriesInstanceUID,SOPInstanceUID,Modality,SeriesDescription,SeriesNumber,NumberOfImages,NumberOfFrames,StorageID");
                    sb.Append(" FROM T_Series");
                    sb.Append(" WHERE StudyInstanceUID=@0");

                    cmd.CommandText = sb.ToString();
                    cmd.Add(key.StudyInstanceUID);

                    //シリーズ
                    using (var dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            //無視するモダリティ
                            if (Array.IndexOf(AppUtil.SkipModality, (string)dr["Modality"]) >= 0)
                            {
                                continue;
                            }

                            string seriesUid = (string)dr["SeriesInstanceUID"];
                            int    noi       = (int)dr["NumberOfImages"];
                            int    nof       = (int)dr["NumberOfFrames"];

                            int cnt = 0;
                            if (nof > noi)
                            {
                                //ウォーターラインのチェック
                                using (var cmd2 = db.CreateCommand())
                                {
                                    cmd2.CommandText = "SELECT COUNT(*) FROM T_Image WHERE StudyInstanceUID=@0 AND SeriesInstanceUID=@1";
                                    cmd2.Add(key.StudyInstanceUID);
                                    cmd2.Add(seriesUid);

                                    cnt = Convert.ToInt32(cmd2.ExecuteScalar());
                                }
                            }

                            //マルチフレームでない or 画像がない
                            if (cnt == 0)
                            {
                                var sekey = new SeriesKey()
                                {
                                    StudyInstanceUID  = key.StudyInstanceUID,
                                    SeriesInstanceUID = seriesUid,
                                    SOPInstanceUID    = (string)dr["SOPInstanceUID"],
                                    StorageID         = (string)dr["StorageID"],
                                    IsImage           = false
                                };

                                var tag = new SeriesTag();
                                tag.SeriesKey         = ConvertUtil.Serialize(sekey);
                                tag.Modality          = (string)dr["Modality"];
                                tag.SeriesDescription = (string)dr["SeriesDescription"];
                                tag.SeriesNumber      = (long)dr["SeriesNumber"];
                                tag.NumberOfImages    = noi;
                                tag.NumberOfFrames    = noi;

                                //ソート用
                                tag.SeriesInstanceUID = seriesUid;

                                //GSPS
                                using (var cmd3 = db.CreateCommand())
                                {
                                    cmd3.CommandText = "SELECT COUNT(*) FROM T_GSPS_R WHERE StudyInstanceUID=@0 AND ReferencedSeriesInstanceUID=@1";
                                    cmd3.Add(key.StudyInstanceUID);
                                    cmd3.Add(seriesUid);

                                    var gsps = Convert.ToInt32(cmd3.ExecuteScalar());
                                    tag.IsGSPS = gsps > 0 ? true : false;
                                }

                                tags.Add(tag);
                            }
                            else
                            {
                                //マルチフレーム
                                using (var cmd2 = db.CreateCommand())
                                {
                                    cmd2.CommandText = "SELECT SOPInstanceUID,InstanceNumber,NumberOfFrames,StorageID FROM T_Image WHERE StudyInstanceUID=@0 AND SeriesInstanceUID=@1";
                                    cmd2.Add(key.StudyInstanceUID);
                                    cmd2.Add(seriesUid);

                                    using (var dr2 = cmd2.ExecuteReader())
                                    {
                                        while (dr2.Read())
                                        {
                                            var sekey = new SeriesKey()
                                            {
                                                StudyInstanceUID  = key.StudyInstanceUID,
                                                SeriesInstanceUID = seriesUid,
                                                SOPInstanceUID    = (string)dr2["SOPInstanceUID"],
                                                StorageID         = (string)dr2["StorageID"],
                                                IsImage           = true
                                            };

                                            var tag = new SeriesTag();
                                            tag.SeriesKey         = ConvertUtil.Serialize(sekey);
                                            tag.Modality          = (string)dr["Modality"];
                                            tag.SeriesDescription = (string)dr["SeriesDescription"];
                                            tag.SeriesNumber      = (long)dr["SeriesNumber"];
                                            tag.NumberOfImages    = 1;
                                            tag.NumberOfFrames    = (int)dr2["NumberOfFrames"];

                                            //ソート用
                                            tag.SeriesInstanceUID = seriesUid;
                                            tag.SOPInstanceUID    = (string)dr2["SOPInstanceUID"];
                                            tag.InstanceNumber    = (long)dr2["InstanceNumber"];

                                            //GSPS
                                            using (var cmd3 = db.CreateCommand())
                                            {
                                                cmd3.CommandText = "SELECT COUNT(*) FROM T_GSPS_R WHERE StudyInstanceUID=@0 AND ReferencedSeriesInstanceUID=@1 AND ReferencedSOPInstanceUID=@2";
                                                cmd3.Add(key.StudyInstanceUID);
                                                cmd3.Add(seriesUid);
                                                cmd3.Add((string)dr2["SOPInstanceUID"]);

                                                var gsps = Convert.ToInt32(cmd3.ExecuteScalar());
                                                tag.IsGSPS = gsps > 0 ? true : false;
                                            }

                                            tags.Add(tag);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //ソート
            tags.Sort(new SeriesTagComparer());
        }
Ejemplo n.º 7
0
        //画像一覧の取得
        public static void GetImageList(SeriesKey key, out List <ImageTag> tags)
        {
            tags = new List <ImageTag>();

            using (var db = new TryDbConnection(settings))
            {
                if (!key.IsImage)
                {
                    using (var cmd = db.CreateCommand())
                    {
                        var sb = new StringBuilder();
                        sb.Append("SELECT SOPInstanceUID,InstanceNumber,SliceThickness,ImagePositionPatient,ImageOrientationPatient,SliceLocation,Rows,Columns,PixelSpacing,WindowCenter,WindowWidth,StorageID");
                        sb.Append(" FROM T_Image");
                        sb.Append(" WHERE StudyInstanceUID=@0 AND SeriesInstanceUID=@1");

                        cmd.CommandText = sb.ToString();
                        cmd.Add(key.StudyInstanceUID);
                        cmd.Add(key.SeriesInstanceUID);

                        using (var dr = cmd.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                var imkey = new ImageKey()
                                {
                                    StudyInstanceUID  = key.StudyInstanceUID,
                                    SeriesInstanceUID = key.SeriesInstanceUID,
                                    SOPInstanceUID    = (string)dr["SOPInstanceUID"],
                                    StorageID         = (string)dr["StorageID"]
                                };

                                var tag = new ImageTag();
                                tag.ImageKey                = ConvertUtil.Serialize(imkey);
                                tag.InstanceNumber          = (long)dr["InstanceNumber"];
                                tag.SliceThickness          = (string)dr["SliceThickness"];
                                tag.ImagePositionPatient    = (string)dr["ImagePositionPatient"];
                                tag.ImageOrientationPatient = (string)dr["ImageOrientationPatient"];
                                tag.SliceLocation           = (string)dr["SliceLocation"];
                                tag.Rows         = (int)dr["Rows"];
                                tag.Columns      = (int)dr["Columns"];
                                tag.PixelSpacing = (string)dr["PixelSpacing"];
                                tag.WindowCenter = (string)dr["WindowCenter"];
                                tag.WindowWidth  = (string)dr["WindowWidth"];

                                //ソート用
                                tag.SOPInstanceUID = (string)dr["SOPInstanceUID"];

                                tags.Add(tag);
                            }
                        }
                    }

                    //ソート
                    tags.Sort(new ImageTagComparer());
                }
                else
                {
                    using (var cmd = db.CreateCommand())
                    {
                        var sb = new StringBuilder();
                        sb.Append("SELECT NumberOfFrames,SliceThickness,ImagePositionPatient,ImageOrientationPatient,SliceLocation,Rows,Columns,PixelSpacing,WindowCenter,WindowWidth,StorageID");
                        sb.Append(" FROM T_Image");
                        sb.Append(" WHERE StudyInstanceUID=@0 AND SeriesInstanceUID=@1 AND SOPInstanceUID=@2");

                        cmd.CommandText = sb.ToString();
                        cmd.Add(key.StudyInstanceUID);
                        cmd.Add(key.SeriesInstanceUID);
                        cmd.Add(key.SOPInstanceUID);

                        using (var dr = cmd.ExecuteReader())
                        {
                            if (dr.Read())
                            {
                                int frames = (int)dr["NumberOfFrames"];
                                for (int i = 0; i < frames; i++)
                                {
                                    var imkey = new ImageKey()
                                    {
                                        StudyInstanceUID  = key.StudyInstanceUID,
                                        SeriesInstanceUID = key.SeriesInstanceUID,
                                        SOPInstanceUID    = key.SOPInstanceUID,
                                        FrameNumber       = i,
                                        StorageID         = (string)dr["StorageID"]
                                    };

                                    var tag = new ImageTag();
                                    tag.ImageKey                = ConvertUtil.Serialize(imkey);
                                    tag.InstanceNumber          = i;
                                    tag.SliceThickness          = (string)dr["SliceThickness"];
                                    tag.ImagePositionPatient    = (string)dr["ImagePositionPatient"];
                                    tag.ImageOrientationPatient = (string)dr["ImageOrientationPatient"];
                                    tag.SliceLocation           = (string)dr["SliceLocation"];
                                    tag.Rows           = (int)dr["Rows"];
                                    tag.Columns        = (int)dr["Columns"];
                                    tag.PixelSpacing   = (string)dr["PixelSpacing"];
                                    tag.WindowCenter   = (string)dr["WindowCenter"];
                                    tag.WindowWidth    = (string)dr["WindowWidth"];
                                    tag.NumberOfFrames = frames;

                                    tags.Add(tag);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        //スタディ一覧の取得 (過去検査)
        public static void GetStudyList_Kako(string patientid, StudyKey key, out List <StudyTag> tags)
        {
            tags = new List <StudyTag>();

            using (var db = new TryDbConnection(settings))
            {
                using (var cmd = db.CreateCommand())
                {
                    var sb = new StringBuilder();
                    sb.Append("SELECT StudyInstanceUID,StudyDate,StudyTime,AccessionNumber,Modality,StudyDescription,T_Study.PatientName,T_Study.PatientID,PatientBirthDate,PatientSex,PatientAge,BodyPartExamined,Comment,Keyword,NumberOfImages,T_Patient.PatientName PatientName2");
                    sb.Append(" FROM T_Study LEFT JOIN T_Patient ON T_Study.PatientID=T_Patient.PatientID");

                    if (patientid.Trim() == "")
                    {
                        sb.Append(" WHERE StudyInstanceUID=" + cmd.Add(key.StudyInstanceUID).ParameterName);
                    }
                    else
                    {
                        sb.Append(" WHERE T_Study.PatientID=" + cmd.Add(patientid).ParameterName);
                    }

                    sb.Append(" AND NumberOfImages>0");
                    sb.Append(" ORDER BY StudyDate DESC,StudyTime DESC,StudyInstanceUID");

                    cmd.CommandText = sb.ToString();

                    using (var dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            var stkey = new StudyKey()
                            {
                                StudyInstanceUID = (string)dr["StudyInstanceUID"]
                            };

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

                            if (dr["StudyDate"] != DBNull.Value)
                            {
                                tag.StudyDate = (string)dr["StudyDate"];
                            }

                            if (dr["StudyTime"] != DBNull.Value)
                            {
                                tag.StudyTime = (string)dr["StudyTime"];
                            }

                            if (dr["AccessionNumber"] != DBNull.Value)
                            {
                                tag.AccessionNumber = (string)dr["AccessionNumber"];
                            }

                            if (dr["Modality"] != DBNull.Value)
                            {
                                tag.Modality = (string)dr["Modality"];
                            }

                            if (dr["StudyDescription"] != DBNull.Value)
                            {
                                tag.StudyDescription = (string)dr["StudyDescription"];
                            }

                            if (dr["PatientName"] != DBNull.Value)
                            {
                                tag.PatientName = (string)dr["PatientName"];
                            }

                            if (dr["PatientName2"] != DBNull.Value)
                            {
                                tag.PatientName = (string)dr["PatientName2"];
                            }

                            if (AppUtil.HideData == "1")
                            {
                                tag.PatientName = "";
                            }

                            if (dr["PatientID"] != DBNull.Value)
                            {
                                tag.PatientID = (string)dr["PatientID"];
                            }

                            if (dr["PatientBirthDate"] != DBNull.Value)
                            {
                                tag.PatientBirthDate = (string)dr["PatientBirthDate"];
                            }

                            if (dr["PatientSex"] != DBNull.Value)
                            {
                                tag.PatientSex = (string)dr["PatientSex"];
                            }

                            if (dr["PatientAge"] != DBNull.Value)
                            {
                                tag.PatientAge = (string)dr["PatientAge"];
                            }

                            if (dr["BodyPartExamined"] != DBNull.Value)
                            {
                                tag.BodyPartExamined = (string)dr["BodyPartExamined"];
                            }

                            if (dr["Comment"] != DBNull.Value)
                            {
                                tag.Comment = (string)dr["Comment"];
                            }

                            if (dr["Keyword"] != DBNull.Value)
                            {
                                tag.Keyword = (string)dr["Keyword"];
                            }

                            if (dr["NumberOfImages"] != DBNull.Value)
                            {
                                tag.NumberOfImages = (int)dr["NumberOfImages"];
                            }

                            //メモ有無
                            using (var cmd2 = db.CreateCommand())
                            {
                                cmd2.CommandText = "SELECT COUNT(*) cnt FROM T_StudyMemo WHERE StudyInstanceUID=@0";
                                cmd2.Add((string)dr["StudyInstanceUID"]);

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

                            tags.Add(tag);
                        }
                    }
                }
            }

            //ソート不要
            //tags.Sort(new StudyTagComparer());
        }
Ejemplo n.º 9
0
        //スタディの取得 (URLコール用)
        public static bool GetStudyKey(FindParam prm, out string patientid, out List <string> studykey)
        {
            patientid = "";
            studykey  = new List <string>();

            using (var db = new TryDbConnection(settings))
            {
                using (var cmd = db.CreateCommand())
                {
                    var sbWhere = new StringBuilder();
                    sbWhere.Append(" WHERE 0=0");

                    if (prm.PatientID != null && prm.PatientID.Length > 0)
                    {
                        sbWhere.Append(" AND T_Study.PatientID ILIKE " + cmd.Add(prm.PatientID.Replace(@"\", @"\\").Replace("%", @"\%").Replace("_", @"\_").Replace('*', '%').Replace('?', '_')).ParameterName);
                    }

                    if (prm.PatientName != null && prm.PatientName.Length > 0)
                    {
                        sbWhere.Append(" AND T_Study.PatientName ILIKE " + cmd.Add(prm.PatientName.Replace(@"\", @"\\").Replace("%", @"\%").Replace("_", @"\_").Replace('*', '%').Replace('?', '_')).ParameterName);
                    }

                    if (prm.AccessionNumber != null && prm.AccessionNumber.Length > 0)
                    {
                        sbWhere.Append(" AND AccessionNumber ILIKE " + cmd.Add(prm.AccessionNumber.Replace(@"\", @"\\").Replace("%", @"\%").Replace("_", @"\_").Replace('*', '%').Replace('?', '_')).ParameterName);
                    }

                    if (prm.Modality != null && prm.Modality.Length > 0)
                    {
                        var mods = new StringBuilder();
                        foreach (var mod in prm.Modality.Split(' '))
                        {
                            if (mod == "")
                            {
                                continue;
                            }
                            mods.Append(cmd.Add(mod.ToUpper()).ParameterName);
                            mods.Append(',');
                        }
                        sbWhere.Append(" AND Modality IN (" + mods.ToString().TrimEnd(',') + ")");
                    }

                    if (prm.StudyDateFrom != null && prm.StudyDateFrom.Length > 0)
                    {
                        sbWhere.Append(" AND StudyDate>=" + cmd.Add(prm.StudyDateFrom).ParameterName);
                    }

                    if (prm.StudyDateTo != null && prm.StudyDateTo.Length > 0)
                    {
                        sbWhere.Append(" AND StudyDate<=" + cmd.Add(prm.StudyDateTo).ParameterName);
                    }

                    if (prm.Comment != null && prm.Comment.Length > 0)
                    {
                        sbWhere.Append(" AND Comment ILIKE " + cmd.Add(prm.Comment.Replace(@"\", @"\\").Replace("%", @"\%").Replace("_", @"\_").Replace('*', '%').Replace('?', '_')).ParameterName);
                    }

                    if (prm.Keyword != null && prm.Keyword.Length > 0)
                    {
                        sbWhere.Append(" AND Keyword ILIKE " + cmd.Add(prm.Keyword.Replace(@"\", @"\\").Replace("%", @"\%").Replace("_", @"\_").Replace('*', '%').Replace('?', '_')).ParameterName);
                    }

                    sbWhere.Append(" AND NumberOfImages>0");

                    var sb = new StringBuilder();
                    sb.Append("SELECT StudyInstanceUID,PatientID");
                    sb.Append(" FROM T_Study");
                    sb.Append(sbWhere.ToString());
                    sb.Append(" ORDER BY StudyDate DESC,StudyTime DESC,StudyInstanceUID");

                    cmd.CommandText = sb.ToString();

                    using (var dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            var key = new StudyKey()
                            {
                                StudyInstanceUID = (string)dr["StudyInstanceUID"]
                            };
                            studykey.Add(ConvertUtil.Serialize(key));

                            string tmp = "";
                            if (dr["PatientID"] != DBNull.Value)
                            {
                                tmp = (string)dr["PatientID"];
                            }

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

            return(true);
        }
Ejemplo n.º 10
0
        //GSPS一覧の取得
        public static void GetGspsList(SeriesKey key, out List <GSPSItem> items)
        {
            items = new List <GSPSItem>();

            using (var db = new TryDbConnection(settings))
            {
                using (var cmd = db.CreateCommand())
                {
                    if (!key.IsImage)
                    {
                        cmd.CommandText = "SELECT DISTINCT ContentLabel,ContentDescription,PresentationCreationDate,PresentationCreationTime,ContentCreatorName FROM T_GSPS_R WHERE StudyInstanceUID=@0 AND ReferencedSeriesInstanceUID=@1 ORDER BY PresentationCreationDate DESC,PresentationCreationTime DESC";
                        cmd.Add(key.StudyInstanceUID);
                        cmd.Add(key.SeriesInstanceUID);

                        using (var dr = cmd.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                var gspskey = new GSPSKey()
                                {
                                    StudyInstanceUID            = key.StudyInstanceUID,
                                    ReferencedSeriesInstanceUID = key.SeriesInstanceUID,
                                    ReferencedSOPInstanceUID    = "",
                                    ContentLabel = (string)dr["ContentLabel"],
                                };

                                var item = new GSPSItem();
                                item.GSPSKey                  = ConvertUtil.Serialize(gspskey);
                                item.ContentLabel             = (string)dr["ContentLabel"];
                                item.ContentDescription       = (string)dr["ContentDescription"];
                                item.PresentationCreationDate = (string)dr["PresentationCreationDate"];
                                item.PresentationCreationTime = (string)dr["PresentationCreationTime"];
                                item.ContentCreatorName       = (string)dr["ContentCreatorName"];

                                items.Add(item);
                            }
                        }
                    }
                    else
                    {
                        cmd.CommandText = "SELECT DISTINCT ContentLabel,ContentDescription,PresentationCreationDate,PresentationCreationTime,ContentCreatorName FROM T_GSPS_R WHERE StudyInstanceUID=@0 AND ReferencedSeriesInstanceUID=@1 AND ReferencedSOPInstanceUID=@2 ORDER BY PresentationCreationDate DESC,PresentationCreationTime DESC";
                        cmd.Add(key.StudyInstanceUID);
                        cmd.Add(key.SeriesInstanceUID);
                        cmd.Add(key.SOPInstanceUID);

                        using (var dr = cmd.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                var gspskey = new GSPSKey()
                                {
                                    StudyInstanceUID            = key.StudyInstanceUID,
                                    ReferencedSeriesInstanceUID = key.SeriesInstanceUID,
                                    ReferencedSOPInstanceUID    = key.SOPInstanceUID,
                                    ContentLabel = (string)dr["ContentLabel"],
                                };

                                var item = new GSPSItem();
                                item.GSPSKey                  = ConvertUtil.Serialize(gspskey);
                                item.ContentLabel             = (string)dr["ContentLabel"];
                                item.ContentDescription       = (string)dr["ContentDescription"];
                                item.PresentationCreationDate = (string)dr["PresentationCreationDate"];
                                item.PresentationCreationTime = (string)dr["PresentationCreationTime"];
                                item.ContentCreatorName       = (string)dr["ContentCreatorName"];

                                items.Add(item);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
        //スタディ一覧の取得
        public static void GetStudyList(FindParam prm, out List <StudyTag> tags, out int count)
        {
            tags  = new List <StudyTag>();
            count = 0;

            using (var db = new TryDbConnection(settings))
            {
                using (var cmd = db.CreateCommand())
                {
                    var sbWhere = new StringBuilder();
                    sbWhere.Append(" WHERE 0=0");

                    if (prm.PatientID != null && prm.PatientID.Length > 0)
                    {
                        sbWhere.Append(" AND T_Study.PatientID ILIKE " + cmd.Add(prm.PatientID.Replace(@"\", @"\\").Replace("%", @"\%").Replace("_", @"\_").Replace('*', '%').Replace('?', '_')).ParameterName);
                    }

                    if (prm.PatientName != null && prm.PatientName.Length > 0)
                    {
                        sbWhere.Append(" AND T_Study.PatientName ILIKE " + cmd.Add(prm.PatientName.Replace(@"\", @"\\").Replace("%", @"\%").Replace("_", @"\_").Replace('*', '%').Replace('?', '_')).ParameterName);
                    }

                    if (prm.AccessionNumber != null && prm.AccessionNumber.Length > 0)
                    {
                        sbWhere.Append(" AND AccessionNumber ILIKE " + cmd.Add(prm.AccessionNumber.Replace(@"\", @"\\").Replace("%", @"\%").Replace("_", @"\_").Replace('*', '%').Replace('?', '_')).ParameterName);
                    }

                    if (prm.Modality != null && prm.Modality.Length > 0)
                    {
                        int idx = 0;
                        foreach (var mod in prm.Modality.Split(' '))
                        {
                            if (idx == 0)
                            {
                                sbWhere.Append(" AND (Modality ILIKE " + cmd.Add("%" + mod + "%").ParameterName);
                            }
                            else
                            {
                                sbWhere.Append(" OR Modality ILIKE " + cmd.Add("%" + mod + "%").ParameterName);
                            }
                            idx++;
                        }
                        sbWhere.Append(")");
                    }

                    if (prm.StudyDateFrom != null && prm.StudyDateFrom.Length > 0)
                    {
                        sbWhere.Append(" AND StudyDate>=" + cmd.Add(prm.StudyDateFrom).ParameterName);
                    }

                    if (prm.StudyDateTo != null && prm.StudyDateTo.Length > 0)
                    {
                        sbWhere.Append(" AND StudyDate<=" + cmd.Add(prm.StudyDateTo).ParameterName);
                    }

                    if (prm.Comment != null && prm.Comment.Length > 0)
                    {
                        sbWhere.Append(" AND Comment ILIKE " + cmd.Add(prm.Comment.Replace(@"\", @"\\").Replace("%", @"\%").Replace("_", @"\_").Replace('*', '%').Replace('?', '_')).ParameterName);
                    }

                    if (prm.Keyword != null && prm.Keyword.Length > 0)
                    {
                        sbWhere.Append(" AND Keyword ILIKE " + cmd.Add(prm.Keyword.Replace(@"\", @"\\").Replace("%", @"\%").Replace("_", @"\_").Replace('*', '%').Replace('?', '_')).ParameterName);
                    }

                    sbWhere.Append(" AND NumberOfImages>0");

                    string top = "";
                    if (AppUtil.MaxStudyList > 0)
                    {
                        top = string.Format(" LIMIT {0}", AppUtil.MaxStudyList);
                    }

                    var sb = new StringBuilder();
                    sb.Append("SELECT COUNT(*) cnt FROM T_Study");
                    sb.Append(sbWhere.ToString() + ";");
                    sb.Append("SELECT StudyInstanceUID,StudyDate,StudyTime,AccessionNumber,Modality,StudyDescription,T_Study.PatientName,T_Study.PatientID,PatientBirthDate,PatientSex,PatientAge,BodyPartExamined,Comment,Keyword,NumberOfImages,T_Patient.PatientName PatientName2");
                    sb.Append(" FROM T_Study LEFT JOIN T_Patient ON T_Study.PatientID=T_Patient.PatientID");
                    sb.Append(sbWhere.ToString());
                    sb.Append(" ORDER BY StudyDate DESC,StudyTime DESC,StudyInstanceUID");
                    sb.Append(top);

                    cmd.CommandText = sb.ToString();

                    using (var dr = cmd.ExecuteReader())
                    {
                        if (dr.Read())
                        {
                            count = Convert.ToInt32(dr["cnt"]);
                            if (count > 0)
                            {
                                dr.NextResult();
                                while (dr.Read())
                                {
                                    var stkey = new StudyKey()
                                    {
                                        StudyInstanceUID = (string)dr["StudyInstanceUID"]
                                    };

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

                                    if (dr["StudyDate"] != DBNull.Value)
                                    {
                                        tag.StudyDate = (string)dr["StudyDate"];
                                    }

                                    if (dr["StudyTime"] != DBNull.Value)
                                    {
                                        tag.StudyTime = (string)dr["StudyTime"];
                                    }

                                    if (dr["AccessionNumber"] != DBNull.Value)
                                    {
                                        tag.AccessionNumber = (string)dr["AccessionNumber"];
                                    }

                                    if (dr["Modality"] != DBNull.Value)
                                    {
                                        tag.Modality = (string)dr["Modality"];
                                    }

                                    if (dr["StudyDescription"] != DBNull.Value)
                                    {
                                        tag.StudyDescription = (string)dr["StudyDescription"];
                                    }

                                    if (dr["PatientName"] != DBNull.Value)
                                    {
                                        tag.PatientName = (string)dr["PatientName"];
                                    }

                                    if (dr["PatientName2"] != DBNull.Value)
                                    {
                                        tag.PatientName = (string)dr["PatientName2"];
                                    }

                                    if (AppUtil.HideData == "1")
                                    {
                                        tag.PatientName = "";
                                    }

                                    if (dr["PatientID"] != DBNull.Value)
                                    {
                                        tag.PatientID = (string)dr["PatientID"];
                                    }

                                    if (dr["PatientBirthDate"] != DBNull.Value)
                                    {
                                        tag.PatientBirthDate = (string)dr["PatientBirthDate"];
                                    }

                                    if (dr["PatientSex"] != DBNull.Value)
                                    {
                                        tag.PatientSex = (string)dr["PatientSex"];
                                    }

                                    if (dr["PatientAge"] != DBNull.Value)
                                    {
                                        tag.PatientAge = (string)dr["PatientAge"];
                                    }

                                    if (dr["BodyPartExamined"] != DBNull.Value)
                                    {
                                        tag.BodyPartExamined = (string)dr["BodyPartExamined"];
                                    }

                                    if (dr["Comment"] != DBNull.Value)
                                    {
                                        tag.Comment = (string)dr["Comment"];
                                    }

                                    if (dr["Keyword"] != DBNull.Value)
                                    {
                                        tag.Keyword = (string)dr["Keyword"];
                                    }

                                    if (dr["NumberOfImages"] != DBNull.Value)
                                    {
                                        tag.NumberOfImages = (int)dr["NumberOfImages"];
                                    }

                                    //メモ有無
                                    using (var cmd2 = db.CreateCommand())
                                    {
                                        cmd2.CommandText = "SELECT COUNT(*) cnt FROM T_StudyMemo WHERE StudyInstanceUID=@0";
                                        cmd2.Add((string)dr["StudyInstanceUID"]);

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

                                    tags.Add(tag);
                                }
                            }
                        }
                    }
                }
            }

            //ソートしない;
        }
Ejemplo n.º 12
0
        //画像一覧の取得
        public static void GetImageList(SeriesKey key, out List <ImageTag> tags)
        {
            tags = new List <ImageTag>();

            if (!key.IsImage)
            {
                var imageQuery = new RBObjectQuery();
                imageQuery.is_filter_on = 1;
                imageQuery.location     = Int32.Parse(key.StorageID);
                imageQuery.StudyUID     = key.StudyInstanceUID;
                imageQuery.SeriesUID    = key.SeriesInstanceUID;

                List <RBImage> imageList;
                if (!GetImageList(imageQuery, out imageList))
                {
                    return;
                }

                //ソート
                imageList.Sort((x, y) =>
                {
                    int c = x.ImageNo.CompareTo(y.ImageNo);
                    if (c == 0)
                    {
                        return(x.InstUID.CompareTo(y.InstUID));
                    }
                    else
                    {
                        return(c);
                    }
                });

                foreach (var image in imageList)
                {
                    var imkey = new ImageKey()
                    {
                        StudyInstanceUID  = key.StudyInstanceUID,
                        SeriesInstanceUID = key.SeriesInstanceUID,
                        SOPInstanceUID    = image.InstUID,
                        StorageID         = key.StorageID
                    };

                    var tag = new ImageTag();
                    tag.ImageKey                = ConvertUtil.Serialize(imkey); //new RsImageKey(key, image.InstUID);
                    tag.InstanceNumber          = image.ImageNo;
                    tag.SliceThickness          = image.SliceThickness.ToString();
                    tag.ImagePositionPatient    = image.ImagePosition.ToString('\\');
                    tag.ImageOrientationPatient = image.ImageOrientation.ToString('\\');
                    tag.SliceLocation           = image.SliceLocation.ToString();
                    tag.Rows         = image.Rows;
                    tag.Columns      = image.Columns;
                    tag.PixelSpacing = image.PixelSpacing.ToString('\\');
                    tag.WindowCenter = image.Level.ToString('\\');
                    tag.WindowWidth  = image.Width.ToString('\\');

                    tags.Add(tag);
                }
            }
            else
            {
                //※イメージで検索できない
                var imageQuery = new RBObjectQuery();
                imageQuery.is_filter_on = 1;
                imageQuery.location     = Int32.Parse(key.StorageID);
                imageQuery.StudyUID     = key.StudyInstanceUID;
                imageQuery.SeriesUID    = key.SeriesInstanceUID;

                List <RBImage> imageList;
                if (!GetImageList(imageQuery, out imageList))
                {
                    return;
                }

                foreach (var image in imageList)
                {
                    if (image.InstUID == key.SOPInstanceUID)
                    {
                        var nof = image.NoOfFrames;
                        if (nof == 0)
                        {
                            nof = 1;
                        }

                        for (int i = 0; i < nof; i++)
                        {
                            var imkey = new ImageKey()
                            {
                                StudyInstanceUID  = key.StudyInstanceUID,
                                SeriesInstanceUID = key.SeriesInstanceUID,
                                SOPInstanceUID    = image.InstUID,
                                FrameNumber       = i,
                                StorageID         = key.StorageID
                            };

                            var tag = new ImageTag();
                            tag.ImageKey                = ConvertUtil.Serialize(imkey); //new RsImageKey(key, i);
                            tag.InstanceNumber          = i;
                            tag.SliceThickness          = image.SliceThickness.ToString();
                            tag.ImagePositionPatient    = image.ImagePosition.ToString('\\');
                            tag.ImageOrientationPatient = image.ImageOrientation.ToString('\\');
                            tag.SliceLocation           = image.SliceLocation.ToString();
                            tag.Rows           = image.Rows;
                            tag.Columns        = image.Columns;
                            tag.PixelSpacing   = image.PixelSpacing.ToString('\\');
                            tag.WindowCenter   = image.Level.ToString('\\');
                            tag.WindowWidth    = image.Width.ToString('\\');
                            tag.NumberOfFrames = nof;

                            tags.Add(tag);
                        }

                        break;
                    }
                }
            }
        }
Ejemplo n.º 13
0
        //シリーズ一覧の取得
        public static void GetSeriesList(StudyKey key, out List <SeriesTag> tags)
        {
            tags = new List <SeriesTag>();

            var seriesQuery = new RBSeriesQuery();

            seriesQuery.is_filter_on = 1;
            seriesQuery.location     = Int32.Parse(key.StorageID);
            seriesQuery.StudyUID     = key.StudyInstanceUID;

            List <RBSeries> seriesList;

            if (!GetSeriesList(seriesQuery, out seriesList))
            {
                return;
            }

            //ソート
            seriesList.Sort((x, y) =>
            {
                int c = x.SeriesNo.CompareTo(y.SeriesNo);
                if (c == 0)
                {
                    return(x.SeriesUID.CompareTo(y.SeriesUID));
                }
                else
                {
                    return(c);
                }
            });

            foreach (var series in seriesList)
            {
                var imageQuery = new RBObjectQuery();
                imageQuery.is_filter_on = 1;
                imageQuery.location     = Int32.Parse(key.StorageID);
                imageQuery.StudyUID     = key.StudyInstanceUID;
                imageQuery.SeriesUID    = series.SeriesUID;

                List <RBImage> imageList;
                if (!GetImageList(imageQuery, out imageList))
                {
                    continue;
                }

                //ソート
                imageList.Sort((x, y) =>
                {
                    int c = x.ImageNo.CompareTo(y.ImageNo);
                    if (c == 0)
                    {
                        return(x.InstUID.CompareTo(y.InstUID));
                    }
                    else
                    {
                        return(c);
                    }
                });

                int nof = 0;
                foreach (var image in imageList)
                {
                    nof += image.NoOfFrames;
                }

                if (nof == 0)
                {
                    var sekey = new SeriesKey()
                    {
                        StudyInstanceUID  = key.StudyInstanceUID,
                        SeriesInstanceUID = series.SeriesUID,
                        SOPInstanceUID    = null,
                        StorageID         = key.StorageID,
                        IsImage           = false
                    };

                    var tag = new SeriesTag();
                    tag.SeriesKey         = ConvertUtil.Serialize(sekey); //new RsSeriesKey(key, series.SeriesUID, series.Modality, series.SeriesDesc, series.SeriesNo);
                    tag.SeriesNumber      = series.SeriesNo;
                    tag.Modality          = series.Modality;
                    tag.SeriesDescription = series.SeriesDesc;
                    tag.NumberOfImages    = series.no_im;
                    tag.NumberOfFrames    = nof;

                    tags.Add(tag);
                }
                else
                {
                    //イメージ
                    foreach (var image in imageList)
                    {
                        var sekey = new SeriesKey()
                        {
                            StudyInstanceUID  = key.StudyInstanceUID,
                            SeriesInstanceUID = series.SeriesUID,
                            SOPInstanceUID    = image.InstUID,
                            StorageID         = key.StorageID,
                            IsImage           = true
                        };

                        var tag = new SeriesTag();
                        tag.SeriesKey         = ConvertUtil.Serialize(sekey); //new RsSeriesKey(key, series.SeriesUID, image.InstUID, image.NoOfFrames);
                        tag.SeriesNumber      = series.SeriesNo;
                        tag.Modality          = series.Modality;
                        tag.SeriesDescription = series.SeriesDesc;
                        tag.NumberOfImages    = 1;
                        tag.NumberOfFrames    = image.NoOfFrames;

                        tags.Add(tag);
                    }
                }
            }
        }
Ejemplo n.º 14
0
        //スタディの取得 (URLコール用)
        public static bool GetStudyKey(FindParam prm, out string patientid, out List <string> studykey)
        {
            patientid = "";
            studykey  = new List <string>();

            using (var db = new TryDbConnection(LCL.settings))
            {
                var studyQuery = new RBStudyQuery();
                studyQuery.is_with_both_exist = AppUtil.rsNas;
                studyQuery.max_no_of_replay   = AppUtil.rsMax;

                if (string.IsNullOrEmpty(prm.PatientID) == false)
                {
                    studyQuery.is_filter_on        = 1;
                    studyQuery.is_pat_id_on        = 1;
                    studyQuery.comp_mode_of_pat_id = AppUtil.cmPatientID;
                    studyQuery.PatientID           = prm.PatientID;
                }

                if (string.IsNullOrEmpty(prm.PatientName) == false)
                {
                    studyQuery.is_filter_on          = 1;
                    studyQuery.is_pat_name_on        = 1;
                    studyQuery.comp_mode_of_pat_name = AppUtil.cmPatientName;
                    studyQuery.PatientName           = prm.PatientName;
                }

                if (string.IsNullOrEmpty(prm.AccessionNumber) == false)
                {
                    studyQuery.is_filter_on        = 1;
                    studyQuery.is_acc_no_on        = 1;
                    studyQuery.comp_mode_of_acc_no = AppUtil.cmAccessionNumber;
                    studyQuery.AccNo = prm.AccessionNumber;
                }

                if (string.IsNullOrEmpty(prm.Modality) == false)
                {
                    studyQuery.is_filter_on          = 1;
                    studyQuery.is_modality_on        = 1;
                    studyQuery.comp_mode_of_modality = AppUtil.cmModality;
                    studyQuery.Modality = prm.Modality.Replace(',', '|');
                }

                if (string.IsNullOrEmpty(prm.StudyDateFrom) == false && string.IsNullOrEmpty(prm.StudyDateTo) == false)
                {
                    studyQuery.is_filter_on  = 1;
                    studyQuery.is_st_date_on = 1;
                    studyQuery.StudyDate     = string.Format("{0}-{1}", prm.StudyDateFrom, prm.StudyDateTo);
                }
                else if (string.IsNullOrEmpty(prm.StudyDateFrom) == false)
                {
                    studyQuery.is_filter_on  = 1;
                    studyQuery.is_st_date_on = 1;
                    studyQuery.StudyDate     = string.Format("{0}-{1}", prm.StudyDateFrom, DateTime.Now.ToString("yyyyMMdd"));
                }
                else if (string.IsNullOrEmpty(prm.StudyDateTo) == false)
                {
                    studyQuery.is_filter_on  = 1;
                    studyQuery.is_st_date_on = 1;
                    studyQuery.StudyDate     = string.Format("{0}-{1}", "19700101", prm.StudyDateTo);
                }

                List <RBStudy> studyList;
                if (!GetStudyList(studyQuery, out studyList))
                {
                    return(false);
                }

                //ソート
                studyList.Sort((x, y) =>
                {
                    int c = (y.StudyDate + y.StudyTime).CompareTo(x.StudyDate + x.StudyTime);
                    if (c == 0)
                    {
                        return(x.StudyUID.CompareTo(y.StudyUID));
                    }
                    else
                    {
                        return(c);
                    }
                });

                foreach (var study in studyList)
                {
                    int nasno = -1;
                    if (!int.TryParse(study.NASHostName, out nasno))
                    {
                        LogUtil.Error1("NASHostName={0}", study.NASHostName);
                        continue;
                    }

                    var key = new StudyKey()
                    {
                        StudyInstanceUID = study.StudyUID,
                        StorageID        = nasno.ToString()
                    };
                    studykey.Add(ConvertUtil.Serialize(key));

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

            return(true);
        }
Ejemplo n.º 15
0
        //スタディ一覧の取得 (過去検査)
        public static void GetStudyList_Kako(string patientid, StudyKey key, out List <StudyTag> tags)
        {
            tags = new List <StudyTag>();

            using (var db = new TryDbConnection(LCL.settings))
            {
                var studyQuery = new RBStudyQuery();
                studyQuery.is_with_both_exist = AppUtil.rsNas;
                studyQuery.max_no_of_replay   = AppUtil.rsMax;

                if (string.IsNullOrEmpty(patientid))
                {
                    studyQuery.is_filter_on          = 1;
                    studyQuery.is_study_id_on        = 1;
                    studyQuery.comp_mode_of_study_id = 1;
                    studyQuery.StudyUID = key.StudyInstanceUID;
                }
                else
                {
                    studyQuery.is_filter_on        = 1;
                    studyQuery.is_pat_id_on        = 1;
                    studyQuery.comp_mode_of_pat_id = 1;
                    studyQuery.PatientID           = patientid;
                }

                List <RBStudy> studyList;
                if (!GetStudyList(studyQuery, out studyList))
                {
                    return;
                }

                var PatName = new Dictionary <string, string>();

                foreach (var study in studyList)
                {
                    int nasno = -1;
                    if (!int.TryParse(study.NASHostName, out nasno))
                    {
                        LogUtil.Error1("NASHostName={0}", study.NASHostName);
                        continue;
                    }

                    var stkey = new StudyKey()
                    {
                        StudyInstanceUID = study.StudyUID,
                        StorageID        = nasno.ToString()
                    };

                    var tag = new StudyTag();
                    tag.StudyKey         = ConvertUtil.Serialize(stkey);
                    tag.StudyDate        = study.StudyDate;
                    tag.StudyTime        = study.StudyTime;
                    tag.AccessionNumber  = study.AccNo;
                    tag.Modality         = study.Modality;
                    tag.StudyDescription = study.StudyDesc;
                    tag.PatientName      = study.PatNameSJ != "" ? study.PatNameSJ : study.PatName;
                    tag.PatientID        = study.PatID;
                    tag.PatientBirthDate = study.BirthDate;
                    tag.PatientSex       = study.Sex;
                    tag.BodyPartExamined = study.BodyPart;
                    tag.NumberOfImages   = (int)study.NoOfImg;

                    //患者名
                    if (PatName.ContainsKey(tag.PatientID))
                    {
                        if (PatName[tag.PatientID] != null)
                        {
                            tag.PatientName = PatName[tag.PatientID];
                        }
                    }
                    else
                    {
                        using (var cmd = db.CreateCommand())
                        {
                            cmd.CommandText = "SELECT PatientName FROM T_Patient WHERE PatientID=@0";
                            cmd.Add(tag.PatientID);

                            using (var dr = cmd.ExecuteReader())
                            {
                                if (dr.Read())
                                {
                                    tag.PatientName = (string)dr["PatientName"];
                                    PatName.Add(tag.PatientID, (string)dr["PatientName"]);
                                }
                                else
                                {
                                    PatName.Add(tag.PatientID, null);
                                }
                            }
                        }
                    }

                    if (AppUtil.HideData == "1")
                    {
                        tag.PatientName = "";
                    }

                    //メモ有無
                    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 = study.StudyUID;

                    tags.Add(tag);
                }
            }

            //ソート
            tags.Sort(new StudyTagComparer());
        }
Ejemplo n.º 16
0
        public static void GetGsps(GSPSKey key, out Dictionary <string, GSPSDataItem> items)
        {
            items = null;

            var tmpItems  = new Dictionary <string, GSPSDataItem>();
            var tmpSeries = new Dictionary <string, string>();
            var delItems  = new List <string>(); //マルチフレーム時の調整

            //GSPSのImageKey取得
            List <ImageKey> gspsImkeys;

            DbUtil.GetGsps(key, out gspsImkeys);

            foreach (var gspsImKey in gspsImkeys)
            {
                var file = FileUtil.GetDicomFile(gspsImKey);
                try
                {
                    using (var dcm = new DicomData(file, DicomTransferSyntax.LittleEndianImplicit))
                    {
                        var pr = new PRAnalyzer(dcm);

                        var tmpSop = new List <PRReferenceSOP>();

                        //ReferencedSeriesSequence
                        foreach (var seq in pr.References)
                        {
                            tmpSop.AddRange(seq.SopRefs);

                            //ReferencedImageSequence
                            foreach (var sop in seq.SopRefs)
                            {
                                if (!tmpSeries.ContainsKey(sop.SOPInstanceUID))
                                {
                                    tmpSeries.Add(sop.SOPInstanceUID, seq.SeriesInstanceUID);
                                }

                                var imkey = new ImageKey()
                                {
                                    StudyInstanceUID  = key.StudyInstanceUID,
                                    SeriesInstanceUID = seq.SeriesInstanceUID,
                                    SOPInstanceUID    = sop.SOPInstanceUID,
                                    FrameNumber       = sop.FrameNumber,
                                    StorageID         = gspsImKey.StorageID
                                };

                                var imkey2 = ConvertUtil.Serialize(imkey);
                                tmpItems.Add(imkey2, new GSPSDataItem());

                                tmpItems[imkey2].Flip   = pr.Flip.ToString().ToLower();
                                tmpItems[imkey2].Rotate = pr.Rotate.ToString();
                            }
                        }

                        //SoftcopyVOILUTSequence
                        foreach (var seq in pr.VoiLuts)
                        {
                            if (seq.SopRefs.Length == 0)
                            {
                                seq.SopRefs = tmpSop.ToArray();
                            }

                            //ReferencedImageSequence
                            foreach (var sop in seq.SopRefs)
                            {
                                var imkey = new ImageKey()
                                {
                                    StudyInstanceUID  = key.StudyInstanceUID,
                                    SeriesInstanceUID = tmpSeries[sop.SOPInstanceUID],
                                    SOPInstanceUID    = sop.SOPInstanceUID,
                                    FrameNumber       = sop.FrameNumber,
                                    StorageID         = gspsImKey.StorageID
                                };

                                var imkey2 = ConvertUtil.Serialize(imkey);

                                if (!tmpItems.ContainsKey(imkey2))
                                {
                                    tmpItems.Add(imkey2, new GSPSDataItem());
                                }

                                tmpItems[imkey2].VoiLut = seq.ToString();
                            }
                        }

                        //GraphicAnnotationSequence
                        foreach (var seq in pr.Infos)
                        {
                            //ReferencedImageSequence
                            foreach (var sop in seq.Reference.SopRefs)
                            {
                                var imkey = new ImageKey()
                                {
                                    StudyInstanceUID  = key.StudyInstanceUID,
                                    SeriesInstanceUID = tmpSeries[sop.SOPInstanceUID],
                                    SOPInstanceUID    = sop.SOPInstanceUID,
                                    FrameNumber       = sop.FrameNumber,
                                    StorageID         = gspsImKey.StorageID
                                };

                                var imkey2 = ConvertUtil.Serialize(imkey);

                                if (!tmpItems.ContainsKey(imkey2))
                                {
                                    tmpItems.Add(imkey2, new GSPSDataItem());
                                }

                                tmpItems[imkey2].Info = seq.ToString();
                            }
                        }

                        //DisplayedAreaSelectionSequence
                        foreach (var seq in pr.DisplayAreas)
                        {
                            if (seq.SopRefs.Length == 0)
                            {
                                seq.SopRefs = tmpSop.ToArray();
                            }

                            //ReferencedImageSequence
                            foreach (var sop in seq.SopRefs)
                            {
                                var imkey = new ImageKey()
                                {
                                    StudyInstanceUID  = key.StudyInstanceUID,
                                    SeriesInstanceUID = tmpSeries[sop.SOPInstanceUID],
                                    SOPInstanceUID    = sop.SOPInstanceUID,
                                    FrameNumber       = sop.FrameNumber,
                                    StorageID         = gspsImKey.StorageID
                                };

                                var imkey2 = ConvertUtil.Serialize(imkey);

                                if (!tmpItems.ContainsKey(imkey2))
                                {
                                    tmpItems.Add(imkey2, new GSPSDataItem());
                                }

                                tmpItems[imkey2].DisplayArea = seq.ToString();

                                //マルチフレーム時の調整
                                if (sop.FrameNumber > 0)
                                {
                                    var imkey3 = new ImageKey()
                                    {
                                        StudyInstanceUID  = key.StudyInstanceUID,
                                        SeriesInstanceUID = tmpSeries[sop.SOPInstanceUID],
                                        SOPInstanceUID    = sop.SOPInstanceUID,
                                        FrameNumber       = 0,
                                        StorageID         = gspsImKey.StorageID
                                    };

                                    var imkey4 = ConvertUtil.Serialize(imkey3);

                                    if (tmpItems.ContainsKey(imkey4))
                                    {
                                        if (tmpItems[imkey2].Flip == "")
                                        {
                                            tmpItems[imkey2].Flip = tmpItems[imkey4].Flip;
                                        }

                                        if (tmpItems[imkey2].Rotate == "")
                                        {
                                            tmpItems[imkey2].Rotate = tmpItems[imkey4].Rotate;
                                        }

                                        if (!delItems.Contains(imkey4))
                                        {
                                            delItems.Add(imkey4);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch
                {
                    LogUtil.Error1("PR Error [{0}]", file);
                    throw;
                }
            }

            //マルチフレーム時の調整
            if (delItems.Count > 0)
            {
                foreach (var delItem in delItems)
                {
                    tmpItems.Remove(delItem);
                }
            }

            items = tmpItems;
        }