Example #1
0
        /// <summary>
        /// Adds the study.
        /// </summary>
        /// <param name="receive">The receive.</param>
        /// <param name="PatientId">The patient id.</param>
        /// <param name="ConnectionString">The connection string.</param>
        /// <param name="AETitle">The AE title.</param>
        /// <param name="dataset">The dataset.</param>
        /// <returns></returns>
        private static string AddStudy(DateTime receive, string PatientId, string ConnectionString, string AETitle, DicomDataSet dataset)
        {
            string studyInstance = dataset.GetValue <string>(DicomTag.StudyInstanceUID, string.Empty);

            if (string.IsNullOrEmpty(studyInstance))
            {
                throw new ArgumentException("Missing dicom tag", "Study Instance UID");
            }

            _newStudy = false;
            if (!RecordExists(ConnectionString, "Studies", "StudyInstanceUID = '" + studyInstance + "'"))
            {
                DateTime?            sd    = dataset.GetValue <DateTime?>(DicomTag.StudyDate, null, GetDate);
                DateTime?            st    = dataset.GetValue <DateTime?>(DicomTag.StudyTime, null, GetDate);
                SqlCeResultSet       rs    = SqlCeHelper.ExecuteResultSet(ConnectionString, "Studies");
                SqlCeUpdatableRecord study = rs.CreateRecord();

                study.SetValue(0, studyInstance);
                string sDate = GetDateString(sd, st).Trim();
                if (sDate.Length > 0)
                {
                    study.SetValue(1, sDate);
                }
                study.SetValue(2, dataset.GetValue <string>(DicomTag.AccessionNumber, string.Empty));
                study.SetValue(3, dataset.GetValue <string>(DicomTag.StudyID, string.Empty));
                study.SetValue(4, dataset.GetValue <string>(DicomTag.ReferringPhysicianName, string.Empty));
                study.SetValue(5, dataset.GetValue <string>(DicomTag.StudyDescription, string.Empty));
                study.SetValue(6, dataset.GetValue <string>(DicomTag.AdmittingDiagnosesDescription, string.Empty));

                string age = dataset.GetValue <string>(DicomTag.PatientAge, string.Empty);

                if (age != string.Empty && age.Length > 0)
                {
                    age = age.Substring(0, 4);
                }

                study.SetValue(7, age);
                study.SetValue(8, dataset.GetValue <double>(DicomTag.PatientSize, 0));
                study.SetValue(9, dataset.GetValue <double>(DicomTag.PatientWeight, 0));
                study.SetValue(10, dataset.GetValue <string>(DicomTag.Occupation, string.Empty));
                study.SetValue(11, dataset.GetValue <string>(DicomTag.AdditionalPatientHistory, string.Empty));
                study.SetValue(12, dataset.GetValue <string>(DicomTag.InterpretationAuthor, string.Empty));
                study.SetValue(13, PatientId);

                sDate = GetDateString(receive, receive).Trim();
                if (sDate.Length > 0)
                {
                    study.SetValue(14, sDate);
                }
                study.SetValue(15, AETitle);

                rs.Insert(study);
                rs.Close();
                _newStudy = true;
            }

            return(studyInstance);
        }
        private static DicomCommandStatusType AddImage(DateTime receive, string sopInstance, string StudyInstanceUid, string SeriesInstanceUid,
                                                       string ConnectionString, string AETitle, DicomDataSet dataset, string ImageDirectory)
        {
            if (string.IsNullOrEmpty(sopInstance))
            {
                throw new ArgumentException("Missing dicom tag", "SOP Instance UID");
            }

            if (!RecordExists(ConnectionString, "Images", "SOPInstanceUID = '" + sopInstance + "'"))
            {
                string               fileName = ImageDirectory + sopInstance + ".dcm";
                SqlCeResultSet       rs       = SqlCeHelper.ExecuteResultSet(ConnectionString, "Images");
                SqlCeUpdatableRecord image    = rs.CreateRecord();

                image.SetValue(0, sopInstance);
                image.SetValue(1, SeriesInstanceUid);
                image.SetValue(2, StudyInstanceUid);
                if (HasValue(dataset, DicomTag.InstanceNumber))
                {
                    image.SetValue(3, dataset.GetValue <int>(DicomTag.InstanceNumber, 0));
                }
                image.SetValue(4, fileName);
                image.SetValue(5, dataset.GetValue <string>(DicomTag.TransferSyntaxUID, DicomUidType.ImplicitVRLittleEndian));
                image.SetValue(6, dataset.GetValue <string>(DicomTag.SOPClassUID, string.Empty));
                image.SetValue(7, dataset.GetValue <string>(DicomTag.StationName, string.Empty));
                image.SetValue(8, GetDateString(DateTime.Now, DateTime.Now));
                image.SetValue(9, AETitle);

                rs.Insert(image);
                rs.Close();

                //
                // store the file
                //
                if (!Directory.Exists(ImageDirectory))
                {
                    Directory.CreateDirectory(ImageDirectory);
                }

                dataset.Save(fileName, DicomDataSetSaveFlags.None);
            }
            else
            {
                return(DicomCommandStatusType.DuplicateInstance);
            }

            return(DicomCommandStatusType.Success);
        }
Example #3
0
        /// <summary>
        /// Adds the series.
        /// </summary>
        /// <param name="receive">The receive.</param>
        /// <param name="StudyInstanceUid">The study instance uid.</param>
        /// <param name="ConnectionString">The connection string.</param>
        /// <param name="AETitle">The AE title.</param>
        /// <param name="dataset">The dataset.</param>
        /// <returns></returns>
        private static string AddSeries(DateTime receive, string StudyInstanceUid, string ConnectionString, string AETitle, DicomDataSet dataset)
        {
            string seriesInstance = dataset.GetValue <string>(DicomTag.SeriesInstanceUID, string.Empty);

            if (string.IsNullOrEmpty(seriesInstance))
            {
                throw new ArgumentException("Missing dicom tag", "Series Instance UID");
            }

            _newSeries = false;
            if (!RecordExists(ConnectionString, "Series", "SeriesInstanceUID = '" + seriesInstance + "'"))
            {
                DateTime?            sd     = dataset.GetValue <DateTime?>(DicomTag.SeriesDate, null, GetDate);
                DateTime?            st     = dataset.GetValue <DateTime?>(DicomTag.SeriesTime, null, GetDate);
                SqlCeResultSet       rs     = SqlCeHelper.ExecuteResultSet(ConnectionString, "Series");
                SqlCeUpdatableRecord series = rs.CreateRecord();

                series.SetValue(0, seriesInstance);
                series.SetValue(1, dataset.GetValue <string>(DicomTag.Modality, string.Empty));
                series.SetValue(2, dataset.GetValue <string>(DicomTag.SeriesNumber, string.Empty));

                string seriesDate = GetDateString(sd, st);

                if (seriesDate.Length > 0)
                {
                    series.SetValue(3, seriesDate);
                }

                series.SetValue(4, dataset.GetValue <string>(DicomTag.SeriesDescription, string.Empty));
                series.SetValue(5, dataset.GetValue <string>(DicomTag.InstitutionName, string.Empty));

                seriesDate = GetDateString(receive, receive);
                if (seriesDate.Length > 0)
                {
                    series.SetValue(6, seriesDate);
                }
                series.SetValue(7, AETitle);
                series.SetValue(8, StudyInstanceUid);

                rs.Insert(series);
                rs.Close();
                _newSeries = true;
            }

            return(seriesInstance);
        }