예제 #1
0
        public void SetComparators(Dvtk.Comparator.BaseComparatorCollection comparatorCollection)
        {
            if (_transaction is DicomTransaction)
            {
                System.String name = System.String.Empty;

                DicomTransaction dicomTransaction = (DicomTransaction)_transaction;
                switch (dicomTransaction.Direction)
                {
                case TransactionDirectionEnum.TransactionReceived:
                    name = System.String.Format("Received by {0} from {1}", ActorNames.Name(_fromActorName), ActorNames.Name(_toActorName));
                    break;

                case TransactionDirectionEnum.TransactionSent:
                    name = System.String.Format("Sent from {0} to {1}", ActorNames.Name(_fromActorName), ActorNames.Name(_toActorName));
                    break;

                default:
                    break;
                }

                for (int i = 0; i < dicomTransaction.DicomMessages.Count; i++)
                {
                    DicomMessage dicomMessage = (DicomMessage)dicomTransaction.DicomMessages[i];

                    DvtkHighLevelInterface.Comparator.Comparator comparator = new DvtkHighLevelInterface.Comparator.Comparator(name);
                    Dvtk.Comparator.DicomComparator dicomComparator         = comparator.InitializeDicomComparator(dicomMessage);
                    if (dicomComparator != null)
                    {
                        comparatorCollection.Add(dicomComparator);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Send a single image generated from the Default Value Manager and
        /// the given Modality Worklist Item.
        /// </summary>
        /// <param name="startNewSeries">Boolean indicating if this image is part of a new
        /// Series or not.</param>
        /// <param name="modalityWorklistItem">Worklist Item used to provide overruling values for
        /// the Image header.</param>
        /// <returns>Boolean indicating success or failure.</returns>
        public bool SendModalityImagesStored(bool startNewSeries, DicomQueryItem modalityWorklistItem)
        {
            if (modalityWorklistItem == null)
            {
                return(false);
            }

            // Update the default SeriesEntity values for the next Storage Message
            if (startNewSeries == true)
            {
                DefaultValueManager.UpdateInstantiatedDefaultTagValues(AffectedEntityEnum.SeriesEntity);
            }

            // 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);
            storageComparator.PopulateDicomMessage(cStoreInstance, dicomWorklistItemComparator);
            if (dicomMppsInProgressComparator != null)
            {
                storageComparator.PopulateDicomMessage(cStoreInstance, dicomMppsInProgressComparator);
            }

            // Trigger the C-STORE-RQ Instance
            DicomTrigger trigger = new DicomTrigger(TransactionNameEnum.RAD_8);

            trigger.HandleInSingleAssociation = true;
            trigger.AddItem(cStoreInstance,
                            "1.2.840.10008.5.1.4.1.1.7",
                            "1.2.840.10008.1.2");

            // Update the default InstanceEntity values for the next Storage Message
            DefaultValueManager.UpdateInstantiatedDefaultTagValues(AffectedEntityEnum.InstanceEntity);

            // RAD-8 - trigger the ImageArchive
            return(TriggerActorInstances(ActorTypeEnum.ImageArchive, trigger, true));
        }
예제 #3
0
        private bool TriggerModalityProcedureStepInProgress(DicomQueryItem modalityWorklistItem)
        {
            // Use modality Worklist Item to help construct the MPPS InProgress Message
            // Get the attribute values to copy
            DvtkHighLevelInterface.Comparator.Comparator worklistItemComparator = new DvtkHighLevelInterface.Comparator.Comparator("WorklistItemComparator");
            DicomComparator dicomWorklistItemComparator = worklistItemComparator.InitializeDicomComparator(modalityWorklistItem.DicomMessage);

            DvtkHighLevelInterface.Comparator.Comparator mppsInProgressComparator = new DvtkHighLevelInterface.Comparator.Comparator("MppsInProgressComparator");
            mppsInProgressComparator.PopulateDicomMessage(_nCreateSetMppsInProgress, dicomWorklistItemComparator);

            // Trigger the N-CREATE-RQ MPPS InProgress
            DicomTrigger trigger = new DicomTrigger(TransactionNameEnum.RAD_6);

            trigger.AddItem(_nCreateSetMppsInProgress,
                            "1.2.840.10008.3.1.2.3.3",
                            "1.2.840.10008.1.2");

            // Update the default PerformedProcedureStepEntity values for the next MPPS In-Progress
            DefaultValueManager.UpdateInstantiatedDefaultTagValues(AffectedEntityEnum.PerformedProcedureStepEntity);

            // RAD-6 - trigger the PerformedProcedureStepManager
            return(TriggerActorInstances(ActorTypeEnum.PerformedProcedureStepManager, trigger, true));
        }
예제 #4
0
        /// <summary>
        /// Set the Comparators needed to handle each message in the Transaction.
        /// </summary>
        /// <param name="comparatorCollection">Comparator collection to fill.</param>
        public void SetComparators(Dvtk.Comparator.BaseComparatorCollection comparatorCollection)
        {
            if (_transaction is DicomTransaction)
            {
                System.String name = System.String.Empty;

                DicomTransaction dicomTransaction = (DicomTransaction)_transaction;
                switch (dicomTransaction.Direction)
                {
                case TransactionDirectionEnum.TransactionReceived:
                    name = System.String.Format("Received by {0}:{1} from {2}:{3}",
                                                ActorTypes.Type(_toActorName.Type),
                                                _toActorName.Id,
                                                ActorTypes.Type(_fromActorName.Type),
                                                _fromActorName.Id);
                    break;

                case TransactionDirectionEnum.TransactionSent:
                    name = System.String.Format("Sent from {0}:{1} to {2}:{3}",
                                                ActorTypes.Type(_toActorName.Type),
                                                _toActorName.Id,
                                                ActorTypes.Type(_fromActorName.Type),
                                                _fromActorName.Id);
                    break;

                default:
                    break;
                }

                for (int i = 0; i < dicomTransaction.DicomMessages.Count; i++)
                {
                    DicomMessage dicomMessage = (DicomMessage)dicomTransaction.DicomMessages[i];

                    DvtkHighLevelInterface.Comparator.Comparator comparator = new DvtkHighLevelInterface.Comparator.Comparator(name);
                    Dvtk.Comparator.DicomComparator dicomComparator         = comparator.InitializeDicomComparator(dicomMessage);
                    if (dicomComparator != null)
                    {
                        comparatorCollection.Add(dicomComparator);
                    }
                }
            }
            else if (_transaction is Hl7Transaction)
            {
                System.String name = System.String.Empty;

                Hl7Transaction hl7Transaction = (Hl7Transaction)_transaction;
                switch (hl7Transaction.Direction)
                {
                case TransactionDirectionEnum.TransactionReceived:
                    name = System.String.Format("Received by {0}:{1} from {2}:{3}",
                                                ActorTypes.Type(_toActorName.Type),
                                                _toActorName.Id,
                                                ActorTypes.Type(_fromActorName.Type),
                                                _fromActorName.Id);
                    break;

                case TransactionDirectionEnum.TransactionSent:
                    name = System.String.Format("Sent from {0}:{1} to {2}:{3}",
                                                ActorTypes.Type(_toActorName.Type),
                                                _toActorName.Id,
                                                ActorTypes.Type(_fromActorName.Type),
                                                _fromActorName.Id);
                    break;

                default:
                    break;
                }

                Hl7Message hl7Message = hl7Transaction.Request;

                DvtkHighLevelInterface.Comparator.Comparator comparator = new DvtkHighLevelInterface.Comparator.Comparator(name);
                Dvtk.Comparator.Hl7Comparator hl7Comparator             = comparator.InitializeHl7Comparator(hl7Message);
                if (hl7Comparator != null)
                {
                    comparatorCollection.Add(hl7Comparator);
                }
            }
        }
예제 #5
0
        /// <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));
        }
예제 #6
0
        public void SetComparators(Dvtk.Comparator.BaseComparatorCollection comparatorCollection)
        {
            if (_transaction is DicomTransaction)
            {
                System.String name = System.String.Empty;

                DicomTransaction dicomTransaction = (DicomTransaction)_transaction;
                switch(dicomTransaction.Direction)
                {
                    case TransactionDirectionEnum.TransactionReceived:
                        name = System.String.Format("Received by {0} from {1}", ActorNames.Name(_fromActorName), ActorNames.Name(_toActorName));
                        break;
                    case TransactionDirectionEnum.TransactionSent:
                        name = System.String.Format("Sent from {0} to {1}", ActorNames.Name(_fromActorName), ActorNames.Name(_toActorName));
                        break;
                    default:
                        break;
                }

                for (int i = 0; i < dicomTransaction.DicomMessages.Count; i++)
                {
                    DicomMessage dicomMessage = (DicomMessage)dicomTransaction.DicomMessages[i];

                    DvtkHighLevelInterface.Comparator.Comparator comparator = new DvtkHighLevelInterface.Comparator.Comparator(name);
                    Dvtk.Comparator.DicomComparator dicomComparator = comparator.InitializeDicomComparator(dicomMessage);
                    if (dicomComparator != null)
                    {
                        comparatorCollection.Add(dicomComparator);
                    }
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Set the Comparators needed to handle each message in the Transaction.
        /// </summary>
        /// <param name="comparatorCollection">Comparator collection to fill.</param>
        public void SetComparators(Dvtk.Comparator.BaseComparatorCollection comparatorCollection)
        {
            if (_transaction is DicomTransaction)
            {
                System.String name = System.String.Empty;

                DicomTransaction dicomTransaction = (DicomTransaction)_transaction;
                switch(dicomTransaction.Direction)
                {
                    case TransactionDirectionEnum.TransactionReceived:
                        name = System.String.Format("Received by {0}:{1} from {2}:{3}",
                            ActorTypes.Type(_toActorName.Type),
                            _toActorName.Id,
                            ActorTypes.Type(_fromActorName.Type),
                            _fromActorName.Id);
                        break;
                    case TransactionDirectionEnum.TransactionSent:
                        name = System.String.Format("Sent from {0}:{1} to {2}:{3}",
                            ActorTypes.Type(_toActorName.Type),
                            _toActorName.Id,
                            ActorTypes.Type(_fromActorName.Type),
                            _fromActorName.Id);
                        break;
                    default:
                        break;
                }

                for (int i = 0; i < dicomTransaction.DicomMessages.Count; i++)
                {
                    DicomMessage dicomMessage = (DicomMessage)dicomTransaction.DicomMessages[i];

                    DvtkHighLevelInterface.Comparator.Comparator comparator = new DvtkHighLevelInterface.Comparator.Comparator(name);
                    Dvtk.Comparator.DicomComparator dicomComparator = comparator.InitializeDicomComparator(dicomMessage);
                    if (dicomComparator != null)
                    {
                        comparatorCollection.Add(dicomComparator);
                    }
                }
            }
            else if (_transaction is Hl7Transaction)
            {
                System.String name = System.String.Empty;

                Hl7Transaction hl7Transaction = (Hl7Transaction)_transaction;
                switch(hl7Transaction.Direction)
                {
                    case TransactionDirectionEnum.TransactionReceived:
                        name = System.String.Format("Received by {0}:{1} from {2}:{3}",
                            ActorTypes.Type(_toActorName.Type),
                            _toActorName.Id,
                            ActorTypes.Type(_fromActorName.Type),
                            _fromActorName.Id);
                        break;
                    case TransactionDirectionEnum.TransactionSent:
                        name = System.String.Format("Sent from {0}:{1} to {2}:{3}",
                            ActorTypes.Type(_toActorName.Type),
                            _toActorName.Id,
                            ActorTypes.Type(_fromActorName.Type),
                            _fromActorName.Id);
                        break;
                    default:
                        break;
                }

                Hl7Message hl7Message= hl7Transaction.Request;

                DvtkHighLevelInterface.Comparator.Comparator comparator = new DvtkHighLevelInterface.Comparator.Comparator(name);
                Dvtk.Comparator.Hl7Comparator hl7Comparator = comparator.InitializeHl7Comparator(hl7Message);
                if (hl7Comparator != null)
                {
                    comparatorCollection.Add(hl7Comparator);
                }
            }
        }
예제 #8
0
        private bool TriggerModalityProcedureStepInProgress(DicomQueryItem modalityWorklistItem)
        {
            // Use modality Worklist Item to help construct the MPPS InProgress Message
            // Get the attribute values to copy
            DvtkHighLevelInterface.Comparator.Comparator worklistItemComparator = new DvtkHighLevelInterface.Comparator.Comparator("WorklistItemComparator");
            DicomComparator dicomWorklistItemComparator = worklistItemComparator.InitializeDicomComparator(modalityWorklistItem.DicomMessage);

            DvtkHighLevelInterface.Comparator.Comparator mppsInProgressComparator = new DvtkHighLevelInterface.Comparator.Comparator("MppsInProgressComparator");
            mppsInProgressComparator.PopulateDicomMessage(_nCreateSetMppsInProgress, dicomWorklistItemComparator);

            // Trigger the N-CREATE-RQ MPPS InProgress
            DicomTrigger trigger = new DicomTrigger(TransactionNameEnum.RAD_6);
            trigger.AddItem(_nCreateSetMppsInProgress,
                "1.2.840.10008.3.1.2.3.3",
                "1.2.840.10008.1.2");

            // Update the default PerformedProcedureStepEntity values for the next MPPS In-Progress
            DefaultValueManager.UpdateInstantiatedDefaultTagValues(AffectedEntityEnum.PerformedProcedureStepEntity);

            // RAD-6 - trigger the PerformedProcedureStepManager
            return TriggerActorInstances(ActorTypeEnum.PerformedProcedureStepManager, trigger, true);
        }
예제 #9
0
        /// <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);
        }
예제 #10
0
        /// <summary>
        /// Send a single image generated from the Default Value Manager and
        /// the given Modality Worklist Item.
        /// </summary>
        /// <param name="startNewSeries">Boolean indicating if this image is part of a new
        /// Series or not.</param>
        /// <param name="modalityWorklistItem">Worklist Item used to provide overruling values for
        /// the Image header.</param>
        /// <returns>Boolean indicating success or failure.</returns>
        public bool SendModalityImagesStored(bool startNewSeries, DicomQueryItem modalityWorklistItem)
        {
            if (modalityWorklistItem == null) return false;

            // Update the default SeriesEntity values for the next Storage Message
            if (startNewSeries == true)
            {
                DefaultValueManager.UpdateInstantiatedDefaultTagValues(AffectedEntityEnum.SeriesEntity);
            }

            // 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);
            storageComparator.PopulateDicomMessage(cStoreInstance, dicomWorklistItemComparator);
            if (dicomMppsInProgressComparator != null)
            {
                storageComparator.PopulateDicomMessage(cStoreInstance, dicomMppsInProgressComparator);
            }

            // Trigger the C-STORE-RQ Instance
            DicomTrigger trigger = new DicomTrigger(TransactionNameEnum.RAD_8);
            trigger.HandleInSingleAssociation = true;
            trigger.AddItem(cStoreInstance,
                            "1.2.840.10008.5.1.4.1.1.7",
                            "1.2.840.10008.1.2");

            // Update the default InstanceEntity values for the next Storage Message
            DefaultValueManager.UpdateInstantiatedDefaultTagValues(AffectedEntityEnum.InstanceEntity);

            // RAD-8 - trigger the ImageArchive
            return TriggerActorInstances(ActorTypeEnum.ImageArchive, trigger, true);
        }