Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #309 #310

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading