Ejemplo n.º 1
0
        /*
         * Creates and modifies the meta header for this dataset
         */
        private void InsertMetaHeader(ref DicomDataSet pDS)
        {
            DicomElement element;

            // Add File Meta Information Version
            element = pDS.FindFirstElement(null, DemoDicomTags.FileMetaInformationVersion, false);
            if (element == null)
            {
                element = pDS.InsertElement(null, false, DemoDicomTags.FileMetaInformationVersion, DicomVRType.OB, false, 0);
            }
            byte[] cValue = new byte[2] {
                0, 1
            };
            pDS.SetBinaryValue(element, cValue, 2);

            // Implementation Class UID
            element = pDS.FindFirstElement(null, DemoDicomTags.ImplementationClassUID, false);
            if (element == null)
            {
                element = pDS.InsertElement(null, false, DemoDicomTags.ImplementationClassUID, DicomVRType.UI, false, 0);
            }
            pDS.SetConvertValue(element, LEAD_IMPLEMENTATION_CLASS_UID, 1);

            // Implementation Version Name
            element = pDS.FindFirstElement(null, DemoDicomTags.ImplementationVersionName, false);
            if (element == null)
            {
                element = pDS.InsertElement(null, false, DemoDicomTags.ImplementationVersionName, DicomVRType.UI, false, 0);
            }
            pDS.SetConvertValue(element, LEAD_IMPLEMENTATION_VERSION_NAME, 1);
        }
Ejemplo n.º 2
0
        private bool ShowImage()
        {
            try
            {
                DicomElement element = null;
                element = _dsImage.FindFirstElement(null, DemoDicomTags.PixelData, true);
                int bitmapCount = _dsImage.GetImageCount(element);
                if (bitmapCount > 0)
                {
                    FreeImage();
                    if (bitmapCount == 1)
                    {
                        if (element != null)
                        {
                            RasterImage image;

                            image = _dsImage.GetImage(element, 0, 0, RasterByteOrder.Gray, _getImageFlags);

                            _viewer.Image = image;
                        }
                    }
                    else
                    {
                        if (element != null)
                        {
                            LoadBitmapList(element);
                        }
                    }

                    if (element != null)
                    {
                        _imageInfo = _dsImage.GetImageInformation(element, 0);
                    }

                    if ((_dicomAnnotationsUtilities != null) && (_viewer.Image != null))
                    {
                        _dicomAnnotationsUtilities.DisplayWidth  = _viewer.Image.Width;
                        _dicomAnnotationsUtilities.DisplayHeight = _viewer.Image.Height;
                    }

                    return(true);
                }
                else
                {
                    Messager.ShowInformation(this, "Please note that this dataset doesn't include any images.");
                }
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.Assert(false);
                throw exception;
            }
            return(false);
        }
Ejemplo n.º 3
0
        /*
         * Sets the appropriate dates for this Dataset
         */
        private void SetStudyDateAndTime(ref DicomDataSet pDS)
        {
            try
            {
                DateTime     SystemTime = DateTime.Now;
                string       strValue;
                DicomElement element;

                // Set study date
                strValue = SystemTime.ToShortDateString();
                element  = pDS.FindFirstElement(null, DemoDicomTags.StudyDate, false);
                if (element != null)
                {
                    pDS.SetConvertValue(element, strValue, 1);
                }

                // Set content date
                element = pDS.FindFirstElement(null, DemoDicomTags.ContentDate, false);
                if (element != null)
                {
                    pDS.SetConvertValue(element, strValue, 1);
                }

                // Set Study time
                strValue = string.Format("{0}:{1}:{2}", SystemTime.Hour, SystemTime.Minute, SystemTime.Second);
                element  = pDS.FindFirstElement(null, DemoDicomTags.StudyTime, false);
                if (element != null)
                {
                    pDS.SetConvertValue(element, strValue, 1);
                }

                // Set content time
                element = pDS.FindFirstElement(null, DemoDicomTags.ContentTime, false);
                if (element != null)
                {
                    pDS.SetConvertValue(element, strValue, 1);
                }

                strValue = string.Format("{0} {1}:{2}:{3}", SystemTime.ToShortDateString(), SystemTime.Hour, SystemTime.Minute, SystemTime.Second);
                // Set acquisition date time
                element = pDS.FindFirstElement(null, DemoDicomTags.AcquisitionDateTime, false);
                if (element != null)
                {
                    pDS.SetConvertValue(element, strValue, 1);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while setting the dataset's dates: \r\n\r\n" + ex.ToString());
            }
        }
Ejemplo n.º 4
0
        private void AddCommitItem(DicomDataSet ds, long tag, StorageCommit.StorageCommit commit)
        {
            DicomElement rppss = null;
            DicomElement element;

            rppss = ds.FindFirstElement(null, tag, true);

            // If SameStudy goes to false, it is false for the entire commit
            if (commit.SameStudy)
            {
                commit.SameStudy = rppss != null;
            }
            commit.TransactionUID = ds.GetValue <string>(DicomTag.TransactionUID, string.Empty);
            element = ds.GetChildElement(rppss, false);
            while (element != null)
            {
                DicomElement child = ds.GetChildElement(element, true);

                if (child != null)
                {
                    StorageCommitItem item = new StorageCommitItem();

                    item.SOPClassUID    = ds.GetValue <string>(child, true, DicomTag.ReferencedSOPClassUID, string.Empty);
                    item.SOPInstanceUID = ds.GetValue <string>(child, true, DicomTag.ReferencedSOPInstanceUID, string.Empty);
                    commit.Items.Add(item);
                }
                element = ds.GetNextElement(element, true, true);
            }
        }
Ejemplo n.º 5
0
        public static DicomExceptionCode SetKeyElement(DicomDataSet dcmRsp, long tag, object tagValue, bool tree)
        {
            DicomExceptionCode ret = DicomExceptionCode.Success;
            DicomElement       element;

            if (tagValue == null)
            {
                return(DicomExceptionCode.Parameter);
            }

            try
            {
                element = dcmRsp.FindFirstElement(null, tag, tree);
                if (element != null)
                {
                    string s = tagValue.ToString();
                    if (IsAscii(s))
                    {
                        dcmRsp.SetConvertValue(element, s, 1);
                    }
                    else
                    {
                        dcmRsp.SetStringValue(element, s, DicomCharacterSetType.UnicodeInUtf8);
                    }
                }
            }
            catch (DicomException de)
            {
                ret = de.Code;
            }

            return(ret);
        }
Ejemplo n.º 6
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            try
            {
                using (DicomDataSet ds = new DicomDataSet())     //New data set
                {
                    if (!File.Exists(_EncapsulatedPDFDicomFile)) //Check to see if the DICOM file has already been created
                    {
                        MessageBox.Show(string.Format("File \"{0}\" doesn't exist, try clicking the \"{1}\" button first", _EncapsulatedPDFDicomFile, btnCreate.Text));
                        return;
                    }

                    ds.Load(_EncapsulatedPDFDicomFile, DicomDataSetLoadFlags.None);                        //Load the DICOM File containing the encapsulsated document
                    DicomElement element = ds.FindFirstElement(null, DicomTag.EncapsulatedDocument, true); //Find the EncapsulatedDocument element (0042:0011)
                    if (element != null)
                    {
                        DicomDataSet_GetEncapsulatedDocumentExample(element, false, ds, _PDFOutFile); //Extract and print the attributes of the encapsulated document

                        _codecs.Options.Load.XResolution = 300;
                        _codecs.Options.Load.YResolution = 300;
                        rasterImageViewer1.Image         = _codecs.Load(_PDFOutFile); //Load the encapsulated document into the image viewer
                    }
                    else
                    {
                        MessageBox.Show("Couldn't find Encapsulated Document element (0042,0011)");
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 7
0
        static List <MedicalViewerPageInfo> GetPagesInfoFromMaster(DicomDataSet ds, MedicalViewerPageInfo ppiMaster)
        {
            try
            {
                List <MedicalViewerPageInfo> ppiLst = new List <MedicalViewerPageInfo>();

                DicomElement        elemPerFrameFunctionalGroupsSequence = ds.FindFirstElement(null, DicomTag.PerFrameFunctionalGroupsSequence, true);
                List <DicomElement> elemImagePositionPatient             = new List <DicomElement>();
                FindChildElements(ds, elemPerFrameFunctionalGroupsSequence, DicomTag.ImagePositionPatient, elemImagePositionPatient);
                foreach (DicomElement de in elemImagePositionPatient)
                {
                    MedicalViewerPageInfo ppi = new MedicalViewerPageInfo
                    {
                        ImageOrientationPatientArray = ppiMaster.ImageOrientationPatientArray,
                        ImagePositionPatientArray    = ds.GetDoubleValue(de, 0, 3),
                        PixelSpacingPatientArray     = ppiMaster.PixelSpacingPatientArray
                    };
                    Normalize(ppi);
                    ppiLst.Add(ppi);
                }

                return(ppiLst);
            }
            catch
            {
                return(new List <MedicalViewerPageInfo>());
            }
        }
Ejemplo n.º 8
0
        bool LoadDicomFile(string filename)
        {
            //if (_cancel)
            //   return false;

            using (DicomDataSet ds = new DicomDataSet())
            {
                ListViewItem item = null;
                DicomElement element;
                string       strTransferSyntax = "";
                bool         succeeded         = true;

                try
                {
                    this.Cursor = Cursors.WaitCursor;
                    ds.Load(filename, DicomDataSetLoadFlags.None);
                    item = listViewImages.Items.Add(ds.GetValue <string>(DicomTag.PatientName, string.Empty));
                    item.SubItems.Add(ds.GetValue <string>(DicomTag.PatientID, string.Empty));
                    item.SubItems.Add(ds.GetValue <string>(DicomTag.StudyID, string.Empty));
                    item.SubItems.Add(ds.GetValue <string>(DicomTag.Modality, string.Empty));

                    strTransferSyntax = "Implicit VR - Little Endian";

                    element = ds.FindFirstElement(null, DicomTag.TransferSyntaxUID, false);
                    if (element != null && ds.GetElementValueCount(element) > 0)
                    {
                        string   uidString;
                        DicomUid uid;

                        uidString = ds.GetValue <string>(element, string.Empty);
                        uid       = DicomUidTable.Instance.Find(uidString);
                        if (uid != null)
                        {
                            strTransferSyntax = uid.Name;
                        }
                    }
                }
                catch (DicomException de)
                {
                    LogText("Dicom error: " + de.Code.ToString(), filename);
                    succeeded = false;
                }

                if (succeeded)
                {
                    // Mark item read if we have a basic directory
                    if (ds.InformationClass == DicomClassType.BasicDirectory)
                    {
                        item.Font = new Font(listViewImages.Font, FontStyle.Bold);
                    }

                    item.SubItems.Add(strTransferSyntax);
                    item.SubItems.Add(filename);

                    item.Checked = true;
                }
                this.Cursor = Cursors.Default;
                return(succeeded);
            }
        }
Ejemplo n.º 9
0
        public static int?MyGetIntValue(this DicomDataSet ds, long tag)
        {
            DicomElement element = ds.FindFirstElement(null, tag, true);

            if (null == element || element.Length == 0)
            {
                return(null);
            }
            else
            {
                int[] values;


                values = ds.GetIntValue(element, 0, 1);

                if (values != null && values.Length > 0)
                {
                    return(values[0]);
                }
                else
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 10
0
        /*
         * Sets a DicomElement that is either a DicomDateValue or DicomTimeValue
         */

        private void SetTimeDateKeyElement(DicomDataSet ResponseDS, DateTime dt, long tag, bool bTimeValue)
        {
            try
            {
                DicomElement element = ResponseDS.FindFirstElement(null, tag, false);
                if (element != null)
                {
                    if (bTimeValue)
                    {
                        DicomTimeValue[] dtv = new DicomTimeValue[1];
                        dtv[0] = new DicomTimeValue(dt);
                        ResponseDS.SetTimeValue(element, dtv);
                    }
                    else
                    {
                        DicomDateValue[] ddv = new DicomDateValue[1];
                        ddv[0] = new DicomDateValue(dt);
                        ResponseDS.SetDateValue(element, ddv);
                    }
                }
            }
            catch (Exception ex)
            {
                server.mf.Log("Error setting time or date element:\r\n\r\n" + ex.ToString());
                return;
            }
        }
Ejemplo n.º 11
0
        public static bool IsTagPresent(DicomDataSet dcm, long tag)
        {
            DicomElement element;

            element = dcm.FindFirstElement(null, tag, true);
            return(element != null);
        }
Ejemplo n.º 12
0
        public static DicomDateRangeValue[] GetDateRange(DicomDataSet ds, long Tag)
        {
            // Get the date range count
            List <string> dateList = ds.GetValue <List <string> >(Tag, null);

            if (dateList == null)
            {
                return(null);
            }

            int count = dateList.Count;

            if (count <= 0)
            {
                return(null);
            }

            DicomDateRangeValue[] d = new DicomDateRangeValue[count];

            DicomElement element = ds.FindFirstElement(null, Tag, true);

            if (element != null)
            {
                if (element.Length > 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        d[i] = ds.GetDateRangeValue(element, i);
                    }
                    return(d);
                }
            }

            return(null);
        }
Ejemplo n.º 13
0
        public static bool HasTag(DicomDataSet ds, long Tag)
        {
            DicomElement element;

            element = ds.FindFirstElement(null, Tag, false);
            return(element != null);
        }
Ejemplo n.º 14
0
        private void DoStoreRequest( )
        {
            DicomCommandStatusType status = DicomCommandStatusType.ProcessingFailure;
            string       msg = "Error saving dataset received from: " + AETitle;
            DicomElement element;

            if (!IsActionSupported())
            {
                string name = GetUIDName();

                server.mf.Log("C-STORE-REQUEST", "Abstract syntax (" + name + ") not supported by association");
                client.SendCStoreResponse(_PresentationID, _MessageID, _Class, _Instance,
                                          DicomCommandStatusType.ClassNotSupported);
                return;
            }

            element = ds.FindFirstElement(null, DemoDicomTags.SOPInstanceUID, true);
            if (element != null)
            {
                string       value = ds.GetConvertValue(element);
                string       file;
                InsertReturn ret;

                file = server.ImageDir + value + ".dcm";
                ret  = server.mf.DicomData.Insert(ds, file);
                switch (ret)
                {
                case InsertReturn.Success:
                    DicomExceptionCode dret = SaveDataSet(file);
                    if (dret == DicomExceptionCode.Success)
                    {
                        status = DicomCommandStatusType.Success;
                    }
                    else
                    {
                        msg = "Error saving dicom file: " + dret.ToString();
                    }
                    server.mf.Log("C-STORE-REQUEST", "New file imported: " + file);
                    break;

                case InsertReturn.Exists:
                    msg = "File (" + file + ") not imported. Record already exists in database";
                    break;

                case InsertReturn.Error:
                    msg = "Error importing file: " + file;
                    break;
                }
            }

            if (status != DicomCommandStatusType.Success)
            {
                server.mf.Log("C-STORE-REQUEST", msg);
            }

            client.SendCStoreResponse(_PresentationID, _MessageID, _Class, _Instance, status);
            server.mf.Log("C-STORE-RESPONSE", "Response sent to " + AETitle);
        }
Ejemplo n.º 15
0
        /*
         * Copies the elements of an MWL dataset (from Step4 (page3.cs) into a newly initialized dataset
         */
        public void MapMWLtoDS(DicomDataSet MWL_DS)
        {
            if (MWL_DS == null)
            {
                return;
            }

            try
            {
                DicomElement element;
                element = MWL_DS.GetFirstElement(null, true, true);
                while (element != null)
                {
                    if (!ReservedElement(element))
                    {
                        if (element.Tag == DemoDicomTags.ScheduledProcedureStepSequence)
                        {
                            DicomElement TmpElement;
                            TmpElement = MWL_DS.FindFirstElement(element, DemoDicomTags.ScheduledProcedureStepID, false);
                            if (TmpElement != null)
                            {
                                MapElement(MWL_DS, TmpElement);
                            }

                            TmpElement = MWL_DS.FindFirstElement(element, DemoDicomTags.ScheduledProcedureStepDescription, false);
                            if (TmpElement != null)
                            {
                                MapElement(MWL_DS, TmpElement);
                            }
                        }
                        else if (!MapElement(MWL_DS, element))
                        {
                            CopyElement(MWL_DS, element, null);
                        }
                    }

                    // Traverse as tree
                    element = MWL_DS.GetNextElement(element, true, true);
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 16
0
        public static void RemoveTag(this DicomDataSet ds, long tag)
        {
            DicomElement element = ds.FindFirstElement(null, tag, false);

            if (element != null)
            {
                ds.DeleteElement(element);
            }
        }
Ejemplo n.º 17
0
        public void Delete(long tag)
        {
            DicomElement element = _Dataset.FindFirstElement(null, tag, false);

            if (element != null)
            {
                _Dataset.DeleteElement(element);
            }
        }
Ejemplo n.º 18
0
        public static int GetCount(this DicomDataSet ds, long tag)
        {
            DicomElement element = ds.FindFirstElement(null, tag, false);

            if (element != null)
            {
                return(ds.GetElementValueCount(element));
            }

            return(0);
        }
Ejemplo n.º 19
0
        /*
         * Loads an image based on the Referened File ID element
         *
         * Preconditions:
         *   1. element != null
         *   2. element.Tag == DemoDicomTags.ReferencedFileID
         */
        private void DisplayImage(DicomElement element)
        {
            if (!m_DicomDir.DataSet.ExistsElement(element))
            {
                return;
            }

            txtElementValue.Text = "";

            // Get file name
            string strFileName = m_strDicomFilesFolder;

            for (int i = 0; i < m_DicomDir.DataSet.GetElementValueCount(element); i++)
            {
                strFileName += "\\" + m_DicomDir.DataSet.GetStringValue(element, i);
            }

            // Load the data set
            DicomDataSet ImageDS = new DicomDataSet();

            try
            {
                ImageDS.Load(strFileName, DicomDataSetLoadFlags.LoadAndClose);
            }
            catch (Exception ex)
            {
                SetStatus(string.Format("Failed to load DataSet.  Error Message: {0}", ex.Message));
                return;
            }

            // Get the image from the Pixel Data element and display it in the viewer
            try
            {
                DicomElement PixelDataElement = ImageDS.FindFirstElement(null, DemoDicomTags.PixelData, false);
                if (PixelDataElement == null)
                {
                    SetStatus(string.Format("Dataset does not contain an image."));
                    return;
                }

                rasterImageViewer1.Image = ImageDS.GetImage(PixelDataElement,
                                                            0,
                                                            0,
                                                            RasterByteOrder.Rgb,
                                                            DicomGetImageFlags.AutoApplyModalityLut | DicomGetImageFlags.AutoApplyVoiLut | DicomGetImageFlags.AllowRangeExpansion);
                rasterImageViewer1.Visible = true;
            }
            catch (Exception ex)
            {
                SetStatus(string.Format("Failed to load the image from the DataSet.  Error Message: {0}", ex.Message));
                return;
            }
        }
Ejemplo n.º 20
0
        private void OpenDataset(string filename)
        {
            try
            {
                _DataSet.Load(filename, DicomDataSetLoadFlags.LoadAndClose);

                // Find Pixel Data
                _PixelElement = _DataSet.FindFirstElement(null, DicomTag.PixelData, true);
                if (_PixelElement != null)
                {
                    // Load Base Image
#if !LEADTOOLS_V20_OR_LATER
                    DicomGetImageFlags getImageFlags =
                        DicomGetImageFlags.AutoApplyModalityLut |
                        DicomGetImageFlags.AutoApplyVoiLut |
                        DicomGetImageFlags.AutoScaleModalityLut |
                        DicomGetImageFlags.AutoScaleVoiLut |
                        DicomGetImageFlags.AutoDectectInvalidRleCompression |
                        DicomGetImageFlags.AutoLoadOverlays;
#else
                    DicomGetImageFlags getImageFlags =
                        DicomGetImageFlags.AutoApplyModalityLut |
                        DicomGetImageFlags.AutoApplyVoiLut |
                        DicomGetImageFlags.AutoScaleModalityLut |
                        DicomGetImageFlags.AutoScaleVoiLut |
                        DicomGetImageFlags.AutoDetectInvalidRleCompression |
                        DicomGetImageFlags.AutoLoadOverlays;
#endif // #if !LEADTOOLS_V20_OR_LATER

                    _rasterImageViewer.Image = _DataSet.GetImage(_PixelElement, 0, 0, RasterByteOrder.Gray, getImageFlags);
                    LoadOverlays();
                    _mnuOverlaysInsertOverlay.Enabled = true;
                    _mnuFileSave.Enabled = true;
                }
                else
                {
                    Messager.ShowError(this, "NO Pixel Data");
                    _mnuOverlaysInsertOverlay.Enabled = false;
                    _mnuFileSave.Enabled = false;
                }

                EnableOverlayOptions();
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, ex);
            }
            finally
            {
                EnableOverlayOptions();
            }
        }
Ejemplo n.º 21
0
        private string GetDicomTag(DicomDataSet ds, long tag)
        {
            DicomElement patientElement = ds.FindFirstElement(null,
                                                              tag,
                                                              true);

            if (patientElement != null)
            {
                return(ds.GetConvertValue(patientElement));
            }

            return(null);
        }
Ejemplo n.º 22
0
        public bool AddPatient(string authenticationCookie, PatientInfo_Json patientInfo, string userData)
        {
            try
            {
                string userName;

                userName = ServiceUtils.Authorize(authenticationCookie, PermissionsTable.Instance.CanStore);

                StoreItemInfo storeItemInfo = new StoreItemInfo();
                storeItemInfo.MimeType = SupportedMimeTypes.DICOM;
                DicomDataSet ds = new DicomDataSet();
                ds.Initialize(DicomClassType.Patient, DicomDataSetInitializeFlags.AddMandatoryElementsOnly);

                // The 2014 specification has added ReferencedStudySequence to the Patient Module (Retired) as a mandatory element
                // Remove this element for adding the patient
                DicomElement element = ds.FindFirstElement(null, DicomTag.ReferencedStudySequence, true);
                if (element != null)
                {
                    ds.DeleteElement(element);
                }

                SetPatientInfo(patientInfo, ds, DicomCharacterSetType.UnicodeInUtf8);

                MemoryStream ms = new MemoryStream();
                ds.Save(ms, DicomDataSetSaveFlags.None);

                //TODO: Store Patient information (Need to determine how this will be handled in the DB. Same for the unapproved captured images)

                QueryOptions queryOptions = new QueryOptions();
                queryOptions.PatientsOptions           = new PatientsQueryOptions();
                queryOptions.PatientsOptions.PatientID = patientInfo.PatientId;

                // If patientID already exists, return 'false'
                PatientData[] patientData = _queryAddin.FindPatients(userName, queryOptions);
                if (patientData.Length > 0)
                {
                    return(false);
                }

                // Otherwise, add the patient
                _storeAddin.StoreItem(ms, storeItemInfo);

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
        }
Ejemplo n.º 23
0
        private RasterImage GetImage(DicomDataSet dicomDs)
        {
            DicomElement element = dicomDs.FindFirstElement(null, DicomTag.PixelData, true);

            if (null != element)
            {
                return(dicomDs.GetImage(element,
                                        0,
                                        0,
                                        RasterByteOrder.Gray,
                                        DicomGetImageFlags.AutoApplyModalityLut | DicomGetImageFlags.AutoApplyVoiLut));
            }
            return(null);
        }
Ejemplo n.º 24
0
        /*
         * Sets the Instance Numbers for this dataset
         */
        private void SetInstanceNumbers(ref DicomDataSet pDS, int nInstanceNumber)
        {
            DicomElement element;
            string       strValue;

            strValue = string.Format("{0}", nInstanceNumber);

            // Series number
            element = pDS.FindFirstElement(null, DemoDicomTags.SeriesNumber, false);
            if (element != null)
            {
                pDS.SetConvertValue(element, strValue, 1);
            }

            // Instance number
            element = pDS.FindFirstElement(null, DemoDicomTags.InstanceNumber, false);
            if (element != null)
            {
                pDS.SetConvertValue(element, strValue, 1);
            }

            // Study ID
            element = pDS.FindFirstElement(null, DemoDicomTags.StudyID, false);
            if (element != null)
            {
                pDS.SetConvertValue(element, strValue, 1);
            }

            strValue = string.Format("854125{0}", nInstanceNumber);
            // Accession number
            element = pDS.FindFirstElement(null, DemoDicomTags.AccessionNumber, false);
            if (element != null)
            {
                pDS.SetConvertValue(element, strValue, 1);
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Helper method to get string value from a DICOM dataset.
        /// </summary>
        /// <param name="dcm">The DICOM dataset.</param>
        /// <param name="tag">Dicom tag.</param>
        /// <returns>String value of the specified DICOM tag.</returns>
        public static string GetStringValue(DicomDataSet dcm, long tag, bool tree)
        {
            DicomElement element;

            element = dcm.FindFirstElement(null, tag, tree);
            if (element != null)
            {
                if (dcm.GetElementValueCount(element) > 0)
                {
                    return(dcm.GetConvertValue(element));
                }
            }

            return("");
        }
Ejemplo n.º 26
0
        public static byte[] GetBinaryValues(DicomDataSet dcm, long tag)
        {
            DicomElement element;

            element = dcm.FindFirstElement(null, tag, true);
            if (element != null)
            {
                if (element.Length > 0)
                {
                    return(dcm.GetBinaryValue(element, (int)element.Length));
                }
            }

            return(null);
        }
Ejemplo n.º 27
0
        /*
         * Sets the necessary UIDs in the Dataset
         */
        private void SetInstanceUIDs(ref DicomDataSet pDS)
        {
            DicomElement element;

            // Set STUDY INSTANCE UID
            element = pDS.FindFirstElement(null, DemoDicomTags.StudyInstanceUID, false);
            if (element == null)
            {
                element = pDS.InsertElement(null, false, DemoDicomTags.StudyInstanceUID, DicomVRType.UI, false, 0);
            }
            pDS.SetConvertValue(element, Utils.GenerateDicomUniqueIdentifier(), 1);

            // Set SERIES INSTANCE UID
            element = pDS.FindFirstElement(null, DemoDicomTags.SeriesInstanceUID, false);
            if (element == null)
            {
                element = pDS.InsertElement(null, false, DemoDicomTags.SeriesInstanceUID, DicomVRType.UI, false, 0);
            }
            pDS.SetConvertValue(element, Utils.GenerateDicomUniqueIdentifier(), 1);

            // Set SOP INSTANCE UID
            element = pDS.FindFirstElement(null, DemoDicomTags.SOPInstanceUID, false);
            if (element == null)
            {
                element = pDS.InsertElement(null, false, DemoDicomTags.SOPInstanceUID, DicomVRType.UI, false, 0);
            }
            pDS.SetConvertValue(element, Utils.GenerateDicomUniqueIdentifier(), 1);

            // Media Storage SOP Instance UID
            element = pDS.FindFirstElement(null, DemoDicomTags.MediaStorageSOPInstanceUID, false);
            if (element == null)
            {
                element = pDS.InsertElement(null, false, DemoDicomTags.MediaStorageSOPInstanceUID, DicomVRType.UI, false, 0);
            }
            pDS.SetConvertValue(element, Utils.GenerateDicomUniqueIdentifier(), 1);
        }
Ejemplo n.º 28
0
        private void BuildDataSet( )
        {
            long         code    = -1;
            DicomTag     tag     = null;
            DicomElement element = null;

            element = _Dataset.FindFirstElement(null, _PreviousCode, false);


            code = OrientationConfigDialog.GetTag(comboBoxTags.Text);

            if (code == -1)
            {
                _Dataset.Reset( );

                dicomPropertyGrid.DataSet = _Dataset;

                MessageBox.Show("Invalid Tag", "Error with tag", MessageBoxButtons.OK, MessageBoxIcon.Error);

                comboBoxTags.Focus( );
            }
            else
            {
                if (element != null && element.Tag != code)
                {
                    _TagValue = null;
                }

                _PreviousCode = code;

                tag = DicomTagTable.Instance.Find(code);

                _Dataset.Reset();

                if (_TagValue != null)
                {
                    _Dataset.InsertElementAndSetValue(code, _TagValue);
                }
                else
                {
                    _Dataset.InsertElement(null, false, code, tag != null ? tag.VR : DicomVRType.UN, tag != null && tag.VR == DicomVRType.SQ, -1);
                }

                dicomPropertyGrid.DataSet = _Dataset;
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Gets the sequence count.
        /// </summary>
        /// <returns>The number of items in the sequence.</returns>
        private int GetSequenceCount()
        {
            DicomElement seq   = _Dataset.FindFirstElement(null, _Tag, false);
            int          count = 0;

            if (seq != null)
            {
                DicomElement child = _Dataset.GetChildElement(seq, true);

                while (child != null)
                {
                    count++;
                    child = _Dataset.GetNextElement(child, true, true);
                }
            }
            return(count);
        }
Ejemplo n.º 30
0
        public static void SetTag(DicomDataSet dcm, long Sequence, long Tag, object TagValue)
        {
            DicomElement seqElement = dcm.FindFirstElement(null, Sequence, true);
            DicomElement seqItem    = null;
            DicomElement item       = null;

            if (seqElement == null)
            {
                seqElement = dcm.InsertElement(null, false, Tag, DicomVRType.SQ, true, -1);
            }

            seqItem = dcm.GetChildElement(seqElement, false);
            if (seqItem == null)
            {
#if (LTV15_CONFIG)
                seqItem = dcm.InsertElement(seqElement, true, DicomTagType.SequenceDelimitationItem, DicomVRType.SQ, true, -1);
#else
                seqItem = dcm.InsertElement(seqElement, true, DicomTag.SequenceDelimitationItem, DicomVRType.SQ, true, -1);
#endif
            }

            item = dcm.GetChildElement(seqItem, true);
            while (item != null)
            {
#if (LTV15_CONFIG)
                if ((long)item.Tag == Tag)
                {
                    break;
                }
#else
                if (item.Tag == Tag)
                {
                    break;
                }
#endif

                item = dcm.GetNextElement(item, true, true);
            }

            if (item == null)
            {
                item = dcm.InsertElement(seqItem, true, Tag, DicomVRType.UN, false, -1);
            }
            dcm.SetConvertValue(item, TagValue.ToString(), 1);
        }
Ejemplo n.º 31
0
      public static StringCollection GetStringValues(DicomDataSet dcm, long tag)
      {
         DicomElement element;
         StringCollection sc = new StringCollection();

         element = dcm.FindFirstElement(null, tag, true);
         if(element != null)
         {
            if(dcm.GetElementValueCount(element) > 0)
            {
               string s = dcm.GetConvertValue(element);
               string[] items = s.Split('\\');

               foreach(string value in items)
               {
                  sc.Add(value);
               }
            }
         }

         return sc;
      }
Ejemplo n.º 32
0
 /// <summary>
 /// Lấy giá trị của một Tag từ DicomDataset của ảnh
 /// </summary>
 /// <param name="ds"></param>
 /// <param name="tag"></param>
 /// <returns></returns>
 string GetStringValue(DicomDataSet ds, long tag)
 {
     try
     {
         if (ds == null) return "";
         DicomElement element;
         element = ds.FindFirstElement(null, tag, false);
         if (element != null)
         {
             if (ds.GetElementValueCount(element) > 0)
             {
                 return ds.GetConvertValue(element);
             }
         }
         return "";
     }
     catch
     {
         return "";
     }
 }
Ejemplo n.º 33
0
        void test()
        {


            string imgFile = @"C:\Images\Chest.dcm";
            try
            {

                using (Leadtools.Commands.Demos.WaitCursor wait = new Leadtools.Commands.Demos.WaitCursor())
                {

                    DicomDataSet ds = new DicomDataSet();
                    ds.Load(imgFile, DicomDataSetLoadFlags.LoadAndClose);

                    DicomElement pixelDataElement = ds.FindFirstElement(null, DicomTag.PixelData, true);
                    DicomImageInformation imageInformation = ds.GetImageInformation(pixelDataElement, 0);
                    ds.SetImages(pixelDataElement, _CurrCell.Image.CloneAll(), imageInformation.Compression, imageInformation.PhotometricInterpretation,
                                _CurrCell.Image.BitsPerPixel, 2, DicomSetImageFlags.AutoSetVoiLut);
                    ds.Save(imgFile, DicomDataSetSaveFlags.None);
                   }
            }
            catch (Exception ex)
            {
               

            }
           
        }
Ejemplo n.º 34
0
      public static DicomExceptionCode InsertKeyElement(DicomDataSet dcmRsp, DicomDataSet dcmReq, long tag)
      {
         DicomExceptionCode ret = DicomExceptionCode.Success;
         DicomElement element;

         try
         {
            element = dcmReq.FindFirstElement(null, tag, true);
            if(element != null)
            {
               dcmRsp.InsertElement(null, false, tag, DicomVRType.UN, false, 0);
            }
         }
         catch(DicomException de)
         {
            ret = de.Code;
         }

         return ret;
      }
Ejemplo n.º 35
0
      public static DicomExceptionCode SetKeyElement(DicomDataSet dcmRsp, long tag, object tagValue, bool tree)
      {
         DicomExceptionCode ret = DicomExceptionCode.Success;
         DicomElement element;

         if (tagValue == null)
            return DicomExceptionCode.Parameter;

         try
         {
            element = dcmRsp.FindFirstElement(null, tag, tree);
            if (element != null)
            {
               dcmRsp.SetConvertValue(element, tagValue.ToString(), 1);
            }
         }
         catch (DicomException de)
         {
            ret = de.Code;
         }

         return ret;
      }
Ejemplo n.º 36
0
      public static void SetTag(DicomDataSet dcm,long Sequence,long Tag,object TagValue)
      {
          DicomElement seqElement = dcm.FindFirstElement(null, Sequence, true);
          DicomElement seqItem = null;
          DicomElement item = null;

          if(seqElement==null)
          {
              seqElement = dcm.InsertElement(null, false, Tag, DicomVRType.SQ, true, -1);
          }

          seqItem = dcm.GetChildElement(seqElement, false);
          if (seqItem == null)
          {
#if (LTV15_CONFIG)
              seqItem = dcm.InsertElement(seqElement, true, DicomTagType.SequenceDelimitationItem, DicomVRType.SQ, true, -1);
#else
              seqItem = dcm.InsertElement(seqElement, true, DicomTag.SequenceDelimitationItem, DicomVRType.SQ, true, -1);
#endif
          }

          item = dcm.GetChildElement(seqItem, true);
          while(item!=null)
          {
#if (LTV15_CONFIG)
              if ((long)item.Tag == Tag)
                  break;
#else
              if (item.Tag == Tag)
                  break;
#endif

              item = dcm.GetNextElement(item, true, true);
          }

          if(item==null)
          {
              item = dcm.InsertElement(seqItem, true, Tag, DicomVRType.UN, false, -1);              
          }
          dcm.SetConvertValue(item, TagValue.ToString(), 1);
      }
Ejemplo n.º 37
0
      public static DicomExceptionCode SetTag(DicomDataSet dcm, long tag, byte[] tagValue)
      {
         DicomExceptionCode ret = DicomExceptionCode.Success;
         DicomElement element;

         if(tagValue == null)
            return DicomExceptionCode.Parameter;

         element = dcm.FindFirstElement(null, tag, true);
         if(element == null)
         {
            element = dcm.InsertElement(null, false, tag, DicomVRType.UN, false, 0);
         }

         dcm.SetBinaryValue(element, tagValue, tagValue.Length);

         return ret;
      }
Ejemplo n.º 38
0
      /// <summary>
      /// 
      /// </summary>
      /// <param name="dcm"></param>
      /// <param name="tag"></param>
      /// <param name="tagValue"></param>
      /// <returns></returns>
      public static DicomExceptionCode SetTag(DicomDataSet dcm, long tag, object tagValue, bool tree)
      {
         DicomExceptionCode ret = DicomExceptionCode.Success;
         DicomElement element;

         if (tagValue == null)
            return DicomExceptionCode.Parameter;

         element = dcm.FindFirstElement(null, tag, tree);
         if (element == null)
         {
            element = dcm.InsertElement(null, false, tag, DicomVRType.UN, false, 0);
         }

         if (element == null)
            return DicomExceptionCode.Parameter;

         try
         {
            dcm.SetConvertValue(element, tagValue.ToString(), 1);
         }
         catch (DicomException de)
         {
            ret = de.Code;
         }

         return ret;
      }
Ejemplo n.º 39
0
      public static bool IsTagPresent(DicomDataSet dcm, long tag)
      {
         DicomElement element;

         element = dcm.FindFirstElement(null, tag, true);
         return (element != null);
      }
Ejemplo n.º 40
0
      public static byte[] GetBinaryValues(DicomDataSet dcm, long tag)
      {
         DicomElement element;

         element = dcm.FindFirstElement(null, tag, true);
         if(element != null)
         {
            if(element.Length > 0)
            {
               return dcm.GetBinaryValue(element, (int)element.Length);
            }
         }

         return null;
      }
Ejemplo n.º 41
0
 private void SetSomeTag(DicomDataSet ds, string FileName)
 {
     try
     {
         
         DicomElement element = ds.FindFirstElement(null, DicomTag.PatientID, false);
         if (element != null)
         {
             ds.DeleteElement(element);
             ds = ds.InsertElementAndSetValue(DicomTag.PatientID, txtID2.Text.Trim());
         }
         if (element == null) ds = ds.InsertElementAndSetValue(DicomTag.PatientID, txtID2.Text.Trim());
         //RegistrationSequence
         element = ds.FindFirstElement(null, DicomTag.RegistrationSequence, false);
         if (element != null)
         {
             ds.DeleteElement(element);
             ds = ds.InsertElementAndSetValue(DicomTag.RegistrationSequence, txtRegNumber2.Text.Trim());
         }
         if (element == null) ds = ds.InsertElementAndSetValue(DicomTag.RegistrationSequence, txtRegNumber2.Text.Trim());
         //Sex
         element = ds.FindFirstElement(null, DicomTag.PatientSex, false);
         if (element != null)
         {
             ds.DeleteElement(element);
             ds = ds.InsertElementAndSetValue(DicomTag.PatientSex, Sex);
         }
         if (element == null) ds = ds.InsertElementAndSetValue(DicomTag.PatientSex, Sex);
         //CreatedDate
         element = ds.FindFirstElement(null, DicomTag.DateTime, false);
         if (element != null)
         {
             ds.DeleteElement(element);
             ds = ds.InsertElementAndSetValue(DicomTag.DateTime, RegDate.ToLongTimeString());
         }
         if (element == null) ds = ds.InsertElementAndSetValue(DicomTag.DateTime, RegDate.ToLongTimeString());
         //pBirthdate
         element = ds.FindFirstElement(null, DicomTag.PatientBirthDate, false);
         if (element != null)
         {
             ds.DeleteElement(element);
             ds = ds.InsertElementAndSetValue(DicomTag.PatientBirthDate, BirthDate);
         }
         if (element == null) ds = ds.InsertElementAndSetValue(DicomTag.PatientBirthDate, BirthDate);
         //pName
         element = ds.FindFirstElement(null, DicomTag.PatientName, false);
         if (element != null)
         {
             ds.DeleteElement(element);
             ds = ds.InsertElementAndSetValue(DicomTag.PatientName, Bodau(txtName2.Text.Trim()));
         }
         if (element == null) ds = ds.InsertElementAndSetValue(DicomTag.PatientName, Bodau(txtName2.Text.Trim()));
         //pAge
         element = ds.FindFirstElement(null, DicomTag.PatientAge, false);
         if (element != null)
         {
             ds.DeleteElement(element);
             ds = ds.InsertElementAndSetValue(DicomTag.PatientAge, txtAge.Text.Trim());
         }
         if (element == null) ds = ds.InsertElementAndSetValue(DicomTag.PatientAge, txtAge.Text.Trim());
     }
     catch
     {
     }
 }
Ejemplo n.º 42
0
      /// <summary>
      /// Helper method to get string value from a DICOM dataset.
      /// </summary>
      /// <param name="dcm">The DICOM dataset.</param>
      /// <param name="tag">Dicom tag.</param>
      /// <returns>String value of the specified DICOM tag.</returns>
      public static string GetStringValue(DicomDataSet dcm, long tag, bool tree)
      {
         DicomElement element;

         element = dcm.FindFirstElement(null, tag, tree);
         if(element != null)
         {
            if(dcm.GetElementValueCount(element) > 0)
            {
               return dcm.GetConvertValue(element);
            }
         }

         return "";
      }