Пример #1
0
        public void UpdateDicomDataSet(DicomDataSet ds, DataRow row, DicomDataSetSaveFlags flags)
        {
            string token          = string.Empty;
            string referencedFile = RegisteredDataRows.InstanceInfo.ReferencedFile(row);

            if (File.Exists(referencedFile))
            {
                // Update the file only if it exists -- otherwise do nothing
                ds.Save(referencedFile, flags);
            }
        }
Пример #2
0
        public Exception StoreDicom(string filename, DicomDataSet ds, DicomDataSetSaveFlags saveFlags, bool overwrite, out string token)
        {
            token = string.Empty;
            Exception ret = null;

            try
            {
                if (overwrite || !File.Exists(filename))
                {
                    SaveDicom(filename, ds, saveFlags, out token);
                }
            }
            catch (Exception ex)
            {
                ret = ex;
            }
            return(ret);
        }
Пример #3
0
        private Exception SaveDicom(string filename, DicomDataSet ds, DicomDataSetSaveFlags saveFlags, out string token)
        {
            Exception ret         = null;
            string    newFileName = GetTokenFromFilename(filename);

            token = newFileName;
            try
            {
                string directory = Path.GetDirectoryName(newFileName);
                Directory.CreateDirectory(directory);
                ds.Save(newFileName, saveFlags);
            }
            catch (Exception ex)
            {
                ret = ex;
            }
            return(ret);
        }
Пример #4
0
        public Exception StoreDicom(string filename, DicomDataSet dataset, DicomDataSetSaveFlags saveFlags, bool overwrite, out string token)
        {
            string message;

            Byte[]    ba  = dataset.ToByteArray(saveFlags);
            Exception ret = Store(ba, filename, overwrite, out token);

            if (ret == null)
            {
                message = string.Format("'{0}' external store addin StoreDicom success, returned store token '{1}'.", Module.AzureFriendlyName, token);
                Logger.Global.SystemMessage(LogType.Debug, message, Module.ServiceName);
            }
            else
            {
                message = string.Format("'{0}' external store addin StoreDicom failure, '{1}'.", Module.AzureFriendlyName, ret.Message);
                Logger.Global.SystemMessage(LogType.Error, message, Module.ServiceName);
            }
            return(ret);
        }
Пример #5
0
        // Patient Updater calls 'UpdateDicom'
        // Write the file if it already exists
        // If no exists, do nothing.
        public Exception UpdateDicom(DataRow row, DicomDataSet dataset, DicomDataSetSaveFlags saveFlags)
        {
            string token = RegisteredDataRows.InstanceInfo.StoreToken(row);

            Exception ret = null;

            try
            {
                // (07.10.2019)
                // Changed this to always write the file, even if it does not exist
                // if (File.Exists(token))
                {
                    dataset.Save(token, saveFlags);
                }
            }
            catch (Exception ex)
            {
                ret = ex;
            }
            return(ret);
        }
Пример #6
0
        // Patient Updater calls 'UpdateDicom'
        public Exception UpdateDicom(DataRow row, DicomDataSet dataset, DicomDataSetSaveFlags saveFlags)
        {
            string message;
            string token = RegisteredDataRows.InstanceInfo.StoreToken(row);

            Byte[]    ba  = dataset.ToByteArray(saveFlags);
            Exception ret = Update(token, ba);

            if (ret == null)
            {
                message = string.Format("'{0}' external store addin UpdateDicom success, returned store token '{1}'.", Module.AtmosFriendlyName, token);
                Logger.Global.SystemMessage(LogType.Debug, message, Module.ServiceName);
            }
            else
            {
                message = string.Format("'{0}' external store addin UpdateDicom failure, '{1}'.", Module.AtmosFriendlyName, ret.Message);
                Logger.Global.SystemMessage(LogType.Error, message, Module.ServiceName);
            }

            return(ret);
        }
Пример #7
0
 public void SaveDicomDataSet(DicomDataSet ds, string path, out string storeToken, out string externalStoreGuid, DicomDataSetSaveFlags flags)
 {
     storeToken        = string.Empty;
     externalStoreGuid = string.Empty;
     ds.Save(path, flags);
 }
Пример #8
0
        private void Change_Click(object sender, EventArgs e)
        {
            // Some sanity checks !
            if (txtInFile.Text.Length == 0)
            {
                MessageBox.Show("Please enter a valid input file name ");
                return;
            }

            if (!System.IO.File.Exists(txtInFile.Text))
            {
                MessageBox.Show("Please enter a valid input file name ");
                return;
            }

            if (txtOutFile.Text.Length == 0)
            {
                MessageBox.Show("Please enter a valid output file name ");
                return;
            }
            if (txtInFile.Text == txtOutFile.Text)
            {
                MessageBox.Show("Input and output file names can't be the same!");
                return;
            }

            DicomDataSetSaveFlags saveFlags = (DicomDataSetSaveFlags.MetaHeaderPresent | DicomDataSetSaveFlags.GroupLengths);

            // Get desired transfer syntax
            string uid = ((MyTransferSyntax)cmbTransferSyntax.Items[cmbTransferSyntax.SelectedIndex]).szUID;
            int    nQFactor;

            if (IsUidUsingQFactor(uid))
            {
                nQFactor = Convert.ToInt16(txtQFactor.Text);
                if ((nQFactor < 2 || nQFactor > 255) && (nQFactor != 0))
                {
                    string message = "Please enter a valid quality factor:\r\n" +
                                     "\t 0 (lossless)\r\n" +
                                     "\t 2 (lossy highest quality) to 255 (lossy most compression)";

                    MessageBox.Show(message, "Please enter a valid quality factor.");
                    return;
                }
            }
            else
            {
                nQFactor = 0;
            }
            //Load input dataset

#if !(LEADTOOLS_V17_OR_LATER)
            RasterCodecs.Startup();
#endif
            DicomEngine.Startup();
            DicomDataSet DicomDs = new DicomDataSet();
            DicomDs.Reset();
            try
            {
                DicomDs.Load(txtInFile.Text, 0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Failed to load the Dataset!");
                return;
            }

            if (IsUidJpeg2000(uid))
            {
                // Setting JPEG 2000 options
                DicomDs.Jpeg2000Options = m_J2KOptions;
            }

            // Ensure that the DICOM File Meta Information is added
            CheckFileMetaInfo(DicomDs);

            //Change dataset to desired transfer syntax
            try
            {
                ChangeTransferSyntaxFlags flags = ChangeTransferSyntaxFlags.None;
#if LEADTOOLS_V175_OR_LATER
                if (checkBoxYbrFull.Checked)
                {
                    flags |= ChangeTransferSyntaxFlags.YbrFull;
                }
#endif

#if LEADTOOLS_V19_OR_LATER
                DicomDs.ChangeTransferSyntax(txtOutFile.Text, uid, nQFactor, flags, saveFlags);
#else
                DicomDs.ChangeTransferSyntax(uid, nQFactor, flags);
#endif
            }
            catch (Exception ex)
            {
                string errorString = ex.Message.ToLower();
                if (errorString.Contains("parameter"))
                {
                    const string strErr = "Failed to change dataset transfer syntax.\nPossible cause:\" Bits Allocated\" for source dataset doesn't match desired \"Transfer Syntax\".";
                    MessageBox.Show(strErr, "Failed to change dataset transfer syntax.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    MessageBox.Show(ex.Message, "LEAD Error");
                }

                return;
            }

#if !LEADTOOLS_V19_OR_LATER
            // Save dataset!
            try
            {
                DicomDs.Save(txtOutFile.Text, saveFlags);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Failed to save dataset");
                return;
            }
#endif // #if !LEADTOOLS_V19_OR_LATER

            DicomEngine.Shutdown();

#if !LEADTOOLS_V17_OR_LATER
            RasterCodecs.Shutdown();
#endif
            MessageBox.Show("Conversion Succeeded", "SUCCESS");

            //this.Cursor = Cursors.WaitCursor;
            //this.Cursor = Cursors.Arrow;
        }