Esempio n. 1
0
 private void OnApplySearch ( MatchingParameterCollection query ) 
 {
    if ( null != PerformSearch )
    {
       PerformSearch ( this, new ApplySearchEventArgs ( query ) ) ;
    }
 }
Esempio n. 2
0
        private CompositeInstanceDataSet GetReferencedCompositeInstancesAndFillInstanceProfiles
        (
            Dictionary <string, string> instanceSopProfileName
        )
        {
            MatchingParameterCollection matchingCollection;
            MatchingParameterList       matchingList;


            matchingCollection = new MatchingParameterCollection( );

            foreach (MediaCreationReferencedSop referencedSop in MediaObject.ReferencedSopSequence)
            {
                matchingList = new MatchingParameterList( );

                matchingCollection.Add(matchingList);

                ICatalogEntity instanceEntity = RegisteredEntities.GetInstanceEntity(referencedSop.SopInstance.ReferencedSopInstanceUid);
                matchingList.Add(instanceEntity);

                instanceSopProfileName.Add(referencedSop.SopInstance.ReferencedSopInstanceUid,
                                           referencedSop.RequestedMediaApplicationProfile);
            }

            return(StorageService.QueryCompositeInstances(matchingCollection).ToCompositeInstanceDataSet());
        }
Esempio n. 3
0
        protected override void OnDoWork(DoWorkEventArgs e)
        {
            MatchingParameterCollection mpc = new MatchingParameterCollection();
            DataSet   images         = _dataAccessAgent.QueryCompositeInstances(mpc);
            DataTable imageDataTable = images.Tables[DataTableHelper.InstanceTableName];

            _dataAccessAgent.DeleteInstance(mpc);
#if (LEADTOOLS_V19_OR_LATER)
            if (_dataAccessAgent3 != null && _dataAccessAgent3.HangingProtocolSupported)
            {
                try
                {
                    DataSet   hangingProtocolDataSet   = _dataAccessAgent3.QueryHangingProtocol(mpc);
                    DataTable hangingProtocolDataTable = hangingProtocolDataSet.Tables[DataTableHelper.HangingProtocolTableName];
                    imageDataTable.Merge(hangingProtocolDataTable);

                    _dataAccessAgent3.DeleteHangingProtocol(mpc);
                }
                catch (Exception)
                {
                }
            }
#endif

            e.Result = imageDataTable;
        }
Esempio n. 4
0
        // This example builds a IDbCommand
        // for querying the MyPatient table
        // The generated WHERE clause contains PatientName and PatientSex
        public void MyExample()
        {
            MatchingParameterCollection matchingParamCollection = new MatchingParameterCollection();
            MatchingParameterList       matchingParamList       = new MatchingParameterList();

            MyPatient myPatient = new MyPatient();

            myPatient.PatientName = "Smith";
            myPatient.PatientSex  = "M";

            matchingParamList.Add(myPatient);
            matchingParamCollection.Add(matchingParamList);

            IDbCommand command = new SqlCommand();

            // This reads the storage catalog
            // Before you run this, make sure and add the following to your application configuration file

            //<configSections>
            //    <section name="xmlStorageCatalogSettings" type="Leadtools.Medical.Storage.DataAccessLayer.XmlStorageCatalogSettings, Leadtools.Medical.Storage.DataAccessLayer" />
            //</configSections>
            StorageCatalog myCatalog = new StorageCatalog();

            Collection <CatalogElement[]> catalogElements = CatalogDescriptor.GetElementsCollection(matchingParamCollection, myCatalog, true);

            PreparePatientsQueryCommand(command, catalogElements, ExtraQueryOptions.Typical);

            // The 'WHERE' clause of command.CommandText is the following:
            //    WHERE ( (  MyPatientTable.PatientName LIKE  'Smith' ) AND (  MyPatientTable.PatientSex LIKE  'M' ) )
            Console.WriteLine(command.CommandText);
        }
Esempio n. 5
0
        public WorklistResult[] QueryWorklist(string userName, WorklistQueryOptions options)
        {
            List <WorklistResult>       results            = new List <WorklistResult>();
            MatchingParameterCollection matchingCollection = new MatchingParameterCollection();
            MatchingParameterList       matchingList       = new MatchingParameterList();
            MWLDataset dataset = null;


            matchingCollection.Add(matchingList);
            AddInsUtils.FillWorklistMatchingParameters(options, matchingList);
            dataset = _DataAccessAgent.QueryModalityWorklists(matchingCollection, new StringCollection());
            foreach (MWLDataset.ScheduledProcedureStepRow row in dataset.ScheduledProcedureStep.Rows)
            {
                WorklistResult result = new WorklistResult();

                result.ScheduledProcedureStep = new WorklistScheduledProcedureStep();
                result.Patient = new WorklistPatient();
                row.CopyTo(result.ScheduledProcedureStep);

                row.RequestedProcedureRowParent.ImagingServiceRequestRow.PatientRowParent.CopyTo(result.Patient);
                results.Add(result);

                result.ImagingServiceRequest = new ImagingServiceRequest();
                row.RequestedProcedureRowParent.ImagingServiceRequestRow.CopyTo(result.ImagingServiceRequest);

                result.RequestedProcedure = new WorklistRequestedProcedure();
                row.RequestedProcedureRowParent.CopyTo(result.RequestedProcedure);
            }

            return(results.ToArray());
        }
        MatchingParameterCollection GenerateMatchingParameterCollection(ViewGenerator.ViewDataRow metadataRow, out string rowKeyValue, out string rowKeyName, out string viewName)
        {
            DataRow originalRow = metadataRow.OriginalRow;
            MatchingParameterCollection matchingParamCollection = new MatchingParameterCollection();
            MatchingParameterList       matchingParamList       = new MatchingParameterList();

            matchingParamCollection.Add(matchingParamList);

            if (string.Compare(originalRow.Table.TableName, DataTableHelper.InstanceTableName) == 0)
            {
                string         sSopInstanceUid = RegisteredDataRows.InstanceInfo.GetElementValue(originalRow, DicomTag.SOPInstanceUID);
                ICatalogEntity imageInstance   = RegisteredEntities.GetInstanceEntity(sSopInstanceUid);

                rowKeyValue = sSopInstanceUid;
                rowKeyName  = "SOPInstanceUID";
                viewName    = "Images";

                matchingParamList.Add(imageInstance);
            }
            else if (string.Compare(originalRow.Table.TableName, DataTableHelper.SeriesTableName) == 0)
            {
                string         sSeriesInstanceUid = RegisteredDataRows.SeriesInfo.GetElementValue(originalRow, DicomTag.SeriesInstanceUID);
                ICatalogEntity seriesEntity       = RegisteredEntities.GetSeriesEntity(sSeriesInstanceUid);

                rowKeyValue = sSeriesInstanceUid;
                rowKeyName  = "SeriesInstanceUID";
                viewName    = "Series";

                matchingParamList.Add(seriesEntity);
            }
            else if (string.Compare(originalRow.Table.TableName, DataTableHelper.StudyTableName) == 0)
            {
                string         sStudyInstanceUid = RegisteredDataRows.StudyInfo.GetElementValue(originalRow, DicomTag.StudyInstanceUID);
                ICatalogEntity studyEntity       = RegisteredEntities.GetStudyEntity(sStudyInstanceUid);

                rowKeyValue = sStudyInstanceUid;
                rowKeyName  = "StudyInstanceUID";
                viewName    = "Studies";

                matchingParamList.Add(studyEntity);
            }
            else if (string.Compare(originalRow.Table.TableName, DataTableHelper.PatientTableName) == 0)
            {
                string         sPatientId    = RegisteredDataRows.PatientInfo.GetElementValue(originalRow, DicomTag.PatientID);
                ICatalogEntity patientEntity = RegisteredEntities.GetPatientEntity(sPatientId);

                rowKeyValue = sPatientId;
                rowKeyName  = "PatientId";
                viewName    = "Patients";

                matchingParamList.Add(patientEntity);
            }
            else
            {
                throw new ApplicationException("Row is not a valid DICOM format.");
            }

            return(matchingParamCollection);
        }
Esempio n. 7
0
        /// <summary>
        /// High-level command that deletes study rows from the 'MyStudy' database tabled based on the search criteria
        /// </summary>
        /// <param name="matchingEntitiesCollection">Contains the query parameters that are used to generate the WHERE statement</param>
        /// <returns>Number of rows deleted</returns>
        /// <remarks>
        /// Uses the PrepareDeleteStudiesCommand() override.
        /// These commands also delete the corresponding rows in the tables above it in the hierarchy
        /// </remarks>
        public override int DeleteStudy(MatchingParameterCollection matchingEntitiesCollection)
        {
            int studyCount = MyDeleteEntity(matchingEntitiesCollection, PrepareDeleteStudiesCommand);

            MyDeleteEntity(PrepareDeletePatientsNoChildStudiesCommand);

            return(studyCount);
        }
Esempio n. 8
0
 /// <summary>
 /// Deletes DICOM instances from the storage databases based on what patients the user has access to
 /// </summary>
 /// <param name="matchingEntitiesCollection"></param>
 /// <param name="user"></param>
 /// <param name="groups"></param>
 /// <returns></returns>
 public Int32 DeleteInstance(MatchingParameterCollection matchingEntitiesCollection, string user, string[] groups)
 {
     //check comments for the FiltersAdded method
     if (FiltersAdded(matchingEntitiesCollection, user, groups))
     {
         return(StorageDataAccess.DeleteInstance(matchingEntitiesCollection));
     }
     return(0);
 }
Esempio n. 9
0
        private ClientQueryDataSet.ImagesRow[] FillImages
        (
            ClientQueryDataSet.SeriesRow seriesRow,
            ClientQueryDataSet informationDS
        )
        {
            IStorageDataAccessAgent     storageDataAccess;
            MatchingParameterCollection matchingcollection;
            MatchingParameterList       matchingList;

            Leadtools.Medical.Storage.DataAccessLayer.MatchingParameters.Study  matchingStudy;
            Leadtools.Medical.Storage.DataAccessLayer.MatchingParameters.Series matchingSeries;
            List <ClientQueryDataSet.ImagesRow> imageRows;


            storageDataAccess = DataAccessServices.GetDataAccessService <IStorageDataAccessAgent> ( );

            if (null == storageDataAccess)
            {
                return(new ClientQueryDataSet.ImagesRow [] {});
            }

            matchingcollection = new MatchingParameterCollection( );
            matchingList       = new MatchingParameterList( );
            matchingStudy      = new Leadtools.Medical.Storage.DataAccessLayer.MatchingParameters.Study(seriesRow.StudyInstanceUID);
            matchingSeries     = new Leadtools.Medical.Storage.DataAccessLayer.MatchingParameters.Series(seriesRow.SeriesInstanceUID);

            matchingList.Add(matchingStudy);
            matchingList.Add(matchingSeries);
            matchingcollection.Add(matchingList);

            CompositeInstanceDataSet instances = storageDataAccess.QueryCompositeInstances(matchingcollection).ToCompositeInstanceDataSet();

            imageRows = new List <ClientQueryDataSet.ImagesRow> ( );

            foreach (CompositeInstanceDataSet.InstanceRow instance in instances.Instance)
            {
                ClientQueryDataSet.ImagesRow imageRow;


                imageRow = informationDS.Images.NewImagesRow( );

                imageRow.StudyInstanceUID  = seriesRow.StudyInstanceUID;
                imageRow.SeriesInstanceUID = seriesRow.SeriesInstanceUID;
                imageRow.SOPInstanceUID    = instance.SOPInstanceUID;
                imageRow.InstanceNumber    = instance.IsInstanceNumberNull( ) ? string.Empty : instance.InstanceNumber.ToString( );
                imageRow.SOPClassUID       = instance.IsSOPClassUIDNull( ) ? string.Empty : instance.SOPClassUID;

                informationDS.Images.AddImagesRow(imageRow);
                imageRows.Add(imageRow);

                __BurningImages.Add(imageRow);
            }

            return(imageRows.ToArray( ));
        }
Esempio n. 10
0
        /// <summary>
        /// High-level command that deletes study rows from the 'MyInstance' database tabled based on the search criteria
        /// </summary>
        /// <param name="matchingEntitiesCollection">Contains the query parameters that are used to generate the WHERE statement</param>
        /// <returns>Number of rows deleted</returns>
        /// <remarks>
        /// Uses the PrepareDeleteInstancesCommand() override.
        /// These commands also delete the corresponding rows in the tables above it in the hierarchy
        /// </remarks>
        public override int DeleteInstance(MatchingParameterCollection matchingEntitiesCollection)
        {
            int instancesCount = MyDeleteEntity(matchingEntitiesCollection, PrepareDeleteInstanceCommand);

            MyDeleteEntity(PrepareDeleteSeriesNoChildInstancesCommand);
            MyDeleteEntity(PrepareDeleteStudiesNoChildSeriesCommand);
            MyDeleteEntity(PrepareDeletePatientsNoChildStudiesCommand);

            return(instancesCount);
        }
Esempio n. 11
0
 /// <summary>
 /// Query series from storage database based on what patients the user has access to
 /// </summary>
 /// <param name="matchingEntitiesCollection"></param>
 /// <param name="user"></param>
 /// <param name="groups"></param>
 /// <returns></returns>
 public DataSet MinimumQuerySeries(MatchingParameterCollection matchingEntitiesCollection, string user, string[] groups)
 {
     if (FiltersAdded(matchingEntitiesCollection, user, groups))
     {
         SetMaxQueryResults(StorageDataAccess);
         DataSet ds = StorageDataAccess.MinimumQuerySeries(matchingEntitiesCollection);
         ResetMaxQueryResults();
         return(ds);
     }
     return(DataTableHelper.CreateTypedDataSet()); //CompositeInstanceDataSet ( ) ;
 }
Esempio n. 12
0
      private MatchingParameterCollection GetMatchingParameters(string sopInstanceUID)
      {
         MatchingParameterCollection matchingParamCollection = new MatchingParameterCollection();
         MatchingParameterList matchingParamList = new MatchingParameterList();
         // Instance instance = new Instance(sopInstanceUID);
         ICatalogEntity instance = RegisteredEntities.GetInstanceEntity(sopInstanceUID);

         matchingParamList.Add(instance);
         matchingParamCollection.Add(matchingParamList);
         return matchingParamCollection;
      }
Esempio n. 13
0
 public ServerInformationControl()
 {
     InitializeComponent();
     _sqlDatabaseList = new Dictionary <string, string>();
     _mpc             = new MatchingParameterCollection();
     _mpc.Add(new MatchingParameterList());
     progressBar.Visible = false;
     _Sorter.Order       = System.Windows.Forms.SortOrder.Ascending;
     listViewModules.ListViewItemSorter = _Sorter;
     LoadModules();
 }
Esempio n. 14
0
 /// <summary>
 /// Query studies from storage database based on what patients the user has access to
 /// </summary>
 /// <param name="matchingEntitiesCollection"></param>
 /// <param name="user"></param>
 /// <param name="groups"></param>
 /// <returns></returns>
 public DataSet QueryStudies(MatchingParameterCollection matchingEntitiesCollection, string user, string[] groups)
 {
     //check comments for the FiltersAdded method
     if (FiltersAdded(matchingEntitiesCollection, user, groups))
     {
         SetMaxQueryResults(StorageDataAccess);
         DataSet ds = StorageDataAccess.QueryStudies(matchingEntitiesCollection);
         ResetMaxQueryResults();
         return(ds);
     }
     return(DataTableHelper.CreateTypedDataSet()); // CompositeInstanceDataSet ( ) ;
 }
Esempio n. 15
0
        public static MWLDataset Find(this IWorklistDataAccessAgent accessAgent, params ICatalogEntity[] queries)
        {
            MatchingParameterCollection parameters = new MatchingParameterCollection();
            MatchingParameterList       matchList  = new MatchingParameterList();

            foreach (ICatalogEntity query in queries)
            {
                matchList.Add(query);
            }
            parameters.Add(matchList);
            return(accessAgent.FindPatientInformation(parameters));
        }
Esempio n. 16
0
        internal static string FindReferencedFile(
#if LEADTOOLS_V19_OR_LATER
            IExternalStoreDataAccessAgent externalStoreAgent,
#endif // #if LEADTOOLS_V19_OR_LATER
            string sopInstanceUID)
        {
            MatchingParameterCollection          mpc = new MatchingParameterCollection();
            MatchingParameterList                mpl = new MatchingParameterList();
            DataSet /*CompositeInstanceDataSet*/ instanceData;
            IStorageDataAccessAgent              agent = null;
            string referencedFile = string.Empty;

            if (DataAccessServices.IsDataAccessServiceRegistered <IStorageDataAccessAgent>())
            {
                agent = DataAccessServices.GetDataAccessService <IStorageDataAccessAgent>();
            }

            if (agent != null)
            {
                ICatalogEntity instanceEntity = RegisteredEntities.GetInstanceEntity(sopInstanceUID);
                mpl.Add(instanceEntity);
                mpc.Add(mpl);

                instanceData = agent.QueryCompositeInstances(mpc);
                if (instanceData.Tables[DataTableHelper.InstanceTableName].Rows.Count == 1)
                {
                    DataRow row = instanceData.Tables[DataTableHelper.InstanceTableName].Rows[0];
                    referencedFile = RegisteredDataRows.InstanceInfo.ReferencedFile(row);

#if (LEADTOOLS_V19_OR_LATER_MEDICAL_EXTERNAL_STORE) || (LEADTOOLS_V19_OR_LATER)
                    if (string.IsNullOrEmpty(referencedFile))
                    {
                        // If empty, it might be on the cloud
                        // Use DicomInstanceRetrieveExternalStoreCommand with cache set to true to copy it locally
                        if (externalStoreAgent == null)
                        {
                            if (DataAccessServices.IsDataAccessServiceRegistered <IExternalStoreDataAccessAgent>())
                            {
                                externalStoreAgent = DataAccessServices.GetDataAccessService <IExternalStoreDataAccessAgent>();
                            }
                        }

                        DicomInstanceRetrieveExternalStoreCommand c = new DicomInstanceRetrieveExternalStoreCommand(agent, externalStoreAgent, AddInsSession.ServiceDirectory, true);
                        DicomDataSet ds = c.GetDicomDataSet(row, out referencedFile);
                    }
#endif // (LEADTOOLS_V19_OR_LATER_MEDICAL_EXTERNAL_STORE) || (LEADTOOLS_V19_OR_LATER)
                }
            }
            return(referencedFile);
        }
        private void ValidateLicense(CancelStoreEventArgs e)
        {
            if (_License == null)
            {
                e.Cancel        = true;
                e.CancelMessage = "No valid license provided.";
            }
            else
            {
                if (_AccessAgent != null)
                {
                    string instance = string.Empty;
                    int    count;
                    MatchingParameterCollection mpc = new MatchingParameterCollection()
                    {
                        { new MatchingParameterList() }
                    };

                    if (_FeatureStudyCount != null)
                    {
                        instance = e.DataSet.GetValue <string>(DicomTag.StudyInstanceUID, string.Empty);
                        if (!_AccessAgent.IsStudyExists(instance))
                        {
                            count = _AccessAgent.FindStudiesCount(mpc);
                            if (_FeatureStudyCount.Counter > 0 && (count + 1) > _FeatureStudyCount.Counter)
                            {
                                e.Cancel        = true;
                                e.CancelMessage = string.Format("Max study limit reached, Study ({0}) not stored.  The license is restricted to storing {1} {2}.", instance, count, count == 1 ? "study" : "studies");
                                return;
                            }
                        }
                    }

                    if (_FeatureSeriesCount != null)
                    {
                        instance = e.DataSet.GetValue <string>(DicomTag.SeriesInstanceUID, string.Empty);
                        if (!_AccessAgent.IsSeriesExists(instance))
                        {
                            count = _AccessAgent.FindSeriesCount(mpc);
                            if (_FeatureSeriesCount.Counter > 0 && (count + 1) > _FeatureSeriesCount.Counter)
                            {
                                e.Cancel        = true;
                                e.CancelMessage = string.Format("Max series limit reached, Series ({0}) not stored.  The license is restricted to storing {1} series.", instance, count);
                                return;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 18
0
        private DataSet QueryCurrentPatient(string patientID)
        {
            MatchingParameterCollection matchingCollection;
            MatchingParameterList       matchingList;
            Patient patient;

            matchingCollection = new MatchingParameterCollection();
            matchingList       = new MatchingParameterList();
            patient            = new Patient(patientID);

            matchingList.Add(patient);
            matchingCollection.Add(matchingList);

            return(_DataAccessAgent.QueryCompositeInstances(matchingCollection));
        }
Esempio n. 19
0
        int Delete()
        {
            if (null == AuthorizedDataAccessAgent)
            {
                throw new ArgumentException();
            }

            int totalDeletedImagesCount = 0;

            MatchingParameterCollection matchingParamCollection;
            MatchingParameterList       matchingParamList;

            matchingParamCollection = new MatchingParameterCollection();
            matchingParamList       = new MatchingParameterList();

            matchingParamCollection.Add(matchingParamList);

            if (!string.IsNullOrEmpty(SOPInstanceUID))
            {
                Instance imageInstance = new Instance(SOPInstanceUID);

                matchingParamList.Add(imageInstance);
            }
            if (!string.IsNullOrEmpty(SeriesInstanceUID))
            {
                Series seriesEntity = new Series(SeriesInstanceUID);

                matchingParamList.Add(seriesEntity);
            }
            if (!string.IsNullOrEmpty(StudyInstanceUID))
            {
                Study studyEntity = new Study(StudyInstanceUID);

                matchingParamList.Add(studyEntity);
            }
            if (!string.IsNullOrEmpty(PatientID))
            {
                Patient patientEntity = new Patient(PatientID);

                matchingParamList.Add(patientEntity);
            }

            totalDeletedImagesCount = AuthorizedDataAccessAgent.DeleteInstance(matchingParamCollection, Owner, null);

            return(totalDeletedImagesCount);
        }
Esempio n. 20
0
        private DataSet QuerySeries(string[] instanceUIDs)
        {
            MatchingParameterCollection matchingCollection;
            MatchingParameterList       matchingList;

            matchingCollection = new MatchingParameterCollection();

            foreach (string instanceUID in instanceUIDs)
            {
                Series intance = new Series(instanceUID);

                matchingList = new MatchingParameterList();
                matchingList.Add(intance);
                matchingCollection.Add(matchingList);
            }

            return(_DataAccessAgent.QueryCompositeInstances(matchingCollection));
        }
Esempio n. 21
0
        private int MyDeleteEntity(MatchingParameterCollection matchingEntitiesCollection, PrepareEntityQueryCommandDelegate deleteHandler)
        {
            DbCommand command = DataProvider.CreateConnection().CreateCommand();
            Collection <CatalogElement[]> matchingParametersCollection = CatalogDescriptor.GetElementsCollection(matchingEntitiesCollection, StorageCatalog, true);

            deleteHandler(command, matchingParametersCollection, ExtraQueryOptions.Typical);

            command.Connection.Open();

            try
            {
                return((int)command.ExecuteNonQuery());
            }
            finally
            {
                command.Connection.Close();
            }
        }
Esempio n. 22
0
        private static string GetPatientName(MediaCreationManagement mediaObject)
        {
            string patientName;
            IStorageDataAccessAgent     dataAccess;
            MatchingParameterCollection matchingCollection;
            MatchingParameterList       matchingList;
            CompositeInstanceDataSet    compositeInstance;


            patientName        = string.Empty;
            dataAccess         = DataAccessServices.GetDataAccessService <IStorageDataAccessAgent> ( );
            matchingCollection = new MatchingParameterCollection( );
            matchingList       = new MatchingParameterList( );
            // Instance matchingInstance   = new Instance ( mediaObject.ReferencedSopSequence [ 0 ].SopInstance.ReferencedSopInstanceUid ) ;
            ICatalogEntity matchingInstance = RegisteredEntities.GetInstanceEntity(mediaObject.ReferencedSopSequence [0].SopInstance.ReferencedSopInstanceUid);

            if (null == dataAccess)
            {
                dataAccess = DataAccessFactory.GetInstance(new StorageDataAccessConfigurationView( )).CreateDataAccessAgent <IStorageDataAccessAgent> ( );
            }

            matchingCollection.Add(matchingList);
            matchingList.Add(matchingInstance);

            compositeInstance = dataAccess.QueryCompositeInstances(matchingCollection).ToCompositeInstanceDataSet();

            if (!string.IsNullOrEmpty(compositeInstance.Patient [0].FamilyName))
            {
                patientName += compositeInstance.Patient [0].FamilyName;
            }

            if (!string.IsNullOrEmpty(compositeInstance.Patient [0].GivenName))
            {
                if (!string.IsNullOrEmpty(patientName))
                {
                    patientName += ", ";
                }

                patientName += compositeInstance.Patient [0].GivenName;
            }

            return(patientName);
        }
Esempio n. 23
0
        /// <summary>
        /// This is the main method that evaluates which patient a user/groups have access to then add them into the matching parameters
        /// </summary>
        /// <param name="matchingEntitiesCollection"></param>
        /// <param name="user"></param>
        /// <param name="groups"></param>
        /// <returns></returns>
        private bool FiltersAdded(MatchingParameterCollection matchingEntitiesCollection, string user, string[] groups)
        {
#if LEADTOOLS_V19_OR_LATER
            if (!EnablePatientRestriction)
            {
                return(true);
            }
#endif
            //if the user has the built-in Admin permission then it has access to all patients (this is legacy, usually there should be no permission called "Admin")
            if (PermissionManagementDataAccess.UserHasPermission("Admin", user) || InRole(user, "Administrators"))
            {
                return(true);
            }

            //query the patient IDS a user have access to
            List <string> patientIds = PatientRightsDataAccess.GetPatientIDs(user, groups);

            if (patientIds == null)
            {
                return(false);
            }

            if (patientIds.Count == 0)
            {
                //if user has no patients assigned then no access to anything
                return(false);
            }


            //add the patient IDs into the matching parameters, when the query runs these IDs will be combined with an OR
            foreach (MatchingParameterList matchingList in matchingEntitiesCollection)
            {
                Patient patient = new Patient( );

                //this join here for patient IDs produce the OR operator
                patient.PatientID = string.Join("\\", patientIds.ToArray( ));

                matchingList.Add(patient);
            }

            return(true);
        }
        public int GetSelectedInstanceCount(ViewGenerator.ViewDataRow[] metadataRows)
        {
            int totalMetadataCount = 0;

            string rowKeyValue;
            string rowKeyName;
            string viewName;

            // Get total count
            totalMetadataCount = 0;
            foreach (ViewGenerator.ViewDataRow metadataRow in metadataRows)
            {
                MatchingParameterCollection matchingParamCollection = GenerateMatchingParameterCollection(metadataRow, out rowKeyValue, out rowKeyName, out viewName);
                DataRow[] rows            = null;
                DataSet   metadataDataSet = metadataDataSet = _dataAccessAgent4.QueryCompositeInstances(matchingParamCollection);
                rows = metadataDataSet.Tables[DataTableHelper.InstanceTableName].Select();
                totalMetadataCount += rows.Count();
            }
            return(totalMetadataCount);
        }
Esempio n. 25
0
        private static DicomDataSet GetFirstReferencedInstanceDataSet
        (
            IStorageDataAccessAgent dataAccess,
            MediaCreationManagement mediaObject)
        {
            MatchingParameterCollection matchingCollection;
            MatchingParameterList       matchingList;
            CompositeInstanceDataSet    compositeInstance;


            matchingCollection = new MatchingParameterCollection( );
            matchingList       = new MatchingParameterList( );
            // Instance instance           = new Instance ( mediaObject.ReferencedSopSequence [ 0 ].SopInstance.ReferencedSopInstanceUid ) ;
            ICatalogEntity instance = RegisteredEntities.GetInstanceEntity(mediaObject.ReferencedSopSequence [0].SopInstance.ReferencedSopInstanceUid);


            matchingCollection.Add(matchingList);
            matchingList.Add(instance);

            compositeInstance = dataAccess.QueryCompositeInstances(matchingCollection).ToCompositeInstanceDataSet();

            if (compositeInstance.Instance.Count > 0)
            {
                DicomDataSet ds;


                ds = new DicomDataSet( );

                ds.Load(compositeInstance.Instance [0].ReferencedFile, DicomDataSetLoadFlags.None);

                return(ds);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 26
0
        // This example is a test to build all queries
        public void MySampleQueries()
        {
            MatchingParameterCollection matchingParamCollection = new MatchingParameterCollection();
            MatchingParameterList       matchingParamList       = new MatchingParameterList();

            matchingParamCollection.Add(matchingParamList);

            StorageCatalog myCatalog = new StorageCatalog();
            Collection <CatalogElement[]> catalogElements = CatalogDescriptor.GetElementsCollection(matchingParamCollection, myCatalog, true);

            IDbCommand command = new SqlCommand();

            PreparePatientsQueryCommand(command, catalogElements, ExtraQueryOptions.Typical);
            PrepareStudiesQueryCommand(command, catalogElements, ExtraQueryOptions.Typical);
            PrepareSeriesQueryCommand(command, catalogElements, ExtraQueryOptions.Typical);
            PrepareInstanceQueryCommand(command, catalogElements, ExtraQueryOptions.Typical);

            PrepareDeletePatientsCommand(command, catalogElements, ExtraQueryOptions.Typical);
            PrepareDeleteStudiesCommand(command, catalogElements, ExtraQueryOptions.Typical);
            PrepareDeleteSeriesCommand(command, catalogElements, ExtraQueryOptions.Typical);
            PrepareDeleteInstanceCommand(command, catalogElements, ExtraQueryOptions.Typical);

            PrepareDeletePatientsNoChildStudiesCommand(command);
            PrepareDeleteStudiesNoChildSeriesCommand(command);
            PrepareDeleteSeriesNoChildInstancesCommand(command);

            DeletePatient(matchingParamCollection);
            DeleteStudy(matchingParamCollection);
            DeleteSeries(matchingParamCollection);
            DeleteInstance(matchingParamCollection);

            PrepareIsPatientExistsCommand(command, "1111");
            PrepareIsStudyExistsCommand(command, "2222");
            PrepareIsSeriesExistsCommand(command, "3333");
            PrepareIsInstanceExistsCommand(command, "4444");
        }
Esempio n. 27
0
 void btnSearch_Click(object sender, EventArgs e)
 {
    try
    {
       MatchingParameterCollection mp = new MatchingParameterCollection();
       if (PrepareSearch == null)
       {
          ActiveSearch.PrepareSearchDefault(mp);
       }
       else
       {
          PrepareSearch(mp);
       }
       OnApplySearch(mp);
    }
    catch (Exception exception)
    {
       Messager.ShowError(this, exception);
    }
    finally
    {
       this.Cursor = Cursors.Default;
    }
 }
Esempio n. 28
0
        private void SendCopy(AutoCopyItem item)
        {
            AeInfoExtended[] aes   = _aeManagementAgent.GetRelatedAeTitles(item.SourceAE, Module.AUTOCOPY_RELATION);
            StoreScu         store = new StoreScu();

            Module.InitializeDicomSecurity(false);
            StoreScu storeSecure = null;

            DicomOpenSslVersion dicomOpenSslVersion = DicomNet.GetOpenSslVersion();

            if (dicomOpenSslVersion.IsAvailable)
            {
                storeSecure = new StoreScu(Module._Server.TemporaryDirectory, DicomNetSecurityMode.Tls, Module._openSslOptions);
                Module.SetCiphers(storeSecure);
            }

            DicomScp scp = null;

            string[] sopInstances = item.Datasets.ToArray();

            if (aes == null || aes.Length == 0)
            {
                return;
            }

            string clientAe = Module.Options.UseCustomAE ? Module.Options.AutoCopyAE : item.ClientAE;

            AddEventHandlers(store, clientAe);
            AddEventHandlers(storeSecure, clientAe);

            foreach (AeInfoExtended ae in aes)
            {
#if LEADTOOLS_V20_OR_LATER
                // Update dbo.AeInfo.LastAccessDate to Date.Now
                ae.LastAccessDate = DateTime.Now;
                _aeManagementAgent.Update(ae.AETitle, ae);
#endif

                bool useTls = ae.ClientPortUsage == ClientPortUsageType.Secure || ((ae.ClientPortUsage == ClientPortUsageType.SameAsServer) && (Module._Server.Secure));
                useTls = (useTls && dicomOpenSslVersion.IsAvailable);

                foreach (string sopInstance in sopInstances)
                {
                    MatchingParameterCollection mpc = new MatchingParameterCollection();
                    MatchingParameterList       mpl = new MatchingParameterList();

                    ICatalogEntity instanceEntity = RegisteredEntities.GetInstanceEntity(sopInstance);
                    mpl.Add(instanceEntity);
                    mpc.Add(mpl);

                    DataSet instanceData = _StorageAgent.QueryCompositeInstances(mpc);
                    // if (instanceData.Instance.Rows.Count == 1)
                    if (instanceData.Tables[DataTableHelper.InstanceTableName].Rows.Count == 1)
                    {
                        // string file = instanceData.Instance[0].ReferencedFile;
                        DataRow instanceRow = instanceData.Tables[DataTableHelper.InstanceTableName].Rows[0];
                        string  file        = RegisteredDataRows.InstanceInfo.ReferencedFile(instanceRow);

                        scp = new DicomScp(IPAddress.Parse(ae.Address), ae.AETitle, ae.Port);
                        try
                        {
                            if (useTls)
                            {
                                storeSecure.Store(scp, file);
                            }
                            else
                            {
                                store.Store(scp, file);
                            }
                        }
                        catch (ClientAssociationException ce)
                        {
                            string message = string.Format("[Auto Copy] Failed to establish association with server: {0}.", ce.Reason);

                            LogEvent(LogType.Error, MessageDirection.None, message, DicomCommandType.Undefined, null, store, null);
                        }
                        catch (DicomException de)
                        {
                            string message = string.Format("[Auto Copy] Error: {0}.", de.Message);

                            LogEvent(LogType.Error, MessageDirection.Input, message, DicomCommandType.Undefined, null, store, null);
                        }
                        catch (Exception e)
                        {
                            string message = "[Auto Copy] " + e.Message;

                            Logger.Global.Log(string.Empty, string.Empty, -1, string.Empty, string.Empty, -1, DicomCommandType.Undefined,
                                              DateTime.Now, LogType.Error, MessageDirection.None, message, null, null);
                        }
                    }
                }
            }

            RemoveEventHandlers(store);
            RemoveEventHandlers(storeSecure);

            foreach (string sopInstance in sopInstances)
            {
                item.Datasets.Remove(sopInstance);
            }
        }
Esempio n. 29
0
        public void RunThread(IExternalStoreDataAccessAgent externalStoreAgent, IStorageDataAccessAgent storageAgent, DateRange range)
        {
            DicomUtilities.DebugString(DebugStringOptions.ShowCounter, "RestoreProcess.Run");

            lock (_restoreLock)
            {
                ExternalStoreInstance[] instances = externalStoreAgent.GetRestoreList(range);
                string message = string.Format("{0} {1} found to restore", instances.Length, "dataset(s)");
                MatchingParameterCollection mpc = new MatchingParameterCollection();

                Logger.Global.SystemMessage(LogType.Information, message, _serviceName);

                CStoreCommandConfiguration storeConfig = new CStoreCommandConfiguration();
                storeConfig.DicomFileExtension = _storageAddinsConfiguration.StoreAddIn.StoreFileExtension;
                FillStoreCommandDefaultSettings(storeConfig, _storageAddinsConfiguration);

                foreach (ExternalStoreInstance instance in instances)
                {
                    if (_cancelRestore)
                    {
                        _cancelRestore = false;
                        Logger.Global.SystemMessage(LogType.Information, "Cancelling Restore Process", _serviceName);
                        break;
                    }

                    MatchingParameterList mpl = new MatchingParameterList();

                    ICatalogEntity instanceEntity = RegisteredEntities.GetInstanceEntity(instance.SOPInstanceUID);
                    mpl.Add(instanceEntity);
                    mpc.Add(mpl);
                    try
                    {
                        DataSet ds = storageAgent.QueryCompositeInstances(mpc);

                        DataRow[] rows = ds.Tables[DataTableHelper.InstanceTableName].Select();
                        foreach (DataRow row in rows)
                        {
                            // Get the ICrud that the file was originally stored with
                            ICrud crud = DataAccessServiceLocator.Retrieve <ICrud>(instance.ExternalStoreGuid);
                            if (crud != null)
                            {
                                DicomDataSet dicomDataSet = null;
                                Exception    ex           = crud.RetrieveDicom(row, DicomDataSetLoadFlags.None, out dicomDataSet);
                                if (ex == null)
                                {
                                    string storageLocation   = CStoreCommand.GetStorageLocation(storeConfig, dicomDataSet);
                                    string dicomInstancePath = Path.Combine(storageLocation,
                                                                            instance.SOPInstanceUID) + "." + storeConfig.DicomFileExtension;

                                    ex = crud.RetrieveFile(row, dicomInstancePath);
                                    if (ex != null)
                                    {
                                        throw ex;
                                    }

                                    externalStoreAgent.SetReferencedFile(instance.SOPInstanceUID, dicomInstancePath);
                                    Logger.Global.SystemMessage(LogType.Information, string.Format("File Restored: {0} ", dicomInstancePath), _serviceName);
                                }
                            }
                            else
                            {
                                Logger.Global.SystemMessage(LogType.Information, string.Format("Error:  File Not Restored -- Store Token: {0}.  The Addin that for ExternalStoreGuid '{1}' cannot be found.", instance.StoreToken, instance.ExternalStoreGuid), _serviceName);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        message = string.Format("Error ({0}) restoring instance: {1}", e.Message, instance.SOPInstanceUID);
                        Logger.Global.SystemMessage(LogType.Error, message, _serviceName);
                    }
                    finally
                    {
                        mpc.Clear();
                    }
                }
            }
        }
Esempio n. 30
0
      public void RunThread(IForwardDataAccessAgent forwardAgent, IStorageDataAccessAgent storageAgent)
      {
         lock (cleanLock)
         {
            ForwardInstance[] instances = forwardAgent.GetCleanList();
            StorageAddInsConfiguration storageSettings = Module.StorageConfigManager.GetStorageAddInsSettings();
            string message = string.Format("[Forwarder] {0} {1} found to clean", instances.Length, instances.Length == 1 ? "dataset" : "datasets");
            DicomFileDeleter deleter = new DicomFileDeleter();
            MatchingParameterCollection mpc = new MatchingParameterCollection();

            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;
            }

            Logger.Global.SystemMessage(LogType.Debug, message, _ServerAE);
            foreach (ForwardInstance instance in instances)
            {
#if LEADTOOLS_V18_OR_LATER
               if (_cancelClean)
               {
                  _cancelClean = false;
                  Logger.Global.SystemMessage(LogType.Information, string.Format("Cancelling Clean Process"), _ServerAE);
                  break;
               }
#endif // #if LEADTOOLS_V18_OR_LATER
               MatchingParameterList mpl = new MatchingParameterList();

               ICatalogEntity instanceEntity = RegisteredEntities.GetInstanceEntity(instance.SOPInstanceUID);
               mpl.Add(instanceEntity);
               mpc.Add(mpl);
               try
               {
                  DataSet ds = storageAgent.QueryCompositeInstances(mpc);

                  //
                  // Find the instance to delete
                  //
                  storageAgent.DeleteInstance(GetMatchingParameters(instance.SOPInstanceUID));
                  if (ds != null)
                  {                     
                     deleter.Delete(null, ds.Tables[DataTableHelper.InstanceTableName].Select());
                  }
               }
               catch (Exception e)
               {
                  message = string.Format("[Forwarder] Error ({0}) deleting instance: {1}", e.Message, instance.SOPInstanceUID);
                  Logger.Global.SystemMessage(LogType.Error, message, _ServerAE);
               }
               finally
               {
                  mpc.Clear();
               }
            }
            deleter.DicomFileDeleted -= deleter_DicomFileDeleted;
            deleter.DicomFileDeleteFailed -= deleter_DicomFileDeleteFailed;
         }
      }