Exemple #1
0
        public static bool BuildDICOMInfo(MElementList elmlist, ref DICOMInfoDto dicomDto)
        {
            try
            {
                var dicom = Mapper.Map <DICOMInfo>(elmlist);
                dicomDto.StudyInstanceUID  = dicom.StudyInstanceUID;
                dicomDto.SeriesInstanceUID = dicom.SeriesInstanceUID;
                dicomDto.SOPInstanceUID    = dicom.SOPInstanceUID;
                dicomDto.PatientID         = dicom.PatientID;
                dicomDto.PatientName       = dicom.PatientName;
                dicomDto.PatientDOB        = dicom.PatientDOB;
                dicomDto.PatientAge        = dicom.PatientAge;
                dicomDto.PatientSex        = dicom.PatientSex;
                dicomDto.AccessionNo       = dicom.AccessionNo;
                dicomDto.BodyPart          = dicom.BodyPart;
                dicomDto.Modality          = dicom.Modality;
                dicomDto.ExamCode          = string.Empty;
                dicomDto.StudyDate         = dicom.StudyDate;
                dicomDto.StudyTime         = dicom.StudyTime;
                dicomDto.StudyDescription  = dicom.StudyDescription;
                dicomDto.ReferPhysician    = dicom.ReferPhysician;
                dicomDto.SeriesNo          = dicom.SeriesNo;
                int parseNo;
                int.TryParse(dicom.ImageNo, out parseNo);
                dicomDto.ImageNo = parseNo;

                if (dicom.PatientID == "")
                {
                    _logger.Error("DicomHeader.BuildDcmInfo(): " + "PatientID is empty.");
                    return(false);
                }
                if (dicom.StudyInstanceUID == "")
                {
                    _logger.Error("DicomHeader.BuildDcmInfo(): " + "StudyInstanceUID is empty.");
                    return(false);
                }
                //Series Group
                if (dicom.SeriesInstanceUID == "")
                {
                    _logger.Error("DicomHeader.BuildDcmInfo(): " + "SeriesInstanceUID is empty.");
                    return(false);
                }
                if (dicom.SOPInstanceUID == "")
                {
                    _logger.Error("DicomHeader.BuildDcmInfo(): " + "SOPInstanceUID is empty.");
                    return(false);
                }
                _logger.Error("DicomHeader.BuildDcmInfo(): " + "build dicom info successfully.");
                return(true);
            }
            catch (Exception e)
            {
                _logger.Error("DicomHeader.BuildDcmInfo(): " + "pop up an exception--" + e.Message + ".");
                return(false);
            }
        }
Exemple #2
0
        /// <summary>
        /// Save DICOM data and file
        /// </summary>
        public bool SaveDICOMInfo(MElementList dataset, ts_t baseTsn, string implClassUid, string versionName, string rootPath)
        {
            var dicom = new DICOMInfoDto();

            DICOMUtility.BuildDICOMInfo(dataset, ref dicom);
            var path = rootPath + dicom.AccessionNo + Convert.ToString(Path.DirectorySeparatorChar);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            var filePath = path + dicom.SOPInstanceUID + ".dcm";
            var result1  = SaveDICOMFile(dataset, baseTsn, implClassUid, versionName, filePath);
            var result2  = false;

            if (result1)
            {
                result2 = SaveDICOMData(dicom, filePath);
            }
            return(result1 && result2);
        }
Exemple #3
0
        /// <summary>
        /// Save DICOM data in SQLCompact
        /// </summary>
        public bool SaveDICOMData(DICOMInfoDto dicom, string filePath)
        {
            try
            {
                var study  = new Study();
                var series = new Series();
                var image  = new Image();
                // Study
                study.StudyInstanceUID = dicom.StudyInstanceUID;
                study.PatientID        = dicom.PatientID;
                study.PatientName      = dicom.PatientName;
                study.PatientDOB       = dicom.PatientDOB;
                study.PatientAge       = dicom.PatientAge;
                study.PatientSex       = dicom.PatientSex;
                study.AccessionNo      = dicom.AccessionNo;
                study.BodyPart         = dicom.BodyPart;
                study.Modality         = dicom.Modality;
                study.ExamCode         = string.Empty;
                study.StudyDate        = dicom.StudyDate;
                study.StudyTime        = dicom.StudyTime;
                study.StudyDescription = dicom.StudyDescription;
                study.ReferPhysician   = dicom.ReferPhysician;
                study.ReceiveTime      = DateTime.Now.AddTicks(-(DateTime.Now.Ticks % TimeSpan.TicksPerSecond));
                // Series
                series.SeriesInstanceUID = dicom.SeriesInstanceUID;
                series.StudyInstanceUID  = dicom.StudyInstanceUID;
                series.BodyPart          = dicom.BodyPart;
                series.Modality          = dicom.Modality;
                //Image
                image.SOPInstanceUID    = dicom.SOPInstanceUID;
                image.SeriesInstanceUID = dicom.SeriesInstanceUID;
                image.FilePath          = filePath;
                image.CreateTime        = DateTime.Now;
                // Retrieve the ConnectionString from App.config
                string connectString = ConfigurationManager.ConnectionStrings["DAPContext"].ToString();
                SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectString);
                // Retrieve the DataSource property.
                string dbPath = builder.DataSource.Substring(0, builder.DataSource.LastIndexOf('\\'));
                if (!Directory.Exists(dbPath))
                {
                    Directory.CreateDirectory(dbPath);
                }
                using (var db = new DAPContext())
                {
                    var studyToUpdate  = db.Studies.FirstOrDefault(s => s.StudyInstanceUID.Equals(study.StudyInstanceUID));
                    var seriesToUpdate = db.Series.FirstOrDefault(s => s.SeriesInstanceUID.Equals(series.SeriesInstanceUID));
                    var imageToUpdate  = db.Images.FirstOrDefault(i => i.SOPInstanceUID.Equals(image.SOPInstanceUID));
                    if (studyToUpdate != null)
                    {
                        db.Entry(studyToUpdate).CurrentValues.SetValues(study);
                    }
                    else
                    {
                        db.Studies.Add(study);
                    }

                    if (seriesToUpdate != null)
                    {
                        db.Entry(seriesToUpdate).CurrentValues.SetValues(seriesToUpdate);
                    }
                    else
                    {
                        db.Series.Add(series);
                    }
                    if (imageToUpdate != null)
                    {
                        db.Entry(imageToUpdate).CurrentValues.SetValues(imageToUpdate);
                    }
                    else
                    {
                        db.Images.Add(image);
                    }
                    db.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message, ex);
                return(false);
            }
        }