Esempio n. 1
0
 public void TestStart()
 {
     scriptRunner = new ScriptRunner();
     scriptRunner.Run();
     scriptRunner.Execute("var Storage = require('storage');");
     storage = scriptRunner.Execute("new Storage(Storage.inMemory)") as StorageInstance;
     if (storage == null)
         Assert.Ignore("Storage not found.");
     scriptRunner.Invoke((r) => r.Engine.SetGlobalValue("s", storage));
 }
Esempio n. 2
0
 /// <summary>
 /// 关闭已打开的bll instances
 /// </summary>
 private void CloseBlls()
 {
     TrackerPositionInstance.Close();
     StorageInstance.Close();
     PositionInstance.Close();
     EquipmentInstance.Close();
     EposInstance.Close();
     DataInstance.Close();
     DailyInstance.Close();
     CustomerInstance.Close();
     AlarmInstance.Close();
 }
Esempio n. 3
0
        public void AddStorageInstance(StorageInstance instance)
        {
            AuditSopClass sopClass;

            if (SopClassDictionary.TryGetValue(instance.SopClass.Uid, out sopClass))
            {
                sopClass.NumberOfInstances++;
            }
            else
            {
                sopClass = new AuditSopClass(instance.SopClass.Uid, 1);
                SopClassDictionary.Add(sopClass.UID, sopClass);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Load all of the instances in a given <see cref="SeriesXml"/> file into the component for sending.
        /// </summary>
        /// <param name="seriesXml"></param>
        /// <param name="seriesPath"></param>
        /// <param name="patientsName"></param>
        /// <param name="patientId"></param>
        /// <param name="studyXml"></param>
        public void LoadSeriesFromSeriesXml(StudyXml studyXml, string seriesPath, SeriesXml seriesXml, string patientsName, string patientId)
        {
            foreach (InstanceXml instanceXml in seriesXml)
            {
                string instancePath = Path.Combine(seriesPath, instanceXml.SopInstanceUid + ServerPlatform.DicomFileExtension);
                var    instance     = new StorageInstance(instancePath);

                AddStorageInstance(instance);
                instance.SopClass         = instanceXml.SopClass;
                instance.TransferSyntax   = instanceXml.TransferSyntax;
                instance.SopInstanceUid   = instanceXml.SopInstanceUid;
                instance.PatientId        = patientId;
                instance.PatientsName     = patientsName;
                instance.StudyInstanceUid = studyXml.StudyInstanceUid;
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 处理查询设备出入库记录的请求
        /// </summary>
        /// <returns></returns>
        private string HandleEquipmentStorage()
        {
            var ret = "[]";

            try
            {
                var id    = ParseInt(Utility.Decrypt(data));
                var start = DateTime.Parse(GetParamenter("start") + " 00:00:00");
                var end   = DateTime.Parse(GetParamenter("end") + " 23:59:59");
                var list  = StorageInstance.FindList(f => f.Equipment == id &&
                                                     f.Stocktime >= start && f.Stocktime <= end).OrderBy(o => o.Savetime).ToList();
                ret = JsonConverter.ToJson(list);
            }
            catch
            { }
            return(ret);
        }
Esempio n. 6
0
        protected void InternalAddStorageInstance(StorageInstance instance)
        {
            if (_participantObjectList.ContainsKey(instance.StudyInstanceUid))
            {
                AuditStudyParticipantObject study = _participantObjectList[instance.StudyInstanceUid] as AuditStudyParticipantObject;

                if (study != null)
                {
                    study.AddStorageInstance(instance);
                }
            }
            else
            {
                AuditStudyParticipantObject o = new AuditStudyParticipantObject(instance.StudyInstanceUid);
                o.AddStorageInstance(instance);
                _participantObjectList.Add(instance.StudyInstanceUid, o);
            }
        }
        /// <summary>
        /// Load all of the instances in a given <see cref="SeriesXml"/> file into the component for sending.
        /// </summary>
        /// <param name="seriesXml"></param>
        /// <param name="location"></param>
        /// <param name="patientsName"></param>
        /// <param name="patientId"></param>
        /// <param name="studyXml"></param>
        private void LoadSeriesFromSeriesXml(StudyXml studyXml, StudyLocation location, SeriesXml seriesXml,
                                             string patientsName, string patientId)
        {
            foreach (InstanceXml instanceXml in seriesXml)
            {
                var instance =
                    new StorageInstance(location.GetSopInstancePath(seriesXml.SeriesInstanceUid,
                                                                    instanceXml.SopInstanceUid));

                AddStorageInstance(instance);
                instance.SopClass         = instanceXml.SopClass;
                instance.TransferSyntax   = instanceXml.TransferSyntax;
                instance.SopInstanceUid   = instanceXml.SopInstanceUid;
                instance.PatientId        = patientId;
                instance.PatientsName     = patientsName;
                instance.StudyInstanceUid = studyXml.StudyInstanceUid;
            }
        }
        private List <WorkQueueUid> FindWorkQueueUids(StorageInstance instance)
        {
            if (_uidMaps == null)
            {
                if (WorkQueueUidList != null)
                {
                    _uidMaps = new Dictionary <string, List <WorkQueueUid> >();
                    foreach (WorkQueueUid uid in WorkQueueUidList)
                    {
                        if (!String.IsNullOrEmpty(uid.SopInstanceUid))
                        {
                            if (!_uidMaps.ContainsKey(uid.SopInstanceUid))
                            {
                                _uidMaps.Add(uid.SopInstanceUid, new List <WorkQueueUid>());
                            }

                            _uidMaps[uid.SopInstanceUid].Add(uid);
                        }
                        else
                        {
                            _uidMaps = null;
                            if (uid.SeriesInstanceUid.Equals(instance.SeriesInstanceUid))
                            {
                                return(new List <WorkQueueUid>(1)
                                {
                                    uid
                                });
                            }
                        }
                    }
                }
            }

            if (_uidMaps != null)
            {
                List <WorkQueueUid> foundUids;
                if (_uidMaps.TryGetValue(instance.SopInstanceUid, out foundUids))
                {
                    return(foundUids);
                }
            }

            return(null);
        }
Esempio n. 9
0
        /// <summary>
        /// Builds the study tree and publishes all the created studies to the specified application entity.
        /// </summary>
        /// <remarks>
        /// <para>The <see cref="BuildTree"/> method is called automatically, and hence does not need to be explicitly called before invoking this method.</para>
        /// </remarks>
        /// <param name="localAE">The local AETITLE that is sending the studies.</param>
        /// <param name="remoteAE">The AETITLE of the device that is receiving the studies.</param>
        /// <param name="remoteHost">The hostname of the device that is receiving the studies.</param>
        /// <param name="remotePort">The port number on which the device receiving the studies is listening.</param>
        /// <returns>A list of the SOP instance UIDs that were created.</returns>
        public IList <string> Publish(string localAE, string remoteAE, string remoteHost, int remotePort)
        {
            List <SopInstanceNode> sops;

            try
            {
                sops = DoBuildTree();
            }
            catch (Exception ex)
            {
                throw new StudyBuilderException("Unexpected StudyBuilder error", ex);
            }

            List <string> uids = new List <string>(sops.Count);

            try
            {
                StorageScu scu = new StorageScu(localAE, remoteAE, remoteHost, remotePort);

                // queue each instance into scu
                foreach (SopInstanceNode sop in sops)
                {
                    StorageInstance sInst = new StorageInstance(sop.DicomFile);
                    scu.AddStorageInstance(sInst);
                    uids.Add(sop.InstanceUid);
                }

                // begin asynch send operation
                scu.Send();
            }
            catch (Exception ex)
            {
                throw new StudyBuilderException("Storage SCU error", ex);
            }

            return(uids.AsReadOnly());
        }
Esempio n. 10
0
        /// <summary>
        ///     Main routine for processing C-MOVE-RQ messages.  Called by the <see cref="DicomScp{TContext}" /> component.
        /// </summary>
        /// <param name="server"></param>
        /// <param name="association"></param>
        /// <param name="presentationID"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public override bool OnReceiveRequest(DicomServer server, ServerAssociationParameters association,
                                              byte presentationID, DicomMessage message)
        {
            var    finalResponseSent = false;
            string errorComment;

            try
            {
                // check for a Cancel Message, and cance the scu
                if (message.CommandField == DicomCommandField.CCancelRequest)
                {
                    if (_theScu != null)
                    {
                        _theScu.Cancel();
                    }

                    return(true);
                }

                var level = message.DataSet[DicomTags.QueryRetrieveLevel].GetString(0, string.Empty);

                var remoteAe = message.MoveDestination.Trim();

                // load remote device for move information
                var device = IoC.Get <IDeviceManager>().LookupDevice(Partition, remoteAe);

                if (device == null)
                {
                    errorComment = string.Format(
                        "Unknown move destination \"{0}\", failing C-MOVE-RQ from {1} to {2}",
                        remoteAe, association.CallingAE, association.CalledAE);
                    Platform.Log(LogLevel.Error, errorComment);
                    server.SendCMoveResponse(presentationID, message.MessageId, new DicomMessage(),
                                             DicomStatuses.QueryRetrieveMoveDestinationUnknown, errorComment);
                    finalResponseSent = true;
                    return(true);
                }

                //If the remote node is a DHCP node, use its IP address from the connection information, else
                // use what is configured.Always use the configured port.
                if (device.Dhcp && association.CallingAE.Equals(remoteAe))
                {
                    device.Hostname = association.RemoteEndPoint.Address.ToString();
                }

                // now setup the storage scu component
                _theScu = new PacsStorageScu(Partition, device, association.CallingAE, message.MessageId);

                bool bOnline;

                if (level.Equals("PATIENT"))
                {
                    bOnline = GetSopListForPatient(message, out errorComment);
                }
                else if (level.Equals("STUDY"))
                {
                    bOnline = GetSopListForStudy(message, out errorComment);
                }
                else if (level.Equals("SERIES"))
                {
                    bOnline = GetSopListForSeries(message, out errorComment);
                }
                else if (level.Equals("IMAGE"))
                {
                    bOnline = GetSopListForInstance(message, out errorComment);
                }
                else
                {
                    errorComment = string.Format("Unexpected Study Root Move Query/Retrieve level: {0}", level);
                    Platform.Log(LogLevel.Error, errorComment);

                    server.SendCMoveResponse(presentationID, message.MessageId, new DicomMessage(),
                                             DicomStatuses.QueryRetrieveIdentifierDoesNotMatchSOPClass,
                                             errorComment);
                    finalResponseSent = true;
                    return(true);
                }

                // Could not find an online/readable location for the requested objects to move.
                // Note that if the C-MOVE-RQ included a list of study instance uids, and some
                // were online and some offline, we don't fail now (ie, the check on the Count)
                if (!bOnline || _theScu.StorageInstanceList.Count == 0)
                {
                    Platform.Log(LogLevel.Error, "Unable to find online storage location for C-MOVE-RQ: {0}",
                                 errorComment);

                    server.SendCMoveResponse(presentationID, message.MessageId, new DicomMessage(),
                                             DicomStatuses.QueryRetrieveUnableToPerformSuboperations,
                                             string.IsNullOrEmpty(errorComment) ? string.Empty : errorComment);
                    finalResponseSent = true;
                    _theScu.Dispose();
                    _theScu = null;
                    return(true);
                }

                _theScu.ImageStoreCompleted += delegate(object sender, ImageStoreEventArgs eventArgs)
                {
                    StorageInstance instance = eventArgs.StorageInstance;

                    var         scu = (StorageScu)sender;
                    var         msg = new DicomMessage();
                    DicomStatus status;

                    if (instance.SendStatus.Status == DicomState.Failure)
                    {
                        errorComment =
                            string.IsNullOrEmpty(instance.ExtendedFailureDescription)
                                ? instance.SendStatus.ToString()
                                : instance.ExtendedFailureDescription;
                    }

                    if (scu.RemainingSubOperations == 0)
                    {
                        foreach (var sop in _theScu.StorageInstanceList)
                        {
                            if ((sop.SendStatus.Status != DicomState.Success) &&
                                (sop.SendStatus.Status != DicomState.Warning))
                            {
                                msg.DataSet[DicomTags.FailedSopInstanceUidList].AppendString(sop.SopInstanceUid);
                            }
                        }
                        if (scu.Status == ScuOperationStatus.Canceled)
                        {
                            status = DicomStatuses.Cancel;
                        }
                        else if (scu.Status == ScuOperationStatus.ConnectFailed)
                        {
                            status = DicomStatuses.QueryRetrieveMoveDestinationUnknown;
                        }
                        else if (scu.FailureSubOperations > 0)
                        {
                            status = DicomStatuses.QueryRetrieveSubOpsOneOrMoreFailures;
                        }
                        else if (!bOnline)
                        {
                            status = DicomStatuses.QueryRetrieveUnableToPerformSuboperations;
                        }
                        else
                        {
                            status = DicomStatuses.Success;
                        }
                    }
                    else
                    {
                        status = DicomStatuses.Pending;

                        if (scu.RemainingSubOperations % 5 != 0)
                        {
                            return;
                        }
                        // Only send a RSP every 5 to reduce network load
                    }

                    server.SendCMoveResponse(presentationID, message.MessageId,
                                             msg, status,
                                             (ushort)scu.SuccessSubOperations,
                                             (ushort)scu.RemainingSubOperations,
                                             (ushort)scu.FailureSubOperations,
                                             (ushort)scu.WarningSubOperations,
                                             status == DicomStatuses.QueryRetrieveSubOpsOneOrMoreFailures
                            ? errorComment
                            : string.Empty);


                    if (scu.RemainingSubOperations == 0)
                    {
                        finalResponseSent = true;
                    }
                };

                _theScu.BeginSend(
                    delegate(IAsyncResult ar)
                {
                    if (_theScu != null)
                    {
                        if (!finalResponseSent)
                        {
                            var msg = new DicomMessage();
                            server.SendCMoveResponse(presentationID, message.MessageId,
                                                     msg, DicomStatuses.QueryRetrieveSubOpsOneOrMoreFailures,
                                                     (ushort)_theScu.SuccessSubOperations,
                                                     0,
                                                     (ushort)
                                                     (_theScu.FailureSubOperations +
                                                      _theScu.RemainingSubOperations),
                                                     (ushort)_theScu.WarningSubOperations, errorComment);
                            finalResponseSent = true;
                        }

                        _theScu.EndSend(ar);
                        _theScu.Dispose();
                        _theScu = null;
                    }
                },
                    _theScu);

                return(true);
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Error, e, "Unexpected exception when processing C-MOVE-RQ");
                if (finalResponseSent == false)
                {
                    try
                    {
                        server.SendCMoveResponse(presentationID, message.MessageId, new DicomMessage(),
                                                 DicomStatuses.QueryRetrieveUnableToProcess, e.Message);
                        finalResponseSent = true;
                    }
                    catch (Exception x)
                    {
                        Platform.Log(LogLevel.Error, x,
                                     "Unable to send final C-MOVE-RSP message on association from {0} to {1}",
                                     association.CallingAE, association.CalledAE);
                        server.Abort();
                    }
                }
            }

            return(false);
        }
Esempio n. 11
0
 /// <summary>
 /// Add details of images within a study.  SOP Class information is automatically updated.
 /// </summary>
 /// <param name="instance">Descriptive object being audited</param>
 public void AddStorageInstance(StorageInstance instance)
 {
     InternalAddStorageInstance(instance);
 }
Esempio n. 12
0
        public void StorageScuFromDisk()
        {
            int port = 2112;

            _serverHandlerList.Clear();

            /* Setup the Server */
            var  serverParameters = new ServerAssociationParameters("AssocTestServer", new IPEndPoint(IPAddress.Any, port));
            byte pcid             = serverParameters.AddPresentationContext(SopClass.MrImageStorage);

            serverParameters.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrLittleEndian);
            serverParameters.AddTransferSyntax(pcid, TransferSyntax.ExplicitVrBigEndian);
            serverParameters.AddTransferSyntax(pcid, TransferSyntax.ImplicitVrLittleEndian);

            _serverType = TestTypes.Receive;
            DicomServer.StartListening(serverParameters, ServerHandlerCreator);

            StorageScu scu = SetupScu();

            IList <DicomAttributeCollection> list = SetupMRSeries(4, 2, DicomUid.GenerateUid().UID);

            foreach (DicomAttributeCollection collection in list)
            {
                var file = new DicomFile("test", new DicomAttributeCollection(), collection)
                {
                    TransferSyntax             = TransferSyntax.ExplicitVrLittleEndian,
                    MediaStorageSopClassUid    = SopClass.MrImageStorage.Uid,
                    MediaStorageSopInstanceUid = collection[DicomTags.SopInstanceUid].ToString()
                };

                string instancePath = file.MediaStorageSopInstanceUid + ".dcm";

                file.Save(instancePath);

                var instance = new StorageInstance(instancePath)
                {
                    SopClass         = file.SopClass,
                    TransferSyntax   = file.TransferSyntax,
                    SopInstanceUid   = file.MediaStorageSopClassUid,
                    PatientId        = file.DataSet[DicomTags.PatientId].GetString(0, string.Empty),
                    PatientsName     = file.DataSet[DicomTags.PatientsName].GetString(0, string.Empty),
                    StudyInstanceUid = file.DataSet[DicomTags.StudyInstanceUid].GetString(0, string.Empty)
                };

                scu.AddStorageInstance(instance);
            }

            scu.Send();
            scu.Join();

            Assert.AreEqual(scu.Status, ScuOperationStatus.NotRunning);

            var handler       = CollectionUtils.FirstElement(_serverHandlerList);
            var serverHandler = handler as ServerHandler;

            Assert.NotNull(serverHandler);

            foreach (var message in serverHandler.MessagesReceived)
            {
                foreach (var file in list)
                {
                    if (message.AffectedSopInstanceUid.Equals(file[DicomTags.SopInstanceUid].ToString()))
                    {
                        Assert.IsTrue(message.DataSet.Equals(file));
                    }
                }
            }

            // StopListening
            DicomServer.StopListening(serverParameters);
        }
        /// <summary>
        /// Gets the list of instances to be sent from the study xml
        /// </summary>
        /// <returns></returns>
        protected override IEnumerable <StorageInstance> GetStorageInstanceList()
        {
            IList <WorkQueueUid> seriesList = WorkQueueUidList;

            Platform.CheckForNullReference(StorageLocation, "StorageLocation");

            var list = new List <StorageInstance>();

            // We alread moved the series
            if (WorkQueueItem.Data != null && seriesList.Count == 0)
            {
                return(list);
            }

            string   studyPath = StorageLocation.GetStudyPath();
            StudyXml studyXml  = LoadStudyXml(StorageLocation);

            foreach (SeriesXml seriesXml in studyXml)
            {
                var matchingSops = new List <string>();
                // FOR SERIES LEVEL Move,
                // Check if the series is in the WorkQueueUid list. If it is not in the list then don't include it.
                if (seriesList.Count > 0)
                {
                    bool found = false;
                    foreach (WorkQueueUid uid in seriesList)
                    {
                        if (!string.IsNullOrEmpty(uid.SeriesInstanceUid))
                        {
                            if (uid.SeriesInstanceUid.Equals(seriesXml.SeriesInstanceUid))
                            {
                                found = true;
                                if (!string.IsNullOrEmpty(uid.SopInstanceUid))
                                {
                                    matchingSops.Add(uid.SopInstanceUid);
                                }
                                else
                                {
                                    matchingSops.Clear();
                                    break;
                                }
                            }
                        }
                    }
                    if (!found)
                    {
                        continue;                             // don't send this series
                    }
                }

                foreach (InstanceXml instanceXml in seriesXml)
                {
                    if (matchingSops.Count > 0)
                    {
                        bool found = matchingSops.Any(uid => uid.Equals(instanceXml.SopInstanceUid));
                        if (!found)
                        {
                            continue;                                 // don't send this sop
                        }
                    }

                    string seriesPath   = Path.Combine(studyPath, seriesXml.SeriesInstanceUid);
                    string instancePath = Path.Combine(seriesPath, instanceXml.SopInstanceUid + ServerPlatform.DicomFileExtension);
                    var    instance     = new StorageInstance(instancePath)
                    {
                        SopClass          = instanceXml.SopClass,
                        TransferSyntax    = instanceXml.TransferSyntax,
                        SopInstanceUid    = instanceXml.SopInstanceUid,
                        StudyInstanceUid  = studyXml.StudyInstanceUid,
                        SeriesInstanceUid = seriesXml.SeriesInstanceUid,
                        PatientId         = studyXml.PatientId,
                        PatientsName      = studyXml.PatientsName
                    };

                    list.Add(instance);
                }
            }

            return(list);
        }
        private void OnImageSent(object sender, StorageInstance storageInstance)
        {
            var scu = sender as ImageViewerStorageScu;

            Progress.TotalImagesToSend = _scu.TotalSubOperations;

            if (storageInstance.SendStatus.Status == DicomState.Success)
            {
                Progress.SuccessSubOperations++;
                Progress.StatusDetails = string.Empty;
            }
            else if (storageInstance.SendStatus.Status == DicomState.Failure)
            {
                Progress.FailureSubOperations++;
                Progress.StatusDetails = storageInstance.ExtendedFailureDescription;
                if (String.IsNullOrEmpty(Progress.StatusDetails))
                {
                    Progress.StatusDetails = storageInstance.SendStatus.ToString();
                }

                if (_scu != null)
                {
                    _scu.FailureDescription = Progress.StatusDetails;
                }
            }
            else if (storageInstance.SendStatus.Status == DicomState.Warning)
            {
                Progress.WarningSubOperations++;
                Progress.StatusDetails = storageInstance.ExtendedFailureDescription;
                if (String.IsNullOrEmpty(Progress.StatusDetails))
                {
                    Progress.StatusDetails = storageInstance.SendStatus.ToString();
                }

                if (_scu != null)
                {
                    _scu.FailureDescription = Progress.StatusDetails;
                }
            }

            Proxy.UpdateProgress();

            if (PublishFiles != null &&
                PublishFiles.DeletionBehaviour != DeletionBehaviour.None)
            {
                bool deleteFile = false;
                if (storageInstance.SendStatus.Status != DicomState.Failure)
                {
                    deleteFile = true;
                }
                else if (PublishFiles.DeletionBehaviour == DeletionBehaviour.DeleteAlways)
                {
                    deleteFile = true;
                }

                if (deleteFile)
                {
                    try
                    {
                        FileUtils.Delete(storageInstance.Filename);
                    }
                    catch (Exception e)
                    {
                        Platform.Log(LogLevel.Warn, e,
                                     "Failed to delete file after storage: {0}",
                                     storageInstance.Filename);
                    }
                }
            }
        }
        void storageScu_StoreCompleted(object sender, StorageInstance e)
        {
            StorageScu storageScu = (StorageScu)sender;

            System.Diagnostics.Debug.Write(e.SendStatus);
        }
Esempio n. 16
0
 public Set()
 {
     StorageInstance = JsonStorage.GetInstance();
     MainStorage     = StorageInstance.Read();
 }
Esempio n. 17
0
 public void TestStart()
 {
     storage = null;
     scriptRunner = new ScriptRunner();
     scriptRunner.Run();
 }
Esempio n. 18
0
 public void CanCreateStorage()
 {
     scriptRunner.Execute("this.Storage = require('storage');");
     storage = scriptRunner.Execute("new Storage()") as StorageInstance;
     storage.Should().Not.Be.Null();
 }
Esempio n. 19
0
 public void CanCreateAbsolutePositionedStorage()
 {
     scriptRunner.Execute("this.Storage = require('storage');");
     storage = scriptRunner.Execute("new Storage('egrss', true)") as StorageInstance;
     storage.Should().Not.Be.Null();
 }