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); }
private void MergePatient() { ReasonDialog dlgReason = new ReasonDialog("Input Reason For Merging Patient"); if (dlgReason.ShowDialog(this) == DialogResult.OK) { MergePatient merge = new MergePatient(); DicomCommandStatusType status = DicomCommandStatusType.Success; ProgressDialog progress = new ProgressDialog(); merge.PatientId = textBoxId.Text; merge.Operator = Environment.UserName != string.Empty ? Environment.UserName : Environment.MachineName; merge.Reason = dlgReason.Reason; merge.Description = "Merge Patient"; merge.PatientToMerge.Add(new MergePatientSequence(_Patient.Id)); Thread thread = new Thread(() => { try { status = _naction.SendNActionRequest <MergePatient>(_scp, merge, NActionScu.MergePatient, NActionScu.PatientUpdateInstance); } catch (Exception e) { ApplicationUtils.ShowException(this, e); status = DicomCommandStatusType.Failure; } }); progress.ActionThread = thread; progress.Title = "Merging Patient: " + _Patient.Name.Full; progress.ProgressInfo = "Performing patient merge."; progress.ShowDialog(this); if (status == DicomCommandStatusType.Success) { Action = ActionType.Merge; TaskDialogHelper.ShowMessageBox(this, "Patient Merge", "The patient has been successfully merged.", GetMergeInfo(), string.Empty, TaskDialogStandardButtons.Close, TaskDialogStandardIcon.Information, null); DialogResult = DialogResult.OK; } else { string message = "The patient has not been merged.\r\nError - "; string footer = string.Empty; if (status == DicomCommandStatusType.Reserved2) { message += "Missing Files"; } else { message += _naction.GetErrorMessage(); } if (status == DicomCommandStatusType.MissingAttribute) { message = "The patient has not been merged.\r\nPatient not found on server."; } else if (status == DicomCommandStatusType.Reserved2) { footer = "Contact system administrator for help in resolving this issue."; } TaskDialogHelper.ShowMessageBox(this, "Merge Patient Error", "The patient has not been merged.", message, footer, TaskDialogStandardButtons.Close, TaskDialogStandardIcon.Information, null); } } }
private static CompositeInstanceDataSet.InstanceRow[] GetInstanceRows(int action, DicomDataSet request, out List <string> studyInstanceUids) { CompositeInstanceDataSet.InstanceRow[] rows = null; CompositeInstanceDataSet ds = null; MatchingParameterCollection mpc = new MatchingParameterCollection(); MatchingParameterList mpl = new MatchingParameterList(); studyInstanceUids = new List <string>(); if (request == null) { return(null); } if (Module.StorageAgent == null) { return(null); } switch (action) { case PatientUpdaterConstants.Action.MergePatient: MergePatient mergePatient = request.Get <MergePatient>(); if (mergePatient.PatientToMerge != null && mergePatient.PatientToMerge.Count > 0) { mpl.Add(new Patient() { PatientID = mergePatient.PatientToMerge[0].PatientId }); mpc.Add(mpl); } break; case PatientUpdaterConstants.Action.DeletePatient: DeletePatient delPatient = request.Get <DeletePatient>(); mpl.Add(new Patient() { PatientID = delPatient.PatientId }); foreach (StudyInstanceReference studyInstanceReference in delPatient.ReferencedStudySequence) { mpl.Add(new Study() { StudyInstanceUID = studyInstanceReference.StudyInstanceUID }); } mpc.Add(mpl); break; case PatientUpdaterConstants.Action.DeleteSeries: DeleteSeries delSeries = request.Get <DeleteSeries>(); mpl.Add(new Series() { SeriesInstanceUID = delSeries.SeriesInstanceUID }); mpc.Add(mpl); break; case PatientUpdaterConstants.Action.ChangePatient: ChangePatient changePatient = request.Get <ChangePatient>(); mpl.Add(new Patient() { PatientID = changePatient.OriginalPatientId }); mpc.Add(mpl); break; default: return(null); } ds = Module.StorageAgent.QueryCompositeInstances(mpc).ToCompositeInstanceDataSet(); CompositeInstanceDataSet.StudyRow[] studyRows = ds.Study.Rows.OfType <CompositeInstanceDataSet.StudyRow>().ToArray(); foreach (CompositeInstanceDataSet.StudyRow studyRow in studyRows) { studyInstanceUids.Add(studyRow.StudyInstanceUID); } rows = ds.Instance.Rows.OfType <CompositeInstanceDataSet.InstanceRow>().ToArray(); return(rows); }