Example #1
0
 public static bool GetStudyKey(FindParam prm, out string patientid, out List <string> studykey)
 {
     if (prm.IsPacsSearch)
     {
         return(DCM.GetStudyKey(prm, out patientid, out studykey));
     }
     else if (AppUtil.DbType == AppUtil.DB_RS)
     {
         return(RS.GetStudyKey(prm, out patientid, out studykey));
     }
     else if (AppUtil.DbType == AppUtil.DB_YCOM)
     {
         return(YCOM.GetStudyKey(prm, out patientid, out studykey));
     }
     else
     {
         return(LCL.GetStudyKey(prm, out patientid, out studykey));
     }
 }
Example #2
0
        //T

        public static void GetStudyList(FindParam prm, out List <StudyTag> tags, out int count)
        {
            if (prm.IsPacsSearch)
            {
                DCM.GetStudyList(prm, out tags, out count);
            }
            else if (AppUtil.DbType == AppUtil.DB_RS)
            {
                RS.GetStudyList(prm, out tags, out count);
            }
            else if (AppUtil.DbType == AppUtil.DB_YCOM)
            {
                YCOM.GetStudyList(prm, out tags, out count);
            }
            else
            {
                LCL.GetStudyList(prm, out tags, out count);
            }
        }
Example #3
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()));
        }
Example #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);
        }
Example #5
0
        //スタディ一覧の取得
        public static void GetStudyList(FindParam prm, out List <StudyTag> tags, out int count)
        {
            tags  = new List <StudyTag>();
            count = 0;

            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;
                }

                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);
                }
            }

            count = tags.Count;

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

            if (tags.Count > AppUtil.MaxStudyList)
            {
                tags.RemoveRange(AppUtil.MaxStudyList, tags.Count - AppUtil.MaxStudyList);
            }
        }
Example #6
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);
        }
Example #7
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);
                                }
                            }
                        }
                    }
                }
            }

            //ソートしない;
        }
Example #8
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);
        }
Example #9
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(LCL.settings))
            {
                var studyQuery = new RBStudyQuery();
                studyQuery.is_with_both_exist = AppUtil.rsNas;
                studyQuery.max_no_of_replay   = AppUtil.MaxStudyList > 0 ? AppUtil.MaxStudyList : 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;
                }

                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);
                }

                count = tags.Count;
            }

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