-
Notifications
You must be signed in to change notification settings - Fork 0
/
python-gdcm-scu.html
259 lines (235 loc) · 14.9 KB
/
python-gdcm-scu.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="faigo" />
<meta name="copyright" content="faigo" />
<meta property="og:type" content="article" />
<meta name="twitter:card" content="summary">
<meta name="keywords" content="python, gdcm, Python, " />
<meta property="og:title" content="GDCM SCU - [dicom scu] "/>
<meta property="og:url" content="http://faigogo.com/python-gdcm-scu" />
<meta property="og:description" content="program dicom scu with python gdcm" />
<meta property="og:site_name" content="Faigo" />
<meta property="og:article:author" content="faigo" />
<meta property="og:article:published_time" content="2016-07-31T00:00:00+08:00" />
<meta name="twitter:title" content="GDCM SCU - [dicom scu] ">
<meta name="twitter:description" content="program dicom scu with python gdcm">
<title>GDCM SCU - [dicom scu] · Faigo
</title>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.1/css/font-awesome.css" rel="stylesheet">
<link rel="stylesheet" href="http://faigogo.com/theme/css/style.min.css?7aeecf36">
<link rel="shortcut icon" href="http://faigogo.com/theme/images/favicon.ico" type="image/x-icon" type="image/png" />
<link rel="icon" href="http://faigogo.com/theme/images/apple-touch-icon-152x152.png" type="image/png" />
<link rel="apple-touch-icon" href="http://faigogo.com/theme/images/apple-touch-icon.png" type="image/png" />
<link rel="apple-touch-icon" sizes="57x57" href="http://faigogo.com/theme/images/apple-touch-icon-57x57.png" type="image/png" />
<link rel="apple-touch-icon" sizes="72x72" href="http://faigogo.com/theme/images/apple-touch-icon-72x72.png" type="image/png" />
<link rel="apple-touch-icon" sizes="76x76" href="http://faigogo.com/theme/images/apple-touch-icon-76x76.png" type="image/png" />
<link rel="apple-touch-icon" sizes="114x114" href="http://faigogo.com/theme/images/apple-touch-icon-114x114.png" type="image/png" />
<link rel="apple-touch-icon" sizes="120x120" href="http://faigogo.com/theme/images/apple-touch-icon-120x120.png" type="image/png" />
<link rel="apple-touch-icon" sizes="144x144" href="http://faigogo.com/theme/images/apple-touch-icon-144x144.png" type="image/png" />
<link rel="apple-touch-icon" sizes="152x152" href="http://faigogo.com/theme/images/apple-touch-icon-152x152.png" type="image/png" />
</head>
<body>
<div id="content-sans-footer">
<div class="navbar navbar-static-top">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="http://faigogo.com/"><span class=site-name>Faigo</span></a>
<div class="nav-collapse collapse">
<ul class="nav pull-right top-menu">
<li ><a href="http://faigogo.com">首页</a></li>
<li ><a href="http://faigogo.com/categories.html">分类</a></li>
<li ><a href="http://faigogo.com/tags.html">标签</a></li>
<li ><a href="http://faigogo.com/archives.html">归档</a></li>
<li ><a href="http://faigogo.com/photo">相册</a></li>
<li ><a href="http://faigogo.com/about">关于</a></li>
<li><form class="navbar-search" action="http://faigogo.com/search.html" onsubmit="return validateForm(this.elements['q'].value);"> <input type="text" class="search-query" placeholder="搜索" name="q" id="tipue_search_input"></form></li>
</ul>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span1"></div>
<div class="span10">
<article>
<div class="row-fluid">
<header class="page-header span10 offset2">
<h1><a href="http://faigogo.com/python-gdcm-scu"> <span class="caps">GDCM</span> <span class="caps">SCU</span> <small> [dicom scu] </small> </a></h1>
</header>
</div>
<div class="row-fluid">
<div class="span8 offset2 article-content">
<p>使用python gdcm编写dicom scu,c-find/c-move/c-store</p>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">_getQuery</span><span class="p">(</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">queryKeys</span> <span class="o">=</span> <span class="n">gdcm</span><span class="o">.</span><span class="n">DataSet</span><span class="p">()</span>
<span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
<span class="k">if</span> <span class="n">key</span> <span class="o">!=</span> <span class="n">studyUIDTag</span><span class="p">:</span>
<span class="k">continue</span>
<span class="n">de</span> <span class="o">=</span> <span class="n">gdcm</span><span class="o">.</span><span class="n">DataElement</span><span class="p">()</span>
<span class="n">de</span><span class="o">.</span><span class="n">SetTag</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
<span class="n">de</span><span class="o">.</span><span class="n">SetByteValue</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="n">key</span><span class="p">],</span><span class="n">gdcm</span><span class="o">.</span><span class="n">VL</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">kwargs</span><span class="p">[</span><span class="n">key</span><span class="p">])))</span>
<span class="n">queryKeys</span><span class="o">.</span><span class="n">Insert</span><span class="p">(</span><span class="n">de</span><span class="p">)</span>
<span class="c1">#ePatientRootType,eStudyRootType # ePatient,eStudy,eSeries,eImage </span>
<span class="n">query</span> <span class="o">=</span> <span class="n">gdcm</span><span class="o">.</span><span class="n">CompositeNetworkFunctions_ConstructQuery</span><span class="p">(</span><span class="n">gdcm</span><span class="o">.</span><span class="n">eStudyRootType</span><span class="p">,</span><span class="n">gdcm</span><span class="o">.</span><span class="n">eStudy</span><span class="p">,</span><span class="n">queryKeys</span><span class="p">,</span><span class="bp">True</span><span class="p">)</span>
<span class="k">return</span> <span class="n">query</span>
<span class="n">scu</span> <span class="o">=</span> <span class="n">gdcm</span><span class="o">.</span><span class="n">ServiceClassUser</span><span class="p">()</span>
<span class="n">scu</span><span class="o">.</span><span class="n">SetHostname</span><span class="p">(</span><span class="n">MOVE_CONFIG</span><span class="p">[</span><span class="s1">'host'</span><span class="p">])</span>
<span class="n">scu</span><span class="o">.</span><span class="n">SetPort</span><span class="p">(</span><span class="n">MOVE_CONFIG</span><span class="p">[</span><span class="s1">'port'</span><span class="p">])</span>
<span class="n">scu</span><span class="o">.</span><span class="n">SetTimeout</span><span class="p">(</span><span class="mi">100</span><span class="p">)</span>
<span class="n">scu</span><span class="o">.</span><span class="n">SetCalledAETitle</span><span class="p">(</span><span class="n">MOVE_CONFIG</span><span class="p">[</span><span class="s1">'callAE'</span><span class="p">])</span>
<span class="n">scu</span><span class="o">.</span><span class="n">SetAETitle</span><span class="p">(</span><span class="n">MOVE_CONFIG</span><span class="p">[</span><span class="s1">'callingAE'</span><span class="p">])</span>
<span class="n">scu</span><span class="o">.</span><span class="n">SetPortSCP</span><span class="p">(</span><span class="n">MOVE_CONFIG</span><span class="p">[</span><span class="s1">'retrievePort'</span><span class="p">])</span>
<span class="n">query</span> <span class="o">=</span> <span class="n">_getQuery</span><span class="p">(</span>
<span class="p">{</span>
<span class="n">studyUIDTag</span><span class="p">:</span><span class="n">studyUID</span><span class="p">,</span>
<span class="n">seriesUIDTag</span><span class="p">:</span><span class="n">seriesUID</span><span class="p">,</span>
<span class="n">sopUIDTag</span><span class="p">:</span><span class="n">sopUID</span>
<span class="p">})</span>
<span class="k">print</span> <span class="s1">'query:'</span><span class="p">,</span> <span class="n">query</span><span class="o">.</span><span class="n">ValidateQuery</span><span class="p">()</span>
<span class="k">print</span> <span class="s1">'InitializeConnection:'</span><span class="p">,</span> <span class="n">scu</span><span class="o">.</span><span class="n">InitializeConnection</span><span class="p">()</span>
<span class="n">generator</span> <span class="o">=</span> <span class="n">gdcm</span><span class="o">.</span><span class="n">PresentationContextGenerator</span><span class="p">()</span>
<span class="n">generator</span><span class="o">.</span><span class="n">GenerateFromUID</span><span class="p">(</span><span class="n">query</span><span class="o">.</span><span class="n">GetAbstractSyntaxUID</span><span class="p">())</span> <span class="c1"># !!!</span>
<span class="n">scu</span><span class="o">.</span><span class="n">SetPresentationContexts</span><span class="p">(</span><span class="n">generator</span><span class="o">.</span><span class="n">GetPresentationContexts</span><span class="p">())</span>
<span class="k">if</span> <span class="n">scu</span><span class="o">.</span><span class="n">StartAssociation</span><span class="p">():</span>
<span class="c1"># print 'Echo:',scu.SendEcho()</span>
<span class="n">res</span> <span class="o">=</span> <span class="n">gdcm</span><span class="o">.</span><span class="n">DataSetArrayType</span><span class="p">()</span>
<span class="c1"># if scu.SendFind(query, res):</span>
<span class="k">if</span> <span class="n">scu</span><span class="o">.</span><span class="n">SendMove</span><span class="p">(</span><span class="n">query</span><span class="p">,</span> <span class="n">MOVE_CONFIG</span><span class="p">[</span><span class="s1">'path'</span><span class="p">]):</span>
<span class="k">pass</span>
<span class="c1"># for dataset in res:</span>
<span class="c1"># print dataset.GetDataElement(studyUIDTag)</span>
<span class="c1"># print dataset.GetDataElement(seriesUIDTag)</span>
<span class="c1"># print dataset.GetDataElement(sopUIDTag)</span>
<span class="n">scu</span><span class="o">.</span><span class="n">StopAssociation</span><span class="p">()</span>
</pre></div>
</td></tr></table>
<hr/>
<aside>
<nav>
<ul class="articles-timeline">
<li class="next-article"><a href="http://faigogo.com/python-any-all" title="Next: any all函数用法">any all函数用法</a> »</li>
</ul>
</nav>
</aside>
</div>
<section>
<div class="span2" style="float:right;font-size:0.9em;">
<h4>发表于</h4>
<time pubdate="pubdate" datetime="2016-07-31T00:00:00+08:00"> 7月 31, 2016</time>
<h4>分类</h4>
<a class="category-link" href="http://faigogo.com/categories.html#python-ref"> Python</a>
<h4>标签</h4>
<ul class="list-of-tags tags-in-article">
<li><a href="http://faigogo.com/tags.html#gdcm-ref"> gdcm
<span>1</span>
</a></li>
<li><a href="http://faigogo.com/tags.html#python-ref"> python
<span>3</span>
</a></li>
</ul>
<h4><br>Contact</h4>
<a href="m" title="E" class="sidebar-social-links" target="_blank">
<i class="fa fa-a sidebar-social-links"></i></a>
<a href="a" title="m" class="sidebar-social-links" target="_blank">
<i class="fa fa-i sidebar-social-links"></i></a>
</div>
</section>
<div class="comments span8 offset2 article-content">
<!-- <h2>Comments !</h2> -->
<!-- Duoshuo Comment BEGIN -->
<div class="ds-thread" data-thread-key="python-gdcm-scu" data-title="python-gdcm-scu" ></div>
<script type="text/javascript">
var duoshuoQuery = {short_name:"Faigo"};
(function() {
var ds = document.createElement('script');
ds.type = 'text/javascript';ds.async = true;
ds.src = 'http://static.duoshuo.com/embed.js';
ds.charset = 'UTF-8';
(document.getElementsByTagName('head')[0]
|| document.getElementsByTagName('body')[0]).appendChild(ds);
})();
</script>
<noscript>Please enable JavaScript to view the comments.</noscript>
<!-- Duoshuo Comment END -->
</div>
</article>
</div>
<div class="span1"></div>
</div>
</div>
<div id="push"></div>
</div>
<footer>
<div id="footer">
<ul class="footer-content">
<!-- <li class="elegant-power">Powered by <a href="http://getpelican.com/" title="Pelican Home Page">Pelican</a>. Theme: <a href="http://oncrashreboot.com/pelican-elegant" title="Theme Elegant Home Page">Elegant</a> by <a href="http://oncrashreboot.com" title="Talha Mansoor Home Page">Talha Mansoor</a></li> -->
</ul>
</div>
</footer> <script src="http://code.jquery.com/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<script>
function validateForm(query)
{
return (query.length > 0);
}
</script>
</body>
<!-- Theme: Elegant built for Pelican
License : http://oncrashreboot.com/pelican-elegant -->
</html>