Last active
February 18, 2025 12:30
-
-
Save nicolay-r/a6eef460ce486560863eadadb59a84e1 to your computer and use it in GitHub Desktop.
Code for compling a simple SR textual report suitable for uploading at ORTHANC and view via OHIF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import highdicom as hd | |
from pydicom.sr.codedict import codes | |
# Define three textual findings | |
finding = hd.sr.TextContentItem( | |
name=codes.DCM.Finding, | |
value="FINDING TEXTUAL CONTENT GOES HERE", | |
relationship_type=hd.sr.RelationshipTypeValues.CONTAINS) | |
# Subsection of the Report. | |
# NOTE: You can make them as many as you like. | |
block = hd.sr.ContainerContentItem( | |
name=codes.DCM.Finding, | |
relationship_type=hd.sr.RelationshipTypeValues.CONTAINS) | |
setattr(block, "ContentSequence", [finding]) | |
# Section of the report. | |
container = hd.sr.ContainerContentItem(name=codes.DCM.StructuredReportDocument) | |
setattr(container, "ContentSequence", [block]) | |
# NOTE: We use dataset as a required evidence for the SR. | |
# https://github.com/pydicom/contrib-pydicom/raw/refs/heads/master/plotting-visualization/matplotlib-dicom/CT_small.dcm | |
ds = hd.imread('CT_small.dcm') | |
sr_dataset = hd.sr.ComprehensiveSR( | |
evidence=[ds], | |
content=container, | |
# Important: Generate new Series and SOP. | |
# Otherwise, ORTHANC would avoid registration of this item (if it is already exist). | |
series_instance_uid=hd.UID(), | |
sop_instance_uid=hd.UID(), | |
series_number=1, | |
instance_number=1) | |
sr_dataset.save_as("sr.dcm") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment