Example #1
0
        private bool LoadTemplate(DvtkData.Dimse.DataSet dataset)
        {
            if (dataset == null)
            {
                return(false);
            }

            // try to find the template tag in the dataset
            foreach (DicomComparisonTag comparisonTag in this._template.ComparisonTags)
            {
                DvtkData.Dimse.Tag tag = comparisonTag.Tag;
                DvtkData.Dimse.Tag parentSequenceTag = comparisonTag.ParentSequenceTag;
                System.String      attributeValue    = System.String.Empty;

                if (parentSequenceTag != Tag.UNDEFINED)
                {
                    DvtkData.Dimse.Attribute sequenceAttribute = dataset.GetAttribute(parentSequenceTag);
                    if ((sequenceAttribute != null) &&
                        (sequenceAttribute.ValueRepresentation == DvtkData.Dimse.VR.SQ))
                    {
                        SequenceOfItems sequenceOfItems = (SequenceOfItems)sequenceAttribute.DicomValue;
                        if (sequenceOfItems.Sequence.Count == 1)
                        {
                            SequenceItem item = sequenceOfItems.Sequence[0];

                            if (item != null)
                            {
                                DvtkData.Dimse.Attribute attribute = item.GetAttribute(tag);
                                attributeValue = GetAttributeValue(attribute);
                            }
                        }
                    }
                }
                else
                {
                    DvtkData.Dimse.Attribute attribute = dataset.GetAttribute(tag);
                    attributeValue = GetAttributeValue(attribute);
                }

                if (attributeValue != System.String.Empty)
                {
                    comparisonTag.DataFormat.FromDicomFormat(attributeValue);
                }
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Create a Worklist Query Dataset from the given DCM file. We assume that the DCM file
        /// contains the appropriate MWL Query Dataset. If the scheduled procedure step start date
        /// is present in the DCM file, it will be overwritten with the value given by scheduledProcedureStepStartDate.
        /// </summary>
        /// <param name="mwlQueryDcmFilename">MWL Query Dcm Filename.</param>
        /// <param name="userDefinedScheduledProcedureStepStartDate">User Defined Scheduled Procedure Step Start Date.</param>
        /// <returns>DvtkData.Dimse.DataSet - Modality Worklist Query Dataset.</returns>
        public static DvtkData.Dimse.DataSet CreateWorklistQueryDataset(System.String mwlQueryDcmFilename, System.String userDefinedScheduledProcedureStepStartDate)
        {
            // Read the DCM file
            DataSet dataset = Dvtk.DvtkDataHelper.ReadDataSetFromFile(mwlQueryDcmFilename);

            dataset.IodId = "Modality Worklist Information Model - FIND SOP Class";

            // Update the scheduled procedure step start date (if present)
            if (userDefinedScheduledProcedureStepStartDate != System.String.Empty)
            {
                DvtkData.Dimse.Attribute scheduledProcedureStepSequence = dataset.GetAttribute(Tag.SCHEDULED_PROCEDURE_STEP_SEQUENCE);
                if (scheduledProcedureStepSequence != null)
                {
                    SequenceOfItems sequenceOfItems = (SequenceOfItems)scheduledProcedureStepSequence.DicomValue;
                    if (sequenceOfItems.Sequence.Count == 1)
                    {
                        SequenceItem queryItem = sequenceOfItems.Sequence[0];

                        // Try to get the Scheduled Procedure Step Start Date
                        // - update it if there is a value defined in the dataset
                        DvtkData.Dimse.Attribute scheduledProcedureStepStartDate = queryItem.GetAttribute(Tag.SCHEDULED_PROCEDURE_STEP_START_DATE);
                        if ((scheduledProcedureStepStartDate != null) &&
                            (scheduledProcedureStepStartDate.Length != 0))
                        {
                            // Remove the existing attribute
                            queryItem.Remove(scheduledProcedureStepStartDate);

                            // Modify value to today's date
                            queryItem.AddAttribute(Tag.SCHEDULED_PROCEDURE_STEP_START_DATE.GroupNumber,
                                                   Tag.SCHEDULED_PROCEDURE_STEP_START_DATE.ElementNumber,
                                                   DvtkData.Dimse.VR.DA,
                                                   userDefinedScheduledProcedureStepStartDate);
                        }
                    }
                }
            }

            return(dataset);
        }
Example #3
0
        private static void AddTagsToDataset(TagValueCollection tags, DvtkData.Dimse.DataSet dataset)
        {
            // iterate over the tags
            foreach (DicomTagValue tag in tags)
            {
                if (tag.ParentSequenceTag != Tag.UNDEFINED)
                {
                    // try to get the sequence tag in the dataset
                    DvtkData.Dimse.Attribute sequenceAttribute = dataset.GetAttribute(tag.ParentSequenceTag);
                    if ((sequenceAttribute != null) &&
                        (sequenceAttribute.ValueRepresentation == DvtkData.Dimse.VR.SQ))
                    {
                        SequenceOfItems sequenceOfItems = (SequenceOfItems)sequenceAttribute.DicomValue;
                        if (sequenceOfItems.Sequence.Count == 1)
                        {
                            SequenceItem item = sequenceOfItems.Sequence[0];

                            if (item != null)
                            {
                                VR vr = VR.UN;

                                // try to get the attribute in the item
                                DvtkData.Dimse.Attribute attribute = item.GetAttribute(tag.Tag);
                                if (attribute != null)
                                {
                                    vr = attribute.ValueRepresentation;
                                    item.Remove(attribute);
                                }

                                // add the query value
                                item.AddAttribute(tag.Tag.GroupNumber,
                                                  tag.Tag.ElementNumber,
                                                  vr,
                                                  tag.Value);
                            }
                        }
                    }
                }
                else
                {
                    VR vr = VR.UN;

                    // try to get the attribute in the dataset
                    DvtkData.Dimse.Attribute attribute = dataset.GetAttribute(tag.Tag);
                    if (attribute != null)
                    {
                        vr = attribute.ValueRepresentation;
                        dataset.Remove(attribute);
                    }

                    // special check for the SPECIFIC CHARACTER SET attribute
                    if (tag.Tag == Tag.SPECIFIC_CHARACTER_SET)
                    {
                        vr = VR.CS;
                    }

                    // add the query value
                    dataset.AddAttribute(tag.Tag.GroupNumber,
                                         tag.Tag.ElementNumber,
                                         vr,
                                         tag.Value);
                }
            }
        }
Example #4
0
        private System.String GetAttributeValue(DvtkData.Dimse.Attribute attribute)
        {
            System.String attributeValue = System.String.Empty;
            if ((attribute == null) ||
                (attribute.Length == 0))
            {
                return(attributeValue);
            }

            switch (attribute.ValueRepresentation)
            {
            case VR.AE:
            {
                ApplicationEntity applicationEntity = (ApplicationEntity)attribute.DicomValue;
                attributeValue = applicationEntity.Values[0];
                break;
            }

            case VR.AS:
            {
                AgeString ageString = (AgeString)attribute.DicomValue;
                attributeValue = ageString.Values[0];
                break;
            }

            case VR.CS:
            {
                CodeString codeString = (CodeString)attribute.DicomValue;
                attributeValue = codeString.Values[0];
                break;
            }

            case VR.DA:
            {
                Date date = (Date)attribute.DicomValue;
                attributeValue = date.Values[0];
                break;
            }

            case VR.DS:
            {
                DecimalString decimalString = (DecimalString)attribute.DicomValue;
                attributeValue = decimalString.Values[0];
                break;
            }

            case VR.DT:
            {
                DvtkData.Dimse.DateTime dateTime = (DvtkData.Dimse.DateTime)attribute.DicomValue;
                attributeValue = dateTime.Values[0];
                break;
            }

            case VR.IS:
            {
                IntegerString integerString = (IntegerString)attribute.DicomValue;
                attributeValue = integerString.Values[0];
                break;
            }

            case VR.LO:
            {
                LongString longString = (LongString)attribute.DicomValue;
                attributeValue = longString.Values[0];
                break;
            }

            case VR.LT:
            {
                LongText longText = (LongText)attribute.DicomValue;
                attributeValue = longText.Value;
                break;
            }

            case VR.PN:
            {
                PersonName personName = (PersonName)attribute.DicomValue;
                attributeValue = personName.Values[0];
                break;
            }

            case VR.SH:
            {
                ShortString shortString = (ShortString)attribute.DicomValue;
                attributeValue = shortString.Values[0];
                break;
            }

            case VR.SQ:
            {
                // Special case looking for the SOP Class UID
                SequenceOfItems sequenceOfItems = (SequenceOfItems)attribute.DicomValue;
                if ((sequenceOfItems != null) &&
                    (sequenceOfItems.Sequence.Count == 1))
                {
                    // Special case looking for the SOP Class UID
                    SequenceItem item = sequenceOfItems.Sequence[0];
                    attribute      = item.GetAttribute(new Tag(0x0008, 0x1150));
                    attributeValue = GetAttributeValue(attribute);
                }
                break;
            }

            case VR.ST:
            {
                ShortText shortText = (ShortText)attribute.DicomValue;
                attributeValue = shortText.Value;
                break;
            }

            case VR.TM:
            {
                Time time = (Time)attribute.DicomValue;
                attributeValue = time.Values[0];
                break;
            }

            case VR.UI:
            {
                UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)attribute.DicomValue;
                attributeValue = uniqueIdentifier.Values[0];
                break;
            }

            default:
                break;
            }

            return(attributeValue);
        }