private void AddCommitItem(DicomDataSet ds, long tag, StorageCommit.StorageCommit commit) { DicomElement rppss = null; DicomElement element; rppss = ds.FindFirstElement(null, tag, true); // If SameStudy goes to false, it is false for the entire commit if (commit.SameStudy) { commit.SameStudy = rppss != null; } commit.TransactionUID = ds.GetValue <string>(DicomTag.TransactionUID, string.Empty); element = ds.GetChildElement(rppss, false); while (element != null) { DicomElement child = ds.GetChildElement(element, true); if (child != null) { StorageCommitItem item = new StorageCommitItem(); item.SOPClassUID = ds.GetValue <string>(child, true, DicomTag.ReferencedSOPClassUID, string.Empty); item.SOPInstanceUID = ds.GetValue <string>(child, true, DicomTag.ReferencedSOPInstanceUID, string.Empty); commit.Items.Add(item); } element = ds.GetNextElement(element, true, true); } }
/* * Recursively add children of an element TreeNode */ private void AddChildrenOfElement(DicomDataSet ds, MyTreeNode parentNode, DicomElement parentElement) { try { DicomElement currentElement = ds.GetChildElement(parentElement, true); int parentNodeChildCount = 0; while (currentElement != null) { DicomIod dIod = DicomIodTable.Instance.Find(null, parentElement.Tag, DicomIodType.Element, false); // Determine the element tag DicomTag tag; long tagValue; #if (LTV15_CONFIG) if (currentElement.Tag != DemoDicomTags.Undefined) { tag = DicomTagTable.Instance.Find(currentElement.Tag); tagValue = (long)currentElement.Tag; } else { tag = DicomTagTable.Instance.Find(currentElement.UserTag); tagValue = currentElement.UserTag; } #else tag = DicomTagTable.Instance.Find(currentElement.Tag); tagValue = (long)currentElement.Tag; #endif // Add new element TreeNode parentNode.Nodes.Add( new MyTreeNode(String.Format("{0:X4}:{1:X4} - {2}", Utils.GetGroup(tagValue), Utils.GetElement(tagValue), tag.Name), ds, currentElement)); // Check to see if the element has children if (ds.GetChildElement(currentElement, true) != null) { parentNode.Nodes[parentNodeChildCount].ImageIndex = (int)MyIconIndex.Sequence; parentNode.Nodes[parentNodeChildCount].SelectedImageIndex = (int)MyIconIndex.Sequence; // Recursively add children of this element AddChildrenOfElement(ds, (MyTreeNode)parentNode.Nodes[parentNode.Nodes.Count - 1], currentElement); } currentElement = ds.GetNextElement(currentElement, true, true); parentNodeChildCount++; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
void FillModuleSubTree(DicomElement element, TreeNode ParentNode, bool recurse) { TreeNode node; string name; string temp = ""; DicomElement tempElement; DicomTag tag = DicomTagTable.Instance.Find(element.Tag); temp = string.Format("{0:x4}:{1:x4} - ", Utils.GetGroup((long)element.Tag), Utils.GetElement((long)element.Tag)); if (tag == null) { name = "Item"; } else { name = tag.Name; } temp = temp + name; if (ParentNode != null) { node = ParentNode.Nodes.Add(temp); } else { node = _treeView_Elements.Nodes.Add(temp); } node.Tag = element; if (_dsImage.IsVolatileElement(element)) { node.ForeColor = Color.Red; } node.ImageIndex = 1; node.SelectedImageIndex = 1; tempElement = _dsImage.GetChildElement(element, true); if (tempElement != null) { node.ImageIndex = 0; node.SelectedImageIndex = 0; FillModuleSubTree(tempElement, node, true); } if (recurse) { tempElement = _dsImage.GetNextElement(element, true, true); if (tempElement != null) { FillModuleSubTree(tempElement, ParentNode, true); } } }
public static void SetTag(DicomDataSet dcm, long Sequence, long Tag, object TagValue) { DicomElement seqElement = dcm.FindFirstElement(null, Sequence, true); DicomElement seqItem = null; DicomElement item = null; if (seqElement == null) { seqElement = dcm.InsertElement(null, false, Tag, DicomVRType.SQ, true, -1); } seqItem = dcm.GetChildElement(seqElement, false); if (seqItem == null) { #if (LTV15_CONFIG) seqItem = dcm.InsertElement(seqElement, true, DicomTagType.SequenceDelimitationItem, DicomVRType.SQ, true, -1); #else seqItem = dcm.InsertElement(seqElement, true, DicomTag.SequenceDelimitationItem, DicomVRType.SQ, true, -1); #endif } item = dcm.GetChildElement(seqItem, true); while (item != null) { #if (LTV15_CONFIG) if ((long)item.Tag == Tag) { break; } #else if (item.Tag == Tag) { break; } #endif item = dcm.GetNextElement(item, true, true); } if (item == null) { item = dcm.InsertElement(seqItem, true, Tag, DicomVRType.UN, false, -1); } dcm.SetConvertValue(item, TagValue.ToString(), 1); }
private static void FillKeySubTree(TreeView treeview, DicomDataSet ds, DicomElement element, TreeNode ParentNode, bool recurse) { TreeNode node; string name; string temp = ""; DicomElement tempElement; DicomTag tag; // Get the tag's numerical display value (XXXX:XXXX) tag = DicomTagTable.Instance.Find(element.Tag); temp = string.Format("{0:x4}:{1:x4} - ", element.Tag.GetGroup(), element.Tag.GetElement()); // Get the tag's name if (tag == null) { name = "Item"; } else { name = tag.Name; } temp = temp + name; // Add the node either on the root or beneath its parent if (ParentNode != null) { node = ParentNode.Nodes.Add(temp); } else { node = treeview.Nodes.Add(temp); } node.Tag = element; node.ImageIndex = 1; node.SelectedImageIndex = 1; // If the element has children, recursively add them tempElement = ds.GetChildElement(element, true); if (tempElement != null) { node.ImageIndex = 0; node.SelectedImageIndex = 0; FillKeySubTree(treeview, ds, tempElement, node, true); } if (recurse) { tempElement = ds.GetNextElement(element, true, true); if (tempElement != null) { FillKeySubTree(treeview, ds, tempElement, ParentNode, true); } } }
private static void BuildTree ( XmlTextWriter DatasetXmlTextWriter, DicomDataSet SourceDataset, DicomElement parentElement, int nLevelDepth ) { try { DicomElement childElement; childElement = SourceDataset.GetChildElement(parentElement, true); nLevelDepth++; while (null != childElement) { WriteStartXML(DatasetXmlTextWriter, SourceDataset, childElement, nLevelDepth); if (SourceDataset.GetChildElement(childElement, true) != null) { BuildTree(DatasetXmlTextWriter, SourceDataset, childElement, nLevelDepth); } DatasetXmlTextWriter.WriteEndElement( ); childElement = SourceDataset.GetNextElement(childElement, true, true); } nLevelDepth--; } catch (Exception exp) { System.Diagnostics.Debug.Assert(false); throw exp; } }
private static void FillSubTree ( DicomDataSet SourceDataset, XmlTextWriter DatasetXmlTextWriter ) { try { int nLevelDepth = 0; try { DicomElement element; nLevelDepth++; element = SourceDataset.GetFirstElement(null, false, true); while (null != element) { WriteStartXML(DatasetXmlTextWriter, SourceDataset, element, nLevelDepth); if (SourceDataset.GetChildElement(element, true) != null) { BuildTree(DatasetXmlTextWriter, SourceDataset, element, nLevelDepth); } DatasetXmlTextWriter.WriteEndElement( ); element = SourceDataset.GetNextElement(element, true, true); } } catch (Exception exp) { System.Diagnostics.Debug.Assert(false); throw exp; } finally { nLevelDepth--; } } catch (Exception exp) { System.Diagnostics.Debug.Assert(false); throw exp; } }
/// <summary> /// Gets the sequence count. /// </summary> /// <returns>The number of items in the sequence.</returns> private int GetSequenceCount() { DicomElement seq = _Dataset.FindFirstElement(null, _Tag, false); int count = 0; if (seq != null) { DicomElement child = _Dataset.GetChildElement(seq, true); while (child != null) { count++; child = _Dataset.GetNextElement(child, true, true); } } return(count); }
static void FindChildElements(DicomDataSet ds, DicomElement element, long tag, List <DicomElement> elemLst) { if (null != element) { DicomElement child = ds.GetChildElement(element, true); if (child != null) { if (child.Tag == tag) { elemLst.Add(child); } FindChildElements(ds, child, tag, elemLst); child = ds.GetNextElement(child, true, true); while (child != null) { FindChildElements(ds, child, tag, elemLst); child = ds.GetNextElement(child, true, true); } } } }
public static void SetTag(DicomDataSet dcm,long Sequence,long Tag,object TagValue) { DicomElement seqElement = dcm.FindFirstElement(null, Sequence, true); DicomElement seqItem = null; DicomElement item = null; if(seqElement==null) { seqElement = dcm.InsertElement(null, false, Tag, DicomVRType.SQ, true, -1); } seqItem = dcm.GetChildElement(seqElement, false); if (seqItem == null) { #if (LTV15_CONFIG) seqItem = dcm.InsertElement(seqElement, true, DicomTagType.SequenceDelimitationItem, DicomVRType.SQ, true, -1); #else seqItem = dcm.InsertElement(seqElement, true, DicomTag.SequenceDelimitationItem, DicomVRType.SQ, true, -1); #endif } item = dcm.GetChildElement(seqItem, true); while(item!=null) { #if (LTV15_CONFIG) if ((long)item.Tag == Tag) break; #else if (item.Tag == Tag) break; #endif item = dcm.GetNextElement(item, true, true); } if(item==null) { item = dcm.InsertElement(seqItem, true, Tag, DicomVRType.UN, false, -1); } dcm.SetConvertValue(item, TagValue.ToString(), 1); }
void FillSubTree(DicomDataSet ds, DicomElement element, TreeNode ParentNode) { TreeNode node; string name; string temp = ""; DicomTag tag; DicomElement tempElement; tag = DicomTagTable.Instance.Find(element.Tag); if (tag != null) { name = tag.Name; } else { name = "Item"; } long tagValue = 0; tagValue = element.Tag; temp = string.Format("{0:x4}:{1:x4} - ", tagValue.GetGroup(), tagValue.GetElement()); temp = temp + name; if (ParentNode != null) { node = ParentNode.Nodes.Add(temp); } else { node = treeViewMPPSDataset.Nodes.Add(temp); } node.Tag = element.Tag; if (ds.IsVolatileElement(element)) { node.ForeColor = Color.Red; } node.ImageIndex = 1; node.SelectedImageIndex = 1; tempElement = ds.GetChildElement(element, true); if (tempElement != null) { node.ImageIndex = 0; node.SelectedImageIndex = 0; FillSubTree(ds, tempElement, node); } tempElement = ds.GetNextElement(element, true, true); if (tempElement != null) { FillSubTree(ds, tempElement, ParentNode); } else { element = ds.GetParentElement(element); } }
public void BuildTreeFromDataset(DicomDataSet ds, bool IsMWLDS) { if (Globals._closing == true || this.Disposing || this.IsDisposed) { return; } if (InvokeRequired) { Invoke(new BuildTreeFromDatasetDelegate(BuildTreeFromDataset), ds, IsMWLDS); } else { try { TreeNodeCollection IODClassNodes; if (IsMWLDS) { // Add a root level node since there could be multiple MWL datasets to be displayed string parentNodeString = String.Format( "{0:D3} Modality Work List - {1} ", (Nodes.Count + 1), Utils.GetStringValue(ds, DemoDicomTags.Modality, false)); MyTreeNode rootNode = new MyTreeNode(parentNodeString, ds); Nodes.Add(rootNode); rootNode.ImageIndex = (int)MyIconIndex.Worklist; rootNode.SelectedImageIndex = (int)MyIconIndex.Worklist; IODClassNodes = rootNode.Nodes; } else { // Use the tree's root for IOD classes IODClassNodes = Nodes; } // Insert nodes for IOD classes for (int i = 0; i < ds.ModuleCount; i++) { DicomModule dm = ds.FindModuleByIndex(i); DicomIod dIod = DicomIodTable.Instance.FindModule(ds.InformationClass, dm.Type); if (dIod != null) { IODClassNodes.Add( new MyTreeNode(dIod.Name, ds, dIod)); IODClassNodes[i].ImageIndex = (int)MyIconIndex.Folder; IODClassNodes[i].SelectedImageIndex = (int)MyIconIndex.Folder; } else { IODClassNodes.Add( new MyTreeNode("UNKNOWN")); IODClassNodes[i].ImageIndex = (int)MyIconIndex.Missing; IODClassNodes[i].SelectedImageIndex = (int)MyIconIndex.Missing; } // Insert nodes for the elements within the current IOD class for (int j = 0; j < dm.Elements.Length; j++) { // Determine the element tag DicomTag tag; long tagValue; #if (LTV15_CONFIG) if (dm.Elements[j].Tag != DemoDicomTags.Undefined) { tag = DicomTagTable.Instance.Find(dm.Elements[j].Tag); tagValue = (long)dm.Elements[j].Tag; } else { tag = DicomTagTable.Instance.Find(dm.Elements[j].UserTag); tagValue = dm.Elements[j].UserTag; } #else tag = DicomTagTable.Instance.Find(dm.Elements[j].Tag); tagValue = (long)dm.Elements[j].Tag; #endif // Add new element TreeNode IODClassNodes[i].Nodes.Add( new MyTreeNode(String.Format("{0:X4}:{1:X4} - {2}", Utils.GetGroup(tagValue), Utils.GetElement(tagValue), tag.Name), ds, dm.Elements[j])); IODClassNodes[i].Nodes[j].ImageIndex = (int)MyIconIndex.Element; IODClassNodes[i].Nodes[j].SelectedImageIndex = (int)MyIconIndex.Element; // Check to see if the element has children if (ds.GetChildElement(dm.Elements[j], true) != null) { IODClassNodes[i].Nodes[j].ImageIndex = (int)MyIconIndex.Sequence; IODClassNodes[i].Nodes[j].SelectedImageIndex = (int)MyIconIndex.Sequence; // Recursively add children of this element AddChildrenOfElement(ds, (MyTreeNode)IODClassNodes[i].Nodes[j], dm.Elements[j]); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
/* * Initializes a blank dataset to send back to the SCU */ private DicomDataSet PrepareResponseDS() { try { DicomDataSet ResponseDicomDS = new DicomDataSet(); ResponseDicomDS.Initialize(DicomClassType.Undefined, DicomDataSetInitializeType.ImplicitVRLittleEndian); DicomElement element; // Scheduled Procedure Step element = ds.FindFirstElement(null, DemoDicomTags.ScheduledProcedureStepSequence, false); if (element != null) { DicomElement sequence = null; DicomElement item = null; sequence = ResponseDicomDS.InsertElement(null, false, DemoDicomTags.ScheduledProcedureStepSequence, DicomVRType.SQ, true, 0); if (sequence != null) { item = ResponseDicomDS.InsertElement(sequence, true, DemoDicomTags.Item, DicomVRType.SQ, false, 0); } if (item != null) { element = ds.GetChildElement(element, true); if (element != null) { element = ds.GetChildElement(element, true); if (element == null) { AddSecheduledProcedureStepSequenceAttributes(ResponseDicomDS, item); } else { while (element != null) { switch (element.Tag) { case DemoDicomTags.ScheduledStationAETitle: case DemoDicomTags.ScheduledProcedureStepStartDate: case DemoDicomTags.ScheduledProcedureStepStartTime: case DemoDicomTags.Modality: case DemoDicomTags.ScheduledPerformingPhysicianName: case DemoDicomTags.ScheduledProcedureStepDescription: case DemoDicomTags.ScheduledProcedureStepLocation: case DemoDicomTags.ScheduledProcedureStepID: ResponseDicomDS.InsertElement(item, true, element.Tag, DicomVRType.UN, false, 0); break; } element = ds.GetNextElement(element, true, true); } } } else { AddSecheduledProcedureStepSequenceAttributes(ResponseDicomDS, item); } } } // Requested Procedure Utils.InsertKeyElement(ResponseDicomDS, ds, DemoDicomTags.RequestedProcedureID); Utils.InsertKeyElement(ResponseDicomDS, ds, DemoDicomTags.RequestedProcedureDescription); Utils.InsertKeyElement(ResponseDicomDS, ds, DemoDicomTags.StudyInstanceUID); Utils.InsertKeyElement(ResponseDicomDS, ds, DemoDicomTags.RequestedProcedurePriority); Utils.InsertKeyElement(ResponseDicomDS, ds, DemoDicomTags.ReasonForTheRequestedProcedure); // Imaging Service Request Utils.InsertKeyElement(ResponseDicomDS, ds, DemoDicomTags.AccessionNumber); Utils.InsertKeyElement(ResponseDicomDS, ds, DemoDicomTags.RequestingPhysician); Utils.InsertKeyElement(ResponseDicomDS, ds, DemoDicomTags.ReferringPhysicianName); // Visit Identification Utils.InsertKeyElement(ResponseDicomDS, ds, DemoDicomTags.AdmissionID); Utils.InsertKeyElement(ResponseDicomDS, ds, DemoDicomTags.InstitutionName); // Patient Identification Utils.InsertKeyElement(ResponseDicomDS, ds, DemoDicomTags.PatientName); Utils.InsertKeyElement(ResponseDicomDS, ds, DemoDicomTags.PatientID); // Patient Demographic Utils.InsertKeyElement(ResponseDicomDS, ds, DemoDicomTags.PatientBirthDate); Utils.InsertKeyElement(ResponseDicomDS, ds, DemoDicomTags.PatientSex); Utils.InsertKeyElement(ResponseDicomDS, ds, DemoDicomTags.PatientWeight); return(ResponseDicomDS); } catch (Exception ex) { // Throw the exception and let the calling function handle it. throw ex; } }
/* * 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()); } }
void FillSubTree(DicomElement element, TreeNode ParentNode) { TreeNode node; string name; string temp = ""; DicomTag tag; DicomElement tempElement; #if (LTV15_CONFIG) if (element.UserTag != 0) { tag = DicomTagTable.Instance.Find(element.UserTag); } else { tag = DicomTagTable.Instance.Find(element.Tag); } #else tag = DicomTagTable.Instance.Find(element.Tag); #endif if (tag != null) { name = tag.Name; } else { name = "Item"; } long tagValue = 0; #if (LTV15_CONFIG) if (element.UserTag != 0) { tagValue = element.UserTag; } else { tagValue = (long)element.Tag; } #else tagValue = (long)element.Tag; #endif temp = string.Format("{0:x4}:{1:x4} - ", Utils.GetGroup(tagValue), Utils.GetElement(tagValue)); temp = temp + name; 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; tempElement = ds.GetChildElement(element, true); if (tempElement != null) { node.ImageIndex = 0; node.SelectedImageIndex = 0; FillSubTree(tempElement, node); } tempElement = ds.GetNextElement(element, true, true); if (tempElement != null) { FillSubTree(tempElement, ParentNode); } }
private static void FillTreeKeys(TreeView treeview, DicomDataSet ds, DicomElement ParentKeyElement, TreeNode ParentNode) { DicomElement CurrentKeyElement, CurrentKeyChildElement; TreeNode node; string name; string temp = ""; if (ParentKeyElement == null) { CurrentKeyElement = ds.GetFirstKey(null, true); } else { CurrentKeyElement = ds.GetChildKey(ParentKeyElement); } // Add the keys to the TreeView while (CurrentKeyElement != null) { // Get key name temp = ds.GetKeyValueString(CurrentKeyElement); if ((temp != null) || (temp == "")) { name = temp; } else { name = "UNKNOWN"; } // Add at root or beneath its parent if (ParentNode == null) { node = treeview.Nodes.Add(name); } else { node = ParentNode.Nodes.Add(name); } node.Tag = CurrentKeyElement; // Add the current key's non-key child elements CurrentKeyChildElement = ds.GetChildElement(CurrentKeyElement, true); while (CurrentKeyChildElement != null) { FillKeySubTree(treeview, ds, CurrentKeyChildElement, node, false); CurrentKeyChildElement = ds.GetNextElement(CurrentKeyChildElement, true, true); } // Recursively add child keys if (ds.GetChildKey(CurrentKeyElement) != null) { FillTreeKeys(treeview, ds, CurrentKeyElement, node); } CurrentKeyElement = ds.GetNextKey(CurrentKeyElement, true); } }