-
Notifications
You must be signed in to change notification settings - Fork 171
/
pdu_primitives.py
2336 lines (1937 loc) · 79 KB
/
pdu_primitives.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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
Implementaion of the service parameter primitives.
"""
import codecs
import logging
from pydicom.uid import UID
from pynetdicom.pdu_items import (
MaximumLengthSubItem,
ImplementationClassUIDSubItem,
ImplementationVersionNameSubItem,
AsynchronousOperationsWindowSubItem,
SCP_SCU_RoleSelectionSubItem,
SOPClassExtendedNegotiationSubItem,
SOPClassCommonExtendedNegotiationSubItem,
UserIdentitySubItemRQ,
UserIdentitySubItemAC
)
from pynetdicom.presentation import PresentationContext
from pynetdicom.utils import validate_ae_title, validate_uid
from pynetdicom._globals import DEFAULT_MAX_LENGTH
LOGGER = logging.getLogger('pynetdicom.pdu_primitives')
# TODO: Rename to UserInformation
class ServiceParameter(object):
""" Base class for Service Parameters """
def __eq__(self, other):
"""Equality of two ServiceParameters"""
if isinstance(other, self.__class__):
return other.__dict__ == self.__dict__
return False
def __ne__(self, other):
"""Inequality of two ServiceParameters"""
return not self == other
# Association Service primitives
class A_ASSOCIATE(object):
"""
An A-ASSOCIATE primitive.
The establishment of an association between two AEs shall be performed
through ACSE A-ASSOCIATE request, indication, response and confirmation
primitives.
The initiator of the service is called the Requestor and the user that
receives the request is the Acceptor.
The A-ASSOCIATE primitive is used by the DUL provider to send/receive
information about the association. It gets converted to
A-ASSOCIATE-RQ, -AC, -RJ PDUs that are sent to the peer DUL provider and
gets deconverted from -RQ, -AC, -RJ PDUs received from the peer.
+------------------+---------+------------+----------+--------------+
| Parameter | Request | Indication | Response | Confirmation |
+------------------+---------+------------+----------+--------------+
| app context name | M | M(=) | M | M(=) |
+------------------+---------+------------+----------+--------------+
| calling ae title | M | M(=) | M | M(=) |
+------------------+---------+------------+----------+--------------+
| called ae title | M | M(=) | M | M(=) |
+------------------+---------+------------+----------+--------------+
| user info | M | M(=) | M | M(=) |
+------------------+---------+------------+----------+--------------+
| result | | | M | M(=) |
+------------------+---------+------------+----------+--------------+
| source | | | | M |
+------------------+---------+------------+----------+--------------+
| diagnostic | | | U | C(=) |
+------------------+---------+------------+----------+--------------+
| calling pres add | M | M(=) | | |
+------------------+---------+------------+----------+--------------+
| called pres add | M | M(=) | | |
+------------------+---------+------------+----------+--------------+
| pres contxt list | M | M(=) | | |
+------------------+---------+------------+----------+--------------+
| pres list result | | | M | M(=) |
+------------------+---------+------------+----------+--------------+
| mode | UF | MF(=) | | |
+------------------+---------+------------+----------+--------------+
| resp ae title | | | MF | MF(=) |
+------------------+---------+------------+----------+--------------+
| resp pres add | | | MF | MF(=) |
+------------------+---------+------------+----------+--------------+
| pres/sess req | UF | UF(=) | UF | UF(=) |
+------------------+---------+------------+----------+--------------+
| U - User option
| UF - User option, fixed value
| C - Conditional (on user option)
| M - Mandatory
| MF - Mandatory, fixed value
| NU - Not used
| (=) - shall have same value as request or response
Attributes
----------
mode : str
Fixed value of ``'normal'``.
application_context_name : pydicom.uid.UID, bytes or str
The application context name proposed by the *Requestor*. *Acceptor*
returns either the same or a different name. Returned name specifies
the application context used for the association. See the DICOM
Standard, Part 8, :dcm:`Annex A<part08/chapter_A.html>`.
The application context name shall be a valid UID or UID string and for
version 3 of the DICOM Standard should be ``'1.2.840.10008.3.1.1.1'``
calling_ae_title : str or bytes
Identifies the *Requestor* of the A-ASSOCIATE service. Must be a valid
AE title.
called_ae_title : str or bytes
Identifies the intended *Acceptor* of the A-ASSOCIATE service. Must be
a valid AE title.
responding_ae_title : str or bytes
Identifies the AE that contains the actual acceptor of the
A-ASSOCIATE service. Shall always contain the same value as the
*Called AE Title* of the A-ASSOCIATE indication
user_information : list
Used by *Requestor* and *Acceptor* to include AE user information. See
the DICOM Standard, Part 8, :dcm:`Annex D<part08/chapter_D.html>` and
Part 7, :dcm:`Annex D.3<part07/sect_D.3.html>`
result : int
Provided either by the *Acceptor* of the A-ASSOCIATE request, the UL
service provider (ACSE related) or the UL service provider
(Presentation related). Indicates the result of the A-ASSOCIATE
service. Allowed values are:
* ``0``: accepted
* ``1``: rejected (permanent)
* ``2``: rejected (transient)
result_source : int
Identifies the creating source of the Result and Diagnostic parameters
Allowed values are:
* ``0``: UL service-user
* ``1``: UL service-provider (ACSE related function)
* ``2``: UL service-provider (presentation related function)
diagnostic : int
If the `result` parameter is ``0`` "rejected (permanent)" or ``1``
"rejected (transient)" then this supplies diagnostic information about
the result. If `result_source` is ``0`` "UL service-user" then allowed
valuesare:
* ``0``: no reason given
* ``1``: application context name not supported
* ``2``: calling AE title not recognised
* ``3``: called AE title not recognised
If `result_source` is ``1`` "UL service-provider (ACSE related
function)" then allowed values are:
* ``0``: no reason given
* ``1``: no common UL version
If `result_source` is ``2`` "UL service-provider (presentation related
function)" then allowed values are:
* ``0``: no reason given
* ``1``: temporary congestion
* ``2``: local limit exceeded
* ``3``: called presentation address unknown
* ``4``: presentation protocol version not supported
* ``5``: no presentation service access point available
calling_presentation_address : str
TCP/IP address of the *Requestor*
called_presentation_address : str
TCP/IP address of the intended *Acceptor*
responding_presentation_address : str
Shall always contain the same value as the
*Called Presentation Address*.
presentation_context_definition_list : list
List of one or more presentation contexts, with each item containing
a presentation context ID, an Abstract Syntax and a list of one or
more Transfer Syntax Names. Sent by the *Requestor* during
request/indication.
presentation_context_definition_results_list : list
Used in response/confirmation to indicate acceptance or rejection of
each presentation context definition.
List of result values, with a one-to-one correspondence between each
of the presentation contexts proposed in the Presentation Context
Definition List parameter.
The result values may be sent in any order and may be different than
the order proposed.
Only one Transfer Syntax per presentation context shall be agreed to
presentation_requirements : str
Fixed value of ``'Presentation Kernel'``.
session_requirements : str
Fixed value of ``''`` (empty string).
References
----------
* DICOM Standard, Part 8,
:dcm:`Section 7.1.1<part08/chapter_7.html#sect_7.1.1>`
"""
# pylint: disable=too-many-instance-attributes
def __init__(self):
self.application_context_name = None
self.calling_ae_title = None
self.called_ae_title = None
self.user_information = []
self.result = None
self.result_source = None
self.diagnostic = None
self.calling_presentation_address = None
self.called_presentation_address = None
self.presentation_context_definition_list = []
self.presentation_context_definition_results_list = []
@property
def mode(self):
"""Return the Mode parameter."""
return "normal"
@property
def application_context_name(self):
"""Return the Application Context Name parameter."""
return self._application_context_name
@application_context_name.setter
def application_context_name(self, value):
"""Set the Application Context Name parameter.
Parameters
----------
value : pydicom.uid.UID, bytes or str
The value for the Application Context Name
"""
# pylint: disable=attribute-defined-outside-init
if isinstance(value, UID):
pass
elif isinstance(value, str):
value = UID(value)
elif isinstance(value, bytes):
value = UID(value.decode('ascii'))
elif value is None:
pass
else:
raise TypeError("application_context_name must be a "
"pydicom.uid.UID, str or bytes")
if value is not None and not validate_uid(value):
LOGGER.error("application_context_name is an invalid UID")
raise ValueError("application_context_name is an invalid UID")
if value and not value.is_valid:
LOGGER.warning(
"The Application Context Name '{}' is non-conformant"
.format(value)
)
self._application_context_name = value
@property
def calling_ae_title(self):
"""Return the Calling AE Title parameter."""
return self._calling_ae_title
@calling_ae_title.setter
def calling_ae_title(self, value):
"""Set the Calling AE Title parameter.
Parameters
----------
value : str or bytes
The Calling AE Title as a string or bytes object. Cannot be an
empty string and will be truncated to 16 characters long
"""
# pylint: disable=attribute-defined-outside-init
if isinstance(value, str):
value = codecs.encode(value, 'ascii')
if value is not None:
self._calling_ae_title = validate_ae_title(value)
else:
self._calling_ae_title = None
@property
def called_ae_title(self):
"""Return the Called AE Title parameter."""
return self._called_ae_title
@called_ae_title.setter
def called_ae_title(self, value):
"""Set the Called AE Title parameter.
Parameters
----------
value : str or bytes
The Called AE Title as a string or bytes object. Cannot be an empty
string and will be truncated to 16 characters long
"""
# pylint: disable=attribute-defined-outside-init
if isinstance(value, str):
value = codecs.encode(value, 'ascii')
if value is not None:
self._called_ae_title = validate_ae_title(value)
else:
self._called_ae_title = None
@property
def responding_ae_title(self):
"""Return the Responding AE Title parameter."""
return self.called_ae_title
@property
def user_information(self):
"""Return the User Information parameter."""
return self._user_information
@user_information.setter
def user_information(self, value_list):
"""Set the A-ASSOCIATE primitive's User Information parameter.
Parameters
----------
value_list : list of user information class objects
A list of user information objects, must contain at least
MaximumLengthNotification and ImplementationClassUIDNotification
"""
# pylint: disable=attribute-defined-outside-init
valid_usr_info_items = []
if isinstance(value_list, list):
# Iterate through the items and check they're an acceptable class
for item in value_list:
if item.__class__.__name__ in \
["MaximumLengthNotification",
"ImplementationClassUIDNotification",
"ImplementationVersionNameNotification",
"AsynchronousOperationsWindowNegotiation",
"SCP_SCU_RoleSelectionNegotiation",
"SOPClassExtendedNegotiation",
"SOPClassCommonExtendedNegotiation",
"UserIdentityNegotiation"]:
valid_usr_info_items.append(item)
else:
LOGGER.info("Attempted to set "
"A_ASSOCIATE.user_information to a list "
"which includes an unsupported item")
else:
LOGGER.error("A_ASSOCIATE.user_information must be a list")
raise TypeError("A_ASSOCIATE.user_information must be a list")
self._user_information = valid_usr_info_items
@property
def result(self):
"""Return te Result parameter."""
return self._result
@result.setter
def result(self, value):
"""Set the A-ASSOCIATE Service primitive's Result parameter.
Parameters
----------
value : str
One of the following:
* 0: accepted
* 1: rejected (permanent)
* 2: rejected (transient)
"""
# pylint: disable=attribute-defined-outside-init
if value is None:
pass
elif value not in [0, 1, 2]:
LOGGER.error("A_ASSOCIATE.result set to an unknown value")
raise ValueError("Unknown A_ASSOCIATE.result value")
self._result = value
@property
def result_str(self):
"""Return the result as str."""
results = {1 : "Rejected Permanent", 2 : "Rejected Transient"}
return results[self.result]
@property
def result_source(self):
"""Return the Result Source parameter."""
return self._result_source
@result_source.setter
def result_source(self, value):
"""Set the A-ASSOCIATE Service primitive's Result Source parameter.
Parameters
----------
value : int
One of the following:
* 1: UL service-user
* 2: UL service-provider (ACSE related function)
* 3: UL service-provider (presentation related function)
"""
# pylint: disable=attribute-defined-outside-init
if value is None:
pass
elif value not in [1, 2, 3]:
LOGGER.error("A_ASSOCIATE.result_source set to an unknown value")
raise ValueError("Unknown A_ASSOCIATE.result_source value")
self._result_source = value
@property
def source_str(self):
"""Return the reject source as str."""
sources = {
1 : 'Service User',
2 : 'Service Provider (ACSE)',
3 : 'Service Provider (Presentation)'
}
return sources[self.result_source]
@property
def diagnostic(self):
"""Return the Diagnostic parameter."""
return self._diagnostic
@diagnostic.setter
def diagnostic(self, value):
"""
Set the A-ASSOCIATE Service primitive's Diagnostic parameter
Parameters
----------
value : int
If `result_source` is "UL service-user" then allowed values are:
* 1: no reason given
* 2: application context name not supported
* 3: calling AE title not recognised
* 7: called AE title not recognised
If `result_source` is "UL service-provider (ACSE related function)"
then allowed values are:
* 1: no reason given
* 2: protocol version not supported"
If `result_source` is "UL service-provider (Presentation related
function)" then allowed values are:
* 1: temporary congestion
* 2: local limit exceeded
"""
# pylint: disable=attribute-defined-outside-init
if value is None:
pass
elif value not in [1, 2, 3, 7]:
LOGGER.error("A_ASSOCIATE.diagnostic set to an unknown value")
raise ValueError("Unknown A_ASSOCIATE.diagnostic value")
self._diagnostic = value
@property
def reason_str(self):
"""Return the rejection reason as str."""
reasons = {
1 : {
1 : 'No reason given',
2 : 'Application context name not supported',
3 : 'Calling AE title not recognised',
4 : 'Reserved',
5 : 'Reserved',
6 : 'Reserved',
7 : 'Called AE title not recognised',
8 : 'Reserved',
9 : 'Reserved',
10 : 'Reserved',
},
2 : {
1 : 'No reason given',
2 : 'Protocol version not supported'
},
3 : {
0 : "Reserved",
1 : "Temporary congestion",
2 : "Local limit exceeded",
3 : 'Reserved',
4 : 'Reserved',
5 : 'Reserved',
6 : 'Reserved',
7 : 'Reserved',
}
}
return reasons[self.result_source][self.diagnostic]
@property
def calling_presentation_address(self):
"""Return the Calling Presentation Address parameter."""
return self._calling_presentation_address
@calling_presentation_address.setter
def calling_presentation_address(self, value):
"""
Set the A-ASSOCIATE Service primitive's Calling Presentation
Address parameter
Parameters
----------
value : (str, int) tuple
A tuple containing a valid TCP/IP address string and the port
number as an int
"""
# pylint: disable=attribute-defined-outside-init
if isinstance(value, tuple):
if len(value) == 2 and isinstance(value[0], str) \
and isinstance(value[1], int):
self._calling_presentation_address = value
else:
LOGGER.error("A_ASSOCIATE.calling_presentation_address must "
"be (str, int) tuple")
raise TypeError("A_ASSOCIATE.calling_presentation_address "
"must be (str, int) tuple")
elif value is None:
self._calling_presentation_address = value
else:
LOGGER.error("A_ASSOCIATE.calling_presentation_address must be "
"(str, int) tuple")
raise TypeError("A_ASSOCIATE.calling_presentation_address must "
"be (str, int) tuple")
@property
def called_presentation_address(self):
"""Return the Called Presentation Address parameter."""
return self._called_presentation_address
@called_presentation_address.setter
def called_presentation_address(self, value):
"""Set the Called Presentation Address parameter.
Parameters
----------
value : (str, int) tuple
A tuple containing a valid TCP/IP address string and the port
number as an int
"""
# pylint: disable=attribute-defined-outside-init
if isinstance(value, tuple):
if len(value) == 2 and isinstance(value[0], str) \
and isinstance(value[1], int):
self._called_presentation_address = value
else:
LOGGER.error("A_ASSOCIATE.called_presentation_address must "
"be (str, int) tuple")
raise TypeError("A_ASSOCIATE.called_presentation_address "
"must be (str, int) tuple")
elif value is None:
self._called_presentation_address = value
else:
LOGGER.error("A_ASSOCIATE.called_presentation_address must be "
"(str, int) tuple")
raise TypeError("A_ASSOCIATE.called_presentation_address must "
"be (str, int) tuple")
@property
def responding_presentation_address(self):
"""Get the Responding Presentation Address parameter."""
return self.called_presentation_address
@property
def presentation_context_definition_list(self):
"""Get the Presentation Context Definition List."""
return self._presentation_context_definition_list
@presentation_context_definition_list.setter
def presentation_context_definition_list(self, value_list):
"""
Set the A-ASSOCIATE Service primitive's Presentation Context Definition
List parameter
Parameters
----------
value_list : list of utils.PresentationContext
The Presentation Contexts proposed by the Association Requestor
"""
# pylint: disable=attribute-defined-outside-init
if isinstance(value_list, list):
valid_items = []
for item in value_list:
if isinstance(item, PresentationContext):
valid_items.append(item)
else:
LOGGER.warning(
"Attempted to set "
"A_ASSOCIATE.presentation_context_definition_list to "
"a list which includes an invalid items"
)
self._presentation_context_definition_list = valid_items
else:
LOGGER.error("A_ASSOCIATE.presentation_context_definition_list "
"must be a list")
raise TypeError("A_ASSOCIATE.presentation_context_definition_list "
"must be a list")
@property
def presentation_context_definition_results_list(self):
"""Get the Presentation Context Definition Results List."""
return self._presentation_context_definition_results_list
@presentation_context_definition_results_list.setter
def presentation_context_definition_results_list(self, value_list):
"""Set the Presentation Context Definition Results List parameter.
Parameters
----------
value_list : list of utils.PresentationContext
The results of the Presentation Contexts proposal by the
Association Requestor
"""
# pylint: disable=attribute-defined-outside-init
if isinstance(value_list, list):
valid_items = []
for item in value_list:
if isinstance(item, PresentationContext):
valid_items.append(item)
else:
LOGGER.warning("Attempted to set A_ASSOCIATE.presentation"
"_context_definition_results_list to a "
"list which includes one or more invalid "
"items.")
self._presentation_context_definition_results_list = valid_items
else:
LOGGER.error("A_ASSOCIATE.presentation_context_definition_"
"results_list must be a list")
raise TypeError("A_ASSOCIATE.presentation_context_definition_"
"results_list must be a list")
@property
def presentation_requirements(self):
"""Get the Presentation Kernel."""
return "Presentation Kernel"
@property
def session_requirements(self):
"""Get the Session Requirements."""
return ""
# Shortcut attributes for User Information items
# Mandatory UI Items
@property
def maximum_length_received(self):
"""Get the Maximum Length Received."""
for item in self.user_information:
if isinstance(item, MaximumLengthNotification):
return item.maximum_length_received
return None
@maximum_length_received.setter
def maximum_length_received(self, value):
"""Set the Maximum Length Received.
If the A_ASSOCIATE.user_information list contains a
MaximumLengthNotification item then set its maximum_length_received
value. If not then add a MaximumLengthNotification item and set its
maximum_length_received value.
Parameters
----------
value : int
The maximum length of each P-DATA in bytes
"""
# Type and value checking for the maximum_length_received parameter is
# done by the MaximumLengthNotification class
# Check for a MaximumLengthNotification item
found_item = False
for item in self.user_information:
if isinstance(item, MaximumLengthNotification):
found_item = True
item.maximum_length_received = value
# No MaximumLengthNotification item found
if not found_item:
max_length = MaximumLengthNotification()
max_length.maximum_length_received = value
self.user_information.append(max_length)
@property
def implementation_class_uid(self):
"""Return the Implementation Class UID."""
for item in self.user_information:
if isinstance(item, ImplementationClassUIDNotification):
if item.implementation_class_uid is None:
LOGGER.error("Implementation Class UID has not been set")
raise ValueError("Implementation Class UID has not "
"been set")
return item.implementation_class_uid
LOGGER.error("Implementation Class UID has not been set")
raise ValueError("Implementation Class UID has not been set")
@implementation_class_uid.setter
def implementation_class_uid(self, value):
"""Set the Implementation Class UID.
If the A_ASSOCIATE.user_information list contains an
ImplementationClassUIDNotification item then set its
implementation_class_uid value. If not then add a
ImplementationClassUIDNotification item and set its
implementation_class_uid value.
Parameters
----------
value : pydicom.uid.UID, bytes or str
The value for the Implementation Class UID
"""
# Type and value checking for the implementation_class_uid parameter is
# done by the ImplementationClassUIDNotification class
# Check for a ImplementationClassUIDNotification item
found_item = False
for item in self.user_information:
if isinstance(item, ImplementationClassUIDNotification):
found_item = True
item.implementation_class_uid = value
# No ImplementationClassUIDNotification item found
if not found_item:
imp_uid = ImplementationClassUIDNotification()
imp_uid.implementation_class_uid = value
self.user_information.append(imp_uid)
class A_RELEASE(object):
"""An A-RELEASE primitive.
+------------------+---------+------------+----------+--------------+
| Parameter | Request | Indication | Response | Confirmation |
+------------------+---------+------------+----------+--------------+
| reason | UF | UF(=) | UF | UF(=) |
+------------------+---------+------------+----------+--------------+
| user info |NU | NU(=) | NU | NU(=) |
+------------------+---------+------------+----------+--------------+
| result | | | MF | MF(=) |
+------------------+---------+------------+----------+--------------+
| U - User option
| UF - User option, fixed value
| C - Conditional (on user option)
| M - Mandatory
| MF - Mandatory, fixed value
| NU - Not used
| (=) - shall have same value as request or response
Attributes
----------
reason : str
Fixed value of ``'normal'``. Identifies the general level of urgency
of the request.
result : str or None
Must be ``None`` for request and indication, ``'affirmative'`` for
response and confirmation.
References
----------
* DICOM Standard, Part 8, :dcm:`Section 7.2<part08/sect_7.2.html>`
"""
def __init__(self):
self.result = None
@property
def reason(self):
"""Return the *Reason* parameter."""
return "normal"
@property
def result(self):
"""Return the *Result* parameter."""
return self._result
@result.setter
def result(self, value):
"""Set the Result parameter."""
# pylint: disable=attribute-defined-outside-init
if value is not None and value != "affirmative":
LOGGER.error("A_RELEASE.result must be None or 'affirmative'")
raise ValueError("A_RELEASE.result must be None or 'affirmative'")
self._result = value
class A_ABORT(object):
"""
An A-ABORT primitive.
+------------------+---------+------------+
| Parameter | Request | Indication |
+------------------+---------+------------+
| abort source | | M |
+------------------+---------+------------+
| user info |NU | NU(=) |
+------------------+---------+------------+
| U - User option
| UF - User option, fixed value
| C - Conditional (on user option)
| M - Mandatory
| MF - Mandatory, fixed value
| NU - Not used
| (=) - shall have same value as request or response
Attributes
----------
abort_source : int
Indicates the initiating source of the abort. Allowed values are:
* ``0``: UL service-user
* ``2``: UL service-provider
References
----------
* DICOM Standard, Part 8, :dcm:`Section 7.3<part08/sect_7.3.html>`
"""
def __init__(self):
self.abort_source = None
@property
def abort_source(self):
"""Return the *Abort Source*."""
if self._abort_source is None:
LOGGER.error("A_ABORT.abort_source parameter not set")
raise ValueError("A_ABORT.abort_source value not set")
return self._abort_source
@abort_source.setter
def abort_source(self, value):
"""Set the Abort Source."""
# pylint: disable=attribute-defined-outside-init
if value in [0, 2]:
self._abort_source = value
elif value is None:
self._abort_source = None
else:
LOGGER.error("Attempted to set A_ABORT.abort_source to an "
"invalid value")
raise ValueError("Attempted to set A_ABORT.abort_source to an "
"invalid value")
class A_P_ABORT(object):
"""
An A-P-ABORT primitive.
+------------------+------------+
| Parameter | Indication |
+------------------+------------+
| abort source | P |
+------------------+------------+
| U - User option
| UF - User option, fixed value
| C - Conditional (on user option)
| M - Mandatory
| MF - Mandatory, fixed value
| NU - Not used
| P - Provider initiated
| (=) - shall have same value as request or response
Attributes
----------
provider_reason : int
Indicates the reason for the abort. Allowed values are:
* ``0``: reason not specified
* ``1``: unrecognised PDU
* ``2``: unexpected PDU
* ``4``: unrecognised PDU parameter
* ``5``: unexpected PDU parameter
* ``6``: invalid PDU parameter value
References
----------
* DICOM Standard, Part 8, :dcm:`Section 7.4<part08/sect_7.4.html>`
"""
def __init__(self):
self.provider_reason = None
@property
def provider_reason(self):
"""Return the *Provider Reason*."""
if self._provider_reason is None:
LOGGER.error("A_ABORT.provider_reason parameter not set")
raise ValueError("A_ABORT.provider_reason value not set")
return self._provider_reason
@provider_reason.setter
def provider_reason(self, value):
"""Set the Provider Reason."""
# pylint: disable=attribute-defined-outside-init
if value in [0, 1, 2, 4, 5, 6]:
self._provider_reason = value
elif value is None:
self._provider_reason = None
else:
msg = (
"Attempted to set A_P_ABORT.provider_reason to an invalid "
"value"
)
LOGGER.error(msg)
raise ValueError(msg)
class P_DATA(object):
"""
A P-DATA primitive.
+------------------------------+---------+------------+
| Parameter | Request | Indication |
+------------------------------+---------+------------+
| presentation data value list | M | M(=) |
+------------------------------+---------+------------+
| U - User option
| UF - User option, fixed value
| C - Conditional (on user option)
| M - Mandatory
| MF - Mandatory, fixed value
| NU - Not used
| (=) - shall have same value as request or response
Attributes
----------
presentation_data_value_list : list of [int, bytes]
Contains one or more Presentation Data Values (PDV), each consisting of
a Presentation Context ID and User Data values. The User Data values
are taken from the Abstract Syntax and encoded in the Transfer Syntax
identified by the Presentation Context ID. Each item in the list is
``[Context ID, PDV Data]``
References
----------
* DICOM Standard, Part 8, :dcm:`Section 7.6<part08/sect_7.6.html>`
"""
def __init__(self):
self.presentation_data_value_list = []
@property
def presentation_data_value_list(self):
"""Return the *Presentation Data Value List*."""
return self._presentation_data_value_list
@presentation_data_value_list.setter
def presentation_data_value_list(self, value_list):
"""Set the Presentation Data Value List."""
# pylint: disable=attribute-defined-outside-init
if isinstance(value_list, list):
for pdv in value_list:
if isinstance(pdv, list):
if isinstance(pdv[0], int) and isinstance(pdv[1], bytes):
pass
else:
raise TypeError("P_DATA.presentation_data_value_list "
"should be a list of [int, bytes]")
else:
raise TypeError("P_DATA.presentation_data_value_list "
"should be a list of [ID, PDV]")
else:
raise TypeError("P_DATA.presentation_data_value_list "
"should be a list of [int, bytes]")
self._presentation_data_value_list = value_list
def __str__(self):
"""String representation of the class."""
s = 'P-DATA\n'
for pdv in self.presentation_data_value_list:
s += ' Context ID: {0!s}\n'.format(pdv[0])
s += ' Value Length: {0!s} bytes\n'.format(len(pdv[1]))
header_byte = pdv[1][0]
# Python 2 compatibility
if isinstance(header_byte, str):