/// <summary>
 /// Deprecated Method for adding a new object to the DicomElement EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToDicomElement(DicomElement dicomElement)
 {
     base.AddObject("DicomElement", dicomElement);
 }
 /// <summary>
 /// Create a new DicomElement object.
 /// </summary>
 /// <param name="groupNumber">Initial value of the GroupNumber property.</param>
 /// <param name="elementNumber">Initial value of the ElementNumber property.</param>
 /// <param name="valueRepresentation">Initial value of the ValueRepresentation property.</param>
 /// <param name="valueMultiplicity">Initial value of the ValueMultiplicity property.</param>
 /// <param name="keyword">Initial value of the Keyword property.</param>
 public static DicomElement CreateDicomElement(global::System.Int32 groupNumber, global::System.Int32 elementNumber, global::System.String valueRepresentation, global::System.String valueMultiplicity, global::System.String keyword)
 {
     DicomElement dicomElement = new DicomElement();
     dicomElement.GroupNumber = groupNumber;
     dicomElement.ElementNumber = elementNumber;
     dicomElement.ValueRepresentation = valueRepresentation;
     dicomElement.ValueMultiplicity = valueMultiplicity;
     dicomElement.Keyword = keyword;
     return dicomElement;
 }
 private bool FilterDicomElement(DicomElement entity)
 {
     return ((entity.GroupNumber == this.GroupNumber) 
                 && (entity.ElementNumber == this.ElementNumber));
 }
 public void DeleteDicomElement(DicomElement dicomElement)
 {
     if ((dicomElement.EntityState != EntityState.Detached))
     {
         this.ObjectContext.ObjectStateManager.ChangeObjectState(dicomElement, EntityState.Deleted);
     }
     else
     {
         this.ObjectContext.DicomElement.Attach(dicomElement);
         this.ObjectContext.DicomElement.DeleteObject(dicomElement);
     }
 }
 public void UpdateDicomElement(DicomElement currentDicomElement)
 {
     this.ObjectContext.DicomElement.AttachAsModified(currentDicomElement, this.ChangeSet.GetOriginal(currentDicomElement));
 }
 public void InsertDicomElement(DicomElement dicomElement)
 {
     if ((dicomElement.EntityState != EntityState.Detached))
     {
         this.ObjectContext.ObjectStateManager.ChangeObjectState(dicomElement, EntityState.Added);
     }
     else
     {
         this.ObjectContext.DicomElement.AddObject(dicomElement);
     }
 }
        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);
            }
        }