private void CopyPatient() { // // If the patient ID has changed then we need to see if a patient with that id already exists // if (_Patient.Id != textBoxId.Text) { PatientRootQueryPatient query = new PatientRootQueryPatient(); List <Patient> patients = new List <Patient>(); query.PatientQuery.PatientId = textBoxId.Text; try { _find.Find <PatientRootQueryPatient, Patient>(_scp, query, (patient, ds) => patients.Add(patient)); if (patients.Count > 0) { TaskDialogResult result = TaskDialogResult.Yes; result = TaskDialogHelper.ShowMessageBox(this, "Patient Id Already Exits", "Would you like to merge with existing patient?", "The patient id already exisits.", "Existing Patient: " + patients[0].Name.Full, TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No, TaskDialogStandardIcon.Error, TaskDialogStandardIcon.Warning); if (result == TaskDialogResult.Yes) { radioButtonMerge.Checked = true; textBoxLastname.Text = patients[0].Name.Family; textBoxFirstname.Text = patients[0].Name.Given; if (string.IsNullOrEmpty(patients[0].Sex)) { comboBoxSex.Text = string.Empty; } else { comboBoxSex.SelectedIndex = comboBoxSex.FindStringExact(patients[0].Sex); } if (patients[0].BirthDate.HasValue) { dateTimePickerBirth.Value = patients[0].BirthDate.Value; dateTimePickerBirth.Checked = true; } else { dateTimePickerBirth.Checked = false; } } else { textBoxId.Text = _Patient.Id; return; } } } catch (Exception e) { ApplicationUtils.ShowException(this, e); return; } } ReasonDialog dlgReason = new ReasonDialog("Input Reason For Copying Patient"); if (dlgReason.ShowDialog(this) == DialogResult.OK) { CopyPatient change = new CopyPatient(); DicomCommandStatusType status = DicomCommandStatusType.Success; change.OriginalPatientId = _Patient.Id.Replace(@"\", @"\\").Replace("'", @"''"); change.Operator = Environment.UserName != string.Empty ? Environment.UserName : Environment.MachineName; change.PatientId = textBoxId.Text.Replace(@"\", @"\\").Replace("'", @"''"); change.Reason = dlgReason.Reason; change.Description = "Copy Patient"; change.Name.Given = textBoxFirstname.Text.Replace(@"\", @"\\").Replace("'", @"''"); change.Name.Family = textBoxLastname.Text.Replace(@"\", @"\\").Replace("'", @"''"); change.Sex = comboBoxSex.Text; if (dateTimePickerBirth.Checked) { change.Birthdate = dateTimePickerBirth.Value; } else { change.Birthdate = null; } #if (LEADTOOLS_V19_OR_LATER) if (textBoxOtherPid.Text.Length > 0) { Leadtools.Dicom.Common.DataTypes.PatientUpdater.OtherPatientID opid = new Leadtools.Dicom.Common.DataTypes.PatientUpdater.OtherPatientID(); change.OtherPatientIdsSequence = new List <Leadtools.Dicom.Common.DataTypes.PatientUpdater.OtherPatientID>(); opid.PatientId = textBoxOtherPid.Text.Replace(@"\", @"\\").Replace("'", @"''"); opid.TypeOfPatientId = "TEXT"; change.OtherPatientIdsSequence.Add(opid); } #endif status = _naction.SendNActionRequest <CopyPatient>(_scp, change, NActionScu.CopyPatient, NActionScu.PatientUpdateInstance); if (status == DicomCommandStatusType.Success) { //_Patient.Id = textBoxId.Text; //_Patient.Name.Given = textBoxFirstname.Text; //_Patient.Name.Family = textBoxLastname.Text; //_Patient.Sex = comboBoxSex.Text; //if (dateTimePickerBirth.Checked) // _Patient.BirthDate = dateTimePickerBirth.Value; //else // _Patient.BirthDate = null; Action = ActionType.CopyPatient; TaskDialogHelper.ShowMessageBox(this, "Patient Copied", "The patient has been successfully copied.", string.Empty, string.Empty, TaskDialogStandardButtons.Close, TaskDialogStandardIcon.Information, null); DialogResult = DialogResult.OK; } else { TaskDialogHelper.ShowMessageBox(this, "Copy Error", "The patient has not been successfully copied.", string.Empty, "Error - " + _naction.GetErrorMessage(), TaskDialogStandardButtons.Close, TaskDialogStandardIcon.Information, null); } } }
private void ChangePatient() { // // If the patient ID has changed then we need to see if a patient with that id already exists // if (_Patient.Id != textBoxId.Text) { PatientRootQueryPatient query = new PatientRootQueryPatient(); List <Patient> patients = new List <Patient>(); query.PatientQuery.PatientId = textBoxId.Text; try { _find.Find <PatientRootQueryPatient, Patient>(_scp, query, (patient, ds) => patients.Add(patient)); if (patients.Count > 0) { TaskDialogResult result = TaskDialogResult.Yes; result = TaskDialogHelper.ShowMessageBox(this, "Patient Id Already Exits", "Would you like to merge with existing patient?", "The patient id already exisits.", "Existing Patient: " + patients[0].Name.Full, TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No, TaskDialogStandardIcon.Error, TaskDialogStandardIcon.Warning); if (result == TaskDialogResult.Yes) { radioButtonMerge.Checked = true; textBoxLastname.Text = patients[0].Name.Family; textBoxFirstname.Text = patients[0].Name.Given; comboBoxSex.SelectedIndex = comboBoxSex.FindStringExact(patients[0].Sex); if (patients[0].BirthDate.HasValue) { dateTimePickerBirth.Value = patients[0].BirthDate.Value; dateTimePickerBirth.Checked = true; } else { dateTimePickerBirth.Checked = false; } MergePatient(); return; } else { textBoxId.Text = _Patient.Id; return; } } } catch (Exception e) { ApplicationUtils.ShowException(this, e); return; } } bool isError = VerifyPatientSettings(); if (isError) { return; } ReasonDialog dlgReason = new ReasonDialog("Input Reason For Changing Patient"); if (dlgReason.ShowDialog(this) == DialogResult.OK) { ChangePatient change = new ChangePatient(); DicomCommandStatusType status = DicomCommandStatusType.Success; change.OriginalPatientId = _Patient.Id.Replace(@"\", @"\\").Replace("'", @"''"); change.Operator = Environment.UserName != string.Empty ? Environment.UserName : Environment.MachineName; change.PatientId = textBoxId.Text.Replace(@"\", @"\\").Replace("'", @"''"); change.Reason = dlgReason.Reason; change.Description = "Change Patient"; change.Name.Given = textBoxFirstname.Text.Replace(@"\", @"\\").Replace("'", @"''"); change.Name.Family = textBoxLastname.Text.Replace(@"\", @"\\").Replace("'", @"''"); change.Sex = comboBoxSex.Text; if (dateTimePickerBirth.Checked) { change.Birthdate = dateTimePickerBirth.Value; } else { change.Birthdate = null; } #if (LEADTOOLS_V19_OR_LATER) if (textBoxOtherPid.Text.Length > 0) { change.OtherPatientIdsSequence = new List <Leadtools.Dicom.Common.DataTypes.PatientUpdater.OtherPatientID>(); string textBoxStringOtherPid = textBoxOtherPid.Text.Replace("'", @"''"); if (!string.IsNullOrEmpty(textBoxStringOtherPid)) { char[] delimiterChars = { '\\' }; string[] otherPatientIds = textBoxStringOtherPid.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries); foreach (string otherPatientId in otherPatientIds) { Leadtools.Dicom.Common.DataTypes.PatientUpdater.OtherPatientID opid = new Leadtools.Dicom.Common.DataTypes.PatientUpdater.OtherPatientID(); opid.PatientId = otherPatientId; opid.TypeOfPatientId = "TEXT"; change.OtherPatientIdsSequence.Add(opid); } } } #endif status = _naction.SendNActionRequest <ChangePatient>(_scp, change, NActionScu.ChangePatient, NActionScu.PatientUpdateInstance); if (status == DicomCommandStatusType.Success) { _Patient.Id = textBoxId.Text; _Patient.Name.Given = textBoxFirstname.Text; _Patient.Name.Family = textBoxLastname.Text; _Patient.Sex = comboBoxSex.Text; if (dateTimePickerBirth.Checked) { _Patient.BirthDate = dateTimePickerBirth.Value; } else { _Patient.BirthDate = null; } Action = ActionType.Change; TaskDialogHelper.ShowMessageBox(this, "Patient Changed", "The patient has been successfully changed.", string.Empty, string.Empty, TaskDialogStandardButtons.Close, TaskDialogStandardIcon.Information, null); DialogResult = DialogResult.OK; if (change.OriginalPatientId != _Patient.Id) { if (Program.OtherPID.ContainsKey(change.OriginalPatientId)) { Program.OtherPID.Remove(change.OriginalPatientId); } } Program.OtherPID[_Patient.Id] = textBoxOtherPid.Text; } else { string message = "The patient was not changed.\r\nError - " + _naction.GetErrorMessage(); if (status == DicomCommandStatusType.MissingAttribute) { message = "The patient was not changed.\r\nPatient not found on server."; } TaskDialogHelper.ShowMessageBox(this, "Change Patient Error", "The patient was not changed.", message, string.Empty, TaskDialogStandardButtons.Close, TaskDialogStandardIcon.Information, null); } } }