Example #1
0
        public static void RegisterInterfaces()
        {
#if TUTORIAL_CUSTOM_DATABASE
            // The 'RegisterInterfaces' method is implemented as part of the "Changing the LEAD HTML5 Medical Viewer to use a different database schema" tutorial.
            // For the tutorial, 'RegisterInterfaces' is used to register custom classes that you define to interact with a custom database.
            // For the shipping version, the 'RegisterInterfaces' does nothing
            //
            // Since the WCF services are stateless (below), this method is called before using any of the services.
            // The AddinsFactory class is used to generate the addins required by each of the services.
            // So the AddinsFactory constructor calls 'RegisterInterfaces' if it has not already been called.
            //
            // WCF Services:
            // * AuthenticationService
            // * ObjectRetrieveService
            // * PacsQueryService
            // * PACSRetrieveService
            // * StoreService
            //
            // The MyPatientInfo, MyStudyInfo, MySeriesInfo, and MyInstanceInfo classes are used for extracting DICOM data from a System.Data.DataRow.
            // The MyStorageSqlDbDataAccessAgent and MyStorageDataAccessConfigurationView classes are used for accessing your custom database
            // The MyPatient, MyStudy, MySeries, and MyInstance classes are used to generate the WHERE statement of the database query
            // For more details, see the "Changing the LEAD HTML5 Medical Viewer to use a different database schema" tutorial.

            if (!DataAccessServiceLocator.IsRegistered <IPatientInfo>())
            {
                DataAccessServiceLocator.Register <IPatientInfo>(new MyPatientInfo());
            }

            if (!DataAccessServiceLocator.IsRegistered <IStudyInfo>())
            {
                DataAccessServiceLocator.Register <IStudyInfo>(new MyStudyInfo());
            }

            if (!DataAccessServiceLocator.IsRegistered <ISeriesInfo>())
            {
                DataAccessServiceLocator.Register <ISeriesInfo>(new MySeriesInfo());
            }

            if (!DataAccessServiceLocator.IsRegistered <IInstanceInfo>())
            {
                DataAccessServiceLocator.Register <IInstanceInfo>(new MyInstanceInfo());
            }

            if (!DataAccessServices.IsDataAccessServiceRegistered <IStorageDataAccessAgent3>())
            {
                System.Configuration.Configuration configuration     = ServiceUtils.GetGlobalPacsConfig();
                IStorageDataAccessAgent3           storageDataAccess = DataAccessFactory.GetInstance(new MyStorageDataAccessConfigurationView(configuration, ServiceUtils.ProductNameStorageServer, null)).CreateDataAccessAgent <IStorageDataAccessAgent3>();
                DataAccessServices.RegisterDataAccessService <IStorageDataAccessAgent3>(storageDataAccess);
            }

            RegisteredEntities.AddItem(RegisteredEntities.PatientEntityName, typeof(MyPatient));
            RegisteredEntities.AddItem(RegisteredEntities.StudyEntityName, typeof(MyStudy));
            RegisteredEntities.AddItem(RegisteredEntities.SeriesEntityName, typeof(MySeries));
            RegisteredEntities.AddItem(RegisteredEntities.InstanceEntityName, typeof(MyInstance));
#endif
        }
Example #2
0
        public void RunThread(IExternalStoreDataAccessAgent externalStoreAgent, IStorageDataAccessAgent storageAgent)
        {
            DicomUtilities.DebugString(DebugStringOptions.ShowCounter, "ExternalStoreProcess.Run");
            string message;
            ICrud  crud = _Options.GetCrud(_externalStoreGuid);

            if (crud == null)
            {
                message = string.Format("ExternalStore ICrud interface not found:ExternalStoreGuid[{0}], FriendlyName[{1}]", _externalStoreGuid, FriendlyName);
                Logger.Global.SystemMessage(LogType.Error, message, _serviceName);
                return;
            }

            if (!DataAccessServiceLocator.IsRegistered(_externalStoreGuid))
            {
                DataAccessServiceLocator.Register(crud, _externalStoreGuid);
            }

            lock (_externalStoreLock)
            {
                ExternalStoreInstance[] instances = externalStoreAgent.GetExternalStoreList();

                if (instances.Length > 0)
                {
                    message = string.Format("{0} {1} found to send to external store", instances.Length, "dataset(s)");
                    Logger.Global.SystemMessage(LogType.Information, message, _serviceName);
                }

                ExternalStoreItem item = _Options.GetExternalStoreItem(_externalStoreGuid);
                if (item == null)
                {
                    return;
                }

                if (instances.Length > 0 && item.Verify)
                {
                    message = string.Format("{0} {1} will be verified after sending to external store", instances.Length, instances.Length == 1 ? "instance" : "instances");
                    Logger.Global.SystemMessage(LogType.Information, message, _serviceName);
                }

                foreach (ExternalStoreInstance instance in instances)
                {
                    if (_cancelExternalStore)
                    {
                        _cancelExternalStore = false;
                        Logger.Global.SystemMessage(LogType.Information, string.Format("Cancelling External Store Process", instance.ReferencedFile), _serviceName);
                        break;
                    }

                    try
                    {
                        if (!File.Exists(instance.ReferencedFile))
                        {
                            message = string.Format("Referenced file doesn't exist.  Instance ({0}) will be removed from external store queue. [{1}]", instance.SOPInstanceUID, instance.ReferencedFile);
                            Logger.Global.SystemMessage(LogType.Warning, message, _serviceName);

                            // TODO: fix this up -- assign a valid token
                            externalStoreAgent.SetInstanceExternalStored(instance.SOPInstanceUID, string.Empty, string.Empty, DateTime.Now, null);
                            continue;
                        }

                        string storeToken;
                        string externalStoreGuid;
                        if (ExternalStoreInstance(crud, instance, out storeToken, out externalStoreGuid))
                        {
                            DateTime?expires           = null;
                            DateTime externalStoreDate = DateTime.Now;

                            if (item.ImageHold != null && item.ImageHold != 0)
                            {
                                switch (item.HoldInterval)
                                {
                                case HoldInterval.Days:
                                    expires = externalStoreDate.AddDays(item.ImageHold.Value);
                                    break;

                                case HoldInterval.Months:
                                    expires = externalStoreDate.AddMonths(item.ImageHold.Value);
                                    break;

                                default:
                                    expires = externalStoreDate.AddYears(item.ImageHold.Value);
                                    break;
                                }
                            }
                            if (!item.Verify || VerifyInstance(crud, storeToken))
                            {
                                if (item.Verify)
                                {
                                    message = string.Format("SOP instance successfully verified: {0}", instance.SOPInstanceUID);
                                    Logger.Global.SystemMessage(LogType.Information, message, _serviceName);
                                }

                                externalStoreAgent.SetInstanceExternalStored(instance.SOPInstanceUID, externalStoreGuid, storeToken, externalStoreDate, expires);
                                externalStoreAgent.SetToken(instance.SOPInstanceUID, storeToken);
                                externalStoreAgent.SetExternalStoreGuid(instance.SOPInstanceUID, externalStoreGuid);
                            }
                            else
                            {
                                message = string.Format("Failed to verify SOP instance: {0}. Instance not marked as externally stored.", instance.SOPInstanceUID);
                                Logger.Global.SystemMessage(LogType.Error, message, _serviceName);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Global.SystemMessage(LogType.Error, string.Format("{0}", e.Message), _serviceName);
                    }
                }
            }
        }