private void treeViewDicomDir_AfterSelect(object sender, TreeViewEventArgs e) { DicomElement element; string value; txtElementValue.Text = ""; if (treeViewDicomDir.SelectedNode.Tag == null) { return; } element = (DicomElement)treeViewDicomDir.SelectedNode.Tag; try { if (element.Tag == DicomTag.PixelData) { return; } value = _Dataset.GetConvertValue(element); if (value != null && value.Length > 0) { value = value.Replace(@"\", "\r\n"); } txtElementValue.Text = value; } catch (Exception ex) { Messager.ShowError(this, "Error getting element value:\r\n\r\n" + ex.ToString()); } }
private void DoStoreRequest( ) { DicomCommandStatusType status = DicomCommandStatusType.ProcessingFailure; string msg = "Error saving dataset received from: " + AETitle; DicomElement element; if (!IsActionSupported()) { string name = GetUIDName(); server.mf.Log("C-STORE-REQUEST", "Abstract syntax (" + name + ") not supported by association"); client.SendCStoreResponse(_PresentationID, _MessageID, _Class, _Instance, DicomCommandStatusType.ClassNotSupported); return; } element = ds.FindFirstElement(null, DemoDicomTags.SOPInstanceUID, true); if (element != null) { string value = ds.GetConvertValue(element); string file; InsertReturn ret; file = server.ImageDir + value + ".dcm"; ret = server.mf.DicomData.Insert(ds, file); switch (ret) { case InsertReturn.Success: DicomExceptionCode dret = SaveDataSet(file); if (dret == DicomExceptionCode.Success) { status = DicomCommandStatusType.Success; } else { msg = "Error saving dicom file: " + dret.ToString(); } server.mf.Log("C-STORE-REQUEST", "New file imported: " + file); break; case InsertReturn.Exists: msg = "File (" + file + ") not imported. Record already exists in database"; break; case InsertReturn.Error: msg = "Error importing file: " + file; break; } } if (status != DicomCommandStatusType.Success) { server.mf.Log("C-STORE-REQUEST", msg); } client.SendCStoreResponse(_PresentationID, _MessageID, _Class, _Instance, status); server.mf.Log("C-STORE-RESPONSE", "Response sent to " + AETitle); }
public static string MyGetStringValue(this DicomDataSet ds, long tag, bool autoTruncate, int maxLength) { DicomElement element = ds.FindFirstElement(null, tag, true); if (null == element || element.Length == 0) { return(null); } else { if (autoTruncate && element.Length > maxLength) { return(ds.GetConvertValue(element).Substring(0, maxLength)); } else { return(ds.GetConvertValue(element)); } } }
private void GetElementValues(DicomElement element) { string value = ""; value = ds.GetConvertValue(element); if (value != null && value.Length > 0) { value = value.Replace(@"\", "\r\n"); } textBoxValues.Text = value; }
private List <string> GetDicomDirectoryImages ( string dicomFile, DicomDataSet dataset ) { try { DicomElement refernceFileElement; List <string> dicomImages; string baseDirectory; refernceFileElement = null; dicomImages = new List <string> ( ); baseDirectory = Path.GetDirectoryName(dicomFile); refernceFileElement = dataset.FindFirstElement(null, DicomTag.ReferencedFileID, false); if (null != refernceFileElement) { dicomImages.Add(Path.Combine(baseDirectory, dataset.GetConvertValue(refernceFileElement))); } while (null != (refernceFileElement = dataset.FindNextElement(refernceFileElement, false))) { dicomImages.Add(Path.Combine(baseDirectory, dataset.GetConvertValue(refernceFileElement))); } return(dicomImages); } catch (Exception exception) { System.Diagnostics.Debug.Assert(false, exception.Message); throw exception; } }
private string GetDicomTag(DicomDataSet ds, long tag) { DicomElement patientElement = ds.FindFirstElement(null, tag, true); if (patientElement != null) { return(ds.GetConvertValue(patientElement)); } return(null); }
/// <summary> /// Helper method to get string value from a DICOM dataset. /// </summary> /// <param name="dcm">The DICOM dataset.</param> /// <param name="tag">Dicom tag.</param> /// <returns>String value of the specified DICOM tag.</returns> public static string GetStringValue(DicomDataSet dcm, long tag, bool tree) { DicomElement element; element = dcm.FindFirstElement(null, tag, tree); if (element != null) { if (dcm.GetElementValueCount(element) > 0) { return(dcm.GetConvertValue(element)); } } return(""); }
public static StringCollection GetStringValues(DicomDataSet dcm, long tag) { DicomElement element; StringCollection sc = new StringCollection(); element = dcm.FindFirstElement(null, tag, true); if (element != null) { if (dcm.GetElementValueCount(element) > 0) { string s = dcm.GetConvertValue(element); string[] items = s.Split('\\'); foreach (string value in items) { sc.Add(value); } } } return(sc); }
private void Init() { string strInfo; string[] values = null; DicomVR vr; DicomTag tag; strInfo = ds.GetConvertValue(element); if (strInfo != null) { values = strInfo.Split('\\'); } if ((values != null) && (values.GetLength(0) > 0)) { foreach (string value in values) { listBoxValues.Items.Add(value); } if (listBoxValues.Items.Count > 0) { listBoxValues.SelectedIndex = 0; } } vr = DicomVRTable.Instance.Find(element.VR); tag = DicomTagTable.Instance.Find(element.Tag); strInfo = "Value Representation: " + vr.Name; labelVR.Text = strInfo; switch (element.VR) { case DicomVRType.OB: case DicomVRType.UN: strInfo = "Hexadecimal"; break; case DicomVRType.SS: case DicomVRType.US: case DicomVRType.OW: case DicomVRType.SL: case DicomVRType.IS: case DicomVRType.UL: strInfo = "Integer"; break; case DicomVRType.AT: strInfo = "Group:Element\r\n(Group and Element should be hexadecimal words)"; break; case DicomVRType.FD: case DicomVRType.FL: case DicomVRType.DS: strInfo = "Float"; break; case DicomVRType.CS: case DicomVRType.SH: case DicomVRType.LO: case DicomVRType.AE: case DicomVRType.LT: case DicomVRType.ST: case DicomVRType.UI: case DicomVRType.UT: case DicomVRType.PN: strInfo = "String"; break; case DicomVRType.AS: strInfo = "Number Reference\r\n(Reference = 'days' or 'weeks' or 'months' or 'years')"; break; case DicomVRType.DA: strInfo = "MM/DD/YYYY\r\n(MM=Month, DD=Day, YYYY=Year)"; break; case DicomVRType.DT: strInfo = "CC MM/DD/YYYY HH:MM:SS.FFFFFF&OOOO\r\n(CC=Centry, MM=Month, DD=Day, YYYY=Year)\r\n(HH=Hours, MM=Minutes,SS=Seconds, "; strInfo += "FFFFFF=Fractional Second, OOOO=Offset from Coordinated Universial Time)"; break; case DicomVRType.TM: strInfo = "HH:MM:SS.FFFF\r\n(HH=Hours, MM=Minutes, SS=Seconds, FFFF=Fractional Second)"; break; default: strInfo = ""; break; } if (tag == null) { buttonBefore.Enabled = false; buttonAfter.Enabled = false; buttonDelete.Enabled = false; buttonModify.Enabled = false; buttonOK.Enabled = false; textBoxValue.Enabled = false; buttonCancel.Enabled = true; } else { buttonBefore.Enabled = tag.MaxVM >= 1 || tag.MaxVM == -1; buttonAfter.Enabled = tag.MaxVM >= 1 || tag.MaxVM == -1; } labelFormat.Text = strInfo; }
public static StringCollection GetStringValues(DicomDataSet dcm, long tag) { DicomElement element; StringCollection sc = new StringCollection(); element = dcm.FindFirstElement(null, tag, true); if(element != null) { if(dcm.GetElementValueCount(element) > 0) { string s = dcm.GetConvertValue(element); string[] items = s.Split('\\'); foreach(string value in items) { sc.Add(value); } } } return sc; }
/// <summary> /// Helper method to get string value from a DICOM dataset. /// </summary> /// <param name="dcm">The DICOM dataset.</param> /// <param name="tag">Dicom tag.</param> /// <returns>String value of the specified DICOM tag.</returns> public static string GetStringValue(DicomDataSet dcm, long tag, bool tree) { DicomElement element; element = dcm.FindFirstElement(null, tag, tree); if(element != null) { if(dcm.GetElementValueCount(element) > 0) { return dcm.GetConvertValue(element); } } return ""; }
private void LoadDicomDir(string filename) { if (_cancel) { return; } string pathname = string.Empty; string refFilename = string.Empty; DicomElement element = null; int count = 0; int totalCount = 0; int nMod = 1; string sMsg = string.Empty; if (!filename.ToUpper().Contains("DICOMDIR")) { return; } pathname = Path.GetDirectoryName(filename) + "\\"; using (DicomDataSet ds = new DicomDataSet()) { try { this.Cursor = Cursors.WaitCursor; LogText("Loading DICOMDIR..."); ds.Load(filename, DicomDataSetLoadFlags.None); // Get the total count LogText("Getting total count..."); element = ds.FindFirstElement(null, DicomTag.ReferencedFileID, false); while (element != null) { totalCount++; element = ds.FindNextElement(element, false); } if (totalCount >= 20) { nMod = 10; } // now get the datasets element = ds.FindFirstElement(null, DicomTag.ReferencedFileID, false); if (element != null && ds.GetElementValueCount(element) > 0) { if (!_cancel) { refFilename = ds.GetConvertValue(element); if (LoadDicomFile(pathname + refFilename)) { count++; } Application.DoEvents(); } } while ((refFilename.Length > 0) && (!_cancel)) { element = ds.FindNextElement(element, false); if (element != null && ds.GetElementValueCount(element) > 0) { refFilename = ds.GetConvertValue(element); if (LoadDicomFile(pathname + refFilename)) { count++; } Application.DoEvents(); } else { refFilename = ""; } if (count % nMod == 0) { sMsg = string.Format("Loaded {0} of {1} files...", count.ToString(), totalCount.ToString()); LogText(sMsg); } } } catch (DicomException de) { LogText("Dicom error: " + de.Code.ToString() + ": " + filename); } } sMsg = string.Format("Loaded {0} of {1} total files", count.ToString(), totalCount.ToString()); LogText(sMsg); RefreshList(); this.Cursor = Cursors.Default; }
/// <summary> /// Lấy giá trị của một Tag từ DicomDataset của ảnh /// </summary> /// <param name="ds"></param> /// <param name="tag"></param> /// <returns></returns> string GetStringValue(DicomDataSet ds, long tag) { try { if (ds == null) return ""; DicomElement element; element = ds.FindFirstElement(null, tag, false); if (element != null) { if (ds.GetElementValueCount(element) > 0) { return ds.GetConvertValue(element); } } return ""; } catch { return ""; } }
private void FillWorklistItem(DicomDataSet response) { try { ListViewItem item = null; DicomElement element = null; foreach (DatabaseDicomTags dbTag in _additionalDisplay) { element = response.FindFirstElement(null, dbTag.DicomTag, false); if (item == null) { item = new ListViewItem( ); item.UseItemStyleForSubItems = false; if (null != element) { item.Text = response.GetConvertValue(element); } } else { string subItemValue = string.Empty; if (null != element) { subItemValue = response.GetConvertValue(element); } item.SubItems.Add(subItemValue); } } if (IsDatabaseUpdated()) { foreach (DatabaseDicomTags dbTag in _source) { element = response.FindFirstElement(null, dbTag.DicomTag, false); string subItemValue = string.Empty; if (null != element) { subItemValue = response.GetConvertValue(element); } ListViewItem.ListViewSubItem subItem = new ListViewItem.ListViewSubItem(item, subItemValue, Color.Red, Color.Blue, Font); item.SubItems.Add(subItem); } } WorklistItemsListView.Items.Add(item); } catch (Exception exception) { Messager.ShowError(this, exception); } }
/* * Recursively fills the tree with elements and modules */ void FillModuleSubTree(DicomElement element, TreeNode ParentNode, bool recurse) { try { TreeNode node; string name, value; string temp = ""; DicomElement tempElement; DicomTag tag; // Build the string representing the tree node // Get the tag { tag = DicomTagTable.Instance.Find(element.Tag); temp = string.Format("{0:x4}:{1:x4} - ", Utils.GetGroup((long)element.Tag), Utils.GetElement((long)element.Tag)); } // Get the tag name if (tag == null) { name = "Item"; } else { name = tag.Name; } // Get the tag value value = ""; value = ds.GetConvertValue(element); temp = temp + name + " : " + value; if (ParentNode != null) { node = ParentNode.Nodes.Add(temp); } else { node = treeViewElements.Nodes.Add(temp); } node.Tag = element; if (ds.IsVolatileElement(element)) { node.ForeColor = Color.Red; } node.ImageIndex = 1; node.SelectedImageIndex = 1; // Recursively fille the tree if there are children tempElement = ds.GetChildElement(element, true); if (tempElement != null) { node.ImageIndex = 0; node.SelectedImageIndex = 0; FillModuleSubTree(tempElement, node, true); } // Recursively fill the tree for the next element if (recurse) { tempElement = ds.GetNextElement(element, true, true); if (tempElement != null) { FillModuleSubTree(tempElement, ParentNode, true); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public Form1() { RasterSupport.SetLicense(@"C:\LEADTOOLS 20\Common\License\LEADTOOLS.LIC", System.IO.File.ReadAllText(@"C:\LEADTOOLS 20\Common\License\LEADTOOLS.LIC.KEY")); InitializeComponent(); RasterCodecs _codecs = new RasterCodecs(); RasterImage _image; string dicomFileName = @"C:\Users\Public\Documents\LEADTOOLS Images\IMAGE3.dcm"; // Create the medical viewer and adjust the size and the location. _medicalViewer = new MedicalViewer(1, 1); _medicalViewer.Location = new Point(0, 0); _medicalViewer.Size = new Size(this.ClientRectangle.Right, this.ClientRectangle.Bottom); // Load an image and then add it to the control. _image = _codecs.Load(dicomFileName); DicomEngine.Startup(); using (DicomDataSet ds = new DicomDataSet()) { MedicalViewerMultiCell cell = new MedicalViewerMultiCell(_image, true, 1, 1); ds.Load(dicomFileName, DicomDataSetLoadFlags.None); string dpatientID = GetDicomTag(ds, DicomTag.PatientID); string dpatientName = GetDicomTag(ds, DicomTag.PatientName); string dpatientAge = GetDicomTag(ds, DicomTag.PatientAge); string dpatientBirthDate = GetDicomTag(ds, DicomTag.PatientBirthDate); string dpatientSex = GetDicomTag(ds, DicomTag.PatientSex); // add some actions that will be used to change the properties of the images inside the control. cell.AddAction(MedicalViewerActionType.WindowLevel); cell.AddAction(MedicalViewerActionType.Offset); cell.AddAction(MedicalViewerActionType.Stack); // assign the added actions to a mouse button, meaning that when the user clicks and drags the mouse button, the associated action will be activated. cell.SetAction(MedicalViewerActionType.Offset, MedicalViewerMouseButtons.Right, MedicalViewerActionFlags.Active); cell.SetAction(MedicalViewerActionType.WindowLevel, MedicalViewerMouseButtons.Left, MedicalViewerActionFlags.Active); cell.SetAction(MedicalViewerActionType.Stack, MedicalViewerMouseButtons.Wheel, MedicalViewerActionFlags.Active); // assign the added actions to a keyboard keys that will work like the mouse. MedicalViewerKeys medicalKeys = new MedicalViewerKeys(Keys.Down, Keys.Up, Keys.Left, Keys.Right, MedicalViewerModifiers.None); cell.SetActionKeys(MedicalViewerActionType.Offset, medicalKeys); medicalKeys.Modifiers = MedicalViewerModifiers.Ctrl; cell.SetActionKeys(MedicalViewerActionType.WindowLevel, medicalKeys); medicalKeys.MouseDown = Keys.PageDown; medicalKeys.MouseUp = Keys.PageUp; cell.SetActionKeys(MedicalViewerActionType.Stack, medicalKeys); medicalKeys.MouseDown = Keys.Subtract; medicalKeys.MouseUp = Keys.Add; cell.SetActionKeys(MedicalViewerActionType.Scale, medicalKeys); _medicalViewer.Cells.Add(cell); // adjust some properties of the cell and add some tags. cell.SetTag(1, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, "Name: " + dpatientName); cell.SetTag(2, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, "ID: " + dpatientID); cell.SetTag(3, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, "DOB: " + dpatientBirthDate); cell.SetTag(4, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, "Age: " + dpatientAge); cell.SetTag(5, MedicalViewerTagAlignment.TopRight, MedicalViewerTagType.UserData, "Sex: " + dpatientSex); cell.SetTag(4, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.Frame); cell.SetTag(6, MedicalViewerTagAlignment.TopLeft, MedicalViewerTagType.Scale); cell.SetTag(2, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.WindowLevelData); cell.SetTag(1, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.FieldOfView); cell.SetTag(0, MedicalViewerTagAlignment.BottomLeft, MedicalViewerTagType.RulerUnit); cell.Rows = 1; cell.Columns = 1; cell.Frozen = false; cell.DisplayRulers = MedicalViewerRulers.Both; cell.ApplyOnIndividualSubCell = false; cell.ApplyActionOnMove = true; cell.FitImageToCell = true; cell.Selected = true; cell.ShowTags = true; } string GetDicomTag(DicomDataSet ds, long tag) { DicomElement patientElement = ds.FindFirstElement(null, tag, true); if (patientElement != null) { return(ds.GetConvertValue(patientElement)); } return(null); } Controls.Add(_medicalViewer); _medicalViewer.Dock = DockStyle.Fill; }