public void OnReceiveRequestMessage(DicomServer server, ServerAssociationParameters association, byte presentationID, ClearCanvas.Dicom.DicomMessage message) { foreach (byte pcid in association.GetPresentationContextIDs()) { DicomPresContext context = association.GetPresentationContext(pcid); if (context.Result == DicomPresContextResult.Accept) { if (context.AbstractSyntax == SopClass.StudyRootQueryRetrieveInformationModelFind) { DicomMessage response = new DicomMessage(); response.DataSet[DicomTags.StudyInstanceUid].SetStringValue("1.2.3"); response.DataSet[DicomTags.PatientId].SetStringValue("1"); response.DataSet[DicomTags.PatientsName].SetStringValue("test"); response.DataSet[DicomTags.StudyId].SetStringValue("1"); response.DataSet[DicomTags.StudyDescription].SetStringValue("dummy"); server.SendCFindResponse(presentationID, message.MessageId, response, DicomStatuses.Pending); DicomMessage finalResponse = new DicomMessage(); server.SendCFindResponse(presentationID, message.MessageId, finalResponse, DicomStatuses.Success); } else if (context.AbstractSyntax == SopClass.VerificationSopClass) { server.SendCEchoResponse(presentationID, message.MessageId, DicomStatuses.Success); } } } }
public override bool OnReceiveRequest(DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message) { server.SendCEchoResponse(presentationID, message.MessageId, DicomStatuses.Success); return(true); }
void IDicomServerHandler.OnReceiveRequestMessage(DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message) { _sessionDebug.SetAssociationDumpString(association); _sessionDebug._request = message.Dump(); #region Cancel request if (message.CommandField == DicomCommandField.CCancelRequest) { Logger.LogInfo("Received CANCEL-RQ message from {0}.", association.CallingAE); _cancelReceived = true; return; } #endregion #region CEcho request if (message.CommandField == DicomCommandField.CEchoRequest) { server.SendCEchoResponse(presentationID, message.MessageId, DicomStatuses.Success); Logger.LogInfo("Received ECHO-RQ message from {0}.", association.CallingAE); return; } #endregion #region MWL C-FIND request if (message.CommandField == DicomCommandField.CFindRequest) { Logger.LogInfo("Message Dumped :\n" + message.Dump("", DicomDumpOptions.KeepGroupLengthElements)); String level = message.DataSet[DicomTags.QueryRetrieveLevel].GetString(0, string.Empty); _cancelReceived = false; if (message.AffectedSopClassUid.Equals(SopClass.ModalityWorklistInformationModelFindUid)) { OnReceiveMWLQuery(server, presentationID, message); } else { // Not supported message type, send a failure status. server.SendCFindResponse(presentationID, message.MessageId, new DicomMessage(), DicomStatuses.QueryRetrieveIdentifierDoesNotMatchSOPClass); } return; } #endregion //ignore all unsupported request server.SendAssociateAbort(DicomAbortSource.ServiceProvider, DicomAbortReason.UnexpectedPDU); Logger.LogInfo("Unexpected Command. Send Associate Abort message from server to {0}.", association.CallingAE); return; }
void IDicomServerHandler.OnReceiveRequestMessage(DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message) { if (message.CommandField == DicomCommandField.CEchoRequest) { server.SendCEchoResponse(presentationID, message.MessageId, DicomStatuses.Success); return; } String studyInstanceUid = null; String seriesInstanceUid = null; DicomUid sopInstanceUid; String patientName = null; 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) { ok = message.DataSet[DicomTags.PatientsName].TryGetString(0, out patientName); } if (!ok) { Platform.Log(LogLevel.Error, "Unable to retrieve UIDs from request message, sending failure status."); server.SendCStoreResponse(presentationID, message.MessageId, sopInstanceUid.UID, DicomStatuses.ProcessingFailure); return; } TransferSyntax syntax = association.GetPresentationContext(presentationID).AcceptedTransferSyntax; if (List) { Platform.Log(LogLevel.Info, message.Dump()); } if (Bitbucket) { Platform.Log(LogLevel.Info, "Received SOP Instance: {0} for patient {1} in syntax {2}", sopInstanceUid, patientName, syntax.Name); server.SendCStoreResponse(presentationID, message.MessageId, sopInstanceUid.UID, DicomStatuses.Success); return; } if (!Directory.Exists(StorageLocation)) { Directory.CreateDirectory(StorageLocation); } var path = new StringBuilder(); path.AppendFormat("{0}{1}{2}{3}{4}", StorageLocation, Path.DirectorySeparatorChar, studyInstanceUid, Path.DirectorySeparatorChar, seriesInstanceUid); Directory.CreateDirectory(path.ToString()); path.AppendFormat("{0}{1}.dcm", Path.DirectorySeparatorChar, sopInstanceUid.UID); var dicomFile = new DicomFile(message, path.ToString()) { TransferSyntaxUid = syntax.UidString, MediaStorageSopInstanceUid = sopInstanceUid.UID, ImplementationClassUid = DicomImplementation.ClassUID.UID, ImplementationVersionName = DicomImplementation.Version, SourceApplicationEntityTitle = association.CallingAE, MediaStorageSopClassUid = message.SopClass.Uid }; dicomFile.Save(DicomWriteOptions.None); Platform.Log(LogLevel.Info, "Received SOP Instance: {0} for patient {1} in syntax {2}", sopInstanceUid, patientName, syntax.Name); server.SendCStoreResponse(presentationID, message.MessageId, sopInstanceUid.UID, DicomStatuses.Success); }
/// <summary> /// Process C-Echo and C-Store request. /// </summary> /// <param name="server"></param> /// <param name="association"></param> /// <param name="presentationID"></param> /// <param name="message"></param> void IDicomServerHandler.OnReceiveRequestMessage(DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message) { if (message.CommandField == DicomCommandField.CEchoRequest) { server.SendCEchoResponse(presentationID, message.MessageId, DicomStatuses.Success); return; } else if (message.CommandField != DicomCommandField.CStoreRequest) { server.SendCEchoResponse(presentationID, message.MessageId, DicomStatuses.UnrecognizedOperation); return; } else if (message.CommandField == DicomCommandField.CStoreRequest) { Platform.Log(LogLevel.Info, message.DataSet.DumpString); ClearCanvas.Common.Platform.Log(LogLevel.Info, "C-Store request for {0}.", message.MessageId); String studyInstanceUid = null; String seriesInstanceUid = null; DicomUid sopInstanceUid; String patientName = null; 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) { ok = message.DataSet[DicomTags.PatientsName].TryGetString(0, out patientName); } //if (!ok) //{ // server.SendCStoreResponse(presentationID, message.MessageId, sopInstanceUid.UID, DicomStatuses.ProcessingFailure); // return; //} try { // You can save the file by using this _storePath = ADCM.GetStoreString(); if (string.IsNullOrEmpty(_storePath)) { throw new Exception("No store path provided"); } string studyfolder = Path.Combine(_storePath, studyInstanceUid); studyfolder = Path.Combine(studyfolder, seriesInstanceUid); if (!Directory.Exists(studyfolder)) { Directory.CreateDirectory(studyfolder); } string filename = Path.Combine(studyfolder, message.DataSet[DicomTags.SopInstanceUid].ToString() + ".dcm"); DicomFile file = new DicomFile(message, filename); file.Save(filename, DicomWriteOptions.Default); ClearCanvas.Common.Platform.Log(ClearCanvas.Common.LogLevel.Info, "Sending C-Store success response."); server.SendCStoreResponse(presentationID, message.MessageId, sopInstanceUid.UID, DicomStatuses.Success); } catch (Exception ex) { ClearCanvas.Common.Platform.Log(LogLevel.Error, ex, "Unable to store request {0}.", message.MessageId); server.SendCStoreResponse(presentationID, message.MessageId, sopInstanceUid != null ? sopInstanceUid.UID : string.Empty, DicomStatuses.ProcessingFailure); } } }
void IDicomServerHandler.OnReceiveRequestMessage(DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message) { if (message.CommandField == DicomCommandField.CEchoRequest) { server.SendCEchoResponse(presentationID, message.MessageId, DicomStatuses.Success); return; } 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); String patientName = dicomFile.DataSet[DicomTags.PatientsName].GetString(0, ""); Logger.LogInfo("Received SOP Instance: {0} for patient {1}", sopInstanceUid, patientName); server.SendCStoreResponse(presentationID, message.MessageId, sopInstanceUid.UID, DicomStatuses.Success); }
/// <summary> /// Handle an incoming request /// </summary> /// <param name="server"></param> /// <param name="association"></param> /// <param name="presentationID"></param> /// <param name="message"></param> void IDicomServerHandler.OnReceiveRequestMessage(DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message) { log.Info("Message received ... "); try { log.Info( string.Format("Request recieved with command field {0} from ae {1}", message.CommandField, message.CommandSet[DicomTags.SourceApplicationEntityTitle].ToString())); if (message.CommandField == DicomCommandField.CEchoRequest) { server.SendCEchoResponse(presentationID, message.MessageId, DicomStatuses.Success); return; } String studyInstanceUid = null; String seriesInstanceUid = null; DicomUid sopInstanceUid = null; DicomUid sopClassUid = null; String patientName = null; 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) { ok = message.DataSet[DicomTags.PatientsName].TryGetString(0, out patientName); } if (ok) { ok = message.DataSet[DicomTags.SopClassUid].TryGetUid(0, out sopClassUid); } if (!ok) { log.Info("Unable to retrieve UIDs from request message, sending failure status."); server.SendCStoreResponse(presentationID, message.MessageId, sopInstanceUid.UID, DicomStatuses.ProcessingFailure); return; } TransferSyntax syntax = association.GetPresentationContext(presentationID).AcceptedTransferSyntax; if (!CacheManager.StorageSpaceAvailable(message, Configuration.Root, Configuration.MaxDiskPercentage)) { log.Error("Insufficient space to store."); server.SendCStoreResponse(presentationID, message.MessageId, sopInstanceUid.UID, DicomStatuses.StorageStorageOutOfResources); return; } log.Info("Adding to cache"); CacheManager.AddToCache( Configuration, association, message, syntax, studyInstanceUid, seriesInstanceUid, sopInstanceUid.UID, patientName); log.Info(string.Format("Received SOP Instance: {0} for patient {1} in syntax {2}", sopInstanceUid, patientName, syntax.Name)); server.SendCStoreResponse(presentationID, message.MessageId, sopInstanceUid.UID, DicomStatuses.Success); } catch (Exception ex) { server.SendCStoreResponse(presentationID, message.MessageId, message.AffectedSopInstanceUid, DicomStatuses.ProcessingFailure); log.Error("Exception thrown " + ex.ToString()); } }
void IDicomServerHandler.OnReceiveRequestMessage(DicomServer server, ServerAssociationParameters association, byte presentationID, DicomMessage message) { _sessionDebug.SetAssociationDumpString(association); _sessionDebug._request = message.Dump(); #region CEcho request if (message.CommandField == DicomCommandField.CEchoRequest) { server.SendCEchoResponse(presentationID, message.MessageId, DicomStatuses.Success); Logger.LogInfo("Received ECHO-RQ message from {0}.", association.CallingAE); return; } #endregion #region MPPS NCreate Request if (message.CommandField == DicomCommandField.NCreateRequest) { // june -1st-2009 : // Unlike the "ModalityWorklistIod" class, the 'partially' implemented ModalityPerformedProcedureStepIod class could // be usefull here. ModalityPerformedProcedureStepIod mppsIod = new ModalityPerformedProcedureStepIod(message.DataSet); Logger.LogInfo("Message Dumped :\n" + message.Dump("", DicomDumpOptions.KeepGroupLengthElements)); // checking message for error and anomalies bool anomalyExist = CheckNCreateDataSetConformance(server, association, presentationID, mppsIod, true); if (anomalyExist) { server.SendNCreateResponse(presentationID, message.MessageId, new DicomMessage(), DicomStatuses.InvalidAttributeValue); Logger.LogError("Sending Invalid Attributes Response."); return; } // wrong status if (mppsIod.PerformedProcedureStepInformation.PerformedProcedureStepStatus != ClearCanvas.Dicom.Iod.Modules.PerformedProcedureStepStatus.InProgress) { server.SendNCreateResponse(presentationID, message.MessageId, new DicomMessage(), DicomStatuses.InvalidAttributeValue); Logger.LogError("Recieved N-Create Request with bad status."); return; } // pps already in cache (duplicated step) string cacheKeyId = message.AffectedSopInstanceUid; bool alreadyCached; MPPSScp.CacheMppsEntity(association, cacheKeyId, mppsIod, out alreadyCached); if (alreadyCached) { server.SendNCreateResponse(presentationID, message.MessageId, new DicomMessage(), DicomStatuses.DuplicateSOPInstance); Logger.LogError("Recieved duplicated N-Create Request."); return; } if (!ProcessNCreateRequest(server, presentationID, message)) { server.SendNCreateResponse(presentationID, message.MessageId, new DicomMessage(), DicomStatuses.ProcessingFailure); Logger.LogError("Sending Processing due to NCreate request Failure."); return; } server.SendNCreateResponse(presentationID, message.MessageId, new DicomMessage(), DicomStatuses.Success); return; } #endregion #region MPPS NSet Request if (message.CommandField == DicomCommandField.NSetRequest) { // june -1st-2009 : // Unlike the "ModalityWorklistIod" class, the ModalityPerformedProcedureStepIod is fully implemented // we can use it here. ModalityPerformedProcedureStepIod mppsIod = new ModalityPerformedProcedureStepIod(message.DataSet); Logger.LogInfo("Message Dumped :\n" + message.Dump("", DicomDumpOptions.KeepGroupLengthElements)); // check if pps already in cache (duplicated step) string cacheKeyId = message.RequestedSopInstanceUid; if (!IsMppsEntitycached(cacheKeyId)) { server.SendNCreateResponse(presentationID, message.MessageId, new DicomMessage(), DicomStatuses.NoSuchObjectInstance); Logger.LogError("Received Unknown NSset SOP."); return; } // status diffrent from in progress if (mppsIod.PerformedProcedureStepInformation.PerformedProcedureStepStatus == ClearCanvas.Dicom.Iod.Modules.PerformedProcedureStepStatus.InProgress) { server.SendNSetResponse(presentationID, message.MessageId, new DicomMessage(), DicomStatuses.InvalidAttributeValue); Logger.LogError("Recieved N-Set Request with In Progress status."); RemoveMppsEntityFromCache(cacheKeyId); return; } // checking the received mppsiod against cached one ModalityPerformedProcedureStepIod cachedMppsIod = GetCachedMppsIod(cacheKeyId); //assuming cachedMppsIod not null. bool anomaly = CheckNSetDataSetConformance(server, association, presentationID, cachedMppsIod, mppsIod, true); if (anomaly) { server.SendNSetResponse(presentationID, message.MessageId, new DicomMessage(), DicomStatuses.InvalidAttributeValue); Logger.LogError("Sending Failure Response."); RemoveMppsEntityFromCache(cacheKeyId); return; } string studyInstanceUID = mppsIod. PerformedProcedureStepRelationship. DicomAttributeProvider[DicomTags.StudyInstanceUid]. GetString(0, ""); XmlElement performedSeriesSQ = GenerateXmlForPerformedSeriesSQ(message, studyInstanceUID); bool success = true; if (mppsIod.PerformedProcedureStepInformation.PerformedProcedureStepStatus == ClearCanvas.Dicom.Iod.Modules.PerformedProcedureStepStatus.Completed) { success = ProcessNSetRequestForCompleted(server, presentationID, message, performedSeriesSQ); } if (mppsIod.PerformedProcedureStepInformation.PerformedProcedureStepStatus == ClearCanvas.Dicom.Iod.Modules.PerformedProcedureStepStatus.Discontinued) { success = ProcessNSetRequestForDiscontinued(server, presentationID, message, performedSeriesSQ); } if (success) { server.SendNSetResponse(presentationID, message.MessageId, new DicomMessage(), DicomStatuses.Success); } else { server.SendNSetResponse(presentationID, message.MessageId, new DicomMessage(), DicomStatuses.ProcessingFailure); } MPPSScp.RemoveMppsEntityFromCache(cacheKeyId); return; } #endregion //ignore all unsupported request server.SendAssociateAbort(DicomAbortSource.ServiceProvider, DicomAbortReason.UnexpectedPDU); Logger.LogInfo("Unexpected Command. Send Associate Abort message from server to {0}.", association.CallingAE); return; }
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"); } } }