/// <summary>
        /// Patient merge request - update modality worklist information model.
        /// </summary>
        /// <param name="dataset">Dataset containing patient merge attributes.</param>
        public override void PatientMerge(DvtkData.Dimse.DataSet dataset)
        {
            // Get the merge patient - need to use this to search for the corresponding patient IE
            DvtkData.Dimse.Attribute mergePatientId = dataset.GetAttribute(Tag.OTHER_PATIENT_IDS);
            if (mergePatientId.Length != 0)
            {
                LongString    longString     = (LongString)mergePatientId.DicomValue;
                System.String attributeValue = longString.Values[0];

                DataSet queryDataset = new DataSet("Transient");
                queryDataset.AddAttribute(Tag.PATIENT_ID.GroupNumber, Tag.PATIENT_ID.ElementNumber, VR.LO, attributeValue);

                // check each patient IE in the patientRootList
                foreach (PatientInformationEntity lPatientInformationEntity in Root)
                {
                    // if IE matches the unique (merge) patient id field in the query dataset
                    if (lPatientInformationEntity.IsUniqueTagFoundIn(queryDataset))
                    {
                        // update the patient demographics - including the patient id
                        lPatientInformationEntity.CopyFrom(dataset);
                        break;
                    }
                }
            }
        }
Example #2
0
 public BaseInformationModel(System.String name)
 {
     _name = name;
     _root = new BaseInformationEntityList();
     _dataDirectory = ".";
     _defaultDataset = new DataSet("Default Dataset");
     _additionalDataset = new DataSet("Additional Dataset");
 }
Example #3
0
        /// <summary>
        /// Compute the Item Offset for DICOMDIR.
        /// </summary>
        /// <param name="dataSet">DICOM Seq Item</param>
        /// <param name="transferSyntax">with transfer syntax</param>
        /// <returns>Offset</returns>
        public static UInt32 ComputeItemOffset(
			DataSet dataSet,
			string transferSyntax)
        {
            if (dataSet == null) throw new System.ArgumentNullException("dataSet");

            return MDataSet.ComputeItemOffset(dataSet, transferSyntax);
        }
Example #4
0
        /// <summary>
        /// Class Constructor.
        /// </summary>
        /// <param name="level">Entity level in the Information Model.</param>
        public BaseInformationEntity(System.String level)
        {
            _level = level;
            _dataset = new DataSet(_level);
            _additionalDataset = new DataSet(_level + " Additional");

            // set up the default Tag Type List
            SetDefaultTagTypeList();
        }
Example #5
0
 /// <summary>
 /// Class constructor.
 /// </summary>
 /// <param name="name">Information Model Name.</param>
 public BaseInformationModel(System.String name)
 {
     _name = name;
     _root = new BaseInformationEntityList();
     _dataDirectory = ".";
     _isDataStored = true;
     _defaultDatasetNoOverWrite = new DataSet("Default Dataset - NoOverWrite");
     _defaultDatasetOverWrite = new DataSet("Default Dataset - OverWrite");
     _additionalDatasetNoOverWrite = new DataSet("Additional Dataset - NoOverWrite");
     _additionalDatasetOverWrite = new DataSet("Additional Dataset - OverWrite");
     _fileIndex = 1;
 }
        /// <summary>
        /// Patient Registration request - update modality worklist information model.
        /// </summary>
        /// <param name="dataset">Dataset containing patient registration attributes.</param>
        public override void PatientRegistration(DvtkData.Dimse.DataSet dataset)
        {
            // update the first patient IE with the registration details
            // - check that there is at least one.
            if (Root.Count == 0)
            {
                return;
            }

            PatientInformationEntity patientInformationEntity = (PatientInformationEntity)Root[0];

            patientInformationEntity.CopyFrom(dataset);
        }
 /// <summary>
 /// Patient Update request - update modality worklist information model.
 /// </summary>
 /// <param name="dataset">Dataset containing patient update attributes.</param>
 public override void PatientUpdate(DvtkData.Dimse.DataSet dataset)
 {
     // check each patient IE in the patientRootList
     foreach (PatientInformationEntity lPatientInformationEntity in Root)
     {
         // if IE matches the unique patient id field
         if (lPatientInformationEntity.IsUniqueTagFoundIn(dataset))
         {
             // update the other patient demographics
             lPatientInformationEntity.CopyFrom(dataset);
             break;
         }
     }
 }
Example #8
0
        /// <summary>
        /// Create a Worklist Query Dataset from the given query tags and the default return keys.
        /// </summary>
        /// <param name="queryTags">Query Tags.</param>
        /// <returns>DvtkData.Dimse.DataSet - Modality Worklist Query Dataset.</returns>
        public static DvtkData.Dimse.DataSet CreateWorklistQueryDataset(TagValueCollection queryTags)
        {
            DvtkData.Dimse.DataSet dataset = new DvtkData.Dimse.DataSet("Modality Worklist Information Model - FIND SOP Class");

            // update the query tags with any parent sequence information needed
            UpdateTagParentSequences(queryTags);

            // add the default return keys
            AddDefaultReturnKeys(dataset);

            // add the query keys
            AddTagsToDataset(queryTags, dataset);

            return dataset;
        }
Example #9
0
        /// <summary>
        /// Create a Worklist Query Dataset from the given query tags and the default return keys.
        /// </summary>
        /// <param name="queryTags">Query Tags.</param>
        /// <returns>DvtkData.Dimse.DataSet - Modality Worklist Query Dataset.</returns>
        public static DvtkData.Dimse.DataSet CreateWorklistQueryDataset(TagValueCollection queryTags)
        {
            DvtkData.Dimse.DataSet dataset = new DvtkData.Dimse.DataSet("Modality Worklist Information Model - FIND SOP Class");

            // update the query tags with any parent sequence information needed
            UpdateTagParentSequences(queryTags);

            // add the default return keys
            AddDefaultReturnKeys(dataset);

            // add the query keys
            AddTagsToDataset(queryTags, dataset);

            return(dataset);
        }
Example #10
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 #11
0
        /// <summary>
        /// Add the attributes in this additional dataset to all Information Entities in the Information
        /// Model. Do not overrule any attribute with the same tag as the additional attribute that may
        /// already be in the Information Entity.
        /// </summary>
        /// <param name="additionalDataset">Dataset containing the additional values.</param>
        public void AddAdditionalAttributesToInformationModel(DataSet additionalDataset)
        {
            if (additionalDataset == null) return;

            // iterate of all Information Entities
            foreach (BaseInformationEntity baseInformationEntity in Root)
            {
                baseInformationEntity.AddAdditionalAttributes(additionalDataset);
            }

            // save these additional attributes - in case of refresh
            foreach (DvtkData.Dimse.Attribute additionalAttribute in additionalDataset)
            {
                DvtkData.Dimse.Attribute lAdditionalAttribute = _additionalDataset.GetAttribute(additionalAttribute.Tag);
                if (lAdditionalAttribute == null)
                {
                    _additionalDataset.Add(additionalAttribute);
                }
            }
        }
Example #12
0
        private static void AddDefaultReturnKeys(DvtkData.Dimse.DataSet dataset)
        {
            // use the Worklist Information Entities to generate the default Return Key attribute set
            PatientInformationEntity patientIe = new PatientInformationEntity();

            foreach (TagType tagType in patientIe.TagTypeList)
            {
                dataset.AddAttribute(tagType.Tag.GroupNumber, tagType.Tag.ElementNumber, tagType.Vr);
            }
            VisitInformationEntity visitIe = new VisitInformationEntity();

            foreach (TagType tagType in visitIe.TagTypeList)
            {
                dataset.AddAttribute(tagType.Tag.GroupNumber, tagType.Tag.ElementNumber, tagType.Vr);
            }
            ImagingServiceRequestInformationEntity imagingServiceRequestIe = new ImagingServiceRequestInformationEntity();

            foreach (TagType tagType in imagingServiceRequestIe.TagTypeList)
            {
                dataset.AddAttribute(tagType.Tag.GroupNumber, tagType.Tag.ElementNumber, tagType.Vr);
            }
            RequestedProcedureInformationEntity requestedProcedureIe = new RequestedProcedureInformationEntity();

            foreach (TagType tagType in requestedProcedureIe.TagTypeList)
            {
                dataset.AddAttribute(tagType.Tag.GroupNumber, tagType.Tag.ElementNumber, tagType.Vr);
            }

            SequenceItem item = new SequenceItem();
            ScheduledProcedureStepInformationEntity scheduledProcedureStepIe = new ScheduledProcedureStepInformationEntity();

            foreach (TagType tagType in scheduledProcedureStepIe.TagTypeList)
            {
                if (tagType.Tag != Tag.SPECIFIC_CHARACTER_SET)
                {
                    item.AddAttribute(tagType.Tag.GroupNumber, tagType.Tag.ElementNumber, tagType.Vr);
                }
            }
            dataset.AddAttribute(Tag.SCHEDULED_PROCEDURE_STEP_SEQUENCE.GroupNumber,
                                 Tag.SCHEDULED_PROCEDURE_STEP_SEQUENCE.ElementNumber, VR.SQ, item);
        }
        /// <summary>
        /// Placer order management request - update modality worklist information model.
        /// </summary>
        /// <param name="dataset">Dataset containing placer order management attributes.</param>
        public override void PlacerOrderManagement(DvtkData.Dimse.DataSet dataset)
        {
            AddToInformationModel(dataset, false);

            /*
             * // check each patient IE in the patientRootList
             * foreach (PatientInformationEntity patientInformationEntity in Root)
             * {
             *      // if IE matches the unique patient id field
             *      if (patientInformationEntity.IsUniqueTagFoundIn(dataset))
             *      {
             *              // update the first visit IE with the order details
             *              // - check that there is at least one.
             *              if (patientInformationEntity.Children.Count == 0) return;
             *              VisitInformationEntity visitInformationEntity = (VisitInformationEntity)patientInformationEntity.Children[0];
             *              visitInformationEntity.CopyFrom(dataset);
             *
             *              // update the first image service request IE with the order details
             *              // - check that there is at least one.
             *              if (visitInformationEntity.Children.Count == 0) return;
             *              ImagingServiceRequestInformationEntity imagingServiceRequestInformationEntity = (ImagingServiceRequestInformationEntity)visitInformationEntity.Children[0];
             *              imagingServiceRequestInformationEntity.CopyFrom(dataset);
             *
             *              // update the first requested procedure IE with the order details
             *              // - check that there is at least one.
             *              if (imagingServiceRequestInformationEntity.Children.Count == 0) return;
             *              RequestedProcedureInformationEntity requestedProcedureInformationEntity = (RequestedProcedureInformationEntity)imagingServiceRequestInformationEntity.Children[0];
             *              requestedProcedureInformationEntity.CopyFrom(dataset);
             *
             *              // update the first scheduled procedure step IE with the order details
             *              // - check that there is at least one.
             *              if (requestedProcedureInformationEntity.Children.Count == 0) return;
             *              ScheduledProcedureStepInformationEntity scheduledProcedureStepInformationEntity = (ScheduledProcedureStepInformationEntity)requestedProcedureInformationEntity.Children[0];
             *              scheduledProcedureStepInformationEntity.CopyFrom(dataset);
             *              break;
             *      }
             * }
             */
        }
Example #14
0
        /// <summary>
        /// Check if the given instance is present in the Information Model. The instance will be at the leaf nodes of the Information Model.
        /// </summary>
        /// <param name="sopClassUid">SOP Class UID to search for.</param>
        /// <param name="sopInstanceUid">SOP Instance UID to search for.</param>
        /// <returns>Boolean - true if instance found in the Information Model, otherwise false.</returns>
        public bool IsInstanceInInformationModel(System.String sopClassUid, System.String sopInstanceUid)
        {
            bool isInstanceInInformationModel = false;

            // set up the commit tag list for comparing with the leaf
            TagTypeList commitTagTypeList = new TagTypeList();

            commitTagTypeList.Add(new TagType(Tag.SOP_INSTANCE_UID, TagTypeEnum.TagRequired));
            commitTagTypeList.Add(new TagType(Tag.SOP_CLASS_UID, TagTypeEnum.TagRequired));

            // set up the commit dataset
            DvtkData.Dimse.DataSet   commitDataset = new DvtkData.Dimse.DataSet();
            DvtkData.Dimse.Attribute attribute     = new DvtkData.Dimse.Attribute(0x00080016, DvtkData.Dimse.VR.UI, sopClassUid);
            commitDataset.Add(attribute);
            attribute = new DvtkData.Dimse.Attribute(0x00080018, DvtkData.Dimse.VR.UI, sopInstanceUid);
            commitDataset.Add(attribute);

            // iterate over the whole information model - we are interested in the leaf nodes
            foreach (PatientInformationEntity patientInformationEntity in Root)
            {
                foreach (StudyInformationEntity studyInformationEntity in patientInformationEntity.Children)
                {
                    foreach (SeriesInformationEntity seriesInformationEntity in studyInformationEntity.Children)
                    {
                        foreach (InstanceInformationEntity instanceInformationEntity in seriesInformationEntity.Children)
                        {
                            if (instanceInformationEntity.IsFoundIn(commitTagTypeList, commitDataset))
                            {
                                // an instance has been found with the matching commit uids
                                isInstanceInInformationModel = true;
                                break;
                            }
                        }
                    }
                }
            }

            return(isInstanceInInformationModel);
        }
Example #15
0
 /*
 /// <summary>
 /// Overloaded constructor.
 /// </summary>
 /// <param name="commandField">Command field</param>
 public DicomMessage(DimseCommand commandField)
 {
     // this._CommandSet.CommandField = commandField;
 }
 */
 /// <summary>
 /// Apply <see cref="CommandSet"/> and <see cref="DataSet"/> to this message.
 /// </summary>
 /// <param name="commandSet">command set</param>
 /// <param name="dataSet">data set</param>
 /// <param name="encodedPCID">Presentation context ID in which message is encoded</param>
 public void Apply(CommandSet commandSet, DataSet dataSet, Byte encodedPCID)
 {
     if (commandSet == null) throw new System.ArgumentNullException("commandSet");
     if (dataSet == null) throw new System.ArgumentNullException("dataSet");
     this.CommandSet = commandSet;
     this.DataSet = dataSet;
     this.EncodedPresentationContextID = encodedPCID;
 }
Example #16
0
 public virtual void AddToInformationModel( DataSet dataset, bool storeDataset)
 {
 }
        /// <summary>
        /// Retrieve a list of filenames from the Information Model. The filenames match the
        /// individual instances matching the retrieve dataset attributes.
        /// </summary>
        /// <param name="retrieveDataset">Retrive dataset.</param>
        /// <returns>File list - containing the filenames of all instances matching the retrieve dataset attributes.</returns>
        public DvtkData.Collections.StringCollection RetrieveInformationModel(DataSet retrieveDataset)
        {
            DvtkData.Collections.StringCollection fileList = new DvtkData.Collections.StringCollection();

            // get the query/retrieve level
            String queryRetrieveLevel = "UNKNOWN";
            DvtkData.Dimse.Attribute queryRetrieveLevelAttribute = retrieveDataset.GetAttribute(Tag.QUERY_RETRIEVE_LEVEL);
            if (queryRetrieveLevelAttribute != null)
            {
                CodeString codeString = (CodeString)queryRetrieveLevelAttribute.DicomValue;
                if (codeString.Values.Count == 1)
                {
                    queryRetrieveLevel = codeString.Values[0].Trim();
                }
            }

            // Find the matching PATIENT.
            PatientInformationEntity patientInformationEntity = null;
            foreach (PatientInformationEntity lPatientInformationEntity in Root)
            {
                if (lPatientInformationEntity.IsUniqueTagFoundIn(retrieveDataset))
                {
                    patientInformationEntity = lPatientInformationEntity;
                    break;
                }
            }

            if (patientInformationEntity != null)
            {
                // retrieve at the PATIENT level
                if (queryRetrieveLevel == "PATIENT")
                {
                    fileList = patientInformationEntity.FileNames;
                }
                else
                {
                    // Find the matching STUDIES.
                    BaseInformationEntityList studyInformationEntities = patientInformationEntity.ChildrenWithUniqueTagFoundIn(retrieveDataset);

                    if (studyInformationEntities.Count > 0)
                    {
                        // Retrieve at the STUDY level
                        if (queryRetrieveLevel == "STUDY")
                        {
                            foreach (StudyInformationEntity studyInformationEntity in studyInformationEntities)
                            {
                                foreach (String fileName in studyInformationEntity.FileNames)
                                {
                                    fileList.Add(fileName);
                                }
                            }
                        }
                        else
                        {
                            // Find the matching SERIES.
                            BaseInformationEntityList seriesInformationEntities = studyInformationEntities[0].ChildrenWithUniqueTagFoundIn(retrieveDataset);

                            if (seriesInformationEntities.Count > 0)
                            {
                                // retrieve at the SERIES level
                                if (queryRetrieveLevel == "SERIES")
                                {
                                    foreach (SeriesInformationEntity seriesInformationEntity in seriesInformationEntities)
                                    {
                                        foreach (String fileName in seriesInformationEntity.FileNames)
                                        {
                                            fileList.Add(fileName);
                                        }
                                    }
                                }
                                else
                                {
                                    // Find the matching IMAGE
                                    BaseInformationEntityList instanceInformationEntities = seriesInformationEntities[0].ChildrenWithUniqueTagFoundIn(retrieveDataset);

                                    // retrieve at the IMAGE level
                                    if ((instanceInformationEntities.Count > 0) &&
                                        (queryRetrieveLevel == "IMAGE"))
                                    {
                                        foreach (InstanceInformationEntity instanceInformationEntity in instanceInformationEntities)
                                        {
                                            if (instanceInformationEntity.Filename != null)
                                                fileList.Add(instanceInformationEntity.Filename);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return fileList;
        }
Example #18
0
        /// <summary>
        /// Create C-Move retrieve.
        /// </summary>
        /// <param name="informationModel">The information model.</param>
        /// <param name="moveDestination">The move destination.</param>
        /// <param name="retrieveTags">The retrieve tags.</param>
        /// <returns>teh C-MOVE message.</returns>
        public static DvtkHighLevelInterface.Dicom.Messages.DicomMessage MakeCMoveRetrieve(QueryRetrieveInformationModelEnum informationModel, System.String moveDestination, TagValueCollection retrieveTags)
        {
            DvtkHighLevelInterface.Dicom.Messages.DicomMessage retrieveMessage = new DvtkHighLevelInterface.Dicom.Messages.DicomMessage(DvtkData.Dimse.DimseCommand.CMOVERQ);
            DvtkData.Dimse.DataSet retrieveDataset = null;

            switch(informationModel)
            {
                case QueryRetrieveInformationModelEnum.PatientRootQueryRetrieveInformationModel:
                default:
                    retrieveMessage.Set("0x00000002", VR.UI, "1.2.840.10008.5.1.4.1.2.1.2");
                    retrieveDataset = new DvtkData.Dimse.DataSet("Patient Root Query/Retrieve Information Model - MOVE SOP Class");
                    break;
                case QueryRetrieveInformationModelEnum.StudyRootQueryRetrieveInformationModel:
                    retrieveMessage.Set("0x00000002", VR.UI, "1.2.840.10008.5.1.4.1.2.2.2");
                    retrieveDataset = new DvtkData.Dimse.DataSet("Study Root Query/Retrieve Information Model - MOVE SOP Class");
                    break;
                case QueryRetrieveInformationModelEnum.PatientStudyOnlyQueryRetrieveInformationModel:
                    retrieveMessage.Set("0x00000002", VR.UI, "1.2.840.10008.5.1.4.1.2.3.2");
                    retrieveDataset = new DvtkData.Dimse.DataSet("Patient/Study Only Query/Retrieve Info. Model - MOVE SOP Class");
                    break;
            }

            retrieveMessage.Set("0x00000600", VR.AE, moveDestination);

            // add the query keys
            AddQueryRetrieveKeys(retrieveTags, retrieveDataset);
            retrieveMessage.DataSet.DvtkDataDataSet = retrieveDataset;

            return retrieveMessage;
        }
Example #19
0
 /// <summary>
 /// Apply only a <see cref="CommandSet"/>. This results in NO dataSet.
 /// </summary>
 /// <param name="commandSet">command set</param>
 public void Apply(CommandSet commandSet)
 {
     if (commandSet == null) throw new System.ArgumentNullException("commandSet");
     this.CommandSet = commandSet;
     this.DataSet = null;
 }
Example #20
0
        /// <summary>
        /// Write DICOM object to a (persistent) Media Storage file.
        /// </summary>
        /// <param name="dataSet">dicom object to write</param>
        /// <param name="mediaFileName">file name to write to</param>
        /// <param name="transferSyntax">with transfer syntax to write</param>
        /// <returns></returns>
        public static bool WriteDataSet(
			DataSet dataSet,
			string mediaFileName,
			string transferSyntax)
        {
            if (dataSet == null) throw new System.ArgumentNullException("dataSet");
            if (mediaFileName == null) throw new System.ArgumentNullException("mediaFileName");

            return MDataSet.WriteDataSet(dataSet, mediaFileName, transferSyntax);
        }
Example #21
0
        /// <summary>
        /// Add the additional attributes to this Entity and any children.
        /// </summary>
        /// <param name="additionalDataset"></param>
        public void AddAdditionalAttributes(DataSet additionalDataset)
        {
            // add the additional attribute
            foreach (DvtkData.Dimse.Attribute additionalAttribute in additionalDataset)
            {
                _additionalDataset.Add(additionalAttribute);
            }

            // include all children
            foreach (BaseInformationEntity informationEntity in _children)
            {
                informationEntity.AddAdditionalAttributes(additionalDataset);
            }
        }
Example #22
0
        /// <summary>
        /// Add the default attribute values to the local dataset if the attribute values
        /// are not already present in the local dataset. A zero-length attribute in the local
        /// dataset will be replaced by a value of the same attribute (tag) in the defaultDataset.
        /// All child Entities are also processed.
        /// </summary>
        /// <param name="defaultDataset"></param>
        public void AddDefaultAttributes(DataSet defaultDataset)
        {
            // use tag list to determine which attributes should take default values
            foreach (TagType tagType in _tagTypeList)
            {
                // only add a default value it the attribute is not already in the dataset.
                DvtkData.Dimse.Attribute attribute = _dataset.GetAttribute(tagType.Tag);
                if ((attribute == null) ||
                    (attribute.Length == 0))
                {
                    // check if a default value is available for this tag
                    DvtkData.Dimse.Attribute defaultAttribute = defaultDataset.GetAttribute(tagType.Tag);
                    if (defaultAttribute != null)
                    {
                        // need to remove any zero-length attribute
                        if ((attribute != null) &&
                            (attribute.Length == 0))
                        {
                            _dataset.Remove(attribute);
                        }

                        // add default value to the dataset
                        _dataset.Add(defaultAttribute);
                    }
                }
            }

            // include all children
            foreach (BaseInformationEntity informationEntity in _children)
            {
                informationEntity.AddDefaultAttributes(defaultDataset);
            }
        }
Example #23
0
        /// <summary>
        /// Add the additional attributes to this Entity and any children.
        /// </summary>
        /// <param name="overWriteExistingValue"></param>        
        /// <param name="additionalDataset"></param>
        public void AddAdditionalAttributes(bool overWriteExistingValue, DataSet additionalDataset)
        {
            // add the additional attribute
            foreach (DvtkData.Dimse.Attribute additionalAttribute in additionalDataset)
            {
                if (overWriteExistingValue == true)
                {
                    _additionalDatasetOverWrite.Add(additionalAttribute);
                }
                else
                {
                    _additionalDatasetNoOverWrite.Add(additionalAttribute);
                }
            }

            // include all children
            foreach (BaseInformationEntity informationEntity in _children)
            {
                informationEntity.AddAdditionalAttributes(overWriteExistingValue, additionalDataset);
            }
        }
Example #24
0
        /// <summary>
        /// Use the information entity tagTypeList to add default values from the defaultDataset
        /// into this _dataset.
        /// A default value will be added if:
        /// overWriteExistingValue is true and a default value exists.
        /// or:
        /// overWriteExistingValue is false and the default value exists and this _dataset either does
        /// not contain the default tag or the default tag has a zero-length value.
        /// All child Entities are also processed.
        /// </summary>
        /// <param name="overWriteExistingValue"></param>
        /// <param name="defaultDataset"></param>
        public void AddDefaultAttributes(bool overWriteExistingValue, DataSet defaultDataset)
        {
            // use tag list to determine which attributes should take default values

            foreach (TagType tagType in _tagTypeList)
            {
                // only add a default value it the attribute is not already in the dataset.
                DvtkData.Dimse.Attribute attribute = _dataset.GetAttribute(tagType.Tag);

                // check if a default value is available for this tag
                DvtkData.Dimse.Attribute defaultAttribute = defaultDataset.GetAttribute(tagType.Tag);

                // Only make changes if a default attribute is found
                if (defaultAttribute != null)
                {
                    // overwrite any existing value
                    if (overWriteExistingValue == true)
                    {
                        if (attribute != null && attribute.ValueRepresentation == VR.SQ&&defaultAttribute.ValueRepresentation==VR.SQ)
                        {
                            DvtkData.Dimse.Attribute actualAttrib = attribute;
                            foreach( SequenceItem sourceItem in ((SequenceOfItems)defaultAttribute.DicomValue).Sequence)
                            {
                                for (int i = 0; i < sourceItem.Count; i++)
                                {
                                    DvtkData.Dimse.Attribute sourceAttrib = sourceItem[i];
                                    foreach (SequenceItem destItem in ((SequenceOfItems)attribute.DicomValue).Sequence)
                                    {
                                        DvtkData.Dimse.Attribute desattrib = destItem.GetAttribute(sourceAttrib.Tag);
                                        if (desattrib != null)
                                        {
                                            destItem.Remove(desattrib);
                                        }
                                        destItem.Add(sourceAttrib);
                                    }
                                }
                            }
                            _dataset.Remove(actualAttrib);
                            _dataset.Add(attribute);
                        }
                        else
                        {
                            if (attribute != null)
                            {
                                // remove the old attribute value
                                _dataset.Remove(attribute);
                            }

                            // add default value to the dataset
                            _dataset.Add(defaultAttribute);
                        }
                    }
                    else
                    {
                        // need to remove any zero-length attribute
                        if ((attribute != null) &&
                            (attribute.Length == 0))
                        {
                            _dataset.Remove(attribute);

                            // add default value to the dataset
                            _dataset.Add(defaultAttribute);
                        }
                        else if (attribute == null)
                        {
                            // add default value to the dataset
                            _dataset.Add(defaultAttribute);
                        }
                    }
                }
            }

            // include all children
            foreach (BaseInformationEntity informationEntity in _children)
            {
                informationEntity.AddDefaultAttributes(overWriteExistingValue, defaultDataset);
            }
        }
        /// <summary>
        /// Add the given Dataset to the Information Model. The data is normalised into the Information Model.
        /// </summary>
        /// <param name="dataset">Dataset to add to Informatio Model.</param>
        /// <param name="storeDataset">Boolean indicating whether or not the dataset should also be stored to file for possible retrieval.</param>
        public void AddToInformationModel(DataSet dataset, bool storeDataset)
        {
            // PATIENT level
            PatientInformationEntity patientInformationEntity = null;

            // check if the patient IE is already in the patientRootList
            foreach (PatientInformationEntity lPatientInformationEntity in Root)
            {
                if (lPatientInformationEntity.IsFoundIn(dataset))
                {
                    patientInformationEntity = lPatientInformationEntity;
                    break;
                }
            }

            // patient IE is not already in the patientRootList
            if (patientInformationEntity == null)
            {
                // create a new patient IE from the dataset and add to the patientRootList
                patientInformationEntity = new PatientInformationEntity();
                patientInformationEntity.CopyFrom(dataset);
                //Root.Add(patientInformationEntity);

                // Modified by RB 20090128 - when handling an order scheduled event from an actor
                // we want to insert the order as the first entry in the information model so that
                // it is returned as the first entry in the worklist query
                Root.Insert(0, patientInformationEntity);
            }

            // VISIT level
            VisitInformationEntity visitInformationEntity = null;

            // check if the visit IE is already in the patient IE children
            foreach (VisitInformationEntity lVisitInformationEntity in patientInformationEntity.Children)
            {
                if (lVisitInformationEntity.IsFoundIn(dataset))
                {
                    visitInformationEntity = lVisitInformationEntity;
                    break;
                }
            }

            // visit IE is not already in the patient IE children
            if (visitInformationEntity == null)
            {
                // create a new visit IE from the dataset and add to the patient IE children
                visitInformationEntity = new VisitInformationEntity();
                visitInformationEntity.CopyFrom(dataset);
                patientInformationEntity.AddChild(visitInformationEntity);
            }

            // IMAGING SERVICE REQUEST level
            ImagingServiceRequestInformationEntity imagingServiceRequestInformationEntity = null;

            // check if the imaging service request IE is already in the visit IE children
            foreach (ImagingServiceRequestInformationEntity lImagingServiceRequestInformationEntity in visitInformationEntity.Children)
            {
                if (lImagingServiceRequestInformationEntity.IsFoundIn(dataset))
                {
                    imagingServiceRequestInformationEntity = lImagingServiceRequestInformationEntity;
                    break;
                }
            }

            // imaging service request IE is not already in the visit IE children
            if (imagingServiceRequestInformationEntity == null)
            {
                // create a new imaging service request IE from the dataset and add to the visit IE children
                imagingServiceRequestInformationEntity = new ImagingServiceRequestInformationEntity();
                imagingServiceRequestInformationEntity.CopyFrom(dataset);
                visitInformationEntity.AddChild(imagingServiceRequestInformationEntity);
            }

            // REQUESTED PROCEDURE level
            RequestedProcedureInformationEntity requestedProcedureInformationEntity = null;

            // check if the requested procedure IE is already in the imaging service request IE children
            foreach (RequestedProcedureInformationEntity lRequestedProcedureInformationEntity in imagingServiceRequestInformationEntity.Children)
            {
                if (lRequestedProcedureInformationEntity.IsFoundIn(dataset))
                {
                    requestedProcedureInformationEntity = lRequestedProcedureInformationEntity;
                    break;
                }
            }

            // requested procedure IE is not already in the imaging service request IE children
            if (requestedProcedureInformationEntity == null)
            {
                // create a new requested procedure IE from the dataset and add to the imaging service request IE children
                requestedProcedureInformationEntity = new RequestedProcedureInformationEntity();
                requestedProcedureInformationEntity.CopyFrom(dataset);
                imagingServiceRequestInformationEntity.AddChild(requestedProcedureInformationEntity);
            }

            // SCHEDULED PROCEDURE STEP level
            ScheduledProcedureStepInformationEntity scheduledProcedureStepInformationEntity = null;

            // check if the scheduled procedure step IE is already in the requested procedure IE children
            foreach (ScheduledProcedureStepInformationEntity lScheduledProcedureStepInformationEntity in requestedProcedureInformationEntity.Children)
            {
                if (lScheduledProcedureStepInformationEntity.IsFoundIn(dataset))
                {
                    scheduledProcedureStepInformationEntity = lScheduledProcedureStepInformationEntity;
                    break;
                }
            }

            // scheduled procedure step IE is not already in the requested procedure IE children
            if (scheduledProcedureStepInformationEntity == null)
            {
                // create a new scheduled procedure step IE from the dataset and add to the requested procedure IE children
                scheduledProcedureStepInformationEntity = new ScheduledProcedureStepInformationEntity();
                scheduledProcedureStepInformationEntity.CopyFrom(dataset);
                requestedProcedureInformationEntity.AddChild(scheduledProcedureStepInformationEntity);
            }
        }
        /// <summary>
        /// Add the given Dataset to the Information Model. The data is normalised into the Information Model.
        /// </summary>
        /// <param name="dataSet">Dataset to add to the informartion model</param>
        /// <param name="transferSyntax">The transfer syntax specified in the dcm file</param>
        /// <param name="fMI">The File Meta Information of the dcm file.</param>
        /// <param name="storeFile">Boolean indicating whether the or not the data set should be stored.</param>
        //public override void AddToInformationModel(DvtkData.Media.DicomFile dicomFile, bool storeFile)
        //{
        //    // PATIENT level
        //    PatientInformationEntity patientInformationEntity = null;
        //    // check if the patient IE is already in the patientRootList
        //    foreach (PatientInformationEntity lPatientInformationEntity in Root)
        //    {
        //        if (lPatientInformationEntity.IsFoundIn(dicomFile.DataSet))
        //        {
        //            patientInformationEntity = lPatientInformationEntity;
        //            break;
        //        }
        //    }
        //    // patient IE is not already in the patientRootList
        //    if (patientInformationEntity == null)
        //    {
        //        // create a new patient IE from the dataset and add to the patientRootList
        //        patientInformationEntity = new PatientInformationEntity();
        //        patientInformationEntity.CopyFrom(dicomFile.DataSet);
        //        //Root.Add(patientInformationEntity);
        //        // Modified by RB 20090128 - when handling an order scheduled event from an actor
        //        // we want to insert the order as the first entry in the information model so that
        //        // it is returned as the first entry in the worklist query
        //        Root.Insert(0, patientInformationEntity);
        //    }
        //    // VISIT level
        //    VisitInformationEntity visitInformationEntity = null;
        //    // check if the visit IE is already in the patient IE children
        //    foreach (VisitInformationEntity lVisitInformationEntity in patientInformationEntity.Children)
        //    {
        //        if (lVisitInformationEntity.IsFoundIn(dicomFile.DataSet))
        //        {
        //            visitInformationEntity = lVisitInformationEntity;
        //            break;
        //        }
        //    }
        //    // visit IE is not already in the patient IE children
        //    if (visitInformationEntity == null)
        //    {
        //        // create a new visit IE from the dataset and add to the patient IE children
        //        visitInformationEntity = new VisitInformationEntity();
        //        visitInformationEntity.CopyFrom(dicomFile.DataSet);
        //        patientInformationEntity.AddChild(visitInformationEntity);
        //    }
        //    // IMAGING SERVICE REQUEST level
        //    ImagingServiceRequestInformationEntity imagingServiceRequestInformationEntity = null;
        //    // check if the imaging service request IE is already in the visit IE children
        //    foreach (ImagingServiceRequestInformationEntity lImagingServiceRequestInformationEntity in visitInformationEntity.Children)
        //    {
        //        if (lImagingServiceRequestInformationEntity.IsFoundIn(dicomFile.DataSet))
        //        {
        //            imagingServiceRequestInformationEntity = lImagingServiceRequestInformationEntity;
        //            break;
        //        }
        //    }
        //    // imaging service request IE is not already in the visit IE children
        //    if (imagingServiceRequestInformationEntity == null)
        //    {
        //        // create a new imaging service request IE from the dataset and add to the visit IE children
        //        imagingServiceRequestInformationEntity = new ImagingServiceRequestInformationEntity();
        //        imagingServiceRequestInformationEntity.CopyFrom(dicomFile.DataSet);
        //        visitInformationEntity.AddChild(imagingServiceRequestInformationEntity);
        //    }
        //    // REQUESTED PROCEDURE level
        //    RequestedProcedureInformationEntity requestedProcedureInformationEntity = null;
        //    // check if the requested procedure IE is already in the imaging service request IE children
        //    foreach (RequestedProcedureInformationEntity lRequestedProcedureInformationEntity in imagingServiceRequestInformationEntity.Children)
        //    {
        //        if (lRequestedProcedureInformationEntity.IsFoundIn(dicomFile.DataSet))
        //        {
        //            requestedProcedureInformationEntity = lRequestedProcedureInformationEntity;
        //            break;
        //        }
        //    }
        //    // requested procedure IE is not already in the imaging service request IE children
        //    if (requestedProcedureInformationEntity == null)
        //    {
        //        // create a new requested procedure IE from the dataset and add to the imaging service request IE children
        //        requestedProcedureInformationEntity = new RequestedProcedureInformationEntity();
        //        requestedProcedureInformationEntity.CopyFrom(dicomFile.DataSet);
        //        imagingServiceRequestInformationEntity.AddChild(requestedProcedureInformationEntity);
        //    }
        //    // SCHEDULED PROCEDURE STEP level
        //    ScheduledProcedureStepInformationEntity scheduledProcedureStepInformationEntity = null;
        //    // check if the scheduled procedure step IE is already in the requested procedure IE children
        //    foreach (ScheduledProcedureStepInformationEntity lScheduledProcedureStepInformationEntity in requestedProcedureInformationEntity.Children)
        //    {
        //        if (lScheduledProcedureStepInformationEntity.IsFoundIn(dicomFile.DataSet))
        //        {
        //            scheduledProcedureStepInformationEntity = lScheduledProcedureStepInformationEntity;
        //            break;
        //        }
        //    }
        //    // scheduled procedure step IE is not already in the requested procedure IE children
        //    if (scheduledProcedureStepInformationEntity == null)
        //    {
        //        // create a new scheduled procedure step IE from the dataset and add to the requested procedure IE children
        //        scheduledProcedureStepInformationEntity = new ScheduledProcedureStepInformationEntity();
        //        scheduledProcedureStepInformationEntity.CopyFrom(dicomFile.DataSet);
        //        requestedProcedureInformationEntity.AddChild(scheduledProcedureStepInformationEntity);
        //    }
        //}
        /// <summary>
        /// Query the Information Model using the given Query Dataset.
        /// </summary>
        /// <param name="queryDataset">Query Dataset.</param>
        /// <returns>A collection of zero or more query reponse datasets.</returns>
        public override DataSetCollection QueryInformationModel(DataSet queryDataset)
        {
            DataSetCollection queryResponses = new DataSetCollection();

            BaseInformationEntityList matchingPatients = new BaseInformationEntityList();
            BaseInformationEntityList matchingVisits = new BaseInformationEntityList();
            BaseInformationEntityList matchingImagingServiceRequests = new BaseInformationEntityList();
            BaseInformationEntityList matchingRequestedProcedures = new BaseInformationEntityList();
            BaseInformationEntityList matchingScheduledProcedureSteps = new BaseInformationEntityList();

            SequenceItem queryItem = null;
            TagTypeList queryTagTypeList = new TagTypeList();
            TagTypeList returnTagTypeList = new TagTypeList();
            foreach (DvtkData.Dimse.Attribute attribute in queryDataset)
            {
                // special check for the Scheduled Procedure Step Sequence
                if (attribute.ValueRepresentation == VR.SQ)
                {
                    foreach (SequenceItem s in ((SequenceOfItems)attribute.DicomValue).Sequence)
                    {
                        if (IsSequenceHavingValue(s))
                        {
                            queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                        }
                    }
                }
                // Query attribute must be present with an attribute value
                // - Do not include the Specific Character Set attribute and group length as a query attribute
                else if ((attribute.Length != 0) &&
                        (attribute.Tag != Tag.SPECIFIC_CHARACTER_SET) &&
                        (attribute.Tag.ElementNumber != 0x0000) &&
                        (attribute.ValueRepresentation != VR.SQ))
                {
                    queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                }

                // Add all attributes as return attributes
                returnTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagOptional));

            }

            // iterate over the Modality Worklist Information Model and save all the matching
            // Scheduled Procedure Steps
            // iterate of all Information Entities
            foreach (PatientInformationEntity patientInformationEntity in Root)
            {
                if (patientInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))

                {
                    Console.WriteLine("-----PatientInformationEntity------");
                    Console.WriteLine(patientInformationEntity.DataSet.Dump("-"));
                    matchingPatients.Add(patientInformationEntity);

                    foreach (VisitInformationEntity visitInformationEntity in patientInformationEntity.Children)
                    {
                        Console.WriteLine("-----VisitInformationEntity------");
                        Console.WriteLine(visitInformationEntity.DataSet.Dump("--"));
                        if (visitInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                        {
                            matchingVisits.Add(visitInformationEntity);

                            foreach (ImagingServiceRequestInformationEntity imagingServiceRequestInformationEntity in visitInformationEntity.Children)
                            {
                                Console.WriteLine("-----ImagingServiceRequestInformationEntity------");
                                Console.WriteLine(imagingServiceRequestInformationEntity.DataSet.Dump("---"));
                                if (imagingServiceRequestInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                                {
                                    matchingImagingServiceRequests.Add(imagingServiceRequestInformationEntity);

                                    foreach (RequestedProcedureInformationEntity requestedProcedureInformationEntity in imagingServiceRequestInformationEntity.Children)
                                    {
                                        Console.WriteLine("-----RequestedProcedureInformationEntity------");
                                        Console.WriteLine(requestedProcedureInformationEntity.DataSet.Dump("----"));
                                        if (requestedProcedureInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                                        {
                                            matchingRequestedProcedures.Add(requestedProcedureInformationEntity);

                                           // if (queryItem != null)
                                            {

                                                foreach (ScheduledProcedureStepInformationEntity scheduledProcedureStepInformationEntity in requestedProcedureInformationEntity.Children)
                                                {
                                                    Console.WriteLine("-----ScheduledProcedureStepInformationEntity------");
                                                    Console.WriteLine(scheduledProcedureStepInformationEntity.DataSet.Dump("------"));
                                                    if (scheduledProcedureStepInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                                                    {
                                                        // add the scheduled procedure step to the matched list
                                                        matchingScheduledProcedureSteps.Add(scheduledProcedureStepInformationEntity);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (matchingScheduledProcedureSteps.Count > 0)
            {
                // we now have a list of all the matching scheduled procedure steps
                foreach (ScheduledProcedureStepInformationEntity matchingScheduledProcedureStepInformationEntity in matchingScheduledProcedureSteps)
                {
                    //SequenceItem responseItem = new SequenceItem();
                    //matchingScheduledProcedureStepInformationEntity.CopyTo(returnTagTypeList, responseItem);

                    //// remove the specific character set from the responseItem - it is only present in the scheduled procedure step as a helper...
                    //DvtkData.Dimse.Attribute specificChararcterSet = responseItem.GetAttribute(Tag.SPECIFIC_CHARACTER_SET);
                    //if (specificChararcterSet != null)
                    //{
                    //    responseItem.Remove(specificChararcterSet);
                    //}

                    //DvtkData.Dimse.Attribute attribute = new DvtkData.Dimse.Attribute(0x00400100, VR.SQ, responseItem);

                    DataSet queryResponse = new DataSet();
                   // queryResponse.Add(attribute);

                    // if the specific character set attribute has been stored in the sps IE - return it in the query response
                    DvtkData.Dimse.Attribute specificCharacterSetAttribute = matchingScheduledProcedureStepInformationEntity.GetSpecificCharacterSet();
                    if (specificCharacterSetAttribute != null)
                    {
                        queryResponse.Add(specificCharacterSetAttribute);
                    }

                    RequestedProcedureInformationEntity matchingRequestedProcedureInformationEntity
                        = (RequestedProcedureInformationEntity)matchingScheduledProcedureStepInformationEntity.Parent;
                    matchingRequestedProcedureInformationEntity.CopyTo(returnTagTypeList, queryResponse);

                    ImagingServiceRequestInformationEntity matchingImagingServiceRequestInformationEntity
                        = (ImagingServiceRequestInformationEntity)matchingRequestedProcedureInformationEntity.Parent;
                    matchingImagingServiceRequestInformationEntity.CopyTo(returnTagTypeList, queryResponse);

                    VisitInformationEntity matchingVisitInformationEntity
                        = (VisitInformationEntity)matchingImagingServiceRequestInformationEntity.Parent;
                    matchingVisitInformationEntity.CopyTo(returnTagTypeList, queryResponse);

                    PatientInformationEntity matchingPatientInformationEntity
                        = (PatientInformationEntity)matchingVisitInformationEntity.Parent;
                    matchingPatientInformationEntity.CopyTo(returnTagTypeList, queryResponse);
                    matchingScheduledProcedureStepInformationEntity.CopyTo(returnTagTypeList, queryResponse);
                    queryResponses.Add(queryResponse);
                }
            }
            //else if (matchingRequestedProcedures.Count > 0)
            //{
            //    // we now have a list of all the matching requested procedures
            //    foreach (RequestedProcedureInformationEntity matchingRequestedProcedureInformationEntity in matchingRequestedProcedures)
            //    {
            //        DataSet queryResponse = new DataSet();

            //        matchingRequestedProcedureInformationEntity.CopyTo(returnTagTypeList, queryResponse);

            //        ImagingServiceRequestInformationEntity matchingImagingServiceRequestInformationEntity
            //            = (ImagingServiceRequestInformationEntity)matchingRequestedProcedureInformationEntity.Parent;
            //        matchingImagingServiceRequestInformationEntity.CopyTo(returnTagTypeList, queryResponse);

            //        VisitInformationEntity matchingVisitInformationEntity
            //            = (VisitInformationEntity)matchingImagingServiceRequestInformationEntity.Parent;
            //        matchingVisitInformationEntity.CopyTo(returnTagTypeList, queryResponse);

            //        PatientInformationEntity matchingPatientInformationEntity
            //            = (PatientInformationEntity)matchingVisitInformationEntity.Parent;
            //        matchingPatientInformationEntity.CopyTo(returnTagTypeList, queryResponse);

            //        queryResponses.Add(queryResponse);
            //    }
            //}
            //else if (matchingImagingServiceRequests.Count > 0)
            //{
            //    // we now have a list of all the matching image service requests
            //    foreach (ImagingServiceRequestInformationEntity matchingImagingServiceRequestInformationEntity in matchingImagingServiceRequests)
            //    {
            //        DataSet queryResponse = new DataSet();

            //        matchingImagingServiceRequestInformationEntity.CopyTo(returnTagTypeList, queryResponse);

            //        VisitInformationEntity matchingVisitInformationEntity
            //            = (VisitInformationEntity)matchingImagingServiceRequestInformationEntity.Parent;
            //        matchingVisitInformationEntity.CopyTo(returnTagTypeList, queryResponse);

            //        PatientInformationEntity matchingPatientInformationEntity
            //            = (PatientInformationEntity)matchingVisitInformationEntity.Parent;
            //        matchingPatientInformationEntity.CopyTo(returnTagTypeList, queryResponse);

            //        queryResponses.Add(queryResponse);
            //    }
            //}
            //else if (matchingVisits.Count > 0)
            //{
            //    // we now have a list of all the matching visits
            //    foreach (VisitInformationEntity matchingVisitInformationEntity in matchingVisits)
            //    {
            //        DataSet queryResponse = new DataSet();

            //        matchingVisitInformationEntity.CopyTo(returnTagTypeList, queryResponse);

            //        PatientInformationEntity matchingPatientInformationEntity
            //            = (PatientInformationEntity)matchingVisitInformationEntity.Parent;
            //        matchingPatientInformationEntity.CopyTo(returnTagTypeList, queryResponse);

            //        queryResponses.Add(queryResponse);
            //    }
            //}
            //else if (matchingPatients.Count > 0)
            //{
            //    // we now have a list of all the matching patients
            //    foreach (PatientInformationEntity matchingPatientInformationEntity in matchingPatients)
            //    {
            //        DataSet queryResponse = new DataSet();

            //        matchingPatientInformationEntity.CopyTo(returnTagTypeList, queryResponse);

            //        queryResponses.Add(queryResponse);
            //    }
            //}

            return queryResponses;
        }
        /// <summary>
        /// Patient merge request - update modality worklist information model.
        /// </summary>
        /// <param name="dataset">Dataset containing patient merge attributes.</param>
        public override void PatientMerge(DvtkData.Dimse.DataSet dataset)
        {
            // Get the merge patient - need to use this to search for the corresponding patient IE
            DvtkData.Dimse.Attribute mergePatientId = dataset.GetAttribute(Tag.OTHER_PATIENT_IDS);
            if (mergePatientId.Length != 0)
            {
                LongString longString = (LongString)mergePatientId.DicomValue;
                System.String attributeValue = longString.Values[0];

                DataSet queryDataset = new DataSet("Transient");
                queryDataset.AddAttribute(Tag.PATIENT_ID.GroupNumber, Tag.PATIENT_ID.ElementNumber, VR.LO, attributeValue);

                // check each patient IE in the patientRootList
                foreach (PatientInformationEntity lPatientInformationEntity in Root)
                {
                    // if IE matches the unique (merge) patient id field in the query dataset
                    if (lPatientInformationEntity.IsUniqueTagFoundIn(queryDataset))
                    {
                        // update the patient demographics - including the patient id
                        lPatientInformationEntity.CopyFrom(dataset);
                        break;
                    }
                }
            }
        }
Example #28
0
 /// <summary>
 /// Apply <see cref="CommandSet"/> and <see cref="DataSet"/> to this message.
 /// </summary>
 /// <param name="commandSet"></param>
 /// <param name="dataSet"></param>
 public void Apply(CommandSet commandSet, DataSet dataSet)
 {
     if (commandSet == null) throw new System.ArgumentNullException("commandSet");
     if (dataSet == null) throw new System.ArgumentNullException("dataSet");
     this.CommandSet = commandSet;
     this.DataSet = dataSet;
     this.EncodedPresentationContextID = unchecked((byte)-1);
 }
Example #29
0
 /// <summary>
 /// Class constructor with Dicom dataset as parameter
 /// </summary>
 /// <param name="_dataSet">DICOM dataset which contains the Patient attributes</param>
 public Patient(DvtkData.Dimse.DataSet _dataSet)
     : base()
 {
     LoadData(_dataSet);
 }
        /// <summary>
        /// Send all the images found in the given storage directory.
        /// </summary>
        /// <param name="storageDirectory">Given storage directory - containing storage DCM files.</param>
        /// <param name="modalityWorklistItem">Worklist Item used to provide overruling values for
        /// the Image headers.</param>
        /// <param name="withSingleAssociation">Boolean indicating whether the images should be sent in a single
        /// association or not.</param>
        /// <returns>Boolean indicating success or failure.</returns>
        public bool SendModalityImagesStored(System.String storageDirectory, DicomQueryItem modalityWorklistItem, bool withSingleAssociation)
        {
            if ((storageDirectory.Length == 0) ||
                (modalityWorklistItem == null))
            {
                return(false);
            }

            // Use a hash table to store the instance uid mappings
            // - the instance uids for the study, series and sop are going to be updated for all the datasets
            // read from the storageDirectory
            Hashtable instanceMapper = new Hashtable();

            // Get the directory info for the storage directory - and make sure that it exists
            DirectoryInfo directoryInfo = new DirectoryInfo(storageDirectory);

            if (directoryInfo.Exists == false)
            {
                System.String message = System.String.Format("storageDirectory:\"{0}\" - does not exist.", storageDirectory);
                throw new System.Exception(message);
            }

            // Get a trigger
            DicomTrigger trigger = new DicomTrigger(TransactionNameEnum.RAD_8);

            trigger.HandleInSingleAssociation = withSingleAssociation;

            // Interate over all the DCM files found in the storage directory
            // - update the instances found with the worklist item contents and
            // set up the triggers for the Image Archive
            foreach (FileInfo fileInfo in directoryInfo.GetFiles())
            {
                if ((fileInfo.Extension.ToLower().Equals(".dcm")) ||
                    (fileInfo.Extension == System.String.Empty))
                {
                    // Read the file meta information - it must be present for this actor
                    DvtkData.Media.FileMetaInformation fileMetaInformation = Dvtk.DvtkDataHelper.ReadFMIFromFile(fileInfo.FullName);
                    if (fileMetaInformation == null)
                    {
                        continue;
                    }

                    // Try to get the transfer syntax uid
                    // - start with Implicit VR Little Endian
                    System.String            transferSyntaxUid = "1.2.840.10008.1.2";
                    DvtkData.Dimse.Attribute attribute         = fileMetaInformation.GetAttribute(DvtkData.Dimse.Tag.TRANSFER_SYNTAX_UID);
                    if (attribute != null)
                    {
                        UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)attribute.DicomValue;
                        if (uniqueIdentifier.Values.Count > 0)
                        {
                            transferSyntaxUid = uniqueIdentifier.Values[0];
                        }
                    }

                    // Read the dataset from the DCM file
                    DvtkData.Dimse.DataSet dataset = Dvtk.DvtkDataHelper.ReadDataSetFromFile(fileInfo.FullName);
                    if (dataset == null)
                    {
                        continue;
                    }

                    // Remove any Group Lengths from the dataset
                    dataset.RemoveGroupLengthAttributes();

                    // Try to get the series instance uid
                    System.String            oldSeriesInstanceUid       = System.String.Empty;
                    DvtkData.Dimse.Attribute seriesInstanceUidAttribute = dataset.GetAttribute(Tag.SERIES_INSTANCE_UID);
                    if (seriesInstanceUidAttribute != null)
                    {
                        UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)seriesInstanceUidAttribute.DicomValue;
                        if (uniqueIdentifier.Values.Count > 0)
                        {
                            oldSeriesInstanceUid = uniqueIdentifier.Values[0];
                        }

                        // Remove the old series instance from the dataset
                        dataset.Remove(seriesInstanceUidAttribute);
                    }

                    // See if a mapping exists
                    System.String newSeriesInstanceUid = (System.String)instanceMapper[oldSeriesInstanceUid];
                    if (newSeriesInstanceUid == null)
                    {
                        // Add a mapping
                        DefaultValueManager.UpdateInstantiatedDefaultTagValues(AffectedEntityEnum.SeriesEntity);
                        newSeriesInstanceUid = DefaultValueManager.GetInstantiatedValue(Tag.SERIES_INSTANCE_UID);
                        instanceMapper.Add(oldSeriesInstanceUid, newSeriesInstanceUid);
                    }

                    // Add the new series instance uid to the dataset
                    dataset.AddAttribute(Tag.SERIES_INSTANCE_UID.GroupNumber, Tag.SERIES_INSTANCE_UID.ElementNumber, VR.UI, newSeriesInstanceUid);

                    // Try to get the sop instance uid
                    System.String            oldSopInstanceUid       = System.String.Empty;
                    DvtkData.Dimse.Attribute sopInstanceUidAttribute = dataset.GetAttribute(Tag.SOP_INSTANCE_UID);
                    if (sopInstanceUidAttribute != null)
                    {
                        UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)sopInstanceUidAttribute.DicomValue;
                        if (uniqueIdentifier.Values.Count > 0)
                        {
                            oldSopInstanceUid = uniqueIdentifier.Values[0];
                        }

                        // Remove the old sop instance from the dataset
                        dataset.Remove(sopInstanceUidAttribute);
                    }

                    // See if a mapping exists
                    System.String newSopInstanceUid = (System.String)instanceMapper[oldSopInstanceUid];
                    if (newSopInstanceUid == null)
                    {
                        // Add a mapping
                        DefaultValueManager.UpdateInstantiatedDefaultTagValues(AffectedEntityEnum.InstanceEntity);
                        newSopInstanceUid = DefaultValueManager.GetInstantiatedValue(Tag.SOP_INSTANCE_UID);
                        instanceMapper.Add(oldSopInstanceUid, newSopInstanceUid);
                    }

                    // Add the new sop instance uid to the dataset
                    dataset.AddAttribute(Tag.SOP_INSTANCE_UID.GroupNumber, Tag.SOP_INSTANCE_UID.ElementNumber, VR.UI, newSopInstanceUid);

                    // Use modality Worklist Item to help construct the Storage Message
                    // Get the attribute values to copy
                    DvtkHighLevelInterface.Comparator.Comparator worklistItemComparator = new DvtkHighLevelInterface.Comparator.Comparator("WorklistItemComparator");
                    DicomComparator dicomWorklistItemComparator = worklistItemComparator.InitializeDicomComparator(modalityWorklistItem.DicomMessage);

                    // Also try to use the MPPS InProgress Message to help construct the Storage Message
                    DvtkHighLevelInterface.Comparator.Comparator mppsInProgressComparator = new DvtkHighLevelInterface.Comparator.Comparator("MppsInProgressComparator");
                    DicomComparator dicomMppsInProgressComparator = null;
                    if (_nCreateSetMppsInProgress != null)
                    {
                        dicomMppsInProgressComparator = mppsInProgressComparator.InitializeDicomComparator(_nCreateSetMppsInProgress);
                    }

                    // Create the Storage message
                    DvtkHighLevelInterface.Comparator.Comparator       storageComparator = new DvtkHighLevelInterface.Comparator.Comparator("StorageComparator");
                    DvtkHighLevelInterface.Dicom.Messages.DicomMessage cStoreInstance    = new DvtkHighLevelInterface.Dicom.Messages.DicomMessage(DvtkData.Dimse.DimseCommand.CSTORERQ);
                    GenerateTriggers.MakeCStoreInstance(DefaultValueManager, cStoreInstance, dataset);
                    storageComparator.PopulateDicomMessage(cStoreInstance, dicomWorklistItemComparator);
                    if (dicomMppsInProgressComparator != null)
                    {
                        storageComparator.PopulateDicomMessage(cStoreInstance, dicomMppsInProgressComparator);
                    }

                    // Try to get the sop class uid
                    System.String            sopClassUid          = System.String.Empty;
                    DvtkData.Dimse.Attribute sopClassUidAttribute = dataset.GetAttribute(Tag.SOP_CLASS_UID);
                    if (sopClassUidAttribute != null)
                    {
                        UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)sopClassUidAttribute.DicomValue;
                        if (uniqueIdentifier.Values.Count > 0)
                        {
                            sopClassUid = uniqueIdentifier.Values[0];
                        }
                    }

                    // Add trigger item to the trigger
                    trigger.AddItem(cStoreInstance,
                                    sopClassUid,
                                    transferSyntaxUid);
                }
            }

            // RAD-8 - trigger the ImageArchive
            return(TriggerActorInstances(ActorTypeEnum.ImageArchive, trigger, true));
        }
Example #31
0
 /// <summary>
 /// Searches for the specified <see cref="DataSet"/> and 
 /// returns the zero-based index of the first occurrence within the entire <see cref="DataSetCollection"/>.
 /// </summary>
 /// <param name="value">The <see cref="DataSet"/> to locate in the <see cref="DataSetCollection"/>.</param>
 /// <returns>
 /// The zero-based index of the first occurrence of value within the entire <see cref="DataSetCollection"/>, 
 /// if found; otherwise, -1.
 /// </returns>
 public int IndexOf(DataSet value)
 {
     return (List.IndexOf(value));
 }
Example #32
0
        //
        // - Methods -
        //
        /// <summary>
        /// Get an item from this sequence.
        /// </summary>
        /// <param name="index">1-based index.</param>
        /// <returns>The item.</returns>
        public DataSet GetItem(int index)
        {
            DataSet dataSet = new DataSet(DvtkDataSequence[index - 1]);

            return dataSet;
        }
        /// <summary>
        /// Check if the given instance is present in the Information Model. The instance will be at the leaf nodes of the Information Model.
        /// </summary>
        /// <param name="sopClassUid">SOP Class UID to search for.</param>
        /// <param name="sopInstanceUid">SOP Instance UID to search for.</param>
        /// <returns>Boolean - true if instance found in the Information Model, otherwise false.</returns>
        public bool IsInstanceInInformationModel(System.String sopClassUid, System.String sopInstanceUid)
        {
            bool isInstanceInInformationModel = false;

            // set up the commit tag list for comparing with the leaf
            TagTypeList commitTagTypeList = new TagTypeList();
            commitTagTypeList.Add(new TagType(Tag.SOP_INSTANCE_UID, TagTypeEnum.TagRequired));
            commitTagTypeList.Add(new TagType(Tag.SOP_CLASS_UID, TagTypeEnum.TagRequired));

            // set up the commit dataset
            DvtkData.Dimse.DataSet commitDataset = new DvtkData.Dimse.DataSet();
            DvtkData.Dimse.Attribute attribute = new DvtkData.Dimse.Attribute(0x00080016, DvtkData.Dimse.VR.UI, sopClassUid);
            commitDataset.Add(attribute);
            attribute = new DvtkData.Dimse.Attribute(0x00080018, DvtkData.Dimse.VR.UI, sopInstanceUid);
            commitDataset.Add(attribute);

            // iterate over the whole information model - we are interested in the leaf nodes
            foreach (PatientInformationEntity patientInformationEntity in Root)
            {
                foreach (StudyInformationEntity studyInformationEntity in patientInformationEntity.Children)
                {
                    foreach (SeriesInformationEntity seriesInformationEntity in studyInformationEntity.Children)
                    {
                        foreach (InstanceInformationEntity instanceInformationEntity in seriesInformationEntity.Children)
                        {
                            if (instanceInformationEntity.IsFoundIn(commitTagTypeList, commitDataset))
                            {
                                // an instance has been found with the matching commit uids
                                isInstanceInInformationModel = true;
                                break;
                            }
                        }
                    }
                }
            }

            return isInstanceInInformationModel;
        }
Example #34
0
        private bool CopyToDicomMessage(DvtkData.Dimse.DicomMessage dicomMessage, DicomComparator sourceComparator)
        {
            bool messagePopulated = true;

            // Check if both templates have been initialized correctly
            if ((this.Template == null) ||
                (sourceComparator.Template == null))
            {
                return(false);
            }

            // Iterate over this comparator
            foreach (DicomComparisonTag thisComparisonTag in this.Template.ComparisonTags)
            {
                // try to get the equivalent tag in the sourceComparator
                DicomComparisonTag sourceComparisonTag = sourceComparator.Template.ComparisonTags.Find(thisComparisonTag.Tag);
                if (sourceComparisonTag != null)
                {
                    System.String          stringValue = sourceComparisonTag.DataFormat.ToDicomFormat();
                    DvtkData.Dimse.DataSet dataset     = dicomMessage.DataSet;
                    if (dataset != null)
                    {
                        // we need to see if the parent sequence has been set up in the dataset
                        if (thisComparisonTag.ParentSequenceTag != Tag.UNDEFINED)
                        {
                            // set up the parent sequence and add it to the dataset
                            SequenceOfItems          sequenceOfItems   = null;
                            DvtkData.Dimse.Attribute sequenceAttribute = dataset.GetAttribute(thisComparisonTag.ParentSequenceTag);
                            if (sequenceAttribute == null)
                            {
                                // add in an empty item
                                DvtkData.Dimse.SequenceItem item = new SequenceItem();
                                dataset.AddAttribute(thisComparisonTag.ParentSequenceTag.GroupNumber,
                                                     thisComparisonTag.ParentSequenceTag.ElementNumber,
                                                     VR.SQ,
                                                     item);
                                sequenceAttribute = dataset.GetAttribute(thisComparisonTag.ParentSequenceTag);
                            }

                            // get the sequence item and add in the required attribute
                            sequenceOfItems = (SequenceOfItems)sequenceAttribute.DicomValue;
                            if (sequenceOfItems.Sequence.Count == 1)
                            {
                                DvtkData.Dimse.SequenceItem item = sequenceOfItems.Sequence[0];
                                if (item != null)
                                {
                                    // add the attribute to the item
                                    if (sourceComparisonTag.Vr == VR.SQ)
                                    {
                                        // add in an empty item
                                        // TODO - fix this properly
                                        DvtkData.Dimse.SequenceItem item1 = new SequenceItem();
                                        item.AddAttribute(sourceComparisonTag.Tag.GroupNumber,
                                                          sourceComparisonTag.Tag.ElementNumber,
                                                          VR.SQ,
                                                          item1);
                                    }
                                    else
                                    {
                                        // if the attribute already exists - then we need to remove it
                                        // - it was probably set to the default value
                                        DvtkData.Dimse.Attribute attribute = item.GetAttribute(sourceComparisonTag.Tag);
                                        if (attribute != null)
                                        {
                                            item.Remove(attribute);
                                        }

                                        // add the attribute to the item
                                        item.AddAttribute(sourceComparisonTag.Tag.GroupNumber,
                                                          sourceComparisonTag.Tag.ElementNumber,
                                                          sourceComparisonTag.Vr,
                                                          stringValue);
                                    }
                                }
                            }
                        }
                        else
                        {
                            // if the attribute already exists - then we need to remove it
                            // - it was probably set to the default value
                            DvtkData.Dimse.Attribute attribute = dataset.GetAttribute(sourceComparisonTag.Tag);
                            if (attribute != null)
                            {
                                dataset.Remove(attribute);
                            }

                            // add the attribute at the top level
                            dataset.AddAttribute(sourceComparisonTag.Tag.GroupNumber,
                                                 sourceComparisonTag.Tag.ElementNumber,
                                                 sourceComparisonTag.Vr,
                                                 stringValue);
                        }
                    }
                }
            }

            return(messagePopulated);
        }
Example #35
0
        public static DvtkHighLevelInterface.Messages.DicomMessage MakeStorageCommitEvent(QueryRetrieveInformationModels informationModels, DvtkHighLevelInterface.Messages.DicomMessage actionMessage)
        {
            // refresh the information models
            informationModels.Refresh();

            DvtkHighLevelInterface.Messages.DicomMessage eventMessage = new DvtkHighLevelInterface.Messages.DicomMessage(DvtkData.Dimse.DimseCommand.NEVENTREPORTRQ);
            eventMessage.Set("0x00000002", DvtkData.Dimse.VR.UI, "1.2.840.10008.1.20.1");
            eventMessage.Set("0x00001000", DvtkData.Dimse.VR.UI, "1.2.840.10008.1.20.1.1");
            eventMessage.Set("0x00001002", DvtkData.Dimse.VR.US, 1);

            DvtkData.Dimse.DataSet actionDataset = actionMessage.DataSet.DvtkDataDataSet;

            DvtkData.Dimse.DataSet eventDataset = new DvtkData.Dimse.DataSet();

            DvtkData.Dimse.Attribute eventReferenceSopSequence        = new DvtkData.Dimse.Attribute(0x00081199, DvtkData.Dimse.VR.SQ);
            SequenceOfItems          eventReferenceSopSequenceOfItems = new SequenceOfItems();

            eventReferenceSopSequence.DicomValue = eventReferenceSopSequenceOfItems;

            DvtkData.Dimse.Attribute eventFailedSopSequence        = new DvtkData.Dimse.Attribute(0x00081198, DvtkData.Dimse.VR.SQ);
            SequenceOfItems          eventFailedSopSequenceOfItems = new SequenceOfItems();

            eventFailedSopSequence.DicomValue = eventFailedSopSequenceOfItems;

            if (actionDataset != null)
            {
                DvtkData.Dimse.Attribute transactionUid = actionDataset.GetAttribute(DvtkData.Dimse.Tag.TRANSACTION_UID);
                if (transactionUid != null)
                {
                    eventDataset.Add(transactionUid);
                }

                DvtkData.Dimse.Attribute referencedSopSequence = actionDataset.GetAttribute(DvtkData.Dimse.Tag.REFERENCED_SOP_SEQUENCE);
                if (referencedSopSequence != null)
                {
                    SequenceOfItems sequenceOfItems = (SequenceOfItems)referencedSopSequence.DicomValue;
                    foreach (DvtkData.Dimse.SequenceItem item in sequenceOfItems.Sequence)
                    {
                        System.String sopClassUid    = "";
                        System.String sopInstanceUid = "";

                        DvtkData.Dimse.Attribute attribute = item.GetAttribute(DvtkData.Dimse.Tag.REFERENCED_SOP_CLASS_UID);
                        if (attribute != null)
                        {
                            UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)attribute.DicomValue;
                            sopClassUid = uniqueIdentifier.Values[0];
                        }

                        attribute = item.GetAttribute(DvtkData.Dimse.Tag.REFERENCED_SOP_INSTANCE_UID);
                        if (attribute != null)
                        {
                            UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)attribute.DicomValue;
                            sopInstanceUid = uniqueIdentifier.Values[0];
                        }

                        if (informationModels.PatientRoot.IsInstanceInInformationModel(sopClassUid, sopInstanceUid))
                        {
                            DvtkData.Dimse.SequenceItem itemOk = new DvtkData.Dimse.SequenceItem();
                            itemOk.AddAttribute(0x00081150, DvtkData.Dimse.VR.UI, sopClassUid);
                            itemOk.AddAttribute(0x00081155, DvtkData.Dimse.VR.UI, sopInstanceUid);

                            // add instance to committed list
                            eventReferenceSopSequenceOfItems.Sequence.Add(itemOk);
                        }
                        else
                        {
                            DvtkData.Dimse.SequenceItem itemNotOk = new DvtkData.Dimse.SequenceItem();
                            itemNotOk.AddAttribute(0x00081150, DvtkData.Dimse.VR.UI, sopClassUid);
                            itemNotOk.AddAttribute(0x00081155, DvtkData.Dimse.VR.UI, sopInstanceUid);
                            itemNotOk.AddAttribute(0x00081197, DvtkData.Dimse.VR.US, 0x0110);

                            // add instance to failed list
                            eventFailedSopSequenceOfItems.Sequence.Add(itemNotOk);
                        }
                    }
                }

                if (eventReferenceSopSequenceOfItems.Sequence.Count > 0)
                {
                    eventDataset.Add(eventReferenceSopSequence);
                }

                if (eventFailedSopSequenceOfItems.Sequence.Count > 0)
                {
                    eventDataset.Add(eventFailedSopSequence);
                }
            }

            eventMessage.DataSet.DvtkDataDataSet = eventDataset;

            return(eventMessage);
        }
Example #36
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 #37
0
        /// <summary>
        /// Cretae a storage commitment event.
        /// </summary>
        /// <param name="informationModels">The information models.</param>
        /// <param name="actionMessage">The action message.</param>
        /// <returns>The created event.</returns>
        public static DvtkHighLevelInterface.Dicom.Messages.DicomMessage MakeStorageCommitEvent(QueryRetrieveInformationModels informationModels, DvtkHighLevelInterface.Dicom.Messages.DicomMessage actionMessage)
        {
            // refresh the information models
            informationModels.Refresh();

            DvtkHighLevelInterface.Dicom.Messages.DicomMessage eventMessage = new DvtkHighLevelInterface.Dicom.Messages.DicomMessage(DvtkData.Dimse.DimseCommand.NEVENTREPORTRQ);
            eventMessage.Set("0x00000002", VR.UI, "1.2.840.10008.1.20.1");
            eventMessage.Set("0x00001000", VR.UI, "1.2.840.10008.1.20.1.1");

            DvtkData.Dimse.DataSet actionDataset = actionMessage.DataSet.DvtkDataDataSet;

            DvtkData.Dimse.DataSet eventDataset = new DvtkData.Dimse.DataSet();

            DvtkData.Dimse.Attribute eventReferenceSopSequence = new DvtkData.Dimse.Attribute(0x00081199, DvtkData.Dimse.VR.SQ);
            SequenceOfItems eventReferenceSopSequenceOfItems = new SequenceOfItems();
            eventReferenceSopSequence.DicomValue = eventReferenceSopSequenceOfItems;

            DvtkData.Dimse.Attribute eventFailedSopSequence = new DvtkData.Dimse.Attribute(0x00081198, DvtkData.Dimse.VR.SQ);
            SequenceOfItems eventFailedSopSequenceOfItems = new SequenceOfItems();
            eventFailedSopSequence.DicomValue = eventFailedSopSequenceOfItems;

            if (actionDataset != null)
            {
                DvtkData.Dimse.Attribute transactionUid = actionDataset.GetAttribute(DvtkData.Dimse.Tag.TRANSACTION_UID);
                if (transactionUid != null)
                {
                    eventDataset.Add(transactionUid);
                }

                DvtkData.Dimse.Attribute referencedSopSequence = actionDataset.GetAttribute(DvtkData.Dimse.Tag.REFERENCED_SOP_SEQUENCE);
                if (referencedSopSequence != null)
                {
                    SequenceOfItems sequenceOfItems = (SequenceOfItems)referencedSopSequence.DicomValue;
                    foreach(DvtkData.Dimse.SequenceItem item in sequenceOfItems.Sequence)
                    {
                        System.String sopClassUid = "";
                        System.String sopInstanceUid = "";

                        DvtkData.Dimse.Attribute attribute = item.GetAttribute(DvtkData.Dimse.Tag.REFERENCED_SOP_CLASS_UID);
                        if (attribute != null)
                        {
                            UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)attribute.DicomValue;
                            if (uniqueIdentifier.Values.Count > 0)
                            {
                                sopClassUid = uniqueIdentifier.Values[0];
                            }
                        }

                        attribute = item.GetAttribute(DvtkData.Dimse.Tag.REFERENCED_SOP_INSTANCE_UID);
                        if (attribute != null)
                        {
                            UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)attribute.DicomValue;
                            if (uniqueIdentifier.Values.Count > 0)
                            {
                                sopInstanceUid = uniqueIdentifier.Values[0];
                            }
                        }

                        if (informationModels.PatientRoot.IsInstanceInInformationModel(sopClassUid, sopInstanceUid))
                        {
                            DvtkData.Dimse.SequenceItem itemOk = new DvtkData.Dimse.SequenceItem();
                            itemOk.AddAttribute(0x00081150, DvtkData.Dimse.VR.UI, sopClassUid);
                            itemOk.AddAttribute(0x00081155, DvtkData.Dimse.VR.UI, sopInstanceUid);

                            // add instance to committed list
                            eventReferenceSopSequenceOfItems.Sequence.Add(itemOk);
                        }
                        else
                        {
                            DvtkData.Dimse.SequenceItem itemNotOk = new DvtkData.Dimse.SequenceItem();
                            itemNotOk.AddAttribute(0x00081150, DvtkData.Dimse.VR.UI, sopClassUid);
                            itemNotOk.AddAttribute(0x00081155, DvtkData.Dimse.VR.UI, sopInstanceUid);
                            itemNotOk.AddAttribute(0x00081197, DvtkData.Dimse.VR.US, 0x0110);

                            // add instance to failed list
                            eventFailedSopSequenceOfItems.Sequence.Add(itemNotOk);
                        }
                    }
                }

                if (eventReferenceSopSequenceOfItems.Sequence.Count > 0)
                {
                    eventMessage.Set("0x00001002", VR.US, 1);
                    eventDataset.Add(eventReferenceSopSequence);
                }

                if (eventFailedSopSequenceOfItems.Sequence.Count > 0)
                {
                    eventMessage.Set("0x00001002", VR.US, 2);
                    eventDataset.Add(eventFailedSopSequence);
                }
            }

            eventMessage.DataSet.DvtkDataDataSet = eventDataset;

            return eventMessage;
        }
Example #38
0
 /// <summary>
 /// Removes the first occurrence of a specific <see cref="DataSet"/> from the <see cref="DataSetCollection"/>.
 /// </summary>
 /// <param name="value">The <see cref="DataSet"/> to remove from the <see cref="DataSetCollection"/>.</param>
 public void Remove(DataSet value)
 {
     List.Remove(value);
 }
        /// <summary>
        /// Query the Information Model using the given Query Dataset.
        /// </summary>
        /// <param name="queryDataset">Query Dataset.</param>
        /// <returns>A collection of zero or more query reponse datasets.</returns>
        public override DataSetCollection QueryInformationModel(DataSet queryDataset)
        {
            DataSetCollection queryResponses = new DataSetCollection();

            // get the query/retrieve level
            String queryRetrieveLevel = "UNKNOWN";
            DvtkData.Dimse.Attribute queryRetrieveLevelAttribute = queryDataset.GetAttribute(Tag.QUERY_RETRIEVE_LEVEL);
            if (queryRetrieveLevelAttribute != null)
            {
                CodeString codeString = (CodeString)queryRetrieveLevelAttribute.DicomValue;
                if (codeString.Values.Count == 1)
                {
                    queryRetrieveLevel = codeString.Values[0].Trim();
                }
            }

            // query at the PATIENT level
            if (queryRetrieveLevel == "PATIENT")
            {
                TagTypeList queryTagTypeList = new TagTypeList();
                TagTypeList returnTagTypeList = new TagTypeList();
                foreach (DvtkData.Dimse.Attribute attribute in queryDataset)
                {
                    if (attribute.ValueRepresentation == VR.SQ)
                    {
                        foreach (SequenceItem s in ((SequenceOfItems)attribute.DicomValue).Sequence)
                        {
                            if (IsSequenceHavingValue(s))
                            {
                                queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                            }
                        }
                    }
                    else if ((attribute.Length != 0) &&
                        (attribute.Tag.ElementNumber != 0x0000))
                    {
                        queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                    }
                    if (attribute.Tag != Tag.SPECIFIC_CHARACTER_SET)
                        returnTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagOptional));
                }

                foreach (PatientInformationEntity patientInformationEntity in Root)
                {
                    if (patientInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                    {
                        // PATIENT level matches
                        DataSet queryResponse = new DataSet();

                        // if the specific character set attribute has been stored in the patient IE - return it in the query response
                        DvtkData.Dimse.Attribute specificCharacterSetAttribute = patientInformationEntity.GetSpecificCharacterSet();
                        if (specificCharacterSetAttribute != null)
                        {
                            queryResponse.Add(specificCharacterSetAttribute);
                        }

                        patientInformationEntity.CopyTo(returnTagTypeList, queryResponse);
                        patientInformationEntity.CopyAdditionalAttributes(queryResponse);
                        queryResponses.Add(queryResponse);
                    }
                }
            }
            else
            {
                // find the matching PATIENT
                PatientInformationEntity patientInformationEntity = null;
                foreach (PatientInformationEntity lPatientInformationEntity in Root)
                {
                    if (lPatientInformationEntity.IsUniqueTagFoundIn(queryDataset))
                    {
                        patientInformationEntity = lPatientInformationEntity;
                        break;
                    }
                }
                if (patientInformationEntity != null)
                {
                    // query at the STUDY level
                    if (queryRetrieveLevel == "STUDY")
                    {
                        TagTypeList queryTagTypeList = new TagTypeList();
                        TagTypeList returnTagTypeList = new TagTypeList();
                        foreach (DvtkData.Dimse.Attribute attribute in queryDataset)
                        {
                            // do not add higher level tag
                            if (attribute.Tag == Tag.PATIENT_ID) continue;

                            if (attribute.ValueRepresentation == VR.SQ)
                            {
                                foreach (SequenceItem s in ((SequenceOfItems)attribute.DicomValue).Sequence)
                                {
                                    if (IsSequenceHavingValue(s))
                                    {
                                        queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                                    }
                                }
                            }
                            else if ((attribute.Length != 0) &&
                                (attribute.Tag.ElementNumber != 0x0000))
                            {
                                queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                            }
                            returnTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagOptional));
                        }

                        foreach (StudyInformationEntity studyInformationEntity in patientInformationEntity.Children)
                        {
                            if (studyInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                            {
                                // STUDY level matches
                                DataSet queryResponse = new DataSet();

                                // if the specific character set attribute has been stored in the study IE - return it in the query response
                                DvtkData.Dimse.Attribute specificCharacterSetAttribute = studyInformationEntity.GetSpecificCharacterSet();
                                if (specificCharacterSetAttribute != null)
                                {
                                    queryResponse.Add(specificCharacterSetAttribute);
                                }

                                patientInformationEntity.CopyUniqueTagTo(queryResponse);
                                studyInformationEntity.CopyTo(returnTagTypeList, queryResponse);
                                studyInformationEntity.CopyAdditionalAttributes(queryResponse);
                                queryResponses.Add(queryResponse);
                            }
                        }
                    }
                    else
                    {
                        // find the matching STUDY
                        StudyInformationEntity studyInformationEntity = null;
                        foreach (StudyInformationEntity lStudyInformationEntity in patientInformationEntity.Children)
                        {
                            if (lStudyInformationEntity.IsUniqueTagFoundIn(queryDataset))
                            {
                                studyInformationEntity = lStudyInformationEntity;
                                break;
                            }
                        }

                        if (studyInformationEntity != null)
                        {
                            // query at the SERIES level
                            if (queryRetrieveLevel == "SERIES")
                            {
                                TagTypeList queryTagTypeList = new TagTypeList();
                                TagTypeList returnTagTypeList = new TagTypeList();
                                foreach (DvtkData.Dimse.Attribute attribute in queryDataset)
                                {
                                    // do not add higher level tags
                                    if ((attribute.Tag == Tag.PATIENT_ID) ||
                                        (attribute.Tag == Tag.STUDY_INSTANCE_UID)) continue;

                                    if (attribute.ValueRepresentation == VR.SQ)
                                    {
                                        foreach (SequenceItem s in ((SequenceOfItems)attribute.DicomValue).Sequence)
                                        {
                                            if (IsSequenceHavingValue(s))
                                            {
                                                queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                                            }
                                        }
                                    }
                                    else if ((attribute.Length != 0) &&
                                        (attribute.Tag.ElementNumber != 0x0000))
                                    {
                                        queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                                    }
                                    returnTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagOptional));
                                }

                                foreach (SeriesInformationEntity seriesInformationEntity in studyInformationEntity.Children)
                                {
                                    if (seriesInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                                    {
                                        // SERIES level matches
                                        DataSet queryResponse = new DataSet();

                                        // if the specific character set attribute has been stored in the series IE - return it in the query response
                                        DvtkData.Dimse.Attribute specificCharacterSetAttribute = seriesInformationEntity.GetSpecificCharacterSet();
                                        if (specificCharacterSetAttribute != null)
                                        {
                                            queryResponse.Add(specificCharacterSetAttribute);
                                        }

                                        patientInformationEntity.CopyUniqueTagTo(queryResponse);
                                        studyInformationEntity.CopyUniqueTagTo(queryResponse);
                                        seriesInformationEntity.CopyTo(returnTagTypeList, queryResponse);
                                        seriesInformationEntity.CopyAdditionalAttributes(queryResponse);
                                        queryResponses.Add(queryResponse);
                                    }
                                }
                            }
                            else
                            {
                                // find the matching SERIES
                                SeriesInformationEntity seriesInformationEntity = null;
                                foreach (SeriesInformationEntity lSeriesInformationEntity in studyInformationEntity.Children)
                                {
                                    if (lSeriesInformationEntity.IsUniqueTagFoundIn(queryDataset))
                                    {
                                        seriesInformationEntity = lSeriesInformationEntity;
                                        break;
                                    }
                                }

                                if (seriesInformationEntity != null)
                                {
                                    // query at the IMAGE level
                                    if (queryRetrieveLevel == "IMAGE")
                                    {
                                        TagTypeList queryTagTypeList = new TagTypeList();
                                        TagTypeList returnTagTypeList = new TagTypeList();
                                        foreach (DvtkData.Dimse.Attribute attribute in queryDataset)
                                        {
                                            // do not add higher level tags
                                            if ((attribute.Tag == Tag.PATIENT_ID) ||
                                                (attribute.Tag == Tag.STUDY_INSTANCE_UID) ||
                                                (attribute.Tag == Tag.SERIES_INSTANCE_UID)) continue;

                                            if (attribute.ValueRepresentation == VR.SQ)
                                            {
                                                foreach (SequenceItem s in ((SequenceOfItems)attribute.DicomValue).Sequence)
                                                {
                                                    if (IsSequenceHavingValue(s))
                                                    {
                                                        queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                                                    }
                                                }
                                            }
                                            else if ((attribute.Length != 0) &&
                                                (attribute.Tag.ElementNumber != 0x0000))
                                            {
                                                queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                                            }
                                            returnTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagOptional));
                                        }

                                        foreach (InstanceInformationEntity instanceInformationEntity in seriesInformationEntity.Children)
                                        {
                                            if (instanceInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                                            {
                                                // IMAGE level matches
                                                DataSet queryResponse = new DataSet();

                                                // if the specific character set attribute has been stored in the instance IE - return it in the query response
                                                DvtkData.Dimse.Attribute specificCharacterSetAttribute = instanceInformationEntity.GetSpecificCharacterSet();
                                                if (specificCharacterSetAttribute != null)
                                                {
                                                    queryResponse.Add(specificCharacterSetAttribute);
                                                }

                                                patientInformationEntity.CopyUniqueTagTo(queryResponse);
                                                studyInformationEntity.CopyUniqueTagTo(queryResponse);
                                                seriesInformationEntity.CopyUniqueTagTo(queryResponse);
                                                instanceInformationEntity.CopyTo(returnTagTypeList, queryResponse);
                                                instanceInformationEntity.CopyAdditionalAttributes(queryResponse);
                                                queryResponses.Add(queryResponse);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return queryResponses;
        }
Example #40
0
 /// <summary>
 /// Inserts an <see cref="DataSet"/> element into the <see cref="DataSet"/> at the specified index.
 /// </summary>
 /// <param name="index">The zero-based index at which value should be inserted.</param>
 /// <param name="value">The <see cref="DataSetCollection"/> to insert.</param>
 public void Insert(int index, DataSet value)
 {
     List.Insert(index, value);
 }
Example #41
0
 /// <summary>
 /// Determines whether the <see cref="DataSetCollection"/> contains a specific element.
 /// </summary>
 /// <param name="value">The <see cref="DataSet"/> to locate in the <see cref="DataSetCollection"/>.</param>
 /// <returns>
 /// <c>true</c> if the <see cref="DataSetCollection"/> contains the specified value; 
 /// otherwise, <c>false</c>.
 /// </returns>
 public bool Contains(DataSet value)
 {
     // If value is not of type Code, this will return false.
     return (List.Contains(value));
 }
Example #42
0
 /// <summary>
 /// Adds an object to the end of the <see cref="DataSetCollection"/>.
 /// </summary>
 /// <param name="value">The <see cref="DataSet"/> to be added to the end of the <see cref="DataSetCollection"/>.</param>
 /// <returns>The <see cref="DataSetCollection"/> index at which the value has been added.</returns>
 public int Add(DataSet value)
 {
     return (List.Add(value));
 }
Example #43
0
 /// <summary>
 /// Patient merge request - update modality worklist information model.
 /// </summary>
 /// <param name="dataset">Dataset containing patient merge attributes.</param>
 public virtual void PatientMerge(DvtkData.Dimse.DataSet dataset)
 {
 }
Example #44
0
 /// <summary>
 /// Copies the elements of the <see cref="ICollection"/> to a strong-typed <c>DataSet[]</c>, 
 /// starting at a particular <c>DataSet[]</c> index.
 /// </summary>
 /// <param name="array">
 /// The one-dimensional <c>DataSet[]</c> that is the destination of the elements 
 /// copied from <see cref="ICollection"/>.
 /// The <c>DataSet[]</c> must have zero-based indexing. 
 /// </param>
 /// <param name="index">
 /// The zero-based index in array at which copying begins.
 /// </param>
 /// <remarks>
 /// Provides the strongly typed member for <see cref="ICollection"/>.
 /// </remarks>
 public void CopyTo(DataSet[] array, int index)
 {
     ((ICollection)this).CopyTo(array, index);
 }
Example #45
0
 /// <summary>
 /// Placer order management request - update modality worklist information model.
 /// </summary>
 /// <param name="dataset">Dataset containing placer order management attributes.</param>
 public virtual void PlacerOrderManagement(DvtkData.Dimse.DataSet dataset)
 {
 }
Example #46
0
 protected override void LoadData(DvtkData.Dimse.DataSet _dataSet)
 {
     base.LoadData(_dataSet);
     patientName = BaseCompositeInformationEntity.GetDicomValue(_dataSet.GetAttribute(DvtkData.Dimse.Tag.PATIENTS_NAME));
     patientId   = BaseCompositeInformationEntity.GetDicomValue(_dataSet.GetAttribute(DvtkData.Dimse.Tag.PATIENT_ID));
 }
Example #47
0
 /// <summary>
 /// Patient Registration request - update modality worklist information model.
 /// </summary>
 /// <param name="dataset">Dataset containing patient registration attributes.</param>
 public virtual void PatientRegistration(DvtkData.Dimse.DataSet dataset)
 {
 }