@@ -4269,31 +4269,46 @@ def __init__(
42694269 PlanarROIMeasurementsAndQualitativeEvaluations |
42704270 VolumetricROIMeasurementsAndQualitativeEvaluations
42714271 )
4272- if imaging_measurements is not None :
4273- measurement_types = (
4274- PlanarROIMeasurementsAndQualitativeEvaluations ,
4275- VolumetricROIMeasurementsAndQualitativeEvaluations ,
4276- MeasurementsAndQualitativeEvaluations ,
4272+
4273+ # Since only imaging meansurements are currently supported, at least
4274+ # one is required. This could be relaxed in the future if evaluations
4275+ # or derived measurements (rows 10 or 12 of the TID1500 table) are
4276+ # supported
4277+ if imaging_measurements is None :
4278+ raise TypeError (
4279+ "Argument 'imaging_measurements' is required."
42774280 )
4278- container_item = ContainerContentItem (
4279- name = codes .DCM .ImagingMeasurements ,
4280- relationship_type = RelationshipTypeValues .CONTAINS
4281+
4282+ if len (imaging_measurements ) == 0 :
4283+ raise ValueError (
4284+ "Argument 'imaging_measurements' must contain at least "
4285+ "one item."
42814286 )
4282- container_item .ContentSequence = ContentSequence ()
4283- for measurements in imaging_measurements :
4284- if not isinstance (measurements , measurement_types ):
4285- raise TypeError (
4286- 'Measurements must have one of the following types: '
4287- '"{}"' .format (
4288- '", "' .join (
4289- [
4290- t .__name__
4291- for t in measurement_types
4292- ]
4293- )
4287+
4288+ measurement_types = (
4289+ PlanarROIMeasurementsAndQualitativeEvaluations ,
4290+ VolumetricROIMeasurementsAndQualitativeEvaluations ,
4291+ MeasurementsAndQualitativeEvaluations ,
4292+ )
4293+ container_item = ContainerContentItem (
4294+ name = codes .DCM .ImagingMeasurements ,
4295+ relationship_type = RelationshipTypeValues .CONTAINS
4296+ )
4297+ container_item .ContentSequence = ContentSequence ()
4298+ for measurements in imaging_measurements :
4299+ if not isinstance (measurements , measurement_types ):
4300+ raise TypeError (
4301+ 'Measurements must have one of the following types: '
4302+ '"{}"' .format (
4303+ '", "' .join (
4304+ [
4305+ t .__name__
4306+ for t in measurement_types
4307+ ]
42944308 )
42954309 )
4296- container_item .ContentSequence .extend (measurements )
4310+ )
4311+ container_item .ContentSequence .extend (measurements )
42974312 item .ContentSequence .append (container_item )
42984313 super ().__init__ ([item ], is_root = True )
42994314
@@ -5119,58 +5134,63 @@ def __init__(
51195134
51205135 """
51215136 super ().__init__ ()
5137+
5138+ if len (datasets ) == 0 :
5139+ raise ValueError (
5140+ "Argument 'datasets' must contain at least one item."
5141+ )
5142+
51225143 library_item = ContainerContentItem (
51235144 name = codes .DCM .ImageLibrary ,
51245145 relationship_type = RelationshipTypeValues .CONTAINS
51255146 )
51265147 library_item .ContentSequence = ContentSequence ()
5127- if datasets is not None :
5128- groups = collections .defaultdict (list )
5129- for ds in datasets :
5130- modality = _get_coded_modality (ds .SOPClassUID )
5131- image_item = ImageContentItem (
5132- name = CodedConcept (
5133- value = '260753009' ,
5134- meaning = 'Source' ,
5135- scheme_designator = 'SCT'
5136- ),
5137- referenced_sop_instance_uid = ds .SOPInstanceUID ,
5138- referenced_sop_class_uid = ds .SOPClassUID ,
5139- relationship_type = RelationshipTypeValues .CONTAINS
5148+ groups = collections .defaultdict (list )
5149+ for ds in datasets :
5150+ modality = _get_coded_modality (ds .SOPClassUID )
5151+ image_item = ImageContentItem (
5152+ name = CodedConcept (
5153+ value = '260753009' ,
5154+ meaning = 'Source' ,
5155+ scheme_designator = 'SCT'
5156+ ),
5157+ referenced_sop_instance_uid = ds .SOPInstanceUID ,
5158+ referenced_sop_class_uid = ds .SOPClassUID ,
5159+ relationship_type = RelationshipTypeValues .CONTAINS
5160+ )
5161+ descriptors = ImageLibraryEntryDescriptors (ds )
5162+
5163+ image_item .ContentSequence = ContentSequence ()
5164+ image_item .ContentSequence .extend (descriptors )
5165+ if 'FrameOfReferenceUID' in ds :
5166+ # Only type 1 attributes
5167+ shared_descriptors = (
5168+ modality ,
5169+ ds .FrameOfReferenceUID ,
51405170 )
5141- descriptors = ImageLibraryEntryDescriptors (ds )
5142-
5143- image_item .ContentSequence = ContentSequence ()
5144- image_item .ContentSequence .extend (descriptors )
5145- if 'FrameOfReferenceUID' in ds :
5146- # Only type 1 attributes
5147- shared_descriptors = (
5148- modality ,
5149- ds .FrameOfReferenceUID ,
5150- )
5151- else :
5152- shared_descriptors = (
5153- modality ,
5154- )
5155- groups [shared_descriptors ].append (image_item )
5156-
5157- for shared_descriptors , image_items in groups .items ():
5158- image = image_items [0 ]
5159- group_item = ContainerContentItem (
5160- name = codes .DCM .ImageLibraryGroup ,
5161- relationship_type = RelationshipTypeValues .CONTAINS
5171+ else :
5172+ shared_descriptors = (
5173+ modality ,
51625174 )
5163- group_item .ContentSequence = ContentSequence ()
5164-
5165- if 'FrameOfReferenceUID' in image :
5166- group_item .ContentSequence .append (
5167- UIDRefContentItem (
5168- name = codes .DCM .FrameOfReferenceUID ,
5169- value = shared_descriptors [1 ],
5170- relationship_type = RelationshipTypeValues .HAS_ACQ_CONTEXT # noqa: E501
5171- )
5175+ groups [shared_descriptors ].append (image_item )
5176+
5177+ for shared_descriptors , image_items in groups .items ():
5178+ image = image_items [0 ]
5179+ group_item = ContainerContentItem (
5180+ name = codes .DCM .ImageLibraryGroup ,
5181+ relationship_type = RelationshipTypeValues .CONTAINS
5182+ )
5183+ group_item .ContentSequence = ContentSequence ()
5184+
5185+ if 'FrameOfReferenceUID' in image :
5186+ group_item .ContentSequence .append (
5187+ UIDRefContentItem (
5188+ name = codes .DCM .FrameOfReferenceUID ,
5189+ value = shared_descriptors [1 ],
5190+ relationship_type = RelationshipTypeValues .HAS_ACQ_CONTEXT # noqa: E501
51725191 )
5173- group_item .ContentSequence .extend (image_items )
5192+ )
5193+ group_item .ContentSequence .extend (image_items )
51745194 if len (group_item ) > 0 :
51755195 library_item .ContentSequence .append (group_item )
51765196
0 commit comments