예제 #1
0
 /// <summary>
 /// Create a new DicomFrame object.
 /// </summary>
 /// <param name="frameId">Initial value of the FrameId property.</param>
 /// <param name="fileId">Initial value of the FileId property.</param>
 /// <param name="frameGuid">Initial value of the FrameGuid property.</param>
 public static DicomFrame CreateDicomFrame(global::System.Int32 frameId, global::System.Int32 fileId, global::System.Guid frameGuid)
 {
     DicomFrame dicomFrame = new DicomFrame();
     dicomFrame.FrameId = frameId;
     dicomFrame.FileId = fileId;
     dicomFrame.FrameGuid = frameGuid;
     return dicomFrame;
 }
예제 #2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the DicomFrame EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDicomFrame(DicomFrame dicomFrame)
 {
     base.AddObject("DicomFrame", dicomFrame);
 }
 private void DetachDicomFrame(DicomFrame entity)
 {
     entity.DicomFile = null;
 }
 private bool FilterDicomFrame(DicomFrame entity)
 {
     return (entity.FileId == this.FileId);
 }
 private void AttachDicomFrame(DicomFrame entity)
 {
     entity.DicomFile = this;
 }
예제 #6
0
 public void DeleteDicomFrame(DicomFrame dicomFrame)
 {
     if ((dicomFrame.EntityState != EntityState.Detached))
     {
         this.ObjectContext.ObjectStateManager.ChangeObjectState(dicomFrame, EntityState.Deleted);
     }
     else
     {
         this.ObjectContext.DicomFrame.Attach(dicomFrame);
         this.ObjectContext.DicomFrame.DeleteObject(dicomFrame);
     }
 }
예제 #7
0
 public void UpdateDicomFrame(DicomFrame currentDicomFrame)
 {
     this.ObjectContext.DicomFrame.AttachAsModified(currentDicomFrame, this.ChangeSet.GetOriginal(currentDicomFrame));
 }
예제 #8
0
 public void InsertDicomFrame(DicomFrame dicomFrame)
 {
     if ((dicomFrame.EntityState != EntityState.Detached))
     {
         this.ObjectContext.ObjectStateManager.ChangeObjectState(dicomFrame, EntityState.Added);
     }
     else
     {
         this.ObjectContext.DicomFrame.AddObject(dicomFrame);
     }
 }
예제 #9
0
        public void UploadDicomFile(string guid)
        {
            string dirPath = string.Format(@"C:\temp\{0}", guid);
            string filePath = string.Format(@"{0}\{1}", dirPath, new DirectoryInfo(dirPath).GetFiles().Single().Name);
            
            try
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    DicomDataset dataset = Dicom.DicomFile.Open(filePath).Dataset;

                    // Vlozenie dat do DicomFile
                    FileInfo fileInfo = new FileInfo(filePath);
                    DateTime uploadTime = DateTime.Now;
                    int studyId = int.Parse(dataset.Get<string>(DicomTag.StudyID));
                    string name = fileInfo.Name;

                    DicomFile dicomFileEntity = new DicomFile
                    {
                        UploadTime = uploadTime,
                        StudyId = studyId,
                        Name = name
                    };
                    ObjectContext.DicomFile.AddObject(dicomFileEntity);
                    ObjectContext.SaveChanges();

                    int fileId = (from df in ObjectContext.DicomFile select df.FileId).DefaultIfEmpty().Max();

                    // Vlozenie dat do DicomElement a DicomElementValue
                    foreach (DicomItem element in dataset)
                    {
                        int groupNumber = element.Tag.Group;
                        int elementNumber = element.Tag.Element;
                        string valueRepresentation = element.ValueRepresentation.ToString();
                        string valueMultiplicity = element.Tag.DictionaryEntry.ValueMultiplicity.ToString();
                        string keyword = element.Tag.DictionaryEntry.Keyword;

                        bool elementExists = Convert.ToBoolean((
                            from de in ObjectContext.DicomElement
                            where de.GroupNumber == groupNumber && de.ElementNumber == elementNumber
                            select de).Count());

                        if (!elementExists)
                        {
                            DicomElement dicomElementEntity = new DicomElement
                            {
                                GroupNumber = groupNumber,
                                ElementNumber = elementNumber,
                                ValueRepresentation = valueRepresentation,
                                ValueMultiplicity = valueMultiplicity,
                                Keyword = keyword
                            };
                            ObjectContext.DicomElement.AddObject(dicomElementEntity);
                            ObjectContext.SaveChanges();
                        }

                        string value = dataset.Get<string>(element.Tag);

                        DicomElementValue dicomElementValueEntity = new DicomElementValue
                        {
                            Value = value,
                            FileId = fileId,
                            GroupNumber = groupNumber,
                            ElementNumber = elementNumber
                        };
                        ObjectContext.DicomElementValue.AddObject(dicomElementValueEntity);
                        ObjectContext.SaveChanges();
                    }

                    //Vlozenie dat do DicomFrame
                    DicomImage dicomImage = new DicomImage(filePath);
                    for (int i = 0; i < dicomImage.NumberOfFrames; i++)
                    {
                        Guid frameGuid = Guid.NewGuid();
                        byte[] frame = dicomImage.PixelData.GetFrame(i).Data;// RangeByteBuffer

                        DicomFrame dicomFrameEntity = new DicomFrame
                        {
                            FileId = fileId,
                            FrameGuid = frameGuid,
                            Frame = frame
                        };
                        ObjectContext.DicomFrame.AddObject(dicomFrameEntity);
                        ObjectContext.SaveChanges();
                    }

                    scope.Complete();
                }
            }
            finally
            {
                if (File.Exists(filePath))
                    File.Delete(filePath);
                if (Directory.Exists(dirPath))
                    Directory.Delete(dirPath);
            }
        }