//SeriesTagの取得 public static void GetSeriesTag(string file, out SeriesTag tag) { tag = new SeriesTag(); using (var dcm = new DicomData(file)) { var dic = DicomTagDictionary.Open(dcm, DcmTag.ToTagArray(DCM.SERIES_TAG)); tag.Modality = dic.GetValue <string>(DcmTag.Modality.Tag, ""); tag.SeriesDescription = dic.GetValue <string>(DcmTag.SeriesDescription.Tag, ""); tag.SeriesNumber = dic.GetValue <long>(DcmTag.SeriesNumber.Tag, 0); tag.NumberOfImages = 1; if (dcm.Images.Load()) { tag.NumberOfFrames = dcm.Images.NumberOfFrame; } } }
public PRAnalyzer(DicomData dcm) { var dic = DicomTagDictionary.Open(dcm, 0x81115, //参照シリーズシーケンス 0x700001, //図形シーケンス 0x283110, //ソフトコピーVOI LUTシーケンス 0x700041, //画像水平フリップ 0x700042, //画像回転 0x70005A //表示領域選択シーケンス ); var tag = dic[0x700001]; if (tag == null) { return; } if (dic[0x700041] != null) { Flip = dic[0x700041].ToString() == "Y"; } if (dic[0x700042] != null) { Rotate = dic[0x700042].ToValue(0d); } List <PRDisplayArea> displayareas = new List <PRDisplayArea>(); var displayareatag = dic[0x70005A]; if (displayareatag != null) { foreach (var t in displayareatag) { if (t.Tag != 0xfffee000) { continue; } PRDisplayArea refobj = new PRDisplayArea(); var dic2 = DicomTagDictionary.Open(t, 0x81140, //参照画像シーケンス 0x700052, //表示領域上左手コーナ 0x700053, //表示領域下右手コーナ 0x700100, //提示寸法モード 0x700101 //提示画素間隔 ); var seriesuid = dic2[0x20000E]; if (dic2[0x700052] != null && dic2[0x700053] != null) { refobj.PointLU = new PRPoint(dic2[0x700052].ToArray(new double[] { 0, 0 })); refobj.PointRD = new PRPoint(dic2[0x700053].ToArray(new double[] { 0, 0 })); } else { continue; } if (dic2[0x700100] != null) { refobj.SizeMode = dic2[0x700100].ToString(); } if (dic2[0x700101] != null) { refobj.PixelSpacing = new PRPoint(dic2[0x700101].ToArray(new double[] { 0, 0 })); } List <PRReferenceSOP> referencesop = new List <PRReferenceSOP>(); var imageseq = dic2[0x81140]; if (imageseq != null) { foreach (var t2 in imageseq) { if (t2.Tag != 0xfffee000) { continue; } var dic3 = DicomTagDictionary.Open(t2, 0x81150, 0x81155, 0x81160); var cuid = dic3[0x81150]; var uid = dic3[0x81155]; var frame = dic3[0x81160]; if (cuid != null && uid != null) { PRReferenceSOP refobjsop = new PRReferenceSOP() { SOPClassUID = cuid.ToString(), SOPInstanceUID = uid.ToString() }; if (frame != null) { refobjsop.FrameNumber = frame.ToValue(0); } referencesop.Add(refobjsop); } } } refobj.SopRefs = referencesop.ToArray(); displayareas.Add(refobj); } } DisplayAreas = displayareas.ToArray(); List <PRVoiLut> voiluts = new List <PRVoiLut>(); var voiluttag = dic[0x283110]; if (voiluttag != null) { foreach (var t in voiluttag) { if (t.Tag != 0xfffee000) { continue; } PRVoiLut refobj = new PRVoiLut(); var dic2 = DicomTagDictionary.Open(t, 0x81140, //参照画像シーケンス 0x281050, //ウィンドウ中心 0x281051 //ウィンドウ幅 ); var seriesuid = dic2[0x20000E]; if (dic2[0x281050] != null && dic2[0x281051] != null) { refobj.WindowCenter = dic2[0x281050].ToValue(0d); refobj.WindowWidth = dic2[0x281051].ToValue(0d); } else { continue; } List <PRReferenceSOP> referencesop = new List <PRReferenceSOP>(); var imageseq = dic2[0x81140]; if (imageseq != null) { foreach (var t2 in imageseq) { if (t2.Tag != 0xfffee000) { continue; } var dic3 = DicomTagDictionary.Open(t2, 0x81150, 0x81155, 0x81160); var cuid = dic3[0x81150]; var uid = dic3[0x81155]; var frame = dic3[0x81160]; if (cuid != null && uid != null) { PRReferenceSOP refobjsop = new PRReferenceSOP() { SOPClassUID = cuid.ToString(), SOPInstanceUID = uid.ToString() }; if (frame != null) { refobjsop.FrameNumber = frame.ToValue(0); } referencesop.Add(refobjsop); } } } refobj.SopRefs = referencesop.ToArray(); voiluts.Add(refobj); } } VoiLuts = voiluts.ToArray(); List <PRReference> reference = new List <PRReference>(); var refseriestag = dic[0x81115]; if (refseriestag != null) { foreach (var t in refseriestag) { if (t.Tag != 0xfffee000) { continue; } PRReference refobj = new PRReference(); var dic2 = DicomTagDictionary.Open(t, 0x81140, //参照画像シーケンス 0x20000E //シリーズインスタンスUID ); var seriesuid = dic2[0x20000E]; if (dic2[0x81140] != null) { refobj.SeriesInstanceUID = dic2[0x81140].ToString(); } List <PRReferenceSOP> referencesop = new List <PRReferenceSOP>(); var imageseq = dic2[0x81140]; if (imageseq != null) { foreach (var t2 in imageseq) { if (t2.Tag != 0xfffee000) { continue; } var dic3 = DicomTagDictionary.Open(t2, 0x81150, 0x81155, 0x81160); var cuid = dic3[0x81150]; var uid = dic3[0x81155]; var frame = dic3[0x81160]; if (cuid != null && uid != null) { PRReferenceSOP refobjsop = new PRReferenceSOP() { SOPClassUID = cuid.ToString(), SOPInstanceUID = uid.ToString() }; if (frame != null) { refobjsop.FrameNumber = frame.ToValue(0); } referencesop.Add(refobjsop); } } } if (seriesuid != null) { refobj.SeriesInstanceUID = seriesuid.ToString(); } refobj.SopRefs = referencesop.ToArray(); reference.Add(refobj); } } References = reference.ToArray(); List <PRInfo> infos = new List <PRInfo>(); foreach (var t in tag) { if (t.Tag != 0xfffee000) { continue; } PRInfo info = new PRInfo(); List <PRReferenceSOP> refs = new List <PRReferenceSOP>(); var dic2 = DicomTagDictionary.Open(t, 0x81140, 0x700002, 0x700008, 0x700009); var reftag = dic2[0x81140]; var layertag = dic2[0x700002]; var txtobjtag = dic2[0x700008]; var shapeobjtag = dic2[0x700009]; foreach (var r in reftag) { var dic3 = DicomTagDictionary.Open(r, 0x81150, 0x81155, 0x81160); var cuid = dic3[0x81150]; var uid = dic3[0x81155]; var frame = dic3[0x81160]; if (cuid != null && uid != null) { PRReferenceSOP refobj = new PRReferenceSOP() { SOPClassUID = cuid.ToString(), SOPInstanceUID = uid.ToString() }; if (frame != null) { refobj.FrameNumber = frame.ToValue(0); } refs.Add(refobj); } } info.Reference.SopRefs = refs.ToArray(); info.Layer = layertag.ToString(); List <PRDrawItem> drawitems = new List <PRDrawItem>(); if (txtobjtag != null) { foreach (var r in txtobjtag) { if (r.Tag != 0xfffee000) { continue; } var dic4 = DicomTagDictionary.Open(r, 0x700006, //Text 0x700010, //LU 0x700011, //RD 0x700012, //Format 0x711001, //Type // 0x41051005,//色 0x00700014, //アンカー点 0x00700015 //アンカー点可視 ); PRDrawItem item = new PRDrawItem(); item.Text = dic4[0x700006].ToString(); if (dic4[0x700010] != null && dic4[0x700011] != null) { item.Points.Add(new PRPoint(dic4[0x700010].ToArray(new double[] { 0, 0 }))); item.Points.Add(new PRPoint(dic4[0x700011].ToArray(new double[] { 0, 0 }))); } else { continue; } if (dic4[0x41051005] != null) { StringBuilder sb = new StringBuilder(); var c = dic4[0x41051005].ToArray(new int[] { 255, 0, 0 });//デフォルトカラー if (c.Length == 3) { sb.AppendFormat("#{0:X2}{1:X2}{2:X2}", c[0], c[1], c[2]);//#RGBを構成 item.Color = sb.ToString(); } } if (dic4[0x00700014] != null && dic4[0x00700015] != null) { item.AnchorPoint = new PRPoint(dic4[0x00700014].ToArray(new double[] { 0, 0 })); item.AnchorVisible = dic4[0x00700015].ToString() == "Y"; } if (dic4[0x711001] != null) { item.DrawType = dic4[0x711001].ToString(); } else { item.DrawType = "TEXT"; } if (dic4[0x700012] != null) { item.TextFormat = dic4[0x700012].ToString(); } drawitems.Add(item); } } if (shapeobjtag != null) { foreach (var r in shapeobjtag) { if (r.Tag != 0xfffee000) { continue; } var dic4 = DicomTagDictionary.Open(r, 0x700022, //図形データ 0x700023 //図形タイプ //,0x41051005//色 //,0x41051001//図形タイプ拡張 //,0x41051002//図形文字 ); PRDrawItem item = new PRDrawItem(); if (dic4[0x700022] != null) { var p = dic4[0x700022].ToArray(new double[0]); for (int i = 0; i < p.Length; i += 2) { item.Points.Add(new PRPoint(p, i)); } } else { continue; } if (dic4[0x700023] != null) { item.DrawType = dic4[0x700023].ToString(); } if (dic4[0x41051005] != null) { StringBuilder sb = new StringBuilder(); var c = dic4[0x41051005].ToArray(new int[] { 255, 0, 0 });//デフォルトカラー if (c.Length == 3) { sb.AppendFormat("#{0:X2}{1:X2}{2:X2}", c[0], c[1], c[2]);//#RGBを構成 item.Color = sb.ToString(); } } if (dic4[0x41051001] != null) { item.DrawTypeEx = dic4[0x41051001].ToString(); } if (dic4[0x41051002] != null) { item.Text = dic4[0x41051002].ToString(); } drawitems.Add(item); } } info.DrawItems = drawitems.ToArray(); infos.Add(info); } Infos = infos.ToArray(); }
//ImageTagの取得 public static void GetImageTag(string file, out ImageTag tag) { tag = new ImageTag(); using (var dcm = new DicomData(file)) { var dic = DicomTagDictionary.Open(dcm, DcmTag.ToTagArray(DCM.IMAGE_TAG)); tag.InstanceNumber = dic.GetValue <long>(DcmTag.InstanceNumber.Tag, 0); tag.SliceThickness = dic.GetValue <string>(DcmTag.SliceThickness.Tag, ""); tag.ImagePositionPatient = dic.GetValue <string>(DcmTag.ImagePositionPatient.Tag, ""); tag.ImageOrientationPatient = dic.GetValue <string>(DcmTag.ImageOrientationPatient.Tag, ""); tag.SliceLocation = dic.GetValue <string>(DcmTag.SliceLocation.Tag, ""); tag.Rows = dic.GetValue <int>(DcmTag.Rows.Tag, 0); tag.Columns = dic.GetValue <int>(DcmTag.Columns.Tag, 0); tag.PixelSpacing = dic.GetValue <string>(DcmTag.PixelSpacing.Tag, ""); tag.WindowCenter = dic.GetValue <string>(DcmTag.WindowCenter.Tag, ""); tag.WindowWidth = dic.GetValue <string>(DcmTag.WindowWidth.Tag, ""); if (dcm.Images.Load()) { if (dcm.Images.Bits == 8 || dcm.Images.Bits == 24) { tag.WindowCenter = "127"; tag.WindowWidth = "255"; } else { ImageControl ctrl = null; if (dcm.Images.WindowCenters.Length > 0) { tag.WindowCenter = dcm.Images.WindowCenters[0].ToString(); } else { if (ctrl == null) { ctrl = dcm.Images.CreateImageControl(0); } //MinMax if (ctrl != null) { tag.WindowCenter = ctrl.WindowCenter.ToString(); } } if (dcm.Images.WindowWidths.Length > 0) { tag.WindowWidth = dcm.Images.WindowWidths[0].ToString(); } else { if (ctrl == null) { ctrl = dcm.Images.CreateImageControl(0); } //MinMax if (ctrl != null) { tag.WindowWidth = ctrl.WindowWidth.ToString(); } } } tag.NumberOfFrames = dcm.Images.NumberOfFrame; } } }
private static void GetImage(string UserName, string StorageID, string StudyUID, string SeriesUID, string SopUID) { LogUtil.Debug3("CMOVE [{0}][{1}][{2}]", StudyUID, SeriesUID, SopUID); var sto = DbCacheUtil.GetStorage(StorageID); using (var pc = new PacsComm()) { //画像取得 DicomFilesResult ret = pc.CMoveImage(StudyUID, SeriesUID, SopUID); 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()); var seriesList = new Dictionary <string, List <Dictionary <string, string> > >(); int cnt = 0; foreach (DicomFile dcmfile in ret.Files) { var file = dcmfile.FileName.Trim(); if (!File.Exists(file)) { continue; } var tags = new Dictionary <string, string>(); tags.Add("StorageID", sto.StorageID); tags.Add("UserName", UserName); tags.Add("AETitle", ""); tags.Add("File", file); var fi = new FileInfo(file); tags.Add("FileSize", fi.Length.ToString()); //タグ取得 using (var dcm = new DicomData(file)) { var tmpTags = new List <uint>(DcmTag.ToTagArray(AppUtil.IMAGE_TAG)); var dic = DicomTagDictionary.Open(dcm, tmpTags.ToArray()); foreach (DcmTag dcmTag in AppUtil.IMAGE_TAG) { tags.Add(dcmTag.Name, dic.GetString(dcmTag.Tag)); } if (dcm.Images.Load()) { if (dcm.Images.Bits == 8 || dcm.Images.Bits == 24) { tags.SetString("WindowCenter", "127"); tags.SetString("WindowWidth", "255"); } else { ImageControl ctrl = null; if (dcm.Images.WindowCenters.Length > 0) { tags.SetString("WindowCenter", dcm.Images.WindowCenters[0].ToString()); } else { if (ctrl == null) { ctrl = dcm.Images.CreateImageControl(0); } //MinMax if (ctrl != null) { tags.SetString("WindowCenter", ctrl.WindowCenter.ToString()); } } if (dcm.Images.WindowWidths.Length > 0) { tags.SetString("WindowWidth", dcm.Images.WindowWidths[0].ToString()); } else { if (ctrl == null) { ctrl = dcm.Images.CreateImageControl(0); } //MinMax if (ctrl != null) { tags.SetString("WindowWidth", ctrl.WindowWidth.ToString()); } } } } } var studyUid = tags[DcmTag.StudyInstanceUID.Name]; var seriesUid = tags[DcmTag.SeriesInstanceUID.Name]; var sopUid = tags[DcmTag.SOPInstanceUID.Name]; var mod = tags[DcmTag.Modality.Name]; //DICOMチェック if (studyUid == "" || seriesUid == "" || sopUid == "" || mod == "") { LogUtil.Error1("NOT DICOM [{0}]", Path.GetFileName(file)); continue; } //無視するモダリティ if (Array.IndexOf(AppUtil.SkipModality, mod) >= 0) { LogUtil.Debug2("SKIP:{0} [{1}]", mod, Path.GetFileName(file)); continue; } if (!seriesList.ContainsKey(seriesUid)) { seriesList.Add(seriesUid, new List <Dictionary <string, string> >()); } seriesList[seriesUid].Add(tags); cnt++; } //SERIES毎のSOPソート foreach (var series in seriesList.Values) { series.Sort((x, y) => { long n1, n2; if (!long.TryParse(x[DcmTag.SeriesNumber.Name], out n1)) { n1 = long.MaxValue; } if (!long.TryParse(y[DcmTag.SeriesNumber.Name], out n2)) { n2 = long.MaxValue; } return((int)(n1 - n2)); }); } int idx = 0; foreach (var series in seriesList.Values) { if (series.Count == 0) { continue; } LogUtil.Info5("AETitle[{0}] StudyDate[{1}] StudyTime[{2}] Modality[{3}] PatientID[{4}]", series[0]["AETitle"], series[0][DcmTag.StudyDate.Name], series[0][DcmTag.StudyTime.Name], series[0][DcmTag.Modality.Name], series[0][DcmTag.PatientID.Name]); var importList = new List <Dictionary <string, string> >(); foreach (var sop in series) { var studyUid = sop[DcmTag.StudyInstanceUID.Name]; var seriesUid = sop[DcmTag.SeriesInstanceUID.Name]; var sopUid = sop[DcmTag.SOPInstanceUID.Name]; var file = sop["File"]; idx++; LogUtil.Debug3("{0}/{1} [{2}]", idx, cnt, Path.GetFileName(file)); //画像圧縮 using (var imp = new Impersonate(sto.LogonUsername, sto.LogonPassword)) { var dicomFile = Path.Combine(sto.DicomPath, studyUid, seriesUid, sopUid + AppUtil.DicomExt); if (DicomUtil.DicomToComp(file, dicomFile, sop)) { sop.Add("DicomFile", dicomFile); LogUtil.Debug("圧縮 end"); var fi = new FileInfo(dicomFile); sop.Add("CompFileSize", fi.Length.ToString()); } else { LogUtil.Error1("圧縮エラー [{0}]", file); return; } } importList.Add(sop); } //DB登録 if (importList.Count > 0) { if (DbUtil.DicomToDB(importList)) { LogUtil.Debug("DB登録 end"); } else { LogUtil.Error("DB登録エラー"); } } else { LogUtil.Debug("DB登録 なし"); } } //DB更新 DbUtil.UpdateStudy(StudyUID); } }