Пример #1
0
        /// <summary>
        /// Send the images of a loaded DICOMDIR to a remote AE.
        /// </summary>
        /// <param name="rootPath"></param>
        /// <param name="aeTitle"></param>
        /// <param name="host"></param>
        /// <param name="port"></param>
        public void Send(string rootPath, string aeTitle, string host, int port)
        {
            if (_dir == null)
            {
                return;
            }

            StorageScu scu = new StorageScu();

            foreach (DirectoryRecordSequenceItem patientRecord in _dir.RootDirectoryRecordCollection)
            {
                foreach (DirectoryRecordSequenceItem studyRecord in patientRecord.LowerLevelDirectoryRecordCollection)
                {
                    foreach (DirectoryRecordSequenceItem seriesRecord in studyRecord.LowerLevelDirectoryRecordCollection)
                    {
                        foreach (DirectoryRecordSequenceItem instanceRecord in seriesRecord.LowerLevelDirectoryRecordCollection)
                        {
                            string path = rootPath;

                            foreach (string subpath in instanceRecord[DicomTags.ReferencedFileId].Values as string[])
                            {
                                path = Path.Combine(path, subpath);
                            }

                            scu.AddFileToSend(path);
                        }
                    }
                }
            }

            // Do the send
            scu.Send("DICOMDIR", aeTitle, host, port);
        }
Пример #2
0
        private void buttonStorageScuConnect_Click(object sender, EventArgs e)
        {
            int port;

            if (!int.TryParse(_textBoxStorageScuRemotePort.Text, out port))
            {
                Logger.LogError("Unable to parse port number: {0}", _textBoxStorageScuRemotePort.Text);
                return;
            }


            _storageScu.Send(_textBoxStorageScuLocalAe.Text, _textBoxStorageScuRemoteAe.Text, _textBoxStorageScuRemoteHost.Text, port);
        }
Пример #3
0
		/// <summary>
		/// Send the images of a loaded DICOMDIR to a remote AE.
		/// </summary>
		/// <param name="rootPath"></param>
		/// <param name="aeTitle"></param>
		/// <param name="host"></param>
		/// <param name="port"></param>
		public void Send(string rootPath, string aeTitle, string host, int port)
		{
			if (_dir == null) return;

			StorageScu scu = new StorageScu();

			foreach (DirectoryRecordSequenceItem patientRecord in _dir.RootDirectoryRecordCollection)
			{
				foreach (DirectoryRecordSequenceItem studyRecord in patientRecord.LowerLevelDirectoryRecordCollection)
				{
					foreach (DirectoryRecordSequenceItem seriesRecord in studyRecord.LowerLevelDirectoryRecordCollection)
					{
						foreach (DirectoryRecordSequenceItem instanceRecord in seriesRecord.LowerLevelDirectoryRecordCollection)
						{
							string path = rootPath;

							foreach (string subpath in instanceRecord[DicomTags.ReferencedFileId].Values as string[])
								path = Path.Combine(path, subpath);

							scu.AddFileToSend(path);
						}
					}
				}
			}

			// Do the send
			scu.Send("DICOMDIR", aeTitle, host, port);

		}
Пример #4
0
        void IDicomServerHandler.OnReceiveRequestMessage(DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message)
        {
            //C-ECHO
            if (message.CommandField == DicomCommandField.CEchoRequest)
            {
                server.SendCEchoResponse(presentationID, message.MessageId, DicomStatuses.Success);
                return;
            }
            //C-Storage
            else if (message.CommandField == DicomCommandField.CStoreRequest)
            {
                String   studyInstanceUid  = null;
                String   seriesInstanceUid = null;
                DicomUid sopInstanceUid;

                bool ok = message.DataSet[DicomTags.SopInstanceUid].TryGetUid(0, out sopInstanceUid);
                if (ok)
                {
                    ok = message.DataSet[DicomTags.SeriesInstanceUid].TryGetString(0, out seriesInstanceUid);
                }
                if (ok)
                {
                    ok = message.DataSet[DicomTags.StudyInstanceUid].TryGetString(0, out studyInstanceUid);
                }

                if (!ok)
                {
                    Logger.LogError("Unable to retrieve UIDs from request message, sending failure status.");

                    server.SendCStoreResponse(presentationID, message.MessageId, sopInstanceUid.UID,
                                              DicomStatuses.ProcessingFailure);
                    return;
                }

                if (!Directory.Exists(StorageScp.StorageLocation))
                {
                    Directory.CreateDirectory(StorageScp.StorageLocation);
                }

                StringBuilder path = new StringBuilder();
                path.AppendFormat("{0}{1}{2}{3}{4}", StorageScp.StorageLocation, Path.DirectorySeparatorChar,
                                  studyInstanceUid, Path.DirectorySeparatorChar, seriesInstanceUid);

                Directory.CreateDirectory(path.ToString());

                path.AppendFormat("{0}{1}.dcm", Path.DirectorySeparatorChar, sopInstanceUid.UID);

                DicomFile dicomFile = new DicomFile(message, path.ToString());

                dicomFile.TransferSyntaxUid            = TransferSyntax.ExplicitVrLittleEndianUid;
                dicomFile.MediaStorageSopInstanceUid   = sopInstanceUid.UID;
                dicomFile.ImplementationClassUid       = DicomImplementation.ClassUID.UID;
                dicomFile.ImplementationVersionName    = DicomImplementation.Version;
                dicomFile.SourceApplicationEntityTitle = association.CallingAE;
                dicomFile.MediaStorageSopClassUid      = message.SopClass.Uid;

                dicomFile.Save(DicomWriteOptions.None);
                #region Database Insert
                String PatientsName = dicomFile.DataSet[DicomTags.PatientsName].GetString(0, "");
                String PatientId    = dicomFile.DataSet[DicomTags.PatientId].GetString(0, "");
                String StudyId      = dicomFile.DataSet[DicomTags.StudyId].GetString(0, "");
                String StudyTime    = dicomFile.DataSet[DicomTags.StudyTime].GetString(0, "");
                String SopClassUid  = dicomFile.DataSet[DicomTags.SopClassUid].GetString(0, "");

                SqlParameter[] sqlParameters = new SqlParameter[] {
                    new SqlParameter("@SopInstanceUid", SqlDbType.VarChar),
                    new SqlParameter("@SqlClassUid", SqlDbType.VarChar),
                    new SqlParameter("@Path", SqlDbType.VarChar),
                    new SqlParameter("@PatientId", SqlDbType.VarChar),
                    new SqlParameter("@PatientsName", SqlDbType.VarChar),
                    new SqlParameter("@StudyId", SqlDbType.VarChar),
                    new SqlParameter("@StudyTime", SqlDbType.VarChar),
                    new SqlParameter("@StudyInstanceUid", SqlDbType.VarChar),
                    new SqlParameter("@SeriesInstanceUid", SqlDbType.VarChar),
                    new SqlParameter("@ImageId", SqlDbType.VarChar)
                };
                sqlParameters[0].Value = sopInstanceUid.ToString();
                sqlParameters[1].Value = SopClassUid;
                sqlParameters[2].Value = path.ToString();
                sqlParameters[3].Value = PatientId;
                sqlParameters[4].Value = PatientsName;
                sqlParameters[5].Value = StudyId;
                sqlParameters[6].Value = StudyTime;
                sqlParameters[7].Value = dicomFile.DataSet[DicomTags.StudyInstanceUid].GetString(0, "");
                sqlParameters[8].Value = dicomFile.DataSet[DicomTags.SeriesInstanceUid].GetString(0, "");
                sqlParameters[9].Value = dicomFile.DataSet[DicomTags.ImageId].GetString(0, "");
                String sql = @"INSERT INTO DICOMLIB VALUES(@SopInstanceUid,@SqlClassUid,@Path,@PatientId,@PatientsName,@StudyId,@StudyTime,@StudyInstanceUid,@SeriesInstanceUid,@ImageId)";
                SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, sqlParameters);
                #endregion
                Logger.LogInfo("Received SOP Instance: {0} for patient {1}", sopInstanceUid, PatientsName);
                server.SendCStoreResponse(presentationID, message.MessageId,
                                          sopInstanceUid.UID,
                                          DicomStatuses.Success);
            }
            //C-Find
            else if (message.CommandField == DicomCommandField.CFindRequest)
            {
                //TODO:读取数据库
                //foreach(构造N+1个Message,SendCFindResponse());
                #region 找出筛选条件
                String[] Patameters = new string[4];
                Patameters[0] = message.DataSet[DicomTags.PatientId].ToString();
                Patameters[1] = message.DataSet[DicomTags.PatientsName].ToString();
                Patameters[2] = message.DataSet[DicomTags.StudyId].ToString();
                Patameters[3] = message.DataSet[DicomTags.StudyTime].ToString();
                String level = message.DataSet[DicomTags.QueryRetrieveLevel].ToString();
                String OnlyFliter = ""; Int32 i = 0;
                while (i < 4)
                {
                    if (Patameters[i] != "")
                    {
                        OnlyFliter = Patameters[i]; break;
                    }
                    i++;
                }
                SqlParameter sqlParameter = null;
                String       sql          = "";
                if (OnlyFliter == "")
                {
                    sql = @"SELECT * FROM DICOMLIB";
                }
                else
                {
                    switch (i)
                    {
                    case 0:
                        sqlParameter       = new SqlParameter("@PatientId", SqlDbType.VarChar);
                        sqlParameter.Value = OnlyFliter; sql = @"SELECT * FROM DICOMLIB WHERE PatientId=@PatientId"; break;

                    case 1:
                        sqlParameter       = new SqlParameter("@PatientsName", SqlDbType.VarChar);
                        sqlParameter.Value = OnlyFliter; sql = @"SELECT * FROM DICOMLIB WHERE PatientsName=@PatientsName"; break;

                    case 2:
                        sqlParameter       = new SqlParameter("@StudyId", SqlDbType.VarChar);
                        sqlParameter.Value = OnlyFliter; sql = @"SELECT * FROM DICOMLIB WHERE StudyId=@StudyId"; break;

                    case 3:
                        sqlParameter       = new SqlParameter("@StudyTime", SqlDbType.VarChar);
                        sqlParameter.Value = OnlyFliter; sql = @"SELECT * FROM DICOMLIB WHERE StudyTime=@StudyTime"; break;
                    }
                }

                #endregion
                DataSet      ds          = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, sqlParameter);
                int          rows        = ds.Tables[0].Rows.Count;
                DicomMessage tempMessage = message;
                for (int mi = 0; mi < rows; mi++)
                {
                    tempMessage.DataSet[DicomTags.PatientsName].SetString(0, ds.Tables[0].Rows[mi]["PatientsName"].ToString());
                    tempMessage.DataSet[DicomTags.PatientId].SetString(0, ds.Tables[0].Rows[mi]["PatientId"].ToString());
                    tempMessage.DataSet[DicomTags.StudyId].SetString(0, ds.Tables[0].Rows[mi]["StudyId"].ToString());
                    tempMessage.DataSet[DicomTags.StudyTime].SetString(0, ds.Tables[0].Rows[mi]["StudyTime"].ToString());
                    tempMessage.DataSet[DicomTags.SopInstanceUid].SetString(0, ds.Tables[0].Rows[mi]["SopInstanceUid"].ToString());
                    tempMessage.DataSet[DicomTags.SopClassUid].SetString(0, ds.Tables[0].Rows[mi]["SqlClassUid"].ToString());
                    tempMessage.DataSet[DicomTags.StudyInstanceUid].SetString(0, ds.Tables[0].Rows[mi]["StudyInstanceUid"].ToString());
                    tempMessage.DataSet[DicomTags.SeriesInstanceUid].SetString(0, ds.Tables[0].Rows[mi]["SeriesInstanceUid"].ToString());
                    tempMessage.DataSet[DicomTags.ImageId].SetString(0, ds.Tables[0].Rows[mi]["ImageId"].ToString());
                    server.SendCFindResponse(presentationID, tempMessage.MessageId, tempMessage, DicomStatuses.Pending);
                }
                server.SendCFindResponse(presentationID, tempMessage.MessageId, tempMessage, DicomStatuses.Success);
            }
            else if (message.CommandField == DicomCommandField.CMoveRequest)
            {
                //检索数据库,找到文件
                //发送
                #region 查询数据库

                String sql = "";

                String       QueryRetrieveLevel = message.DataSet[DicomTags.QueryRetrieveLevel].ToString();
                SqlParameter sqlParameter       = null;
                if (QueryRetrieveLevel == "PATIENT")
                {
                    sqlParameter       = new SqlParameter("@PatientId", SqlDbType.VarChar);
                    sqlParameter.Value = message.DataSet[DicomTags.PatientId].ToString();
                    sql = "SELECT Path FROM DICOMLIB WHERE PatientId = @PatientId";
                }
                else if (QueryRetrieveLevel == "STUDY")
                {
                    sqlParameter       = new SqlParameter("@StudyInstanceUid", SqlDbType.VarChar);
                    sqlParameter.Value = message.DataSet[DicomTags.StudyInstanceUid].ToString();
                    sql = "SELECT Path FROM DICOMLIB WHERE StudyInstanceUid = @StudyInstanceUid";
                }
                else if (QueryRetrieveLevel == "SERIES")
                {
                    sqlParameter       = new SqlParameter("@SeriesInstanceUid", SqlDbType.VarChar);
                    sqlParameter.Value = message.DataSet[DicomTags.SeriesInstanceUid].ToString();
                    sql = "SELECT Path FROM DICOMLIB WHERE SeriesInstanceUid = @SeriesInstanceUid";
                }
                else if (QueryRetrieveLevel == "IMAG")
                {
                    sqlParameter       = new SqlParameter("@ImageId", SqlDbType.VarChar);
                    sqlParameter.Value = message.DataSet[DicomTags.ImageId].ToString();
                    sql = "SELECT Path FROM DICOMLIB WHERE ImageId = @ImageId";
                }
                DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, sqlParameter);

                #endregion
                DicomFile dicomFile       = new DicomFile(message, message.DataSet[DicomTags.ImageId].ToString());
                String    MoveDestination = message.MoveDestination.ToString();

                StorageScu _storagescu = new StorageScu();
                if (ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        String path = ds.Tables[0].Rows[i]["Path"].ToString();
                        _storagescu.AddFileToSend(path);
                    }
                    if (MoveDestination == Samples.Properties.Settings.Default.AETs)
                    {
                        _storagescu.Send(Samples.Properties.Settings.Default.ScpAETitle, Properties.Settings.Default.AETs, Properties.Settings.Default.RemoteHost, Properties.Settings.Default.RemotePort);
                    }
                }
                else
                {
                    Logger.LogInfo("NoFiles");
                }
            }
        }