string path; if (Path.GetFileName(path).Equals("DICOMDIR")) retern; TreeView treeView = new TreeView(); TreeNode treeNode = new TreeNode(); List<string[]> imageList = new List<string[]>(); treeNode.Nodes.Clear(); treeView.Nodes.Clear(); //DicomDir dicomDir = new DicomDir(path); //ReadDicomDir(dicomDir); Stream stream = null; DcmParser parser = null; Dataset ds = null; try { stream = new BufferedStream(new FileStream(path, FileMode.Open, FileAccess.Read)); parser = new org.dicomcs.data.DcmParser(stream); org.dicomcs.data.FileFormat format = parser.DetectFileFormat(); if (format != null) { ds = new org.dicomcs.data.Dataset(); parser.DcmHandler = ds.DcmHandler; parser.ParseDcmFile(format); TreeNode nodePatient = new TreeNode(); TreeNode nodeStudy = new TreeNode(); TreeNode nodeSeries = new TreeNode(); TreeNode nodeStudat = new TreeNode(); // int tmpStudat = 0; int patBirdat = 0; string patName = string.Empty; // DcmObject doRoot = (DcmObject)ds; IEnumerator enuRoot = doRoot.GetEnumerator(); int count = 0; while (enuRoot.MoveNext()) { DcmElement elRoot = (DcmElement)enuRoot.Current; if (elRoot.HasItems()) { for (int i = 0; i < elRoot.vm(); i++) { DcmObject dcmObj = (DcmObject)elRoot.GetItem(i); IEnumerator enu = dcmObj.GetEnumerator(); while (enu.MoveNext()) { DcmElement el = (DcmElement)enu.Current; if (el.tag() == DcmTags.DirectoryRecordType) { string rs = el.GetString(Encoding.Unicode); if (rs == "PATIENT") { PatientTable pt = new PatientTable(); if (dcmObj.Contains(Tags.PatientBirthDate)) patBirdat = Convert.ToInt32(dcmObj.GetDate(DcmTags.PatientBirthDate).ToString("yyyyMMdd")); if (dcmObj.Contains(Tags.PatientName)) patName = dcmObj.GetString(DcmTags.PatientName); } else if (rs == "STUDY") { if (dcmObj.Contains(DcmTags.StudyDate)) { int studat = Convert.ToInt32(dcmObj.GetDate(Tags.StudyDate).ToString("yyyyMMdd")); string stuinsuid = string.Empty; string studes = string.Empty; if (dcmObj.Contains(DcmTags.StudyInstanceUID)) stuinsuid = dcmObj.GetString(DcmTags.StudyInstanceUID); if (dcmObj.Contains(DcmTags.StudyDescription)) studes = dcmObj.GetString(DcmTags.StudyInstanceUID); if (studat != tmpStudat) { nodeStudat = new TreeNode(studat.ToString("####/##/##")); nodeStudat.Tag = studat; treeViewStudy.Nodes.Add(nodeStudat); tmpStudat = studat; } nodeStudy = new TreeNode(""); nodeStudat.Nodes.Add(nodeStudy); } } else if (rs == "SERIES") { imageList = new List<string[]>(); string serinsuid = string.Empty; string sernum = string.Empty; ; string numserrelima = string.Empty; string serdes = string.Empty; string bodparexa = string.Empty; string modality = string.Empty; if (dcmObj.Contains(DcmTags.SeriesInstanceUID)) serinsuid = dcmObj.GetString(DcmTags.SeriesInstanceUID); if (dcmObj.Contains(DcmTags.SeriesNumber)) sernum = dcmObj.GetString(DcmTags.SeriesNumber); if (dcmObj.Contains(DcmTags.SeriesDescription)) serdes = dcmObj.GetString(DcmTags.SeriesDescription); if (dcmObj.Contains(DcmTags.Modality)) modality = dcmObj.GetString(DcmTags.Modality); nodeSeries = new TreeNode(modality + "." + sernum); nodeStudy.Nodes.Add(nodeSeries); if (nodeStudy.Text == string.Empty) nodeStudy.Text = modality; nodeSeries.Tag=imageList; //Add (refFile and uid)List } else if (rs == "IMAGE") { string refFileID = string.Empty; string uid = string.Empty; if (dcmObj.Contains(DcmTags.RefFileID)) refFileID = dcmObj.GetString(DcmTags.RefFileID); if (dcmObj.Contains(DcmTags.RefSOPInstanceUIDInFile)) uid = dcmObj.GetString(DcmTags.RefSOPInstanceUIDInFile); string[] ss = new string[2]; ss[0] = refFileID; ss[1] = uid; imageList.Add(ss); } } } } } }
2011年9月17日土曜日
DICOMDIR から TreeNode へ
登録:
投稿
(
Atom
)