private static IList <StudyIntegrityQueueUid> LoadDuplicateSopUid(DuplicateSopReceivedQueue entry)
        {
            IStudyIntegrityQueueUidEntityBroker broker =
                HttpContextData.Current.ReadContext.GetBroker <IStudyIntegrityQueueUidEntityBroker>();

            StudyIntegrityQueueUidSelectCriteria criteria = new StudyIntegrityQueueUidSelectCriteria();

            criteria.StudyIntegrityQueueKey.EqualTo(entry.GetKey());
            return(broker.Find(criteria));
        }
        protected override void OnExecute(CommandProcessor theProcessor, IUpdateContext updateContext)
        {
            var broker = updateContext.GetBroker <IInsertDuplicateSopReceivedQueue>();
            var parms  = new InsertDuplicateSopReceivedQueueParameters
            {
                GroupID            = _groupId,
                ServerPartitionKey = _studyLocation.ServerPartitionKey,
                StudyStorageKey    = _studyLocation.Key,
                StudyInstanceUid   = _file.DataSet[DicomTags.StudyInstanceUid].ToString(),
                SeriesDescription  = _file.DataSet[DicomTags.SeriesDescription].ToString(),
                SeriesInstanceUid  = _file.DataSet[DicomTags.SeriesInstanceUid].ToString(),
                SopInstanceUid     = _file.MediaStorageSopInstanceUid
            };
            ReconcileStudyQueueDescription queueDesc = CreateQueueEntryDescription(_file);

            parms.Description = queueDesc != null?queueDesc.ToString() : String.Empty;

            var queueData = new DuplicateSIQQueueData
            {
                StoragePath = _duplicateStoragePath,
                Details     = new ImageSetDetails(_file.DataSet),
                TimeStamp   = Platform.Time
            };

            if (_reasons != null && _reasons.Count > 0)
            {
                queueData.ComparisonResults = _reasons;
            }

            var imageSet = new ImageSetDescriptor(_file.DataSet);

            parms.StudyData       = XmlUtils.SerializeAsXmlDoc(imageSet);
            parms.Details         = XmlUtils.SerializeAsXmlDoc(queueData);
            parms.UidRelativePath = _relativePath;
            IList <DuplicateSopReceivedQueue> entries = broker.Find(parms);

            Platform.CheckForNullReference(entries, "entries");
            Platform.CheckTrue(entries.Count == 1, "entries.Count==1");

            DuplicateSopReceivedQueue queueEntry = entries[0];

            var data = XmlUtils.Deserialize <DuplicateSIQQueueData>(queueEntry.Details);

            data.Details.InsertFile(_file);

            queueEntry.Details = XmlUtils.SerializeAsXmlDoc(data);

            var siqBroker = updateContext.GetBroker <IStudyIntegrityQueueEntityBroker>();

            if (!siqBroker.Update(queueEntry))
            {
                throw new ApplicationException("Unable to update duplicate queue entry");
            }
        }
        public override void DataBind()
        {
            ExistingPatientSeriesGridView.DataSource    = DuplicateEntryDetails.ExistingStudy.Series;
            ConflictingPatientSeriesGridView.DataSource = DuplicateEntryDetails.ConflictingImageSet.StudyInfo.Series;
            StudyStorage storage =
                StudyStorage.Load(HttpContext.Current.GetSharedPersistentContext(), StudyIntegrityQueueItem.StudyStorageKey);

            IList <StudyStorageLocation> studyLocations = StudyStorageLocation.FindStorageLocations(storage);

            StudyLocation.Text = studyLocations[0].GetStudyPath();

            var entry = new DuplicateSopReceivedQueue(StudyIntegrityQueueItem);

            DuplicateSopLocation.Text = entry.GetFolderPath(HttpContext.Current.GetSharedPersistentContext());

            ComparisonResultGridView.DataSource = DuplicateEntryDetails.QueueData.ComparisonResults;
            base.DataBind();
        }
 public DuplicateEntryDetails(StudyIntegrityQueue siqEntry) : base(siqEntry)
 {
     _duplicateSIQEntry = new DuplicateSopReceivedQueue(siqEntry);
 }
        /// <summary>
        /// Inserts work queue entry to process the duplicates.
        /// </summary>
        /// <param name="entryKey"><see cref="ServerEntityKey"/> of the <see cref="StudyIntegrityQueue"/> entry  that has <see cref="StudyIntegrityReasonEnum"/> equal to <see cref="StudyIntegrityReasonEnum.Duplicate"/> </param>
        /// <param name="action"></param>
        public void Process(ServerEntityKey entryKey, ProcessDuplicateAction action)
        {
            DuplicateSopReceivedQueue entry = DuplicateSopReceivedQueue.Load(HttpContextData.Current.ReadContext, entryKey);

            Platform.CheckTrue(entry.StudyIntegrityReasonEnum == StudyIntegrityReasonEnum.Duplicate, "Invalid type of entry");

            IList <StudyIntegrityQueueUid> uids = LoadDuplicateSopUid(entry);

            using (IUpdateContext context = PersistentStoreRegistry.GetDefaultStore().OpenUpdateContext(UpdateContextSyncMode.Flush))
            {
                ProcessDuplicateQueueEntryQueueData data = new ProcessDuplicateQueueEntryQueueData
                {
                    Action             = action,
                    DuplicateSopFolder = entry.GetFolderPath(context),
                    UserName           = ServerHelper.CurrentUserName,
                };

                LockStudyParameters lockParms = new LockStudyParameters
                {
                    QueueStudyStateEnum = QueueStudyStateEnum.ReconcileScheduled,
                    StudyStorageKey     = entry.StudyStorageKey
                };

                ILockStudy lockBbroker = context.GetBroker <ILockStudy>();
                lockBbroker.Execute(lockParms);
                if (!lockParms.Successful)
                {
                    throw new ApplicationException(lockParms.FailureReason);
                }

                IWorkQueueProcessDuplicateSopBroker       broker  = context.GetBroker <IWorkQueueProcessDuplicateSopBroker>();
                WorkQueueProcessDuplicateSopUpdateColumns columns = new WorkQueueProcessDuplicateSopUpdateColumns
                {
                    Data           = XmlUtils.SerializeAsXmlDoc(data),
                    GroupID        = entry.GroupID,
                    ScheduledTime  = Platform.Time,
                    ExpirationTime =
                        Platform.Time.Add(TimeSpan.FromMinutes(15)),
                    ServerPartitionKey    = entry.ServerPartitionKey,
                    WorkQueuePriorityEnum =
                        WorkQueuePriorityEnum.Medium,
                    StudyStorageKey     = entry.StudyStorageKey,
                    WorkQueueStatusEnum = WorkQueueStatusEnum.Pending
                };

                WorkQueueProcessDuplicateSop processDuplicateWorkQueueEntry = broker.Insert(columns);

                IWorkQueueUidEntityBroker           workQueueUidBroker = context.GetBroker <IWorkQueueUidEntityBroker>();
                IStudyIntegrityQueueUidEntityBroker duplicateUidBroke  = context.GetBroker <IStudyIntegrityQueueUidEntityBroker>();
                foreach (StudyIntegrityQueueUid uid in uids)
                {
                    WorkQueueUidUpdateColumns uidColumns = new WorkQueueUidUpdateColumns
                    {
                        Duplicate         = true,
                        Extension         = ServerPlatform.DuplicateFileExtension,
                        SeriesInstanceUid = uid.SeriesInstanceUid,
                        SopInstanceUid    = uid.SopInstanceUid,
                        RelativePath      = uid.RelativePath,
                        WorkQueueKey      = processDuplicateWorkQueueEntry.GetKey()
                    };

                    workQueueUidBroker.Insert(uidColumns);

                    duplicateUidBroke.Delete(uid.GetKey());
                }

                IDuplicateSopEntryEntityBroker duplicateEntryBroker =
                    context.GetBroker <IDuplicateSopEntryEntityBroker>();
                duplicateEntryBroker.Delete(entry.GetKey());


                context.Commit();
            }
        }