public static void GetImageInfo(ImageKey key, out ImageTag tag) { if (AppUtil.DbType == AppUtil.DB_YCOM) { YCOM.GetImageInfo(key, out tag); } else { throw new NotImplementedException(); } }
public static void PrefetchImage(ImageKey key) { if (AppUtil.DbType == AppUtil.DB_YCOM) { YCOM.PrefetchImage(key); } else { throw new NotImplementedException(); } }
public static string GetDicomFile(ImageKey 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 if (AppUtil.DbType == AppUtil.DB_YCOM) { var sto = DbCacheUtil.GetStorage(); return(Path.Combine(sto.DicomPath, key.StudyInstanceUID, key.SeriesInstanceUID, key.SOPInstanceUID + AppUtil.DicomExt)); } else { var sto = DbCacheUtil.GetStorage(key.StorageID); return(Path.Combine(sto.DicomPath, key.StudyInstanceUID, key.SeriesInstanceUID, key.SOPInstanceUID + AppUtil.DicomExt)); } }
//GSPSの取得 public static void GetGsps(GSPSKey key, out List <ImageKey> items) { items = new List <ImageKey>(); using (var db = new TryDbConnection(settings)) { using (var cmd = db.CreateCommand()) { if (key.ReferencedSOPInstanceUID == "") { cmd.CommandText = "SELECT DISTINCT SeriesInstanceUID,SOPInstanceUID,StorageID FROM T_GSPS_R WHERE StudyInstanceUID=@0 AND ReferencedSeriesInstanceUID=@1 AND ContentLabel=@2"; cmd.Add(key.StudyInstanceUID); cmd.Add(key.ReferencedSeriesInstanceUID); cmd.Add(key.ContentLabel); } else { cmd.CommandText = "SELECT DISTINCT SeriesInstanceUID,SOPInstanceUID,StorageID FROM T_GSPS_R WHERE StudyInstanceUID=@0 AND ReferencedSeriesInstanceUID=@1 AND ReferencedSOPInstanceUID=@2 AND ContentLabel=@3"; cmd.Add(key.StudyInstanceUID); cmd.Add(key.ReferencedSeriesInstanceUID); cmd.Add(key.ReferencedSOPInstanceUID); cmd.Add(key.ContentLabel); } using (var dr = cmd.ExecuteReader()) { while (dr.Read()) { var imkey = new ImageKey() { StudyInstanceUID = key.StudyInstanceUID, SeriesInstanceUID = (string)dr["SeriesInstanceUID"], SOPInstanceUID = (string)dr["SOPInstanceUID"], StorageID = (string)dr["StorageID"] }; items.Add(imkey); } } } } }
//画像一覧の取得 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; } }
public static string GetThumbFile(ImageKey key) { return(Path.Combine(AppUtil.ThumbPath, key.StudyInstanceUID, key.SeriesInstanceUID, key.SOPInstanceUID + AppUtil.EXT_THUMB)); }
//画像一覧の取得 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 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 GetGsps(GSPSKey key, out Dictionary <string, GSPSDataItem> items) { items = null; var tmpItems = new Dictionary <string, GSPSDataItem>(); var tmpSeries = new Dictionary <string, string>(); var delItems = new List <string>(); //マルチフレーム時の調整 //GSPSのImageKey取得 List <ImageKey> gspsImkeys; DbUtil.GetGsps(key, out gspsImkeys); foreach (var gspsImKey in gspsImkeys) { var file = FileUtil.GetDicomFile(gspsImKey); try { using (var dcm = new DicomData(file, DicomTransferSyntax.LittleEndianImplicit)) { var pr = new PRAnalyzer(dcm); var tmpSop = new List <PRReferenceSOP>(); //ReferencedSeriesSequence foreach (var seq in pr.References) { tmpSop.AddRange(seq.SopRefs); //ReferencedImageSequence foreach (var sop in seq.SopRefs) { if (!tmpSeries.ContainsKey(sop.SOPInstanceUID)) { tmpSeries.Add(sop.SOPInstanceUID, seq.SeriesInstanceUID); } var imkey = new ImageKey() { StudyInstanceUID = key.StudyInstanceUID, SeriesInstanceUID = seq.SeriesInstanceUID, SOPInstanceUID = sop.SOPInstanceUID, FrameNumber = sop.FrameNumber, StorageID = gspsImKey.StorageID }; var imkey2 = ConvertUtil.Serialize(imkey); tmpItems.Add(imkey2, new GSPSDataItem()); tmpItems[imkey2].Flip = pr.Flip.ToString().ToLower(); tmpItems[imkey2].Rotate = pr.Rotate.ToString(); } } //SoftcopyVOILUTSequence foreach (var seq in pr.VoiLuts) { if (seq.SopRefs.Length == 0) { seq.SopRefs = tmpSop.ToArray(); } //ReferencedImageSequence foreach (var sop in seq.SopRefs) { var imkey = new ImageKey() { StudyInstanceUID = key.StudyInstanceUID, SeriesInstanceUID = tmpSeries[sop.SOPInstanceUID], SOPInstanceUID = sop.SOPInstanceUID, FrameNumber = sop.FrameNumber, StorageID = gspsImKey.StorageID }; var imkey2 = ConvertUtil.Serialize(imkey); if (!tmpItems.ContainsKey(imkey2)) { tmpItems.Add(imkey2, new GSPSDataItem()); } tmpItems[imkey2].VoiLut = seq.ToString(); } } //GraphicAnnotationSequence foreach (var seq in pr.Infos) { //ReferencedImageSequence foreach (var sop in seq.Reference.SopRefs) { var imkey = new ImageKey() { StudyInstanceUID = key.StudyInstanceUID, SeriesInstanceUID = tmpSeries[sop.SOPInstanceUID], SOPInstanceUID = sop.SOPInstanceUID, FrameNumber = sop.FrameNumber, StorageID = gspsImKey.StorageID }; var imkey2 = ConvertUtil.Serialize(imkey); if (!tmpItems.ContainsKey(imkey2)) { tmpItems.Add(imkey2, new GSPSDataItem()); } tmpItems[imkey2].Info = seq.ToString(); } } //DisplayedAreaSelectionSequence foreach (var seq in pr.DisplayAreas) { if (seq.SopRefs.Length == 0) { seq.SopRefs = tmpSop.ToArray(); } //ReferencedImageSequence foreach (var sop in seq.SopRefs) { var imkey = new ImageKey() { StudyInstanceUID = key.StudyInstanceUID, SeriesInstanceUID = tmpSeries[sop.SOPInstanceUID], SOPInstanceUID = sop.SOPInstanceUID, FrameNumber = sop.FrameNumber, StorageID = gspsImKey.StorageID }; var imkey2 = ConvertUtil.Serialize(imkey); if (!tmpItems.ContainsKey(imkey2)) { tmpItems.Add(imkey2, new GSPSDataItem()); } tmpItems[imkey2].DisplayArea = seq.ToString(); //マルチフレーム時の調整 if (sop.FrameNumber > 0) { var imkey3 = new ImageKey() { StudyInstanceUID = key.StudyInstanceUID, SeriesInstanceUID = tmpSeries[sop.SOPInstanceUID], SOPInstanceUID = sop.SOPInstanceUID, FrameNumber = 0, StorageID = gspsImKey.StorageID }; var imkey4 = ConvertUtil.Serialize(imkey3); if (tmpItems.ContainsKey(imkey4)) { if (tmpItems[imkey2].Flip == "") { tmpItems[imkey2].Flip = tmpItems[imkey4].Flip; } if (tmpItems[imkey2].Rotate == "") { tmpItems[imkey2].Rotate = tmpItems[imkey4].Rotate; } if (!delItems.Contains(imkey4)) { delItems.Add(imkey4); } } } } } } } catch { LogUtil.Error1("PR Error [{0}]", file); throw; } } //マルチフレーム時の調整 if (delItems.Count > 0) { foreach (var delItem in delItems) { tmpItems.Remove(delItem); } } items = tmpItems; }