public void Discard(ServerEntityKey itemKey)
        {
            ReconcileDiscardImagesDescriptor command = new ReconcileDiscardImagesDescriptor();
            InconsistentDataSIQRecord        record  = new InconsistentDataSIQRecord(StudyIntegrityQueue.Load(itemKey));

            command.UserName = ServerHelper.CurrentUserName;

            command.Automatic     = false;
            command.ExistingStudy = record.ExistingStudyInfo;
            command.ImageSetData  = record.ConflictingImageDescriptor;
            String xml = XmlUtils.SerializeAsString(command);

            ReconcileStudy(xml, record.QueueItem);
        }
        public void IgnoreDifferences(ServerEntityKey key)
        {
            ReconcileProcessAsIsDescriptor command = new ReconcileProcessAsIsDescriptor();
            InconsistentDataSIQRecord      record  = new InconsistentDataSIQRecord(StudyIntegrityQueue.Load(key));

            command.UserName      = ServerHelper.CurrentUserName;
            command.Automatic     = false;
            command.Description   = "Ignore the differences";
            command.ExistingStudy = record.ExistingStudyInfo;
            command.ImageSetData  = record.ConflictingImageDescriptor;

            String xml = XmlUtils.SerializeAsString(command);

            ReconcileStudy(xml, record.QueueItem);
        }
        public void CreateNewStudy(ServerEntityKey itemKey)
        {
            InconsistentDataSIQRecord      record  = new InconsistentDataSIQRecord(StudyIntegrityQueue.Load(itemKey));
            ReconcileCreateStudyDescriptor command = new ReconcileCreateStudyDescriptor
            {
                Automatic     = false,
                UserName      = ServerHelper.CurrentUserName,
                ExistingStudy = record.ExistingStudyInfo,
                ImageSetData  = record.ConflictingImageDescriptor
            };

            command.Commands.Add(new SetTagCommand(DicomTags.StudyInstanceUid, record.ExistingStudyInfo.StudyInstanceUid, DicomUid.GenerateUid().UID));
            String xml = XmlUtils.SerializeAsString(command);

            ReconcileStudy(xml, record.QueueItem);
        }
        public void MergeStudy(ServerEntityKey itemKey, Boolean useExistingStudy)
        {
            InconsistentDataSIQRecord record = new InconsistentDataSIQRecord(StudyIntegrityQueue.Load(itemKey));
            ReconcileMergeToExistingStudyDescriptor command = new ReconcileMergeToExistingStudyDescriptor
            {
                UserName      = ServerHelper.CurrentUserName,
                Automatic     = false,
                ExistingStudy = record.ExistingStudyInfo,
                ImageSetData  = record.ConflictingImageDescriptor
            };

            if (useExistingStudy)
            {
                command.Description = "Merge using existing study information.";
                String xml = XmlUtils.SerializeAsString(command);
                ReconcileStudy(xml, record.QueueItem);
            }
            else
            {
                command.Description = "Using study information from the conflicting images.";

                if (record.ConflictingImageDetails != null)
                {
                    // The conflicting study data is stored in Details column
                    string newPatientName = record.ConflictingImageDetails.StudyInfo.PatientInfo.Name;
                    if (!String.IsNullOrEmpty(newPatientName))
                    {
                        string acceptableName = PatientNameRules.GetAcceptableName(newPatientName);
                        if (!acceptableName.Equals(newPatientName))
                        {
                            //override the value
                            newPatientName = acceptableName;
                        }
                    }
                    command.Commands.Add(new SetTagCommand(DicomTags.PatientsName, record.ExistingStudyInfo.PatientInfo.Name, newPatientName));
                    command.Commands.Add(new SetTagCommand(DicomTags.PatientId, record.ExistingStudyInfo.PatientInfo.PatientId, record.ConflictingImageDetails.StudyInfo.PatientInfo.PatientId));
                    command.Commands.Add(new SetTagCommand(DicomTags.PatientsBirthDate, record.ExistingStudyInfo.PatientInfo.PatientsBirthdate, record.ConflictingImageDetails.StudyInfo.PatientInfo.PatientsBirthdate));
                    command.Commands.Add(new SetTagCommand(DicomTags.PatientsSex, record.ExistingStudyInfo.PatientInfo.Sex, record.ConflictingImageDetails.StudyInfo.PatientInfo.Sex));
                    command.Commands.Add(new SetTagCommand(DicomTags.IssuerOfPatientId, record.ExistingStudyInfo.PatientInfo.IssuerOfPatientId, record.ConflictingImageDetails.StudyInfo.PatientInfo.IssuerOfPatientId));
                    command.Commands.Add(new SetTagCommand(DicomTags.AccessionNumber, record.ExistingStudyInfo.AccessionNumber, record.ConflictingImageDetails.StudyInfo.AccessionNumber));
                }
                else
                {
                    // The conflicting study data is stored in StudyData column
                    String patientName = record.ConflictingImageDescriptor[DicomTags.PatientsName] != null
                                             ? record.ConflictingImageDescriptor[DicomTags.PatientsName].Value
                                             : null;

                    if (!String.IsNullOrEmpty(patientName))
                    {
                        string acceptableName = PatientNameRules.GetAcceptableName(patientName);
                        if (!acceptableName.Equals(patientName))
                        {
                            //override the value
                            patientName = acceptableName;
                        }
                    }

                    if (patientName != null)
                    {
                        command.Commands.Add(new SetTagCommand(DicomTags.PatientsName, record.ExistingStudyInfo.PatientInfo.Name, patientName));
                    }

                    String patientId = record.ConflictingImageDescriptor[DicomTags.PatientId] != null
                                             ? record.ConflictingImageDescriptor[DicomTags.PatientId].Value
                                             : null;
                    if (patientId != null)
                    {
                        command.Commands.Add(new SetTagCommand(DicomTags.PatientId, record.ExistingStudyInfo.PatientInfo.PatientId, patientId));
                    }

                    String patientsBirthDate = record.ConflictingImageDescriptor[DicomTags.PatientsBirthDate] != null
                                             ? record.ConflictingImageDescriptor[DicomTags.PatientsBirthDate].Value
                                             : null;
                    if (patientsBirthDate != null)
                    {
                        command.Commands.Add(new SetTagCommand(DicomTags.PatientsBirthDate, record.ExistingStudyInfo.PatientInfo.PatientsBirthdate, patientsBirthDate));
                    }

                    String patientsSex = record.ConflictingImageDescriptor[DicomTags.PatientsSex] != null
                                             ? record.ConflictingImageDescriptor[DicomTags.PatientsSex].Value
                                             : null;
                    if (patientsSex != null)
                    {
                        command.Commands.Add(new SetTagCommand(DicomTags.PatientsSex, record.ExistingStudyInfo.PatientInfo.Sex, patientsSex));
                    }

                    String issuerOfPatientId = record.ConflictingImageDescriptor[DicomTags.IssuerOfPatientId] != null
                                             ? record.ConflictingImageDescriptor[DicomTags.IssuerOfPatientId].Value
                                             : null;
                    if (issuerOfPatientId != null)
                    {
                        command.Commands.Add(new SetTagCommand(DicomTags.IssuerOfPatientId, record.ExistingStudyInfo.PatientInfo.IssuerOfPatientId, issuerOfPatientId));
                    }

                    String accessionNumber = record.ConflictingImageDescriptor[DicomTags.AccessionNumber] != null
                                             ? record.ConflictingImageDescriptor[DicomTags.AccessionNumber].Value
                                             : null;
                    if (accessionNumber != null)
                    {
                        command.Commands.Add(new SetTagCommand(DicomTags.AccessionNumber, record.ExistingStudyInfo.AccessionNumber, accessionNumber));
                    }
                }

                String xml = XmlUtils.SerializeAsString(command);
                ReconcileStudy(xml, record.QueueItem);
            }
        }