コード例 #1
0
ファイル: SequenceTests.cs プロジェクト: bangush/server-1
        public void TestSequenceImplicitVr2()
        {
            var syntax = TransferSyntax.ImplicitVrLittleEndian;
            var sq     = new DicomAttributeSQ(DicomTags.IconImageSequence);

            var item1 = new DicomSequenceItem();

            item1[DicomTags.AccessionNumber].SetStringValue("ABCDEFG");
            sq.AddSequenceItem(item1);

            var item2 = new DicomSequenceItem();

            item2[DicomTags.AccessionNumber].SetStringValue("XYZ");
            sq.AddSequenceItem(item2);

            // note: both sequence and item delimiter tags are calculated as part of the sequence - the item considers only the total length of its contents

            // item1_length = contents(16)
            Assert.AreEqual(16, item1[DicomTags.AccessionNumber].CalculateWriteLength(syntax, DicomWriteOptions.None), "Attr1 Length");
            Assert.AreEqual(16, item1.CalculateWriteLength(syntax, DicomWriteOptions.None), "Item1 Length");

            // item2_length = contents(12)
            Assert.AreEqual(12, item2[DicomTags.AccessionNumber].CalculateWriteLength(syntax, DicomWriteOptions.None), "Attr2 Length");
            Assert.AreEqual(12, item2.CalculateWriteLength(syntax, DicomWriteOptions.None), "Item2 Length");

            // sq_length = tag(4) + len(4) + item_tag(4) + item_len(4) + item1_length(16) + item_delimiter_tag(4) + item_delimiter_len(4)
            //                             + item_tag(4) + item_len(4) + item2_length(12) + item_delimiter_tag(4) + item_delimiter_len(4)
            //                             + sq_delimiter_tag(4) + sq_delimiter_len(4)
            var options = DicomWriteOptions.None;

            Assert.AreEqual(76, sq.CalculateWriteLength(syntax, options), "SQ Length (Options={0})", options);

            // sq_length = tag(4) + len(4) + item_tag(4) + item_len(4) + item1_length(16) + item_delimiter_tag(4) + item_delimiter_len(4)
            //                             + item_tag(4) + item_len(4) + item2_length(12) + item_delimiter_tag(4) + item_delimiter_len(4)
            options = DicomWriteOptions.ExplicitLengthSequence;
            Assert.AreEqual(68, sq.CalculateWriteLength(syntax, options), "SQ Length (Options={0})", options);

            // sq_length = tag(4) + len(4) + item_tag(4) + item_len(4) + item1_length(16)
            //                             + item_tag(4) + item_len(4) + item2_length(12)
            //                             + sq_delimiter_tag(4) + sq_delimiter_len(4)
            options = DicomWriteOptions.ExplicitLengthSequenceItem;
            Assert.AreEqual(60, sq.CalculateWriteLength(syntax, options), "SQ Length (Options={0})", options);

            // sq_length = tag(4) + len(4) + item_tag(4) + item_len(4) + item1_length(16)
            //                             + item_tag(4) + item_len(4) + item2_length(12)
            options = DicomWriteOptions.ExplicitLengthSequence | DicomWriteOptions.ExplicitLengthSequenceItem;
            Assert.AreEqual(52, sq.CalculateWriteLength(syntax, options), "SQ Length (Options={0})", options);
        }
コード例 #2
0
        public virtual void ReadData(string tableName, string columnName, object value)
        {
            var column    = SchemaProvider.GetColumn(tableName, columnName);
            var dicomTags = column.Tags;

            if (column.IsKey)
            {
                CurrentData.KeyValue = value.ToString( );
            }

            if (column.IsForeign)
            {
                string keyString = value.ToString( );

                KeyToDataSetCollection resultSet = null;

                if (ResultSets.TryGetValue(column.Table.Parent, out resultSet))
                {
                    DicomAttributeCollection foreignDs = resultSet[keyString];

                    if (QueryLevel == column.Table.Name)
                    {
                        foreignDs.Merge(CurrentData.CurrentDs);

                        //resultSet[keyString] = CurrentData.CurrentDs ;
                    }
                    else
                    {
                        if (column.Table.IsSequence)
                        {
                            DicomAttributeSQ  sq   = (DicomAttributeSQ)CurrentData.ForeignDs [CurrentData.ForeignTagValue];
                            DicomSequenceItem item = new DicomSequenceItem( );

                            sq.AddSequenceItem(item);

                            CurrentData.CurrentDs.Merge(item);

                            CurrentData.CurrentDs = item;
                        }
                        else if (column.Table.IsMultiValue)
                        {
                            CurrentData.CurrentDs = foreignDs;
                        }
                        else
                        {
                            CurrentData.CurrentDs.Merge(foreignDs);

                            CurrentData.CurrentDs = foreignDs.Copy( );
                        }
                    }
                }
            }

            if (null == dicomTags)
            {
                return;
            }

            ReadTags(columnName, value, dicomTags);
        }
コード例 #3
0
		public void TestSequenceImplicitVr2()
		{
			var syntax = TransferSyntax.ImplicitVrLittleEndian;
			var sq = new DicomAttributeSQ(DicomTags.IconImageSequence);

			var item1 = new DicomSequenceItem();
			item1[DicomTags.AccessionNumber].SetStringValue("ABCDEFG");
			sq.AddSequenceItem(item1);

			var item2 = new DicomSequenceItem();
			item2[DicomTags.AccessionNumber].SetStringValue("XYZ");
			sq.AddSequenceItem(item2);

			// note: both sequence and item delimiter tags are calculated as part of the sequence - the item considers only the total length of its contents

			// item1_length = contents(16)
			Assert.AreEqual(16, item1[DicomTags.AccessionNumber].CalculateWriteLength(syntax, DicomWriteOptions.None), "Attr1 Length");
			Assert.AreEqual(16, item1.CalculateWriteLength(syntax, DicomWriteOptions.None), "Item1 Length");

			// item2_length = contents(12)
			Assert.AreEqual(12, item2[DicomTags.AccessionNumber].CalculateWriteLength(syntax, DicomWriteOptions.None), "Attr2 Length");
			Assert.AreEqual(12, item2.CalculateWriteLength(syntax, DicomWriteOptions.None), "Item2 Length");

			// sq_length = tag(4) + len(4) + item_tag(4) + item_len(4) + item1_length(16) + item_delimiter_tag(4) + item_delimiter_len(4)
			//                             + item_tag(4) + item_len(4) + item2_length(12) + item_delimiter_tag(4) + item_delimiter_len(4)
			//                             + sq_delimiter_tag(4) + sq_delimiter_len(4)
			var options = DicomWriteOptions.None;
			Assert.AreEqual(76, sq.CalculateWriteLength(syntax, options), "SQ Length (Options={0})", options);

			// sq_length = tag(4) + len(4) + item_tag(4) + item_len(4) + item1_length(16) + item_delimiter_tag(4) + item_delimiter_len(4)
			//                             + item_tag(4) + item_len(4) + item2_length(12) + item_delimiter_tag(4) + item_delimiter_len(4)
			options = DicomWriteOptions.ExplicitLengthSequence;
			Assert.AreEqual(68, sq.CalculateWriteLength(syntax, options), "SQ Length (Options={0})", options);

			// sq_length = tag(4) + len(4) + item_tag(4) + item_len(4) + item1_length(16)
			//                             + item_tag(4) + item_len(4) + item2_length(12)
			//                             + sq_delimiter_tag(4) + sq_delimiter_len(4)
			options = DicomWriteOptions.ExplicitLengthSequenceItem;
			Assert.AreEqual(60, sq.CalculateWriteLength(syntax, options), "SQ Length (Options={0})", options);

			// sq_length = tag(4) + len(4) + item_tag(4) + item_len(4) + item1_length(16)
			//                             + item_tag(4) + item_len(4) + item2_length(12)
			options = DicomWriteOptions.ExplicitLengthSequence | DicomWriteOptions.ExplicitLengthSequenceItem;
			Assert.AreEqual(52, sq.CalculateWriteLength(syntax, options), "SQ Length (Options={0})", options);
		}
コード例 #4
0
ファイル: MWLScp.cs プロジェクト: vincent1996/mwl-mpps
        private void PopulateScheduledProcedureStepSequence(DicomAttributeSQ dicomAttribute, ExamsScheduled row)
        {
            DicomSequenceItem item;

            item = new DicomSequenceItem();

            item[DicomTags.ScheduledStationAeTitle].SetStringValue(row.ScheduledAET);
            item[DicomTags.ScheduledProcedureStepStartDate].SetStringValue(GetDateStringOnly(row.ExamScheduledDateAndTime));
            item[DicomTags.ScheduledProcedureStepStartTime].SetStringValue(GetTimeStringOnly(row.ExamScheduledDateAndTime));
            item[DicomTags.Modality].SetStringValue(row.Modality);
            item[DicomTags.PerformedProcedureStepId].SetStringValue(string.Format("{0}", row.ProcedureStepID)); //O M K supported
            item[DicomTags.ScheduledProcedureStepLocation].SetStringValue(row.ExamRoom);                        //return type 2 -O M K supported
            item[DicomTags.ScheduledProcedureStepDescription].SetStringValue(row.ExamDescription);              //return type 2 -O M K supported
            dicomAttribute.AddSequenceItem(item);
        }
コード例 #5
0
            private static DicomAttribute AddAttributeToResult(DicomTagPath atrributePath, DicomAttributeCollection result)
            {
                int i = 0;

                while (i < atrributePath.TagsInPath.Count - 1)
                {
                    DicomAttributeSQ sequence = (DicomAttributeSQ)result[atrributePath.TagsInPath[i++]];
                    if (sequence.IsEmpty)
                    {
                        sequence.AddSequenceItem(new DicomSequenceItem());
                    }

                    result = ((DicomSequenceItem[])sequence.Values)[0];
                }

                return(result[atrributePath.TagsInPath[i]]);
            }
コード例 #6
0
        private void CreateSequence(List <string> elements, int currentElementIndex, DicomAttributeCollection dicomRequest, string value)
        {
            uint tag = uint.Parse(elements[currentElementIndex], System.Globalization.NumberStyles.HexNumber);   //TODO: need to handle the case of keywords

            DicomAttributeSQ  sequence = dicomRequest[tag] as DicomAttributeSQ;
            DicomSequenceItem item;


            if (sequence.Count > 0)
            {
                item = sequence[0];
            }
            else
            {
                item = new DicomSequenceItem( );

                sequence.AddSequenceItem(item);
            }

            for (int index = (currentElementIndex + 1); index < elements.Count; index++)
            {
                tag = uint.Parse(elements[index], System.Globalization.NumberStyles.HexNumber);

                DicomAttribute childElement = item[tag];  //TODO: if item.Contains(tag)??? throw error?

                if (childElement.Tag.VR.Equals(DicomVr.SQvr))
                {
                    CreateSequence(elements, index, item, value);

                    break;
                }
                else
                {
                    childElement.SetStringValue(value);
                }
            }
        }
        public static DicomSequenceItem CreateOriginalAttributesSequence(IEnumerable <DicomAttribute> originalValues,
                                                                         string originalAttributesSource, string modifyingSystem, string reasonForModification)
        {
            DicomSequenceItem item = new DicomSequenceItem();

            item[DicomTags.AttributeModificationDatetime]
            .SetDateTime(0, DateTime.Now);
            if (!string.IsNullOrEmpty(originalAttributesSource))
            {
                item[DicomTags.SourceOfPreviousValues]
                .SetStringValue(originalAttributesSource);
            }
            if (!string.IsNullOrEmpty(modifyingSystem))
            {
                item[DicomTags.ModifyingSystem]
                .SetStringValue(modifyingSystem);
            }
            if (!string.IsNullOrEmpty(reasonForModification))
            {
                item[DicomTags.ReasonForTheAttributeModification]
                .SetStringValue(reasonForModification);
            }
            DicomAttributeSQ sq =
                new DicomAttributeSQ(DicomTags.ModifiedAttributesSequence);

            item[sq.Tag] = sq;

            DicomSequenceItem modified = new DicomSequenceItem();

            sq.AddSequenceItem(modified);

            foreach (DicomAttribute value in originalValues)
            {
                modified[value.Tag] = value;
            }
            return(item);
        }
コード例 #8
0
ファイル: SequenceIodList.cs プロジェクト: top501/GoldenEagle
 /// <summary>
 /// Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1"/>.
 /// </summary>
 /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param>
 /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.</exception>
 public void Add(T item)
 {
     _dicomAttributeSQ.AddSequenceItem(item.DicomSequenceItem);
 }
コード例 #9
0
ファイル: InstanceXml.cs プロジェクト: hksonngan/Xian
        private static void ParseAttribute(DicomAttributeCollection theCollection, XmlNode attributeNode)
        {
            if (attributeNode.Name.Equals("Attribute"))
            {
                DicomTag theTag = GetTagFromAttributeNode(attributeNode);

                DicomAttribute attribute = theCollection[theTag];
                if (attribute is DicomAttributeSQ)
                {
                    DicomAttributeSQ attribSQ = (DicomAttributeSQ)attribute;
                    //set the null value in case there are no child nodes.
                    attribute.SetNullValue();

                    if (attributeNode.HasChildNodes)
                    {
                        XmlNode itemNode = attributeNode.FirstChild;

                        while (itemNode != null)
                        {
                            DicomSequenceItem theItem = new InstanceXmlDicomSequenceItem();

                            ParseCollection(theItem, itemNode);

                            attribSQ.AddSequenceItem(theItem);

                            itemNode = itemNode.NextSibling;
                        }
                    }
                }
                else
                {
                    // Cleanup the common XML character replacements
                    string tempString = attributeNode.InnerText;
                    tempString = XmlUnescapeString(tempString);
                    try
                    {
                        attribute.SetStringValue(tempString);
                    }
                    catch (Exception e)
                    {
                        Platform.Log(LogLevel.Error, e,
                                     "Unexpected exception with tag {0} setting value '{1}'.  Ignoring tag value.",
                                     attribute.Tag,
                                     tempString);
                    }

                    ((IPrivateInstanceXmlDicomAttributeCollection)theCollection).ExcludedTagsHelper.Remove(theTag);
                }
            }
            else if (attributeNode.Name.Equals("EmptyAttribute"))
            {
                //Means that the tag should not be in this collection, but is in the base.  So, we remove it.
                DicomTag theTag = GetTagFromAttributeNode(attributeNode);

                //NOTE: we want these attributes to be in the collection and empty so that
                //the base collection doesn't need to be modified in order to insert
                //excluded tags in the correct order.
                theCollection[theTag].SetEmptyValue();

                ((IPrivateInstanceXmlDicomAttributeCollection)theCollection).ExcludedTagsHelper.Remove(theTag);
            }
            else if (attributeNode.Name.Equals("ExcludedAttribute"))
            {
                DicomTag theTag = GetTagFromAttributeNode(attributeNode);

                //NOTE: we want these attributes to be in the collection and empty so that
                //the base collection doesn't need to be modified in order to insert
                //excluded tags in the correct order.
                theCollection[theTag].SetEmptyValue();

                ((IPrivateInstanceXmlDicomAttributeCollection)theCollection).ExcludedTagsHelper.Add(theTag);
            }
        }
        private static void DoParseAttributes(
            StudyLoaderArgs studyLoaderArgs,
            ParseResult result,
            string metaUri,
            XmlElement elem)
        {
            var collection = result.Attributes;

            collection.ValidateVrValues  = false;
            collection.ValidateVrLengths = false;
            foreach (var node in elem)
            {
                var attrElem = node as XmlElement;
                if (attrElem == null)
                {
                    continue;
                }
                if (!attrElem.Name.Equals("attr"))
                {
                    continue;
                }
                var              dcmTag = GetTagFromAttrElement(attrElem);
                DicomAttribute   attr   = collection[dcmTag];
                DicomAttributeSQ sq     = attr as DicomAttributeSQ;
                if (sq != null)
                {
                    sq.ClearSequenceItems();
                    foreach (XmlNode itemNode in attrElem)
                    {
                        var itemElem = itemNode as XmlElement;
                        if (itemElem != null)
                        {
                            if (itemElem.Name.Equals("item"))
                            {
                                var subResult   = new ParseResult();
                                var subSequence = new DicomSequenceItem();
                                subResult.Attributes = subSequence;
                                DoParseAttributes(studyLoaderArgs, subResult, metaUri, itemElem);
                                sq.AddSequenceItem(subSequence);
                            }
                        }
                    }
                }
                else
                {
                    string val = null;
                    if (attrElem.Attributes["val"] != null)
                    {
                        val = attrElem.Attributes["val"].Value;
                        attr.SetStringValue(val);
                    }
                    else if (attrElem.Attributes["bid"] != null)
                    {
                        // TODO: This tag's value is binary. We're not interested in binary items other
                        // than the pixel data so we ignore them -- they will be added to the
                        // sequence but they will not have any value set.
                        if (attr.Tag.TagValue == DicomTags.PixelData)
                        {
                            result.PixelDataBid = attrElem.Attributes["bid"].Value;
                        }
                    }
                    else if (attrElem.Attributes["bytes"] != null)
                    {
                        // TODO: This tag's value is binary. We're not interested in binary items other
                        // than the pixel data so we ignore them -- they will be added to the
                        // sequence but they will not have any value set.
                        ;
                    }
                    else if (attrElem.Attributes["bsize"] != null)
                    {
                        // TODO: Bulk binary loading can use this.
                    }
                    else
                    {
                        Platform.Log(LogLevel.Warn, "Attr element {0} missing ",
                                     attr.Tag, val);
                    }
                }
            }
        }