-
Notifications
You must be signed in to change notification settings - Fork 172
/
service_class_n.py
362 lines (297 loc) · 12.7 KB
/
service_class_n.py
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
"""Implements the supported Service Classes that make use of DIMSE-N."""
import logging
from typing import TYPE_CHECKING
from pynetdicom.dimse_primitives import (
N_ACTION,
N_CREATE,
N_DELETE,
N_EVENT_REPORT,
N_GET,
N_SET,
C_FIND,
)
from pynetdicom.service_class import ServiceClass
from pynetdicom.status import (
GENERAL_STATUS,
APPLICATION_EVENT_LOGGING_SERVICE_CLASS_STATUS,
MEDIA_CREATION_MANAGEMENT_SERVICE_CLASS_STATUS,
PRINT_JOB_MANAGEMENT_SERVICE_CLASS_STATUS,
PROCEDURE_STEP_STATUS,
STORAGE_COMMITMENT_SERVICE_CLASS_STATUS,
STORAGE_MANAGEMENT_SERVICE_CLASS_STATUS,
RT_MACHINE_VERIFICATION_SERVICE_CLASS_STATUS,
UNIFIED_PROCEDURE_STEP_SERVICE_CLASS_STATUS,
)
if TYPE_CHECKING: # pragma: no cover
from pynetdicom.presentation import PresentationContext
_MCM = N_CREATE | N_GET | N_ACTION
_PJ = N_CREATE | N_EVENT_REPORT | N_GET | N_SET | N_ACTION | N_DELETE
_PS = N_CREATE | N_EVENT_REPORT | N_GET | N_SET
_SCS = N_EVENT_REPORT | N_ACTION
_SMS = N_ACTION | N_EVENT_REPORT
_UPS = N_CREATE | N_EVENT_REPORT | N_GET | N_SET | N_ACTION | C_FIND
LOGGER = logging.getLogger(__name__)
class ApplicationEventLoggingServiceClass(ServiceClass):
"""Implementation of the Application Event Logging Service Class
.. versionadded:: 1.4
"""
statuses = APPLICATION_EVENT_LOGGING_SERVICE_CLASS_STATUS
def SCP(self, req: N_ACTION, context: "PresentationContext") -> None:
"""The SCP implementation for Application Event Logging Service Class.
Parameters
----------
req : dimse_primitives.N_ACTION
The N-ACTION request primitive sent by the peer.
context : presentation.PresentationContext
The presentation context that the service is operating under.
"""
if isinstance(req, N_ACTION):
self._n_action_scp(req, context)
else:
raise ValueError(
f"Invalid DIMSE primitive '{req.__class__.__name__}' used "
f"with Application Event Logging"
)
class DisplaySystemManagementServiceClass(ServiceClass):
"""Implementation of the Display System Management Service Class."""
statuses = GENERAL_STATUS
def SCP(self, req: N_GET, context: "PresentationContext") -> None:
"""The SCP implementation for Display System Management.
Parameters
----------
req : dimse_primitives.N_GET
The N-GET request primitive sent by the peer.
context : presentation.PresentationContext
The presentation context that the service is operating under.
"""
if isinstance(req, N_GET):
self._n_get_scp(req, context)
else:
raise ValueError(
f"Invalid DIMSE primitive '{req.__class__.__name__}' used "
f"with Display System Management"
)
class InstanceAvailabilityNotificationServiceClass(ServiceClass):
"""Implementation of the Instance Availability Service Class
.. versionadded:: 1.4
"""
statuses = GENERAL_STATUS
def SCP(self, req: N_CREATE, context: "PresentationContext") -> None:
"""The SCP implementation for Instance Availability Service Class.
Parameters
----------
req : dimse_primitives.N_CREATE
The N-CREATE request primitive sent by the peer.
context : presentation.PresentationContext
The presentation context that the service is operating under.
"""
if isinstance(req, N_CREATE):
self._n_create_scp(req, context)
else:
raise ValueError(
f"Invalid DIMSE primitive '{req.__class__.__name__}' used "
f"with Instance Availability"
)
class MediaCreationManagementServiceClass(ServiceClass):
"""Implementation of the Media Creation Management Service Class
.. versionadded:: 1.4
"""
statuses = MEDIA_CREATION_MANAGEMENT_SERVICE_CLASS_STATUS
def SCP(self, req: "_MCM", context: "PresentationContext") -> None:
"""The SCP implementation for Media Creation Management Service Class.
Parameters
----------
req : dimse_primitives.N_CREATE or N_GET or N_ACTION
The N-CREATE, N-GET or N-ACTION request primitive sent by the peer.
context : presentation.PresentationContext
The presentation context that the service is operating under.
"""
if isinstance(req, N_CREATE):
self._n_create_scp(req, context)
elif isinstance(req, N_GET):
self._n_get_scp(req, context)
elif isinstance(req, N_ACTION):
self._n_action_scp(req, context)
else:
raise ValueError(
f"Invalid DIMSE primitive '{req.__class__.__name__}' used "
f"with Media Creation Management"
)
class PrintManagementServiceClass(ServiceClass):
"""Implementation of the Print Management Service Class
.. versionadded:: 1.4
"""
statuses = PRINT_JOB_MANAGEMENT_SERVICE_CLASS_STATUS
def SCP(self, req: "_PJ", context: "PresentationContext") -> None:
"""The SCP implementation for Print Management Service Class.
Parameters
----------
req : dimse_primitives.N_CREATE or N_SET or N_DELETE or N_GET or N_EVENT_REPORT or N_ACTION
The N-CREATE, N-SET, N-GET, N-DELETE, N-ACTION or N-EVENT-REPORT
request primitive sent by the peer.
context : presentation.PresentationContext
The presentation context that the service is operating under.
"""
if isinstance(req, N_CREATE):
self._n_create_scp(req, context)
elif isinstance(req, N_EVENT_REPORT):
self._n_event_report_scp(req, context)
elif isinstance(req, N_GET):
self._n_get_scp(req, context)
elif isinstance(req, N_SET):
self._n_set_scp(req, context)
elif isinstance(req, N_ACTION):
self._n_action_scp(req, context)
elif isinstance(req, N_DELETE):
self._n_delete_scp(req, context)
else:
raise ValueError(
f"Invalid DIMSE primitive '{req.__class__.__name__}' used "
f"with Print Management"
)
class ProcedureStepServiceClass(ServiceClass):
"""Implementation of the Modality Performed Procedure Step Service Class
.. versionadded:: 1.3
"""
statuses = PROCEDURE_STEP_STATUS
def SCP(self, req: "_PS", context: "PresentationContext") -> None:
"""The SCP implementation for Modality Performed Procedure Step.
Parameters
----------
req : dimse_primitives.N_CREATE or N_SET or N_GET or N_EVENT_REPORT
The N-CREATE, N-SET, N-GET or N-EVENT-REPORT request primitive
sent by the peer.
context : presentation.PresentationContext
The presentation context that the service is operating under.
"""
if isinstance(req, N_CREATE):
# Modality Performed Procedure Step
self._n_create_scp(req, context)
elif isinstance(req, N_EVENT_REPORT):
# Modality Performed Procedure Step Notification
self._n_event_report_scp(req, context)
elif isinstance(req, N_GET):
# Modality Performed Procedure Step Retrieve
self._n_get_scp(req, context)
elif isinstance(req, N_SET):
# Modality Performed Procedure Step
self._n_set_scp(req, context)
else:
raise ValueError(
f"Invalid DIMSE primitive '{req.__class__.__name__}' used "
f"with Modality Performed Procedure Step"
)
class RTMachineVerificationServiceClass(ServiceClass):
"""Implementation of the RT Machine Verification Service Class
.. versionadded:: 1.4
"""
statuses = RT_MACHINE_VERIFICATION_SERVICE_CLASS_STATUS
def SCP(self, req: "_PJ", context: "PresentationContext") -> None:
"""The SCP implementation for RT Machine Verification Service Class.
Parameters
----------
req : dimse_primitives.N_CREATE or N_SET or N_DELETE or N_GET or N_EVENT_REPORT or N_ACTION
The N-CREATE, N-SET, N-GET, N-DELETE, N-ACTION or N-EVENT-REPORT
request primitive sent by the peer.
context : presentation.PresentationContext
The presentation context that the service is operating under.
"""
if isinstance(req, N_CREATE):
self._n_create_scp(req, context)
elif isinstance(req, N_EVENT_REPORT):
self._n_event_report_scp(req, context)
elif isinstance(req, N_GET):
self._n_get_scp(req, context)
elif isinstance(req, N_SET):
self._n_set_scp(req, context)
elif isinstance(req, N_ACTION):
self._n_action_scp(req, context)
elif isinstance(req, N_DELETE):
self._n_delete_scp(req, context)
else:
raise ValueError(
f"Invalid DIMSE primitive '{req.__class__.__name__}' used "
f"with RT Machine Verification"
)
class StorageCommitmentServiceClass(ServiceClass):
"""Implementation of the Storage Commitment Service Class
.. versionadded:: 1.4
"""
statuses = STORAGE_COMMITMENT_SERVICE_CLASS_STATUS
def SCP(self, req: "_SCS", context: "PresentationContext") -> None:
"""The SCP implementation for Storage Commitment Service Class.
Parameters
----------
req : dimse_primitives.N_EVENT_REPORT or N_ACTION
The N-ACTION or N-EVENT-REPORT request primitive sent by the peer.
context : presentation.PresentationContext
The presentation context that the service is operating under.
"""
if isinstance(req, N_EVENT_REPORT):
self._n_event_report_scp(req, context)
elif isinstance(req, N_ACTION):
self._n_action_scp(req, context)
else:
raise ValueError(
f"Invalid DIMSE primitive '{req.__class__.__name__}' used "
f"with Storage Commitment"
)
class StorageManagementServiceClass(ServiceClass):
"""Implementation of the Storage Management Service Class
.. versionadded:: 2.1
"""
statuses = STORAGE_MANAGEMENT_SERVICE_CLASS_STATUS
def SCP(self, req: "_SMS", context: "PresentationContext") -> None:
"""The SCP implementation for Storage Management Service Class.
Parameters
----------
req : dimse_primitives.N_EVENT_REPORT or N_ACTION
The N-ACTION or N-EVENT-REPORT request primitive sent by the peer.
context : presentation.PresentationContext
The presentation context that the service is operating under.
"""
if isinstance(req, N_EVENT_REPORT):
self._n_event_report_scp(req, context)
elif isinstance(req, N_ACTION):
self._n_action_scp(req, context)
else:
raise ValueError(
f"Invalid DIMSE primitive '{req.__class__.__name__}' used "
f"with Storage Management"
)
class UnifiedProcedureStepServiceClass(ServiceClass):
"""Implementation of the Unified Procedure Step Service Class
.. versionadded:: 1.4
"""
statuses = UNIFIED_PROCEDURE_STEP_SERVICE_CLASS_STATUS
def SCP(self, req: "_UPS", context: "PresentationContext") -> None:
"""The SCP implementation for Unified Procedure Step Service Class.
Parameters
----------
req : dimse_primitives.N_CREATE or C_FIND or N_SET or N_GET or N_EVENT_REPORT or N_ACTION
The N-CREATE, C-FIND, N-SET, N-GET, N-ACTION or N-EVENT-REPORT
request primitive sent by the peer.
context : presentation.PresentationContext
The presentation context that the service is operating under.
"""
# UPS Push: N-CREATE, N-ACTION, N-GET
# UPS Pull: C-FIND, N-GET, N-SET, N-ACTION
# UPS Watch: N-ACTION, N-GET, C-FIND
# UPS Event: N-EVENT-REPORT
if isinstance(req, N_CREATE):
self._n_create_scp(req, context)
elif isinstance(req, N_EVENT_REPORT):
self._n_event_report_scp(req, context)
elif isinstance(req, N_GET):
self._n_get_scp(req, context)
elif isinstance(req, N_SET):
self._n_set_scp(req, context)
elif isinstance(req, N_ACTION):
self._n_action_scp(req, context)
elif isinstance(req, C_FIND):
self._c_find_scp(req, context)
else:
raise ValueError(
f"Invalid DIMSE primitive '{req.__class__.__name__}' used "
f"with Unified Procedure Step"
)