Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }
Ejemplo n.º 3
0
        /*
         * 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());
            }
        }
Ejemplo n.º 4
0
        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);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Clears the specified dataset.
        /// </summary>
        /// <param name="ds">The ds.</param>
        public static void Clear(DicomDataSet ds)
        {
            DicomElement element = ds.GetFirstElement(null, false, true);

            while (element != null)
            {
                ds.SetConvertValue(element, string.Empty, 1);
                element = ds.GetNextElement(element, false, true);
            }
        }
Ejemplo n.º 6
0
        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;
            }
        }
Ejemplo n.º 7
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        /// <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);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        /*
         * Copies the elements of an MWL dataset (from Step4 (page3.cs) into a newly initialized dataset
         */
        public void MapMWLtoDS(DicomDataSet MWL_DS)
        {
            if (MWL_DS == null)
            {
                return;
            }

            try
            {
                DicomElement element;
                element = MWL_DS.GetFirstElement(null, true, true);
                while (element != null)
                {
                    if (!ReservedElement(element))
                    {
                        if (element.Tag == DemoDicomTags.ScheduledProcedureStepSequence)
                        {
                            DicomElement TmpElement;
                            TmpElement = MWL_DS.FindFirstElement(element, DemoDicomTags.ScheduledProcedureStepID, false);
                            if (TmpElement != null)
                            {
                                MapElement(MWL_DS, TmpElement);
                            }

                            TmpElement = MWL_DS.FindFirstElement(element, DemoDicomTags.ScheduledProcedureStepDescription, false);
                            if (TmpElement != null)
                            {
                                MapElement(MWL_DS, TmpElement);
                            }
                        }
                        else if (!MapElement(MWL_DS, element))
                        {
                            CopyElement(MWL_DS, element, null);
                        }
                    }

                    // Traverse as tree
                    element = MWL_DS.GetNextElement(element, true, true);
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 11
0
        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;
            }
        }
Ejemplo n.º 12
0
        /*
         * 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;
            }
        }
Ejemplo n.º 13
0
        /*
         * 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());
            }
        }
Ejemplo n.º 14
0
        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);
            }
        }
Ejemplo n.º 15
0
        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);
            }
        }
Ejemplo n.º 16
0
      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);
      }
Ejemplo n.º 17
0
        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);
            }
        }