-
Notifications
You must be signed in to change notification settings - Fork 34
/
templates.py
3431 lines (3143 loc) · 132 KB
/
templates.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
"""DICOM structured reporting templates."""
from typing import Any, Dict, List, Optional, Sequence, Union
import numpy as np
from pydicom.dataset import Dataset
from pydicom.sr.coding import Code
from pydicom.sr.codedict import codes
from highdicom.sr.coding import CodedConcept
from highdicom.sr.content import (
FindingSite,
LongitudinalTemporalOffsetFromEvent,
ImageRegion,
ImageRegion3D,
VolumeSurface,
RealWorldValueMap,
ReferencedSegment,
ReferencedSegmentationFrame,
SourceImageForMeasurement,
)
from highdicom.sr.enum import (
GraphicTypeValues,
GraphicTypeValues3D,
RelationshipTypeValues,
ValueTypeValues,
)
from highdicom.uid import UID
from highdicom.sr.utils import find_content_items, get_coded_name
from highdicom.sr.value_types import (
CodeContentItem,
ContainerContentItem,
ContentItem,
ContentSequence,
NumContentItem,
TextContentItem,
UIDRefContentItem,
)
DEFAULT_LANGUAGE = CodedConcept(
value='en-US',
scheme_designator='RFC5646',
meaning='English (United States)'
)
def _contains_planar_rois(group_item: ContainerContentItem) -> bool:
"""Checks whether a measurement group item contains planar ROIs.
Parameters
----------
group_item: highdicom.sr.value_types.ContainerContentItem
SR Content Item representing a "Measurement Group"
Returns
-------
bool
Whether the `group_item` contains any content items with value type
SCOORD, SCOORD3D, IMAGE, or COMPOSITE representing planar ROIs
"""
if group_item.ValueType != ValueTypeValues.CONTAINER.value:
raise ValueError(
'SR Content Item does not represent a measurement group '
'because it does not have value type CONTAINER.'
)
if group_item.name == codes.DCM.MeasurementGroup:
raise ValueError(
'SR Content Item does not represent a measurement group '
'because it does not have name "Measurement Group".'
)
image_region_items = find_content_items(
group_item,
name=codes.DCM.ImageRegion,
value_type=ValueTypeValues.SCOORD,
relationship_type=RelationshipTypeValues.CONTAINS
)
image_region_items += find_content_items(
group_item,
name=codes.DCM.ImageRegion,
value_type=ValueTypeValues.SCOORD3D,
relationship_type=RelationshipTypeValues.CONTAINS
)
volume_surface_items = find_content_items(
group_item,
name=codes.DCM.VolumeSurface,
value_type=ValueTypeValues.SCOORD3D,
relationship_type=RelationshipTypeValues.CONTAINS
)
referenced_segment_items = find_content_items(
group_item,
name=codes.DCM.ReferencedSegment,
value_type=ValueTypeValues.IMAGE,
relationship_type=RelationshipTypeValues.CONTAINS
)
referenced_segmentation_frame_items = find_content_items(
group_item,
name=codes.DCM.ReferencedSegmentationFrame,
value_type=ValueTypeValues.IMAGE,
relationship_type=RelationshipTypeValues.CONTAINS
)
regions_in_space_items = find_content_items(
group_item,
name=codes.DCM.RegionInSpace,
value_type=ValueTypeValues.COMPOSITE,
relationship_type=RelationshipTypeValues.CONTAINS
)
if (
len(image_region_items) == 1 or
len(referenced_segmentation_frame_items) > 0 or
len(regions_in_space_items) == 1
) and (
len(volume_surface_items) == 0 and
len(referenced_segment_items) == 0
):
return True
return False
def _contains_volumetric_rois(group_item: Dataset) -> bool:
"""Checks whether a measurement group item contains volumetric ROIs.
Parameters
----------
group_item: pydicom.dataset.Dataset
SR Content Item representing a "Measurement Group"
Returns
-------
bool
Whether the `group_item` contains any content items with value type
SCOORD, SCOORD3D, IMAGE, or COMPOSITE representing volumetric ROIs
"""
if group_item.ValueType != ValueTypeValues.CONTAINER.value:
raise ValueError(
'SR Content Item does not represent a measurement group '
'because it does not have value type CONTAINER.'
)
if group_item.name == codes.DCM.MeasurementGroup:
raise ValueError(
'SR Content Item does not represent a measurement group '
'because it does not have name "Measurement Group".'
)
image_region_items = find_content_items(
group_item,
name=codes.DCM.ImageRegion,
value_type=ValueTypeValues.SCOORD,
relationship_type=RelationshipTypeValues.CONTAINS
)
image_region_items += find_content_items(
group_item,
name=codes.DCM.ImageRegion,
value_type=ValueTypeValues.SCOORD3D,
relationship_type=RelationshipTypeValues.CONTAINS
)
volume_surface_items = find_content_items(
group_item,
name=codes.DCM.VolumeSurface,
value_type=ValueTypeValues.SCOORD3D,
relationship_type=RelationshipTypeValues.CONTAINS
)
referenced_segment_items = find_content_items(
group_item,
name=codes.DCM.ReferencedSegment,
value_type=ValueTypeValues.IMAGE,
relationship_type=RelationshipTypeValues.CONTAINS
)
referenced_segmentation_frame_items = find_content_items(
group_item,
name=codes.DCM.ReferencedSegmentationFrame,
value_type=ValueTypeValues.IMAGE,
relationship_type=RelationshipTypeValues.CONTAINS
)
regions_in_space_items = find_content_items(
group_item,
name=codes.DCM.RegionInSpace,
value_type=ValueTypeValues.COMPOSITE,
relationship_type=RelationshipTypeValues.CONTAINS
)
if (
len(image_region_items) > 1 or
len(referenced_segment_items) > 0 or
len(volume_surface_items) > 0 or
len(regions_in_space_items) == 1
) and (
len(referenced_segmentation_frame_items) == 0
):
return True
return False
def _contains_code_items(
parent_item: ContentItem,
name: Union[Code, CodedConcept],
value: Optional[Union[Code, CodedConcept]]
) -> bool:
"""Checks whether an item contains a specific item with value type CODE.
Parameters
----------
parent_item: highdicom.sr.value_types.ContentItem
Parent SR Content Item
name: Union[highdicom.sr.coding.CodedConcept, pydicom.sr.coding.Code]
Name of the child SR Content Item
value: Union[highdicom.sr.coding.CodedConcept, pydicom.sr.coding.Code], optional
Code value of the child SR Content Item
Returns
-------
bool
Whether any of the SR Content Items contained in `parent_item`
match the filter criteria
""" # noqa
matched_items = find_content_items(
parent_item,
name=name,
value_type=ValueTypeValues.CODE,
relationship_type=RelationshipTypeValues.CONTAINS
)
for item in matched_items:
if value is not None:
if item.value == value:
return True
else:
return True
return False
def _contains_text_items(
parent_item: ContentItem,
name: Union[Code, CodedConcept],
value: Optional[str] = None
) -> bool:
"""Checks whether an item contains a specific item with value type TEXT.
Parameters
----------
parent_item: highdicom.sr.value_types.ContentItem
Parent SR Content Item
name: Union[highdicom.sr.coding.CodedConcept, pydicom.sr.coding.Code]
Name of the child SR Content Item
value: str, optional
Text value of the child SR Content Item
Returns
-------
bool
Whether any of the SR Content Items contained in `parent_item`
match the filter criteria
""" # noqa
matched_items = find_content_items(
parent_item,
name=name,
value_type=ValueTypeValues.TEXT,
relationship_type=RelationshipTypeValues.CONTAINS
)
for item in matched_items:
if value is not None:
if item.TextValue == value:
return True
else:
return True
return False
def _contains_scoord_items(
parent_item: ContentItem,
name: Union[Code, CodedConcept],
graphic_type: Optional[GraphicTypeValues] = None
) -> bool:
"""Checks whether an item contains a specific item with value type SCOORD.
Parameters
----------
parent_item: highdicom.sr.value_types.ContentItem
Parent SR Content Item
name: Union[highdicom.sr.coding.CodedConcept, pydicom.sr.coding.Code]
Name of the child SR Content Item
graphic_type: highdicom.sr.enum.GraphicTypeValues, optional
Graphic type of the child SR Content Item
Returns
-------
bool
Whether any of the SR Content Items contained in `parent_item`
match the filter criteria
""" # noqa
matched_items = find_content_items(
parent_item,
name=name,
value_type=ValueTypeValues.SCOORD,
relationship_type=RelationshipTypeValues.CONTAINS
)
for item in matched_items:
if graphic_type is not None:
if item.GraphicType == graphic_type.value:
return True
else:
return True
return False
def _contains_scoord3d_items(
parent_item: ContentItem,
name: Union[Code, CodedConcept],
graphic_type: Optional[GraphicTypeValues3D] = None
) -> bool:
"""Checks whether an item contains specific items with value type SCOORD3D.
Parameters
----------
parent_item: highdicom.sr.value_types.ContentItem
Parent SR Content Item
name: Union[highdicom.sr.coding.CodedConcept, pydicom.sr.coding.Code]
Name of the child SR Content Item
graphic_type: highdicom.sr.enum.GraphicTypeValues3D, optional
Graphic type of the child SR Content Item
Returns
-------
bool
Whether any of the SR Content Items contained in `parent_item`
match the filter criteria
""" # noqa
matched_items = find_content_items(
parent_item,
name=name,
value_type=ValueTypeValues.SCOORD3D,
relationship_type=RelationshipTypeValues.CONTAINS
)
for item in matched_items:
if graphic_type is not None:
if item.GraphicType == graphic_type.value:
return True
else:
return True
return False
class Template(ContentSequence):
"""Abstract base class for a DICOM SR template."""
def __init__(self, items: Optional[Sequence[ContentItem]] = None) -> None:
"""
Parameters
----------
items: Sequence[ContentItem], optional
content items
"""
super().__init__(items)
class AlgorithmIdentification(Template):
"""`TID 4019 <http://dicom.nema.org/medical/dicom/current/output/chtml/part16/sect_TID_4019.html>`_
Algorithm Identification""" # noqa: E501
def __init__(
self,
name: str,
version: str,
parameters: Optional[Sequence[str]] = None
) -> None:
"""
Parameters
----------
name: str
name of the algorithm
version: str
version of the algorithm
parameters: Sequence[str], optional
parameters of the algorithm
"""
super().__init__()
name_item = TextContentItem(
name=CodedConcept(
value='111001',
meaning='Algorithm Name',
scheme_designator='DCM'
),
value=name,
relationship_type=RelationshipTypeValues.HAS_CONCEPT_MOD
)
self.append(name_item)
version_item = TextContentItem(
name=CodedConcept(
value='111003',
meaning='Algorithm Version',
scheme_designator='DCM'
),
value=version,
relationship_type=RelationshipTypeValues.HAS_CONCEPT_MOD
)
self.append(version_item)
if parameters is not None:
for param in parameters:
parameter_item = TextContentItem(
name=CodedConcept(
value='111002',
meaning='Algorithm Parameters',
scheme_designator='DCM'
),
value=param,
relationship_type=RelationshipTypeValues.HAS_CONCEPT_MOD
)
self.append(parameter_item)
class TrackingIdentifier(Template):
"""`TID 4108 <http://dicom.nema.org/medical/dicom/current/output/chtml/part16/sect_TID_4108.html>`_
Tracking Identifier""" # noqa: E501
def __init__(
self,
uid: Optional[str] = None,
identifier: Optional[str] = None
):
"""
Parameters
----------
uid: Union[pydicom.uid.UID, str], optional
globally unique identifier
identifier: str, optional
human readable identifier
"""
super().__init__()
if uid is None:
uid = UID()
if identifier is not None:
tracking_identifier_item = TextContentItem(
name=CodedConcept(
value='112039',
meaning='Tracking Identifier',
scheme_designator='DCM'
),
value=identifier,
relationship_type=RelationshipTypeValues.HAS_OBS_CONTEXT
)
self.append(tracking_identifier_item)
tracking_uid_item = UIDRefContentItem(
name=CodedConcept(
value='112040',
meaning='Tracking Unique Identifier',
scheme_designator='DCM'
),
value=uid,
relationship_type=RelationshipTypeValues.HAS_OBS_CONTEXT
)
self.append(tracking_uid_item)
class TimePointContext(Template):
"""`TID 1502 <http://dicom.nema.org/medical/dicom/current/output/chtml/part16/chapter_A.html#sect_TID_1502>`_
Time Point Context""" # noqa: E501
def __init__(
self,
time_point: str,
time_point_type: Optional[Union[CodedConcept, Code]] = None,
time_point_order: Optional[int] = None,
subject_time_point_identifier: Optional[str] = None,
protocol_time_point_identifier: Optional[str] = None,
temporal_offset_from_event: Optional[
LongitudinalTemporalOffsetFromEvent
] = None
):
"""
Parameters
----------
time_point: str
actual value representation of the time point
time_point_type: Union[highdicom.sr.coding.CodedConcept, pydicom.sr.coding.Code], optional
coded type of time point, e.g., "Baseline" or "Posttreatment" (see
`CID 6146 <http://dicom.nema.org/medical/dicom/current/output/chtml/part16/sect_CID_6146.html>`_
"Time Point Types" for options)
time_point_order: int, optional
number indicating the order of a time point relative to other
time points in a time series
subject_time_point_identifier: str, optional
identifier of a specific time point in a time series, which is
unique within an appropriate local context and specific to a
particular subject (patient)
protocol_time_point_identifier: str, optional
identifier of a specific time point in a time series, which is
unique within an appropriate local context and specific to a
particular protocol using the same value for different subjects
temporal_offset_from_event: highdicom.sr.content.LongitudinalTemporalOffsetFromEvent, optional
offset in time from a particular event of significance, e.g., the
baseline of an imaging study or enrollment into a clinical trial
""" # noqa
super().__init__()
time_point_item = TextContentItem(
name=CodedConcept(
value='C2348792',
meaning='Time Point',
scheme_designator='UMLS'
),
value=time_point,
relationship_type=RelationshipTypeValues.HAS_OBS_CONTEXT
)
self.append(time_point_item)
if time_point_type is not None:
time_point_type_item = CodeContentItem(
name=CodedConcept(
value='126072',
meaning='Time Point Type',
scheme_designator='DCM'
),
value=time_point_type,
relationship_type=RelationshipTypeValues.HAS_OBS_CONTEXT
)
self.append(time_point_type_item)
if time_point_order is not None:
time_point_order_item = NumContentItem(
name=CodedConcept(
value='126073',
meaning='Time Point Order',
scheme_designator='DCM'
),
value=time_point_order,
unit=Code('1', 'UCUM', 'no units'),
relationship_type=RelationshipTypeValues.HAS_OBS_CONTEXT
)
self.append(time_point_order_item)
if subject_time_point_identifier is not None:
subject_time_point_identifier_item = TextContentItem(
name=CodedConcept(
value='126070',
meaning='Subject Time Point Identifier',
scheme_designator='DCM'
),
value=subject_time_point_identifier,
relationship_type=RelationshipTypeValues.HAS_OBS_CONTEXT
)
self.append(subject_time_point_identifier_item)
if protocol_time_point_identifier is not None:
protocol_time_point_identifier_item = TextContentItem(
name=CodedConcept(
value='126071',
meaning='Protocol Time Point Identifier',
scheme_designator='DCM'
),
value=protocol_time_point_identifier,
relationship_type=RelationshipTypeValues.HAS_OBS_CONTEXT
)
self.append(protocol_time_point_identifier_item)
if temporal_offset_from_event is not None:
if not isinstance(temporal_offset_from_event,
LongitudinalTemporalOffsetFromEvent):
raise TypeError(
'Argument "temporal_offset_from_event" must have type '
'LongitudinalTemporalOffsetFromEvent.'
)
self.append(temporal_offset_from_event)
class MeasurementStatisticalProperties(Template):
"""`TID 311 <http://dicom.nema.org/medical/dicom/current/output/chtml/part16/chapter_A.html#sect_TID_311>`_
Measurement Statistical Properties""" # noqa: E501
def __init__(
self,
values: Sequence[NumContentItem],
description: Optional[str] = None,
authority: Optional[str] = None
):
"""
Parameters
----------
values: Sequence[highdicom.sr.value_types.NumContentItem]
reference values of the population of measurements, e.g., its
mean or standard deviation (see
`CID 226 <http://dicom.nema.org/medical/dicom/current/output/chtml/part16/sect_CID_226.html>`_
"Population Statistical Descriptors" and
`CID 227 <http://dicom.nema.org/medical/dicom/current/output/chtml/part16/sect_CID_227.html>`_
"Sample Statistical Descriptors" for options)
description: str, optional
description of the reference population of measurements
authority: str, optional
authority for a description of the reference population of
measurements
""" # noqa: E501
super().__init__()
if not isinstance(values, (list, tuple)):
raise TypeError('Argument "values" must be a list.')
for concept in values:
if not isinstance(concept, NumContentItem):
raise ValueError(
'Items of argument "values" must have type '
'NumContentItem.'
)
self.extend(values)
if description is not None:
description_item = TextContentItem(
name=CodedConcept(
value='121405',
meaning='Population Description',
scheme_designator='DCM'
),
value=description,
relationship_type=RelationshipTypeValues.HAS_PROPERTIES
)
self.append(description_item)
if authority is not None:
authority_item = TextContentItem(
name=CodedConcept(
value='121406',
meaning='Reference Authority',
scheme_designator='DCM'
),
value=authority,
relationship_type=RelationshipTypeValues.HAS_PROPERTIES
)
self.append(authority_item)
class NormalRangeProperties(Template):
"""`TID 312 <http://dicom.nema.org/medical/dicom/current/output/chtml/part16/chapter_A.html#sect_TID_312>`_
Normal Range Properties""" # noqa: E501
def __init__(
self,
values: Sequence[NumContentItem],
description: Optional[str] = None,
authority: Optional[str] = None
):
"""
Parameters
----------
values: Sequence[highdicom.sr.value_types.NumContentItem]
reference values of the normal range, e.g., its upper and lower
bound (see
`CID 223 <http://dicom.nema.org/medical/dicom/current/output/chtml/part16/sect_CID_223.html>`_
"Normal Range Values" for options)
description: str, optional
description of the normal range
authority: str, optional
authority for the description of the normal range
""" # noqa: E501
super().__init__()
if not isinstance(values, (list, tuple)):
raise TypeError('Argument "values" must be a list.')
for concept in values:
if not isinstance(concept, NumContentItem):
raise ValueError(
'Items of argument "values" must have type '
'NumContentItem.'
)
self.extend(values)
if description is not None:
description_item = TextContentItem(
name=codes.DCM.NormalRangeDescription,
value=description,
relationship_type=RelationshipTypeValues.HAS_PROPERTIES
)
self.append(description_item)
if authority is not None:
authority_item = TextContentItem(
name=codes.DCM.NormalRangeAuthority,
value=authority,
relationship_type=RelationshipTypeValues.HAS_PROPERTIES
)
self.append(authority_item)
class MeasurementProperties(Template):
"""`TID 310 <http://dicom.nema.org/medical/dicom/current/output/chtml/part16/chapter_A.html#sect_TID_310>`_
Measurement Properties""" # noqa: E501
def __init__(
self,
normality: Optional[Union[CodedConcept, Code]] = None,
level_of_significance: Optional[Union[CodedConcept, Code]] = None,
selection_status: Optional[Union[CodedConcept, Code]] = None,
measurement_statistical_properties: Optional[
MeasurementStatisticalProperties
] = None,
normal_range_properties: Optional[NormalRangeProperties] = None,
upper_measurement_uncertainty: Optional[Union[int, float]] = None,
lower_measurement_uncertainty: Optional[Union[int, float]] = None
):
"""
Parameters
----------
normality: Union[highdicom.sr.coding.CodedConcept, pydicom.sr.coding.Code], optional
the extend to which the measurement is considered normal or abnormal
(see `CID 222 <http://dicom.nema.org/medical/dicom/current/output/chtml/part16/sect_CID_222.html>`_
"Normality Codes" for options)
level_of_significance: Union[highdicom.sr.coding.CodedConcept, pydicom.sr.coding.Code], optional
the extend to which the measurement is considered normal or abnormal
(see `CID 220 <http://dicom.nema.org/medical/dicom/current/output/chtml/part16/sect_CID_220.html>`_
"Level of Significance" for options)
selection_status: Union[highdicom.sr.coding.CodedConcept, pydicom.sr.coding.Code], optional
how the measurement value was selected or computed from a set of
available values (see
`CID 224 <http://dicom.nema.org/medical/dicom/current/output/chtml/part16/sect_CID_224.html>`_
"Selection Method" for options)
measurement_statistical_properties: highdicom.sr.templates.MeasurementStatisticalProperties, optional
statistical properties of a reference population for a measurement
and/or the position of a measurement in such a reference population
normal_range_properties: highdicom.sr.templates.NormalRangeProperties, optional
statistical properties of a reference population for a measurement
and/or the position of a measurement in such a reference population
upper_measurement_uncertainty: Union[int, float], optional
upper range of measurment uncertainty
lower_measurement_uncertainty: Union[int, float], optional
lower range of measurment uncertainty
""" # noqa
super().__init__()
if normality is not None:
normality_item = CodeContentItem(
name=CodedConcept(
value='121402',
meaning='Normality',
scheme_designator='DCM'
),
value=normality,
relationship_type=RelationshipTypeValues.HAS_PROPERTIES
)
self.append(normality_item)
if measurement_statistical_properties is not None:
if not isinstance(measurement_statistical_properties,
MeasurementStatisticalProperties):
raise TypeError(
'Argument "measurment_statistical_properties" must have '
'type MeasurementStatisticalProperties.'
)
self.extend(measurement_statistical_properties)
if normal_range_properties is not None:
if not isinstance(normal_range_properties,
NormalRangeProperties):
raise TypeError(
'Argument "normal_range_properties" must have '
'type NormalRangeProperties.'
)
self.extend(normal_range_properties)
if level_of_significance is not None:
level_of_significance_item = CodeContentItem(
name=CodedConcept(
value='121403',
meaning='Level of Significance',
scheme_designator='DCM'
),
value=level_of_significance,
relationship_type=RelationshipTypeValues.HAS_PROPERTIES
)
self.append(level_of_significance_item)
if selection_status is not None:
selection_status_item = CodeContentItem(
name=CodedConcept(
value='121404',
meaning='Selection Status',
scheme_designator='DCM'
),
value=selection_status,
relationship_type=RelationshipTypeValues.HAS_PROPERTIES
)
self.append(selection_status_item)
if upper_measurement_uncertainty is not None:
upper_measurement_uncertainty_item = CodeContentItem(
name=CodedConcept(
value='371886008',
meaning='+, range of upper measurement uncertainty',
scheme_designator='SCT'
),
value=upper_measurement_uncertainty,
relationship_type=RelationshipTypeValues.HAS_PROPERTIES
)
self.append(upper_measurement_uncertainty_item)
if lower_measurement_uncertainty is not None:
lower_measurement_uncertainty_item = CodeContentItem(
name=CodedConcept(
value='371885007',
meaning='-, range of lower measurement uncertainty',
scheme_designator='SCT'
),
value=lower_measurement_uncertainty,
relationship_type=RelationshipTypeValues.HAS_PROPERTIES
)
self.append(lower_measurement_uncertainty_item)
class PersonObserverIdentifyingAttributes(Template):
"""`TID 1003 <http://dicom.nema.org/medical/dicom/current/output/chtml/part16/chapter_A.html#sect_TID_1003>`_
Person Observer Identifying Attributes""" # noqa: E501
def __init__(
self,
name: str,
login_name: Optional[str] = None,
organization_name: Optional[str] = None,
role_in_organization: Optional[Union[CodedConcept, Code]] = None,
role_in_procedure: Optional[Union[CodedConcept, Code]] = None
):
"""
Parameters
----------
name: str
name of the person
login_name: str
login name of the person
organization_name: str, optional
name of the person's organization
role_in_organization: Union[highdicom.sr.coding.CodedConcept, pydicom.sr.coding.Code], optional
role of the person within the organization
role_in_procedure: Union[highdicom.sr.coding.CodedConcept, pydicom.sr.coding.Code], optional
role of the person in the reported procedure
""" # noqa
super().__init__()
name_item = TextContentItem(
name=CodedConcept(
value='121008',
meaning='Person Observer Name',
scheme_designator='DCM',
),
value=name,
relationship_type=RelationshipTypeValues.HAS_OBS_CONTEXT
)
self.append(name_item)
if login_name is not None:
login_name_item = TextContentItem(
name=CodedConcept(
value='128774',
meaning='Person Observer\'s Login Name',
scheme_designator='DCM',
),
value=login_name,
relationship_type=RelationshipTypeValues.HAS_OBS_CONTEXT
)
self.append(login_name_item)
if organization_name is not None:
organization_name_item = TextContentItem(
name=CodedConcept(
value='121009',
meaning='Person Observer\'s Organization Name',
scheme_designator='DCM',
),
value=organization_name,
relationship_type=RelationshipTypeValues.HAS_OBS_CONTEXT
)
self.append(organization_name_item)
if role_in_organization is not None:
role_in_organization_item = CodeContentItem(
name=CodedConcept(
value='121010',
meaning='Person Observer\'s Role in the Organization',
scheme_designator='DCM',
),
value=role_in_organization,
relationship_type=RelationshipTypeValues.HAS_OBS_CONTEXT
)
self.append(role_in_organization_item)
if role_in_procedure is not None:
role_in_procedure_item = CodeContentItem(
name=CodedConcept(
value='121011',
meaning='Person Observer\'s Role in this Procedure',
scheme_designator='DCM',
),
value=role_in_procedure,
relationship_type=RelationshipTypeValues.HAS_OBS_CONTEXT
)
self.append(role_in_procedure_item)
@property
def name(self) -> str:
"""str: name of the person"""
return self[0].value
@property
def login_name(self) -> Union[str, None]:
"""Union[str, None]: login name of the person"""
matches = [
item for item in self
if item.name == codes.DCM.PersonObserverLoginName
]
if len(matches) > 0:
return matches[0].value
return None
@property
def organization_name(self) -> Union[str, None]:
"""Union[str, None]: name of the person's organization"""
matches = [
item for item in self
if item.name == codes.DCM.PersonObserverOrganizationName
]
if len(matches) > 0:
return matches[0].value
return None
@property
def role_in_organization(self) -> Union[str, None]:
"""Union[str, None]: role of the person in the organization"""
matches = [
item for item in self
if item.name == codes.DCM.PersonObserverRoleInTheOrganization
]
if len(matches) > 0:
return matches[0].value
return None
@property
def role_in_procedure(self) -> Union[str, None]:
"""Union[str, None]: role of the person in the procedure"""
matches = [
item for item in self
if item.name == codes.DCM.PersonObserverRoleInThisProcedure
]
if len(matches) > 0:
return matches[0].value
return None
@classmethod
def from_sequence(
cls,
sequence: Sequence[Dataset]
) -> 'PersonObserverIdentifyingAttributes':
"""Construct instance from a sequence of datasets.
Parameters
----------
sequence: Sequence[pydicom.dataset.Dataset]
Datasets representing SR Content Items of template
TID 1003 "Person Observer Identifying Attributes"
Returns
-------
highdicom.sr.templates.PersonObserverIdentifyingAttributes
Content Sequence containing SR Content Items
"""
attr_codes = [
('name', codes.DCM.PersonObserverName),
('login_name', codes.DCM.PersonObserverLoginName),
('organization_name',
codes.DCM.PersonObserverOrganizationName),
('role_in_organization',
codes.DCM.PersonObserverRoleInTheOrganization),
('role_in_procedure',
codes.DCM.PersonObserverRoleInThisProcedure),
]
kwargs = {}
for dataset in sequence:
content_item = ContentItem.from_dataset(dataset)
for param, name in attr_codes:
if content_item.name == name:
kwargs[param] = content_item.value
return PersonObserverIdentifyingAttributes(**kwargs)
class DeviceObserverIdentifyingAttributes(Template):
"""`TID 1004 <http://dicom.nema.org/medical/dicom/current/output/chtml/part16/chapter_A.html#sect_TID_1004>`_
Device Observer Identifying Attributes""" # noqa: E501
def __init__(
self,
uid: str,
name: Optional[str] = None,
manufacturer_name: Optional[str] = None,
model_name: Optional[str] = None,
serial_number: Optional[str] = None,
physical_location: Optional[str] = None,
role_in_procedure: Optional[str] = None
):
"""
Parameters
----------