Exemple #1
0
        public DicomCommandStatusType OnNAction
        (
            DicomClient client,
            byte presentationId,
            int messageID,
            string affectedClass,
            string instance,
            int action,
            DicomDataSet request,
            DicomDataSet response
        )
        {
            ClientSession clientSession;
            INActionClientSessionProxy sessionProxy;
            DicomCommand mediaActionCommand;


            clientSession = new ClientSession(client);
            sessionProxy  = new NActionClientSessionProxy(clientSession, presentationId, messageID, affectedClass, instance, action, response);

            //by default this will return a strategy which switch between the actual Action command based on the Action Type
            mediaActionCommand = DicomCommandFactory.GetInstance( ).CreateNActionCommand(sessionProxy, request);

#if DEBUG
            if (mediaActionCommand is MediaCreationNActionCommandStrategy)
            {
                System.Diagnostics.Trace.WriteLine((( MediaCreationNActionCommandStrategy )mediaActionCommand).StrategyCommand.ToString( ));
            }
#endif

            _clientSession = clientSession;
            _sessionProxy  = sessionProxy;

            clientSession.NActionResponse += new EventHandler <NActionResponseEventArgs> (clientSession_NActionResponse);

            clientSession.ProcessNActionRequest(presentationId, messageID, affectedClass, instance, action, mediaActionCommand).WaitOne( );

            return(_status);
        }
        public DicomCommandStatusType OnNAction(DicomClient Client, byte PresentationId, int MessageID, string AffectedClass, string Instance, int Action, DicomDataSet Request, DicomDataSet Response)
        {
            ClientSession clientSession             = null;
            INActionClientSessionProxy sessionProxy = null;
            DicomCommand patientUpdateCommand       = null;

            CompositeInstanceDataSet.InstanceRow[] instanceRows = null;

            if (_TemporaryDirectory == null)
            {
                _TemporaryDirectory = Client.Server.TemporaryDirectory;
            }

            if (Instance != PatientUpdaterConstants.UID.PatientUpdateInstance)
            {
                return(DicomCommandStatusType.InvalidObjectInstance);
            }

            if (clientSession != null)
            {
                clientSession.NActionResponse -= clientSession_NActionResponse;
                clientSession = null;
            }

            clientSession = new ClientSession(Client);
            clientSession.NActionResponse += new EventHandler <NActionResponseEventArgs>(clientSession_NActionResponse);
            sessionProxy         = new NActionClientSessionProxy(clientSession, PresentationId, MessageID, AffectedClass, Instance, Action, Response);
            patientUpdateCommand = DicomCommandFactory.GetInstance().CreateNActionCommand(sessionProxy, Request);

            _ClientSession = clientSession;
            _SessionProxy  = sessionProxy;


            //
            // If we are deleting we need to get the instance rows
            //
            List <string> studyInstanceUids;

            instanceRows = GetInstanceRows(Action, Request, out studyInstanceUids);

            ConfigureCommand(patientUpdateCommand as PatientUpdaterCommand);
            _ClientSession.ProcessNActionRequest(PresentationId, MessageID, AffectedClass, Instance, Action, patientUpdateCommand).WaitOne();

            if (_Status == DicomCommandStatusType.Success)
            {
                //
                // We need to delete the dicom files according to the user options
                //
                if (Action == PatientUpdaterConstants.Action.DeletePatient || Action == PatientUpdaterConstants.Action.DeleteSeries)
                {
                    if (instanceRows != null)
                    {
                        DicomFileDeleter deleter = new DicomFileDeleter();

                        try
                        {
                            StorageAddInsConfiguration storageSettings = Module.StorageConfigManager.GetStorageAddInsSettings();

                            deleter.DicomFileDeleted      += new EventHandler <Leadtools.Medical.Winforms.EventBrokerArgs.DicomFileDeletedEventArgs>(deleter_DicomFileDeleted);
                            deleter.DicomFileDeleteFailed += new EventHandler <Leadtools.Medical.Winforms.EventBrokerArgs.DicomFileDeletedEventArgs>(deleter_DicomFileDeleteFailed);
                            if (storageSettings != null)
                            {
                                deleter.DeleteFilesOnDatabaseDelete = storageSettings.StoreAddIn.DeleteFiles;
                                deleter.BackupFilesOnDatabaseDelete = storageSettings.StoreAddIn.BackupFilesOnDelete;
                                deleter.BackupFilesOnDeleteFolder   = storageSettings.StoreAddIn.DeleteBackupLocation;
                            }
                            deleter.Delete(null, instanceRows);
                        }
                        catch (Exception e)
                        {
                            Logger.Global.Error(Module.Source, "[Patient Updater] " + e.Message);
                        }
                        finally
                        {
                            deleter.DicomFileDeleted      -= deleter_DicomFileDeleted;
                            deleter.DicomFileDeleteFailed -= deleter_DicomFileDeleteFailed;
                        }
                    }
                }

                //
                // If auto update is enabled we need to forward this message to associated ae title
                //
                if (Module.Options != null && Module.Options.EnableAutoUpdate && Module.UpdateQueue != null)
                {
                    AutoUpdateItem item = new AutoUpdateItem(Client.AETitle)
                    {
                        Action = Action, ClientAE = Client.Server.AETitle
                    };

                    if (Action == PatientUpdaterConstants.Action.MergePatient && (instanceRows != null))
                    {
                        MergePatient mergePatientData = Request.Get <MergePatient>(null);
                        foreach (string studyInstanceUid in studyInstanceUids)
                        {
                            mergePatientData.ReferencedStudySequence.Add(new StudyInstanceReference(studyInstanceUid));
                        }
                        mergePatientData.PatientToMerge.Clear();
                        Request.Set(mergePatientData);
                    }
                    else if (studyInstanceUids.Count > 0)
                    {
                        DeletePatient deletePatientData = Request.Get <DeletePatient>(null);
                        foreach (string studyInstanceUid in studyInstanceUids)
                        {
                            deletePatientData.ReferencedStudySequence.Add(new StudyInstanceReference(studyInstanceUid));
                        }
                        Request.Set(deletePatientData);
                    }


                    // Request.InsertElementAndSetValue(DicomTag.ReferencedStudySequence)
                    item.Dicom = Request;

                    if (ShouldAutoUpdate(item.Action))
                    {
                        Module.UpdateQueue.AddItem(item);
                    }
                }
            }
            return(_Status);
        }