Skip to content

Commit edf89e6

Browse files
authored
Merge pull request #310 from rhaxton/master
Fix for #309
2 parents 69281fc + d5a3e56 commit edf89e6

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

src/highdicom/sr/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,17 @@ def search_tree(
9090
matched_content_items = []
9191
for content_item in node.ContentSequence:
9292
name_code = content_item.ConceptNameCodeSequence[0]
93+
if hasattr(name_code, "CodeValue"):
94+
code_value = name_code.CodeValue
95+
elif hasattr(name_code, "LongCodeValue"):
96+
code_value = name_code.LongCodeValue
97+
else:
98+
code_value = name_code.URNCodeValue
99+
93100
item = ContentItem(
94101
value_type=content_item.ValueType,
95102
name=CodedConcept(
96-
value=name_code.CodeValue,
103+
value=code_value,
97104
scheme_designator=name_code.CodingSchemeDesignator,
98105
meaning=name_code.CodeMeaning
99106
),

tests/test_sr.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4476,6 +4476,38 @@ def test_find_content_items(self):
44764476
items = find_content_items(self._sr_document)
44774477
assert len(items) == 8
44784478

4479+
def test_find_content_items_with_URN_code_value(self):
4480+
file_path = Path(__file__)
4481+
data_dir = file_path.parent.parent.joinpath('data')
4482+
my_sr_document = dcmread(
4483+
str(data_dir.joinpath('test_files', 'sr_document.dcm'))
4484+
)
4485+
content_sequence = my_sr_document.ContentSequence[0]
4486+
concept_name_code_sequence = content_sequence.ConceptNameCodeSequence[0]
4487+
# remove existing code value
4488+
del concept_name_code_sequence.CodeValue
4489+
# add URN Code Value
4490+
URN_code_value = "http://example.com/my_urn_value"
4491+
concept_name_code_sequence.URNCodeValue = URN_code_value
4492+
items = find_content_items(my_sr_document)
4493+
assert len(items) == 8
4494+
4495+
def test_find_content_items_with_long_code_value(self):
4496+
file_path = Path(__file__)
4497+
data_dir = file_path.parent.parent.joinpath('data')
4498+
my_sr_document = dcmread(
4499+
str(data_dir.joinpath('test_files', 'sr_document.dcm'))
4500+
)
4501+
content_sequence = my_sr_document.ContentSequence[0]
4502+
concept_name_code_sequence = content_sequence.ConceptNameCodeSequence[0]
4503+
# remove existing code value
4504+
del concept_name_code_sequence.CodeValue
4505+
# add Long Code Value
4506+
long_code_value = "Test_A_Long_Code_Value"
4507+
concept_name_code_sequence.LongCodeValue = long_code_value
4508+
items = find_content_items(my_sr_document)
4509+
assert len(items) == 8
4510+
44794511
def test_find_content_items_filtered_by_name(self):
44804512
items = find_content_items(
44814513
self._sr_document,

0 commit comments

Comments
 (0)