Skip to content

Commit

Permalink
Merge pull request #310 from rhaxton/master
Browse files Browse the repository at this point in the history
Fix for #309
  • Loading branch information
CPBridge authored Oct 9, 2024
2 parents 69281fc + d5a3e56 commit edf89e6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/highdicom/sr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,17 @@ def search_tree(
matched_content_items = []
for content_item in node.ContentSequence:
name_code = content_item.ConceptNameCodeSequence[0]
if hasattr(name_code, "CodeValue"):
code_value = name_code.CodeValue
elif hasattr(name_code, "LongCodeValue"):
code_value = name_code.LongCodeValue
else:
code_value = name_code.URNCodeValue

item = ContentItem(
value_type=content_item.ValueType,
name=CodedConcept(
value=name_code.CodeValue,
value=code_value,
scheme_designator=name_code.CodingSchemeDesignator,
meaning=name_code.CodeMeaning
),
Expand Down
32 changes: 32 additions & 0 deletions tests/test_sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4476,6 +4476,38 @@ def test_find_content_items(self):
items = find_content_items(self._sr_document)
assert len(items) == 8

def test_find_content_items_with_URN_code_value(self):
file_path = Path(__file__)
data_dir = file_path.parent.parent.joinpath('data')
my_sr_document = dcmread(
str(data_dir.joinpath('test_files', 'sr_document.dcm'))
)
content_sequence = my_sr_document.ContentSequence[0]
concept_name_code_sequence = content_sequence.ConceptNameCodeSequence[0]
# remove existing code value
del concept_name_code_sequence.CodeValue
# add URN Code Value
URN_code_value = "http://example.com/my_urn_value"
concept_name_code_sequence.URNCodeValue = URN_code_value
items = find_content_items(my_sr_document)
assert len(items) == 8

def test_find_content_items_with_long_code_value(self):
file_path = Path(__file__)
data_dir = file_path.parent.parent.joinpath('data')
my_sr_document = dcmread(
str(data_dir.joinpath('test_files', 'sr_document.dcm'))
)
content_sequence = my_sr_document.ContentSequence[0]
concept_name_code_sequence = content_sequence.ConceptNameCodeSequence[0]
# remove existing code value
del concept_name_code_sequence.CodeValue
# add Long Code Value
long_code_value = "Test_A_Long_Code_Value"
concept_name_code_sequence.LongCodeValue = long_code_value
items = find_content_items(my_sr_document)
assert len(items) == 8

def test_find_content_items_filtered_by_name(self):
items = find_content_items(
self._sr_document,
Expand Down

0 comments on commit edf89e6

Please sign in to comment.