Dicom 學(xué)習(xí)筆記-DICOM C-Get 消息服務(wù)

引言


??前篇介紹了 DICOM C-Find 消息服務(wù),本文結(jié)合開(kāi)源 DICOM 庫(kù) fo-dicom 詳細(xì)介紹一下 C-Get 服務(wù)。

C-Get 消息服務(wù)


??C-Get 服務(wù)主要用于獲取影像,用于一個(gè) DIMSE-service-user 在同等的DIMSE-service-user 上查詢復(fù)合 SOP 實(shí)例的屬性滿足查詢條件給出的一組屬性的復(fù)合 SOP 實(shí)例,并取回這些符合條件的復(fù)合 SOP 實(shí)例,同時(shí)在這個(gè)過(guò)程中將觸發(fā)一個(gè)或多個(gè) C-STORE 子操作過(guò)程,所有的操作(包含 C-STORE 子操作)均在同一個(gè) association 連接中。
??有關(guān)C-Get 服務(wù)流程圖,我通過(guò)不同的 C-Get SCP 的實(shí)現(xiàn),出現(xiàn)了兩種流程圖,參考如下:

  • 每個(gè) C-Store 子操作完成后都會(huì)有一個(gè) C-Get 響應(yīng)
C-Get workflow 1

-C-Get 響應(yīng)只會(huì)在 C-Store 子操作全部完成后發(fā)送

C-Get workflow 2

C-Get SCU


??通過(guò)結(jié)合 DICOM 開(kāi)源庫(kù) fo-dicom 來(lái)實(shí)現(xiàn) C-Get SCU,部分代碼如下:
需要引用命名空間【Dicom.Network】和【System.Threading】

using Dicom.Network;
using System.Threading;
var client = new DicomClient();

// 添加能夠接收的抽象語(yǔ)法 abstract syntax,通過(guò)查看 DICOM 文件的 SOPClassUID 可獲得,否則不會(huì)觸發(fā) C-Store 子操作
var pc = DicomPresentationContext.GetScpRolePresentationContext(DicomUID.CTImageStorage);
client.AdditionalPresentationContexts.Add(pc);

var counter = 0;
var locker = new object();
client.OnCStoreRequest = (DicomCStoreRequest request) =>
{
    lock (locker)
    {
        ++counter;
        Console.WriteLine(DateTime.Now.ToString() + " recived, count is " + counter);
    }
    // 可以通過(guò) request.Dataset 獲取到 DICOM 文件

    return new DicomCStoreResponse(request, DicomStatus.Success);
};

var get = new DicomCGetRequest({StudyInstanceUID});

var handle = new ManualResetEventSlim();
get.OnResponseReceived = (DicomCGetRequest requ, DicomCGetResponse response) =>
{
    if (response.Remaining == 0)
    {
        handle.Set();
    }
};
client.AddRequest(get);
client.Send({C-Get SCP IP}, {C-Get SCP Port}, false, {C-Get SCU AE Title}, {C-Get SCP AE Title});
handle.Wait();
  • StudyInstanceUID:檢查唯一標(biāo)識(shí);
  • C-Get SCP IP:C-Get 服務(wù)端的 IP 地址或機(jī)器名;
  • C-Get SCP Port:C-Get 服務(wù)端的端口;
  • C-Get SCU AE Title:C-Get 客戶端應(yīng)用實(shí)體的名稱;
  • C-Get SCP AE Title:C-Get 服務(wù)端應(yīng)用實(shí)體的名稱;

C-Get SCP


??在本文開(kāi)頭部分給出了兩張流程圖,這是通過(guò)不同 C-Get SCP 的實(shí)現(xiàn)進(jìn)行抓包得到的,針對(duì)這塊流程中不同的地方在 DICOM 標(biāo)準(zhǔn)中到底是如何定義的,可以在 DICOM 標(biāo)準(zhǔn)的第4部分【C.1.4 Service Definition】 中找到,具體的描述如下:

A C-GET service conveys the following semantics:
?
The SCU supplies Unique Key values to identify an entity at the level of the retrieval. The SCP generates C-STORE sub-oper- ations for the corresponding storage SOP Instances identified by the Unique Key values. These C-STORE sub-operations occur on the same Association as the C-GET service and the SCU/SCP roles will be reversed for the C-STORE.
?
The SCP may optionally generate responses to the C-GET with status equal to Pending during the processing of the C-STORE sub-operations. These C-GET responses indicate the number of Remaining C-STORE sub-operations and the number of C- STORE sub-operations returning the status of Success, Warning, and Failed.
?
When the number of Remaining C-STORE sub-operations reaches zero, the SCP generates a final response with a status equal to Success, Warning, Failed, or Refused. This response may indicate the number of C-STORE sub-operations returning the status of Success, Warning, and Failed. If the status of a C-STORE sub-operation was Failed a UID List will be returned.
?
The SCU may cancel the C-GET service by issuing a C-GET-CANCEL request at any time during the processing of the C- GET. The SCP terminates all incomplete C-STORE sub-operations and returns a status of Canceled.

這里已經(jīng)說(shuō)明了是可選的,更詳細(xì)的 C-Get 過(guò)程在 DICOM 標(biāo)準(zhǔn)第7部分【9.1.3.2】有描述,不過(guò)針對(duì)這塊沒(méi)有描述,所以才出現(xiàn)如文章開(kāi)頭兩種流程圖。C-Get SCP 可以通過(guò)派生 DicomService 服務(wù)類來(lái)實(shí)現(xiàn) Dicom 服務(wù)的基本框架,然后實(shí)現(xiàn) IDicomServiceProvider 和 IDicomCGetProvider 接口來(lái)實(shí)現(xiàn),部分代碼可以參考這里,核心部分是實(shí)現(xiàn) OnCGetRequest 方法。

C-Get 過(guò)程分析


??我這里選擇本文開(kāi)頭第一種流程圖的抓包數(shù)據(jù)進(jìn)行分析,由于包的數(shù)據(jù)量比較大,我這里過(guò)濾掉不能被解碼成 DICOM 協(xié)議的包,只分析能被解碼成 DICOM 協(xié)議的包,先看前面部分:

C-Get pcap

紅色框內(nèi)的兩行是兩個(gè) AE 建立 association 的過(guò)程:

  1. C-Get SCU(10.3.13.202)向 C-Get SCP(10.3.2.209) 發(fā)送 A-ASSOCIATE 請(qǐng)求;
  2. C-Get SCP(10.3.2.209)響應(yīng) C-Get SCU(10.3.13.202)的 A-ASSOCIATE 請(qǐng)求,然后兩個(gè) AE 就建立了一個(gè) association;

接著藍(lán)色框第一行就是 C-Get SCU(10.3.13.202)向 C-Get SCP(10.3.2.209) 發(fā)送 C-Get 請(qǐng)求了;
藍(lán)色框第二行是 C-Get SCP(10.3.2.209)經(jīng)過(guò)查找,找到滿足條件的復(fù)合 SOP 實(shí)例對(duì)象,返回找到的信息,從下圖紅色框可以看到有3個(gè)子操作待執(zhí)行,這里表示找到了3個(gè)滿足條件的復(fù)合 SOP 實(shí)例對(duì)象,接下來(lái)會(huì)觸發(fā)3個(gè) C-Store 子操作。

C-Get Response

接著就是 C-Store 歸檔數(shù)據(jù)的操作了

C-Store

一個(gè)復(fù)合 SOP 實(shí)例對(duì)象數(shù)據(jù)歸檔的最后一個(gè)包是一個(gè)畸形數(shù)據(jù)包【Malformed packet】:

Malformed packet

從上圖可以看出,前面?zhèn)鬏數(shù)臄?shù)據(jù)包都將在收到 Frame 609后進(jìn)行重組,F(xiàn)rame 609就在 Malformed Packet 這個(gè)數(shù)據(jù)包,下面的藍(lán)色框是這個(gè)數(shù)據(jù)包將前面所有收到的數(shù)據(jù)包重組之后,解析 SOP 對(duì)象得到的 TAG 值;
然后 C-Get SCU(10.3.13.202)向 C-Get SCP(10.3.2.209) 發(fā)送 C-Store 響應(yīng),并告知狀態(tài)為 Success;

C-Store Response

接著 C-Get SCP(10.3.2.209)向 C-Get SCU(10.3.13.202)發(fā)送 C-Get 請(qǐng)求的響應(yīng),內(nèi)容包括當(dāng)前的狀態(tài)、剩下多少個(gè)子操作待執(zhí)行、已完成多少個(gè)子操作和失敗的子操作個(gè)數(shù):

C-Get Response

這個(gè)數(shù)據(jù)包結(jié)束后就又是下一個(gè) SOP 實(shí)例對(duì)象的歸檔數(shù)據(jù)包了,和上面一樣,這里不再繼續(xù)分析。
當(dāng)所有的 C-Store 子操作結(jié)束后 C-Get SCP(10.3.2.209)會(huì)向 C-Get SCU(10.3.13.202)發(fā)送一個(gè) C-Get 請(qǐng)求的響應(yīng),這里會(huì)返回 C-Get 請(qǐng)求的狀態(tài),如果前面的子操作都成功的話,這里會(huì)返回狀態(tài)為 Success:

C-Get Response

最后 C-Get SCU(10.3.13.202)向 C-Get SCP(10.3.2.209) 發(fā)送 A-RELEASE 請(qǐng)求斷開(kāi) association;
C-Get SCP(10.3.2.209)響應(yīng) C-Get SCU(10.3.13.202)的 A-RELEASE 請(qǐng)求,然后斷開(kāi)兩個(gè) AE 之間的 association;
至此,整個(gè) DICOM 協(xié)議相關(guān)的包就全部發(fā)送完畢。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,863評(píng)論 0 10
  • 引言 ??前篇介紹了 DICOM C-Store 消息服務(wù),本文結(jié)合開(kāi)源 DICOM 庫(kù) fo-dicom 詳細(xì)介...
    Statmoon閱讀 7,900評(píng)論 0 4
  • 3721
    汝南江閱讀 252評(píng)論 0 0
  • 南方的梅雨 似乎 比往年來(lái)的早一些 淅淅瀝瀝 濕漉漉的 古寺瓦棱上的青苔 如得到心愛(ài)禮物的童心 著實(shí)更艷 更青 而...
    瘋?cè)?/span>閱讀 581評(píng)論 2 7
  • 春來(lái)葉落驚新蕾, 染血踟躕發(fā)幾枝? 望盡花都南國(guó)路, 守回赤膽北山陂。 千芳映日藏螓首, 獨(dú)木披風(fēng)露峨眉。 皆道傾...
    煙雨雨巷閱讀 476評(píng)論 1 3

友情鏈接更多精彩內(nèi)容