//レポート連携情報取得 public static void GetReportInfo(StudyKey key, out StudyTag tag) { tag = new StudyTag(); using (var db = new TryDbConnection(settings)) { using (var cmd = db.CreateCommand()) { cmd.CommandText = "SELECT AccessionNumber,PatientID,StudyDate,StudyTime,Modality FROM T_Study WHERE StudyInstanceUID=@0"; cmd.Add(key.StudyInstanceUID); using (var dr = cmd.ExecuteReader()) { if (dr.Read()) { tag.AccessionNumber = (string)dr["AccessionNumber"]; tag.PatientID = (string)dr["PatientID"]; tag.StudyDate = (string)dr["StudyDate"]; tag.StudyTime = (string)dr["StudyTime"]; tag.Modality = (string)dr["Modality"]; } } } } }
//検査メモ履歴の取得 public static void GetStudyMemoHistory(StudyKey key, out List <StudyMemoItem> items) { items = new List <StudyMemoItem>(); using (var db = new TryDbConnection(settings)) { using (var cmd = db.CreateCommand()) { cmd.CommandText = "SELECT MemoDate,Memo,UserName FROM T_StudyMemoHistory WHERE StudyInstanceUID=@0 ORDER BY MemoDate DESC"; cmd.Add(key.StudyInstanceUID); using (var dr = cmd.ExecuteReader()) { while (dr.Read()) { var item = new StudyMemoItem(); item.Memo = (string)dr["Memo"]; item.UserName = (string)dr["UserName"]; item.MemoDate = (DateTime)dr["MemoDate"]; items.Add(item); } } } } }
public static bool DelStudy(StudyKey key, out List <string> items) { if (AppUtil.DbType == AppUtil.DB_CLD) { return(LCL.DelStudy(key, out items)); } else { throw new NotImplementedException(); } }
public static bool SetKeyword(StudyKey key, string item) { if (AppUtil.DbType == AppUtil.DB_CLD) { return(LCL.SetKeyword(key, item)); } else { throw new NotImplementedException(); } }
public static bool SetStudyMemo(StudyKey key, StudyMemoItem item) { if (AppUtil.DbType == AppUtil.DB_CLD) { return(LCL.SetStudyMemo(key, item)); } else { throw new NotImplementedException(); } }
public static void GetStudyMemoHistory(StudyKey key, out List <StudyMemoItem> items) { if (AppUtil.DbType == AppUtil.DB_CLD) { LCL.GetStudyMemoHistory(key, out items); } else { throw new NotImplementedException(); } }
public static void GetStudyMemo(StudyKey key, out StudyMemoItem item, out int count) { if (AppUtil.DbType == AppUtil.DB_CLD) { LCL.GetStudyMemo(key, out item, out count); } else { throw new NotImplementedException(); } }
public static void GetStudyList_Kako(string patientid, StudyKey key, out List <StudyTag> tags) { if (key.IsPacsSearch) { DCM.GetStudyList_Kako(patientid, key, out tags); } else if (AppUtil.DbType == AppUtil.DB_RS) { RS.GetStudyList_Kako(patientid, key, out tags); } else if (AppUtil.DbType == AppUtil.DB_YCOM) { YCOM.GetStudyList_Kako(patientid, key, out tags); } else { LCL.GetStudyList_Kako(patientid, key, out tags); } }
//キーワードの設定 public static bool SetKeyword(StudyKey key, string item) { for (int i = 0; i < AppUtil.RetryCount; i++) { string err = ""; using (var db = new TryDbConnection(settings)) { db.BeginTransaction(); try { using (var cmd = db.CreateCommand()) { cmd.CommandText = "UPDATE T_Study SET Keyword=@1 WHERE StudyInstanceUID=@0"; cmd.Add(key.StudyInstanceUID); cmd.Add(item); cmd.ExecuteNonQuery(); } db.Commit(); return(true); } catch (Exception ex) { db.Rollback(); err = ex.ToString(); } } //リトライ if (i < AppUtil.RetryCount - 1) { System.Threading.Thread.Sleep(AppUtil.SleepTime); } else { LogUtil.Error(err); } } return(false); }
public static void GetSeriesList(StudyKey key, out List <SeriesTag> tags) { if (key.IsPacsSearch) { DCM.GetSeriesList(key, out tags); } else if (AppUtil.DbType == AppUtil.DB_RS) { RS.GetSeriesList(key, out tags); } else if (AppUtil.DbType == AppUtil.DB_YCOM) { YCOM.GetSeriesList(key, out tags); } else { LCL.GetSeriesList(key, out tags); } }
//検査メモの取得 public static void GetStudyMemo(StudyKey key, out StudyMemoItem item, out int histCount) { item = null; histCount = 0; using (var db = new TryDbConnection(settings)) { using (var cmd = db.CreateCommand()) { cmd.CommandText = "SELECT MemoDate,Memo,UserName FROM T_StudyMemo WHERE StudyInstanceUID=@0"; cmd.Add(key.StudyInstanceUID); using (var dr = cmd.ExecuteReader()) { if (dr.Read()) { item = new StudyMemoItem(); item.Memo = (string)dr["Memo"]; item.UserName = (string)dr["UserName"]; item.MemoDate = (DateTime)dr["MemoDate"]; } } } using (var cmd = db.CreateCommand()) { cmd.CommandText = "SELECT COUNT(*) cnt FROM T_StudyMemoHistory WHERE StudyInstanceUID=@0"; cmd.Add(key.StudyInstanceUID); using (var dr = cmd.ExecuteReader()) { if (dr.Read()) { histCount = Convert.ToInt32(dr["cnt"]); } } } } }
//スタディ一覧の取得 (過去検査) 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()); }
//シリーズ一覧の取得 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); } } }
//スタディの取得 (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); }
//スタディの削除 public static bool DelStudy(StudyKey key, out List <string> items) { items = new List <string>(); using (var db = new TryDbConnection(settings)) { using (var cmd = db.CreateCommand()) { cmd.CommandText = "SELECT DISTINCT StorageID FROM T_Image WHERE StudyInstanceUID=@0"; cmd.Add(key.StudyInstanceUID); using (var dr = cmd.ExecuteReader()) { while (dr.Read()) { items.Add((string)dr["StorageID"]); } } } } for (int i = 0; i < AppUtil.RetryCount; i++) { using (var db = new TryDbConnection(settings)) { db.BeginTransaction(); try { using (var cmd = db.CreateCommand()) { cmd.CommandText = "DELETE FROM T_Study WHERE StudyInstanceUID=@0"; cmd.Add(key.StudyInstanceUID); cmd.ExecuteNonQuery(); } db.Commit(); return(true); } catch (Exception ex) { db.Rollback(); LogUtil.Warn(ex); } } //リトライ if (i < AppUtil.RetryCount - 1) { System.Threading.Thread.Sleep(AppUtil.SleepTime); LogUtil.Info1("RETRY:{0}", i + 1); } else { LogUtil.Error1("STUDY削除:失敗 [{0}]", key.StudyInstanceUID); return(false); } } return(true); }
//スタディ一覧の取得 (過去検査) 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()); }
//シリーズ一覧の取得 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()); }
//スタディの取得 (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); }
//スタディ一覧の取得 (過去検査) 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()); }
//スタディ一覧の取得 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); } } } } } } //ソートしない; }
//検査メモの設定 public static bool SetStudyMemo(StudyKey key, StudyMemoItem item) { for (int i = 0; i < AppUtil.RetryCount; i++) { string err = ""; var now = DateTime.Now; using (var db = new TryDbConnection(settings)) { db.BeginTransaction(); try { using (var cmd = db.CreateCommand()) { cmd.CommandText = "DELETE FROM T_StudyMemo WHERE StudyInstanceUID=@0"; cmd.Add(key.StudyInstanceUID); cmd.ExecuteNonQuery(); } if (item.Memo.Trim() != "") { using (var cmd = db.CreateCommand()) { cmd.CommandText = "INSERT INTO T_StudyMemo(StudyInstanceUID,MemoDate,Memo,UserName) VALUES(@0,@1,@2,@3)"; cmd.Add(key.StudyInstanceUID); cmd.Add(now); cmd.Add(item.Memo); cmd.Add(item.UserName); cmd.ExecuteNonQuery(); } } using (var cmd = db.CreateCommand()) { cmd.CommandText = "INSERT INTO T_StudyMemoHistory(StudyInstanceUID,MemoDate,Memo,UserName) VALUES(@0,@1,@2,@3)"; cmd.Add(key.StudyInstanceUID); cmd.Add(now); cmd.Add(item.Memo); cmd.Add(item.UserName); cmd.ExecuteNonQuery(); } db.Commit(); return(true); } catch (Exception ex) { db.Rollback(); err = ex.ToString(); } } //リトライ if (i < AppUtil.RetryCount - 1) { System.Threading.Thread.Sleep(AppUtil.SleepTime); } else { LogUtil.Error(err); } } return(false); }
//シリーズ一覧の取得 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); } } } }
//スタディの取得 (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); }