//StorageIDの取得 (DCM用) public static void GetImageStorageID(ref SeriesKey key) { if (key.StorageID != null && key.StorageID != "") { return; } using (var db = new TryDbConnection(settings)) { using (var cmd = db.CreateCommand()) { cmd.CommandText = "SELECT StorageID FROM T_Image WHERE StudyInstanceUID=@0 AND SeriesInstanceUID=@1 AND SOPInstanceUID=@2"; cmd.Add(key.StudyInstanceUID); cmd.Add(key.SeriesInstanceUID); cmd.Add(key.SOPInstanceUID); using (var dr = cmd.ExecuteReader()) { if (dr.Read()) { key.StorageID = (string)dr["StorageID"]; } } } } }
//サムネイルの取得 public static void GetThumbnail(SeriesKey key, out byte[] thumb) { thumb = null; if (key.SOPInstanceUID == null) { string thumbFile = Path.Combine(server[Int32.Parse(key.StorageID)], key.StudyInstanceUID, key.SeriesInstanceUID, FILE_THUMB); if (File.Exists(thumbFile)) { thumb = File.ReadAllBytes(thumbFile); } else { LogUtil.Error("File Not Found: " + thumbFile); } } else { string dicomFile = Path.Combine(server[Int32.Parse(key.StorageID)], key.StudyInstanceUID, key.SeriesInstanceUID, key.SOPInstanceUID + EXT_DICOM); if (File.Exists(dicomFile)) { DicomUtil.DicomToThumb(dicomFile, out thumb); } else { LogUtil.Error("File Not Found: " + dicomFile); } } }
//THUMBファイルを返す public static string GetThumbFile(SeriesKey key) { if (key.IsImage) { return(Path.Combine(AppUtil.ThumbPath, key.StudyInstanceUID, key.SeriesInstanceUID, key.SOPInstanceUID + AppUtil.EXT_THUMB)); } else { return(Path.Combine(AppUtil.ThumbPath, key.StudyInstanceUID, key.SeriesInstanceUID + AppUtil.EXT_THUMB)); } }
public static void PrefetchImageList(SeriesKey key, out List <string> keys) { if (AppUtil.DbType == AppUtil.DB_YCOM) { YCOM.PrefetchImageList(key, out keys); } else { throw new NotImplementedException(); } }
//DICOMファイルを返す public static string GetDicomFile(SeriesKey key) { if (AppUtil.DbType == AppUtil.DB_RS) { return(Path.Combine(RS.server[Int32.Parse(key.StorageID)], key.StudyInstanceUID, key.SeriesInstanceUID, key.SOPInstanceUID + RS.EXT_DICOM)); } else { var sto = DbCacheUtil.GetStorage(key.StorageID); return(Path.Combine(sto.DicomPath, key.StudyInstanceUID, key.SeriesInstanceUID, key.SOPInstanceUID + AppUtil.DicomExt)); } }
//サムネイルの取得 public static void GetThumbnail(SeriesKey key, out byte[] thumb) { thumb = null; var sto = DbCacheUtil.GetStorage(key.StorageID); using (var imp = new Impersonate(sto.LogonUsername, sto.LogonPassword)) { var dicomFile = FileUtil.GetDicomFile(key); if (File.Exists(dicomFile)) { DicomUtil.DicomToThumb(dicomFile, out thumb); } } }
public static void GetThumbnail(SeriesKey key, out byte[] thumb, out bool save) { if (key.IsPacsSearch) { DCM.GetThumbnail(key, out thumb); save = true; } else if (AppUtil.DbType == AppUtil.DB_RS) { RS.GetThumbnail(key, out thumb); save = false; } else if (AppUtil.DbType == AppUtil.DB_YCOM) { YCOM.GetThumbnail(key, out thumb, out save); } else { LCL.GetThumbnail(key, out thumb); save = true; } }
public static void GetImageList(LoginItem login, SeriesKey key, out List <ImageTag> imTags, out List <SeriesTag> seTags) { if (key.IsPacsSearch) { DCM.GetImageList(login, key, out imTags, out seTags); } else if (AppUtil.DbType == AppUtil.DB_RS) { RS.GetImageList(key, out imTags); seTags = null; } else if (AppUtil.DbType == AppUtil.DB_YCOM) { YCOM.GetImageList(key, out imTags); seTags = null; } else { LCL.GetImageList(key, out imTags); seTags = null; } }
//画像一覧の取得 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); } } } } } } }
//シリーズ一覧の取得 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()); }
//サムネイルの作成 public static void GetThumbnail(SeriesKey key, out byte[] thumb) { thumb = null; if (key.SOPInstanceUID == null || key.SOPInstanceUID == "") { using (var pc = new PacsComm()) { DicomTagsResult ret = pc.CFindImage(key.StudyInstanceUID, key.SeriesInstanceUID); if (!ret.IsSuccess) { LogUtil.Error("CFINDに失敗しました。"); return; } var tags = new List <Tuple <string, long> >(); foreach (var dcmTag in ret.Tags) { long InstanceNumber = 0; Int64.TryParse(dcmTag.GetTagValue(DicomDic.Find("InstanceNumber").Tag), out InstanceNumber); var tag = Tuple.Create(dcmTag.GetTagValue(DicomDic.Find("SOPInstanceUID").Tag), InstanceNumber); tags.Add(tag); } //ソート tags = tags.OrderBy(n => n.Item2).ToList(); if (tags.Count > 0) { key.SOPInstanceUID = tags[0].Item1; } } } if (key.SOPInstanceUID != null && key.SOPInstanceUID != "") { //DICOMがある { LCL.GetImageStorageID(ref key); if (key.StorageID != null && key.StorageID != "") { var sto = DbCacheUtil.GetStorage(key.StorageID); using (var imp = new Impersonate(sto.LogonUsername, sto.LogonPassword)) { var file = FileUtil.GetDicomFile(key); if (File.Exists(file)) { DicomUtil.DicomToThumb(file, out thumb); if (thumb != null) { return; } } } } } //DICOMがない using (var pc = new PacsComm()) { //画像取得 DicomFilesResult ret = pc.CMoveImage(key.StudyInstanceUID, key.SeriesInstanceUID, key.SOPInstanceUID); if (!ret.IsSuccess) { LogUtil.Error("CMoveImage"); return; } if (ret.Files.Length == 0) { LogUtil.Error("CMoveImage [File=0]"); return; } LogUtil.Debug1("CMoveImage [File={0}]", ret.Files.Length.ToString()); foreach (DicomFile dcmfile in ret.Files) { var file = dcmfile.FileName.Trim(); if (!File.Exists(file)) { continue; } DicomUtil.DicomToThumb(file, out thumb); if (thumb != null) { return; } } } } }
//DICOMの取得 public static void GetImage(LoginItem login, SeriesKey key) { GetImage(login.UserName, login.StorageID, key.StudyInstanceUID, key.SeriesInstanceUID, key.SOPInstanceUID); }
//画像一覧の取得 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; } } } }
//シリーズ一覧の取得 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); } } } }
//GSPS public static void GetGspsList(SeriesKey key, out List <GSPSItem> items) { LCL.GetGspsList(key, out items); }
//シリーズ一覧の取得 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); } } }
//画像一覧の取得 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; } }
//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); } } } } } }