Exemple #1
0
		/// <summary>
		/// Perform the edit.
		/// </summary>
		/// <param name="actionXml">A serialized XML representation of <see cref="SetTagCommand"/> objects</param>
		/// <returns></returns>
		public bool Edit(XmlElement actionXml)
		{
			Platform.Log(LogLevel.Info,
						 "Starting Edit of study {0} for Patient {1} (PatientId:{2} A#:{3}) on Partition {4}",
						 Study.StudyInstanceUid, Study.PatientsName, Study.PatientId,
						 Study.AccessionNumber, ServerPartition.Description);

			LoadExtensions();

            EditStudyWorkQueueDataParser parser = new EditStudyWorkQueueDataParser();
		    EditStudyWorkQueueData data = parser.Parse(actionXml);

			using (ServerCommandProcessor processor = new ServerCommandProcessor("Web Edit Study"))
			{
				// Convert UpdateItem in the request into BaseImageLevelUpdateCommand
				List<BaseImageLevelUpdateCommand> updateCommands = null;
				if (data != null)
				{
					updateCommands = CollectionUtils.Map<Edit.UpdateItem, BaseImageLevelUpdateCommand>(
						data.EditRequest.UpdateEntries,
						delegate(Edit.UpdateItem item)
							{
								// Note: For edit, we assume each UpdateItem is equivalent to SetTagCommand
								return new SetTagCommand(item.DicomTag.TagValue, item.OriginalValue, item.Value);
							}
						);
				}

				UpdateStudyCommand updateStudyCommand =
					new UpdateStudyCommand(ServerPartition, StorageLocation, updateCommands, 
						ServerRuleApplyTimeEnum.SopEdited);
				processor.AddCommand(updateStudyCommand);

				// Note, this command will only insert the ArchiveQueue command if a delete doesn't exist
				processor.AddCommand(new InsertArchiveQueueCommand(ServerPartition.Key, StorageLocation.Key));

			    var context = new WebEditStudyContext
			                      {
			                          CommandProcessor = processor,
			                          EditType = data.EditRequest.EditType,
			                          OriginalStudyStorageLocation = StorageLocation,
			                          EditCommands = updateCommands,
			                          OriginalStudy = Study,
			                          OrginalPatient = Patient,
			                          UserId = data.EditRequest.UserId,
			                          Reason = data.EditRequest.Reason
			                      };

				OnStudyUpdating(context);

				if (!processor.Execute())
				{
					Platform.Log(LogLevel.Error, processor.FailureException, "Unexpected failure editing study: {0}",
					             processor.FailureReason);
					FailureReason = processor.FailureReason;

					return false;
				}

				// reload the StudyStorageLocation
				NewStorageLocation = StudyStorageLocation.FindStorageLocations(StorageLocation.StudyStorage)[0];
				context.NewStudystorageLocation = NewStorageLocation;

				OnStudyUpdated(context);

				if (updateStudyCommand.Statistics != null)
					StatisticsLogger.Log(LogLevel.Info, updateStudyCommand.Statistics);

				return true;
			}
		}
        private static WorkQueueDetails CreateEditWorkQueueItemDetails(Model.WorkQueue item)
        {
            string studyPath;
            try
            {
                StudyStorageLocation storage = WorkQueueController.GetLoadStorageLocation(item);
                studyPath = storage.GetStudyPath();
            }
            catch(Exception)
            {
                studyPath = string.Empty;
            }
            var detail = new WorkQueueDetails
                             {
                                 Key = item.Key,
                                 ScheduledDateTime = item.ScheduledTime,
                                 ExpirationTime = item.ExpirationTime,
                                 InsertTime = item.InsertTime,
                                 FailureCount = item.FailureCount,
                                 Type = item.WorkQueueTypeEnum,
                                 Status = item.WorkQueueStatusEnum,
                                 Priority = item.WorkQueuePriorityEnum,
                                 FailureDescription = item.FailureDescription,
                                 ServerDescription = item.ProcessorID,
                                 StorageLocationPath = studyPath
                             };



            // Fetch UIDs
            var wqUidsAdaptor = new WorkQueueUidAdaptor();
            var uidCriteria = new WorkQueueUidSelectCriteria();
            uidCriteria.WorkQueueKey.EqualTo(item.GetKey());
            IList<WorkQueueUid> uids = wqUidsAdaptor.Get(uidCriteria);

            var mapSeries = new Hashtable();
            foreach (WorkQueueUid uid in uids)
            {
                if (mapSeries.ContainsKey(uid.SeriesInstanceUid) == false)
                    mapSeries.Add(uid.SeriesInstanceUid, uid.SopInstanceUid);
            }

            detail.NumInstancesPending = uids.Count;
            detail.NumSeriesPending = mapSeries.Count;


            // Fetch the study and patient info
            var ssAdaptor = new StudyStorageAdaptor();
            StudyStorage storages = ssAdaptor.Get(item.StudyStorageKey);

            var studyAdaptor = new StudyAdaptor();
            var studycriteria = new StudySelectCriteria();
            studycriteria.StudyInstanceUid.EqualTo(storages.StudyInstanceUid);
            studycriteria.ServerPartitionKey.EqualTo(item.ServerPartitionKey);
            Study study = studyAdaptor.GetFirst(studycriteria);

            // Study may not be available until the images are processed.
            if (study != null)
            {
                var studyAssembler = new StudyDetailsAssembler();
                detail.Study = studyAssembler.CreateStudyDetail(study);
            }

            var parser = new EditStudyWorkQueueDataParser();
            EditStudyWorkQueueData data = parser.Parse(item.Data.DocumentElement);

            detail.EditUpdateItems = data.EditRequest.UpdateEntries.ToArray();

            return detail;
        }