Esempio n. 1
0
        private void DeIdentifactionMethod(FileInfo fileName, string saveFileNametemp)
        {
            try
            {
                string _DCMFileName = fileName.FullName;

                // Read the DCM File
                DicomFile dcmFile = new DicomFile();
                dcmFile.Read(_DCMFileName, mainThread);

                // Get the Data set from the selected DCM file
                dcmDataset = dcmFile.DataSet;
                int numberOfAttribute = dcmDataset.Count;
                utility.PatientAttributes(dcmDataset);
                for (int number = 0; number < numberOfAttribute; number++)
                {
                    HLI.Attribute attribute = dcmDataset[number];
                    if (attribute.VR == VR.SQ)
                    {
                        utility.SequenceAttribute_recursive(attribute);
                    }
                    else
                    {
                        utility.CacheAndRepairIdentifyingAttribute(attribute);
                        utility.UpdateAnonymizedAttributes(attribute);
                    }
                }
                dcmFile.DataSet = dcmDataset;
                dcmFile.Write(saveFileNametemp);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 2
0
        private void RetrievingFilesFromDirectory()
        {
            try
            {
                String        indexFileName = initialDirectory + @"/index1.htm";
                StringBuilder indexContent  = new StringBuilder();
                indexContent.Append("<center><font size='5' color='#0000ff'>");
                if (utility.AnonymizationType)
                {
                    indexContent.Append("Anonymized DCM files (Basic)</font></center>");
                }
                else
                {
                    indexContent.Append("Anonymized DCM files (Complete)</font></center>");
                }

                indexContent.Append("<left><font color='black' size = '4'><br></br> Input Directory: " + inputDirectory);
                indexContent.Append("</font>");
                indexContent.Append("</left>");
                indexContent.Append("<br></br>");
                indexContent.Append("<font size='3'>");

                HLI.DataSet srcDataset = null;
                DicomFile   dcmFile    = null;

                allDCMFilesTemp = new ArrayList();
                FileInfo      mediaInputFileInfo = null;
                string        mediaFileDir       = inputDirectory;
                DirectoryInfo theDirectoryInfo   = new DirectoryInfo(mediaFileDir);
                allDCMFilesTemp = utility.GetFilesRecursively(theDirectoryInfo);
                foreach (string fileName in allDCMFilesTemp)
                {
                    mediaInputFileInfo = new FileInfo(fileName);

                    counter++;

                    dcmFile = new DicomFile();
                    dcmFile.Read(fileName, mainThread);

                    // Get the Data set from the selected DCM file
                    srcDataset = dcmFile.DataSet;

                    indexContent.Append("<li><a href='" + mediaInputFileInfo.Name + "_" + counter.ToString() + ".html'>" + fileName.Substring(inputDirectory.Length) + "</a></li>");

                    HLI.DataSet annonymizedDataset = srcDataset.Clone();

                    utility.PatientAttributes(annonymizedDataset);
                    for (int number = 0; number < annonymizedDataset.Count; number++)
                    {
                        HLI.Attribute attribute = annonymizedDataset[number];
                        if (attribute.VR == VR.SQ)
                        {
                            utility.SequenceAttribute_recursive(attribute);
                        }
                        else
                        {
                            utility.CacheAndRepairIdentifyingAttribute(attribute);
                            utility.UpdateAnonymizedAttributes(attribute);
                        }
                    }

                    //Save annonymized data to selected directory
                    string savedFileName = "";
                    if (mediaInputFileInfo.Extension != "")
                    {
                        string srcFileNameWithoutExtn = mediaInputFileInfo.Name.Substring(0, (mediaInputFileInfo.Name.Length - 4));
                        savedFileName = outputDirectory + "\\" + srcFileNameWithoutExtn + "_an";
                    }
                    else
                    {
                        savedFileName = outputDirectory + "\\" + mediaInputFileInfo.Name + "_an";
                    }

                    dcmFile.DataSet = annonymizedDataset;
                    dcmFile.Write(savedFileName);

                    datasets = new AttributeCollections();
                    datasets.Add(srcDataset);
                    datasets.Add(annonymizedDataset);

                    //Cleanup temp file
                    utility.cleanup();

                    resultFileName = mediaInputFileInfo.Name;

                    CreateTableWithoutNav();
                }

                StreamWriter writer = new StreamWriter(indexFileName);
                indexContent.Append("</font>");
                indexContent.Append("<left><font color='black' size = '4'><br></br> Output Directory: " + outputDirectory);

                indexContent.Append("</font>");
                indexContent.Append("</left>");
                writer.Write(indexContent.ToString());
                writer.Close();

                dvtkWebBrowser.Navigate(indexFileName);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 3
0
        private void AnonymizeDCMFile()
        {
            try
            {
                utility.AnonymizationType = anonymizationMode;
                CreateDICOMDIR.Enabled    = true;

                OpenFileDialog fileDialog = new OpenFileDialog();
                fileDialog.Multiselect     = false;
                fileDialog.ReadOnlyChecked = true;
                fileDialog.Title           = "Select DCM File";
                fileDialog.Filter          = "DCM files (*.dcm) |*.dcm|All files (*.*)|*.*";

                // Show the file dialog.
                // If the user pressed the OK button...
                if (fileDialog.ShowDialog() == DialogResult.OK)
                {
                    DicomFile dcmFile = new DicomFile();
                    dcmFile.Read(fileDialog.FileName, mainThread);

                    // Get the Data set from the selected DCM file
                    HLI.DataSet srcDataset = dcmFile.DataSet;

                    SaveFileDialog saveDialog   = new SaveFileDialog();
                    FileInfo       saveFileInfo = null;
                    saveDialog.Filter = "DCM files (*.dcm) |*.dcm|All files (*.*)|*.*";
                    if (saveDialog.ShowDialog() == DialogResult.OK)
                    {
                        HLI.DataSet annonymizedDataset = srcDataset.Clone();

                        utility.PatientAttributes(annonymizedDataset);
                        for (int number = 0; number < annonymizedDataset.Count; number++)
                        {
                            HLI.Attribute attribute = annonymizedDataset[number];
                            if (attribute.VR == VR.SQ)
                            {
                                utility.SequenceAttribute_recursive(attribute);
                            }
                            else
                            {
                                utility.CacheAndRepairIdentifyingAttribute(attribute);
                                utility.UpdateAnonymizedAttributes(attribute);
                            }
                        }

                        datasets = new AttributeCollections();
                        datasets.Add(srcDataset);
                        datasets.Add(annonymizedDataset);

                        //Save annonymized data to selected file
                        saveFileInfo    = new FileInfo(saveDialog.FileName);
                        dcmFile.DataSet = annonymizedDataset;
                        dcmFile.Write(saveFileInfo.FullName);

                        //Cleanup temp file
                        utility.cleanup();
                    }
                    else
                    {
                        return;
                    }

                    string        htmlFileName = initialDirectory + "\\" + saveFileInfo.Name + ".html";
                    XmlTextWriter writer       = new XmlTextWriter(htmlFileName, System.Text.Encoding.UTF8);
                    writer.WriteStartElement("b");
                    writer.WriteRaw(@"<b><font size='3' color='#ff0000'>DCM File Anonymization Started...</font></b>");
                    writer.WriteEndElement();
                    writer.Close();
                    resultFileName = htmlFileName;
                    System.Threading.Thread t = new System.Threading.Thread(new ThreadStart(CreateTable));
                    dvtkWebBrowser.Navigate(htmlFileName);
                    t.Start();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 4
0
        private void ReadDicomdirRefFiles(string dicomFile)
        {
            FileInfo dicomDir = new FileInfo(dicomFile);
            
            _RefFileDatasets.Clear();
            _RefFileFMIs.Clear();
            _RefFileNames.Clear();

            // Read all reference file datasets
            HLI.Attribute recordSeqAttr = _DCMdataset["0x00041220"];
            int recordCount = recordSeqAttr.ItemCount;

            for (int i = 0; i < recordCount; i++)
            {
                HLI.SequenceItem item = recordSeqAttr.GetItem(i + 1);

                // Read all attributes in a item
                for (int j = 0; j < item.Count; j++)
                {
                    HLI.Attribute recordTypeAttr = item["0x00041430"];
                    if ((recordTypeAttr.Values[0] == "IMAGE") ||
                        (recordTypeAttr.Values[0] == "PRESENTATION"))
                    {
                        HLI.Attribute refFileIDAttr = item["0x00041500"];
                        if (refFileIDAttr != null)
                        {
                            string refFileName = dicomDir.DirectoryName + "\\";
                            if (refFileIDAttr.Values.Count != 0)
                            {
                                for (int k = 0; k < refFileIDAttr.Values.Count; k++)
                                {
                                    refFileName += refFileIDAttr.Values[k];
                                    refFileName += @"\";
                                }
                            }
                            refFileName = refFileName.Remove((refFileName.Length - 1), 1);
                            FileInfo refFileInfo = new FileInfo(refFileName);
                            if (refFileInfo.Exists)
                            {
                                HLI.DataSet refFileDataset = new HLI.DataSet();
                                
                                // Read the ref file
                                DicomFile refFile = new DicomFile();
                                refFile.Read(refFileName, _MainThread);

                                //refFileDataset.DvtkDataDataSet = Dvtk.DvtkDataHelper.ReadDataSetFromFile(refFileName);
                                _RefFileDatasets.Add(refFile.DataSet);
                                _RefFileFMIs.Add(refFile.FileMetaInformation);
                                _RefFileNames.Add(refFileName);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 5
0
		void LoadDCMFile(string dicomFile)
		{	
			DCMFile = dicomFile;
            string definitionDir = Environment.GetEnvironmentVariable("COMMONPROGRAMFILES") + @"\DVTk\Definition Files\DICOM\";
			try
			{
				// Load the Definition Files
                DirectoryInfo theDefDirectoryInfo = new DirectoryInfo(definitionDir);
				if(theDefDirectoryInfo.Exists)
				{
					FileInfo[] theDefFilesInfo = theDefDirectoryInfo.GetFiles();
					foreach (FileInfo defFile in theDefFilesInfo)
					{
						bool ok = _MainThread.Options.LoadDefinitionFile(defFile.FullName);
						if(!ok)
						{
							string theWarningText = string.Format("The Definition file {0} could not be loaded.\n", defFile.FullName);
							richTextBoxLog.AppendText(theWarningText);
						}
					}
				}				

				//Subscribe the Dvtk activity report event handler for getting all activity logging.
				_MainThread.Options.DvtkScriptSession.ActivityReportEvent += activityReportEventHandler;
				_MainThread.Options.DvtkScriptSession.AddGroupLength = true;

				// Set the Results & Data directory
				_MainThread.Options.ResultsDirectory = Application.StartupPath + "\\" + "Results";
				_MainThread.Options.DataDirectory = Application.StartupPath + "\\" + "Results";

                // Read the Media file
				DicomFile dcmFile = new DicomFile();
				
				dcmFile.Read(dicomFile, _MainThread);
              // dcmFile.Read(dicomFile);

                // Get the FMI from the selected Media file
				if(_FileMetaInfo == null)
					_FileMetaInfo = new FileMetaInformation();

				_FileMetaInfo = dcmFile.FileMetaInformation;

                string tsStr = "Undefined";
				if(_FileMetaInfo.Exists("0x00020010"))
				{
					// Get the Transfer syntax
					HLI.Attribute tranferSyntaxAttr = _FileMetaInfo["0x00020010"];
					_TransferSyntax = tranferSyntaxAttr.Values[0];
					tsStr = _TransferSyntax;
				}

                menuItemSaveAsELE.Visible = true;
                menuItemSaveAsILE.Visible = true;
                menuItemSaveAsEBE.Visible = true;

                if (_TransferSyntax == "1.2.840.10008.1.2.1")
                    menuItemSaveAsELE.Visible = false;
                else if (_TransferSyntax == "1.2.840.10008.1.2")
                    menuItemSaveAsILE.Visible = false;
                else if (_TransferSyntax == "1.2.840.10008.1.2.2")
                    menuItemSaveAsEBE.Visible = false;
                else
                {
                    menuItemSaveAsELE.Visible = false;
                    menuItemSaveAsILE.Visible = false;
                    menuItemSaveAsEBE.Visible = false;
                }

				// Get the Data set from the selected DICOM file/DICOMDIR
				string sopClassUID = "";
				if(_FileMetaInfo.Exists("0x00020002"))
				{
					// Get the Transfer syntax
					HLI.Attribute sopClassUIDAttr = _FileMetaInfo["0x00020002"];
					sopClassUID = sopClassUIDAttr.Values[0];
				}

				if(_DCMdataset == null)
					_DCMdataset = new HLI.DataSet();
				
				if(sopClassUID == "1.2.840.10008.1.3.10")
				{
					// Read the DICOMDIR dataset
                    _DCMdataset.DvtkDataDataSet = Dvtk.DvtkDataHelper.ReadDataSetFromFile(dicomFile);
                    _IsDICOMDIR = true;
                    IsRefFilesReadCompleted = false;

                    backgroundWorkerEditor.RunWorkerAsync();
              
                    string msg = "DICOMDIR read successfully.\n";
                    richTextBoxLog.AppendText(msg);
				}
				else
				{
                    // Read the Media file dataset
					_DCMdataset = dcmFile.DataSet;
					_IsDICOMDIR = false;
				}

				string theInfoText;
				if(_DCMdataset != null)
				{
					_IsDCMFileLoaded = true;
					UpdateAttributeDataGrid();
					UpdateFMIDataGrid();

                    theInfoText = string.Format("Media file {0} read successfully with Transfer Syntax: {1}.\n\n", dicomFile, tsStr);
                    richTextBoxLog.AppendText(theInfoText);
				}
				else
				{
					theInfoText = string.Format("Error in reading Media file {0}\n\n", DCMFile);

					richTextBoxLog.AppendText(theInfoText);
				}				
			}
			catch(Exception exception)
			{
				//Ask user to get more detailed logging
                string theErrorText = string.Format("Media file {0} could not be read:\n{1}\nDo you want to see detail logging?\n", dicomFile, exception.Message);

				DialogResult theDialogResult = MessageBox.Show(theErrorText, "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error);

				if (theDialogResult == DialogResult.Yes) 
				{
					GetDetailedLogging();
				}
				else
				{
                    richTextBoxLog.AppendText("Select another Media file.");
				}

				_IsDCMFileLoaded = false;
				_DCMdataset = null;
				_FileMetaInfo = null;
				UpdateTitleBarText();
                if (datasetBinding != null)
                    datasetBinding.Clear();
			}			
			
			//Reset the variable 
			_IsNewDCMFileLoaded = false;
		}
Esempio n. 6
0
        void SaveFileAsDefinedTS(string transferSyntax)
        {
            if (DCMFile == "")
            {
                richTextBoxLog.AppendText("There is no Media file to save, please select Media file.\n");
                return;
            }

            try
            {
                SaveFileDialog saveAsDlg = new SaveFileDialog();
                saveAsDlg.Filter = "DCM files (*.dcm) |*.dcm | All files (*.*)|*.*";
                FileInfo dcmFileInfo = new FileInfo(DCMFile);
                saveAsDlg.InitialDirectory = dcmFileInfo.DirectoryName;
                saveAsDlg.FileName = dcmFileInfo.Name;
                saveAsDlg.Title = "Save DICOM file...";
                if (saveAsDlg.ShowDialog() == DialogResult.OK)
                {
                    richTextBoxLog.AppendText("Saving the modified Media file.\n");

                    _NewDCMFileName = saveAsDlg.FileName.Trim();

                    if (DCMFile != _NewDCMFileName)
                        _IsSavedInNewDCMFile = true;

                    DvtkData.Media.DicomFile dicomMediaFile = new DvtkData.Media.DicomFile();

                    // set up the file head
                    DvtkData.Media.FileHead fileHead = new DvtkData.Media.FileHead();

                    // add the Transfer Syntax UID
                    DvtkData.Dul.TransferSyntax tSyntax = new DvtkData.Dul.TransferSyntax(transferSyntax);
                    fileHead.TransferSyntax = tSyntax;

                    // set up the file meta information
                    DvtkData.Media.FileMetaInformation fileMetaInformation = new DvtkData.Media.FileMetaInformation();

                    // add the FMI version
                    fileMetaInformation.AddAttribute(DvtkData.Dimse.Tag.FILE_META_INFORMATION_VERSION.GroupNumber,
                        DvtkData.Dimse.Tag.FILE_META_INFORMATION_VERSION.ElementNumber, VR.OB, 1, 2);

                    // add the SOP Class UID
                    fileMetaInformation.AddAttribute(DvtkData.Dimse.Tag.MEDIA_STORAGE_SOP_CLASS_UID.GroupNumber,
                        DvtkData.Dimse.Tag.MEDIA_STORAGE_SOP_CLASS_UID.ElementNumber, VR.UI, _FileMetaInfo.MediaStorageSOPClassUID);

                    // add the SOP Instance UID
                    fileMetaInformation.AddAttribute(DvtkData.Dimse.Tag.MEDIA_STORAGE_SOP_INSTANCE_UID.GroupNumber,
                        DvtkData.Dimse.Tag.MEDIA_STORAGE_SOP_INSTANCE_UID.ElementNumber, VR.UI, _FileMetaInfo.MediaStorageSOPInstanceUID);

                    // add the Transfer Syntax UID
                    fileMetaInformation.AddAttribute(DvtkData.Dimse.Tag.TRANSFER_SYNTAX_UID.GroupNumber,
                        DvtkData.Dimse.Tag.TRANSFER_SYNTAX_UID.ElementNumber, VR.UI, transferSyntax);

                    // add the Implemenation Class UID
                    string implClassUID = "";
				    if(_FileMetaInfo.Exists("0x00020012"))
				    {
					    // Get the Transfer syntax
					    HLI.Attribute implClassUIDAttr = _FileMetaInfo["0x00020012"];
					    implClassUID = implClassUIDAttr.Values[0];
				    }

                    fileMetaInformation.AddAttribute(DvtkData.Dimse.Tag.IMPLEMENTATION_CLASS_UID.GroupNumber,
                        DvtkData.Dimse.Tag.IMPLEMENTATION_CLASS_UID.ElementNumber, VR.UI, implClassUID);

                    // add the Implementation Version Name
                    string implClassVersion = "";
				    if(_FileMetaInfo.Exists("0x00020013"))
				    {
					    // Get the Transfer syntax
					    HLI.Attribute implClassVersionAttr = _FileMetaInfo["0x00020013"];
					    implClassVersion = implClassVersionAttr.Values[0];
				    }

                    fileMetaInformation.AddAttribute(DvtkData.Dimse.Tag.IMPLEMENTATION_VERSION_NAME.GroupNumber,
                        DvtkData.Dimse.Tag.IMPLEMENTATION_VERSION_NAME.ElementNumber, VR.SH, implClassVersion);

                    // set up the dicomMediaFile contents
                    dicomMediaFile.FileHead = fileHead;
                    dicomMediaFile.FileMetaInformation = fileMetaInformation;
                    dicomMediaFile.DataSet = _DCMdataset.DvtkDataDataSet;

                    // write the dicomMediaFile to file
                    Dvtk.DvtkDataHelper.WriteDataSetToFile(dicomMediaFile, _NewDCMFileName);

                    string theLogText = string.Format("Dataset {0} saved successfully with transfer syntax: {1}.\n\n", _NewDCMFileName, transferSyntax);

                    richTextBoxLog.AppendText(theLogText);
                    richTextBoxLog.ScrollToCaret();
                    richTextBoxLog.Focus();

                    //Cleanup the FMI & Dataset
                    IsDCMFileModified = false;
                    _IsAttributeGroupLengthDefined = false;
                    _DCMdataset = null;
                    _FileMetaInfo = null;

                    if (_IsSavedInNewDCMFile)
                    {
                        FileInfo newDcmFileInfo = new FileInfo(_NewDCMFileName);

                        _IsNewDCMFileLoaded = true;
                        this.dirListBox.Path = newDcmFileInfo.DirectoryName;
                        this.fileListBox.Path = this.dirListBox.Path;
                        this.fileListBox.SelectedItem = newDcmFileInfo.Name;

                        this.dirListBox.Refresh();
                        this.fileListBox.Refresh();

                        //Load the new Media file
                        LoadDCMFile(_NewDCMFileName);
                    }
                    else
                    {
                        _IsNewDCMFileLoaded = false;
                        this.dirListBox.Path = dcmFileInfo.DirectoryName;
                        this.fileListBox.Path = this.dirListBox.Path;
                        this.fileListBox.SelectedItem = dcmFileInfo.Name;

                        //Load the new Media file
                        LoadDCMFile(DCMFile);
                    }

                    UpdateTitleBarText();
                }
            }
            catch (Exception exception)
            {
                string theErrorText;

                theErrorText = string.Format("Media file {0} could not be saved:\n{1}\n\n", _NewDCMFileName, exception.Message);

                richTextBoxLog.AppendText(theErrorText);
                richTextBoxLog.ScrollToCaret();
                richTextBoxLog.Focus();

                IsDCMFileModified = false;
                UpdateTitleBarText();
            }            
        }
Esempio n. 7
0
		private void buttonSave_Click(object sender, System.EventArgs e)
		{
			if(DCMFile == "")
			{
                richTextBoxLog.AppendText("There is no Media file to save, please select Media file.\n");
				return;
			}

			try
			{
				SaveFileDialog saveAsDlg = new SaveFileDialog();
				saveAsDlg.Filter = "DCM files (*.dcm)|*.dcm|All files (*.*)|*.*";
				FileInfo dcmFileInfo = new FileInfo(DCMFile);
				saveAsDlg.InitialDirectory = dcmFileInfo.DirectoryName;
				saveAsDlg.FileName = dcmFileInfo.Name;
                saveAsDlg.Title = "Save Media file...";
				if (saveAsDlg.ShowDialog () == DialogResult.OK)
				{
                    richTextBoxLog.AppendText("Saving the modified Media file.\n");

					_NewDCMFileName = saveAsDlg.FileName.Trim();

					if(DCMFile != _NewDCMFileName)
						_IsSavedInNewDCMFile = true;
                    
                    string theLogText;
                    if (!_IsDICOMDIR)
                    {
                        DicomFile dcmFile = new DicomFile();

                        // Add FMI as it is to Media file
                        dcmFile.FileMetaInformation = _FileMetaInfo;
                        dcmFile.FileMetaInformation.TransferSyntax = _TransferSyntax;

                        // Add modified dataset to Media file
                        dcmFile.DataSet = _DCMdataset;

                        //Set attribute group length
                        if (_IsAttributeGroupLengthDefined)
                            dcmFile.AddGroupLength = true;

                        dcmFile.Write(_NewDCMFileName);
                    }
                    else
                    {
                        //DicomDir dicomdir = new DicomDir();

                        //// Add FMI as it is to Media file
                        //dicomdir.FileMetaInformation = _FileMetaInfo;
                        //dicomdir.FileMetaInformation.TransferSyntax = _TransferSyntax;

                        //// Add modified dataset to Media file
                        //dicomdir.DataSet = _DCMdataset;

                        //dicomdir.Write(_NewDCMFileName);
                    }
				
					theLogText = string.Format("Media file {0} saved successfully.\n\n", _NewDCMFileName);

					richTextBoxLog.AppendText(theLogText);
					richTextBoxLog.ScrollToCaret();
					richTextBoxLog.Focus();

					//Cleanup the FMI & Dataset
					IsDCMFileModified = false;
					_IsAttributeGroupLengthDefined = false;
					_DCMdataset = null;
					_FileMetaInfo = null;

					if(_IsSavedInNewDCMFile)
					{
						FileInfo newDcmFileInfo = new FileInfo(_NewDCMFileName);

						_IsNewDCMFileLoaded = true;
						this.dirListBox.Path = newDcmFileInfo.DirectoryName;
						this.fileListBox.Path = this.dirListBox.Path;
						this.fileListBox.SelectedItem = newDcmFileInfo.Name;

                        this.dirListBox.Refresh();
						this.fileListBox.Refresh();

                        //Load the new Media file
						LoadDCMFile(_NewDCMFileName);
					}
					else
					{
						_IsNewDCMFileLoaded = false;
						this.dirListBox.Path = dcmFileInfo.DirectoryName;
						this.fileListBox.Path = this.dirListBox.Path;
						this.fileListBox.SelectedItem = dcmFileInfo.Name;

                        //Load the new Media file
						LoadDCMFile(DCMFile);
					}

					UpdateTitleBarText();
				}
			}
			catch(Exception exception)
			{
				string theErrorText;

				theErrorText = string.Format("Media file {0} could not be saved:\n{1}\n\n", _NewDCMFileName, exception.Message);

				richTextBoxLog.AppendText(theErrorText);
				richTextBoxLog.ScrollToCaret();
				richTextBoxLog.Focus();

				IsDCMFileModified = false;
				UpdateTitleBarText();
			}						
		}
Esempio n. 8
0
		public DICOMEditor()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			// Initialize the Dvtk library
			Dvtk.Setup.Initialize();

			_DCMdataset = new HLI.DataSet();
			_FileMetaInfo = new FileMetaInformation();

			_AttributesInfoForDataGrid = new ArrayList();
			_FMIForDataGrid = new ArrayList();
			InitializeDatasetGrid();
			InitializeFMIGrid();

			// Get the session context 
			ThreadManager threadMgr = new ThreadManager();
			_MainThread = new MainThread();
			_MainThread.Initialize(threadMgr);
	
			// Subscribe to Dvtk Activity report handler
			activityReportEventHandler = new Dvtk.Events.ActivityReportEventHandler(OnActivityReportEvent);

			// Subscribe to Sniffer Activity report handler
			activityLoggingDelegate = new appendTextToActivityLogging_ThreadSafe_Delegate(this.AppendTextToActivityLogging_ThreadSafe);

            // Provide functionality to open application with Media file or Directory
            // which contains Media files
			if(dcmFileOrDirToBeOpened != "")
			{
				DirectoryInfo userDirInfo = new DirectoryInfo(dcmFileOrDirToBeOpened.Trim());
				if(userDirInfo.Exists)
				{
                    //It's a directory contains Media files
					this.dirListBox.Path = userDirInfo.FullName;
					this.fileListBox.Path = this.dirListBox.Path;
				}
				else
				{
                    //It's a Media file
					FileInfo dcmFileInfo = new FileInfo(dcmFileOrDirToBeOpened.Trim());

					this.dirListBox.Path = dcmFileInfo.DirectoryName;
					this.fileListBox.Path = this.dirListBox.Path;
					this.fileListBox.SelectedItem = dcmFileInfo.Name;
				}				
			}
		}
Esempio n. 9
0
		/// <summary>
		/// Constructor
		/// </summary>
		public DCMEditor()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
            fileTypeCombo.DropDownStyle = ComboBoxStyle.DropDownList;
            fileTypeCombo.SelectedIndex = 0;
            
			_DCMdataset = new HLI.DataSet();
			_FileMetaInfo = new FileMetaInformation();

			_AttributesInfoForDataGrid = new ArrayList();
			_FMIForDataGrid = new ArrayList();
			InitializeDatasetGrid();
			InitializeFMIGrid();

			// Get the session context & load definition file
			ThreadManager threadMgr = new ThreadManager();
			_MainThread = new MainThread();
			_MainThread.Initialize(threadMgr);			
		}
Esempio n. 10
0
		void LoadDCMFile(string dicomFile)
		{	
			DCMFile = dicomFile;
			
			try
			{
				// Load the Definition Files
				foreach (string defFile in _DefFiles)
				{
					if(!_MainThread.Options.LoadDefinitionFile(defFile))
					{
						string theWarningText = string.Format("The Definition file {0} could not be loaded.\n", defFile);

						richTextBoxLog.AppendText(theWarningText);
					}
				}

				_DefFiles.Clear();

				// Set the Data directory
				_MainThread.Options.DataDirectory = _DataDirectory;

				// Read the DCM File
				DicomFile dcmFile = new DicomFile();
				dcmFile.DataSet.UnVrDefinitionLookUpWhenReading = false;
				dcmFile.Read(_DCMFileName, _MainThread);

				// Get the FMI from the selected DCM file
				// Get the FMI from the selected DCM file
				if(_FileMetaInfo == null)
					_FileMetaInfo = new FileMetaInformation();

				_FileMetaInfo = dcmFile.FileMetaInformation;

				string tsStr;
				if(_FileMetaInfo.Exists("0x00020010"))
				{
					// Get the Transfer syntax
					HLI.Attribute tranferSyntaxAttr = _FileMetaInfo["0x00020010"];
					_TransferSyntax = tranferSyntaxAttr.Values[0];
					tsStr = _TransferSyntax;
				}
				else
				{
					_TransferSyntax = "1.2.840.10008.1.2.1";
					tsStr = "Undefined, the default transfer syntax will Explicit VR Little Endian";
					_FileMetaInfo.Set("0x00020010",VR.UI,"1.2.840.10008.1.2.1");
				}

				// Get the Data set from the selected DCM file
				if(_DCMdataset == null)
					_DCMdataset = new HLI.DataSet();

				_DCMdataset = dcmFile.DataSet;

				string theInfoText;
				if(_DCMdataset != null)
				{
					UpdateAttributeDataGrid();
					UpdateFMIDataGrid();

					theInfoText = string.Format("DCM file {0} read successfully with Transfer Syntax {1}.\n\n", _DCMFileName,tsStr);

					richTextBoxLog.AppendText(theInfoText);
				}
				else
				{
					theInfoText = string.Format("Error in reading DCM file {0}\n\n", _DCMFileName);

					richTextBoxLog.AppendText(theInfoText);
				}	
			}
			catch(Exception exception)
			{
				string theErrorText;

				theErrorText = string.Format("DCM file {0} could not be read:\n{1}\n\n", _DCMFileName, exception.Message);

				richTextBoxLog.AppendText(theErrorText);

				_DCMdataset = null;
				_FileMetaInfo = null;
				//dataGridAttributes.SetDataBinding(null, "");
			}
			
		
			//Reset the variable 
			_IsNewDCMFileLoaded = false;
		}
Esempio n. 11
0
		private void buttonSave_Click(object sender, System.EventArgs e)
		{
			if(_DCMFileName == "")
			{
				richTextBoxLog.AppendText("There is no DCM File to save, please select DCM file.\n");
				return;
			}

			richTextBoxLog.AppendText("Saving the modified DCM file.\n");

			try
			{
				SaveFileDialog saveAsDlg = new SaveFileDialog();
				saveAsDlg.Filter = "DCM files (*.dcm)|*.dcm|All files (*.*)|*.*";
				FileInfo dcmFileInfo = new FileInfo(_DCMFileName);
				saveAsDlg.InitialDirectory = dcmFileInfo.DirectoryName;
				saveAsDlg.FileName = dcmFileInfo.Name;
				saveAsDlg.Title = "Save DCM File...";
				if (saveAsDlg.ShowDialog () == DialogResult.OK)
				{
					_NewDCMFileName = saveAsDlg.FileName.Trim();

					if(_DCMFileName != _NewDCMFileName)
						_IsSavedInNewDCMFile = true;

					_DCMFileName = saveAsDlg.FileName;

					DicomFile dcmFile = new DicomFile();
									
					// Add FMI as it is to DCM file
					dcmFile.FileMetaInformation = _FileMetaInfo;

					// Add modified dataset to DCM file
					dcmFile.DataSet = _DCMdataset;

					string theLogText;

					dcmFile.Write(_NewDCMFileName);

					theLogText = string.Format("DCM file {0} saved successfully.\n\n", _NewDCMFileName);
					richTextBoxLog.AppendText(theLogText);
					richTextBoxLog.ScrollToCaret();
					_IsDCMFileChanged = false;
					_DCMdataset = null;
					_FileMetaInfo = null;

					if(_IsSavedInNewDCMFile)
					{
						FileInfo newDcmFileInfo = new FileInfo(_NewDCMFileName);

						_IsNewDCMFileLoaded = true;
						this.dirListBox.Path = newDcmFileInfo.DirectoryName;
						this.fileListBox.Path = this.dirListBox.Path;
						this.fileListBox.SelectedItem = newDcmFileInfo.Name;

						this.dirListBox.Refresh();
						this.fileListBox.Refresh();

						//Load the new DCM file
						LoadDCMFile(_NewDCMFileName);
					}
					else
					{
						_IsNewDCMFileLoaded = false;
						this.dirListBox.Path = dcmFileInfo.DirectoryName;
						this.fileListBox.Path = this.dirListBox.Path;
						this.fileListBox.SelectedItem = dcmFileInfo.Name;

						//Load the new DCM file
						LoadDCMFile(_DCMFileName);
					}
				}
			}
			catch(Exception exception)
			{
				string theErrorText;

				theErrorText = string.Format("DCM file {0} could not be saved:\n{1}\n\n", _NewDCMFileName, exception.Message);

				richTextBoxLog.AppendText(theErrorText);
				richTextBoxLog.ScrollToCaret();

				_IsDCMFileChanged = false;
			}						
		}