Packages
sr
Structured Reports: read the content tree of an SR document, change it and write it back, and read Key Object Selection documents (TID 2010).
import "github.com/amrshadid/go-dicom/sr" · pkg.go.dev
When to use it
- Read the findings, measurements and codes of an SR as a tree:
ReadContentTree. - Write a content tree into a data set:
WriteContentTree. - Find which images a Key Object Selection points at, and whether it is a
rejection note:
ReadKeyObjectSelection,IsRejection.
The command line's sr prints a content tree.
Key types and functions
| Name | What it is for |
|---|---|
ReadContentTree | The document's root item, with every child below it. |
ContentItem | One item: value type, relationship, concept name, value, children, and the data set it came from. |
ContentItem.Walk, ContentItem.Count | Visit every item; count them. |
WriteContentTree | Write a tree into a data set: the root's attributes at the top, the children as Content Sequence. |
Code, Measurement | A coded value; a NUM item's value and units. |
ValueTypeText, RelationshipContains and the other constants | Value types and relationship types. |
ReadKeyObjectSelection, KeyObjectSelection | Title, modifiers, description, references and evidence of a KOS. |
KeyObjectSelectionOptions, DefaultMaxKeyObjectReferences | The bound on references read. |
IsRejection, IsRejectionWithdrawal | Whether a KOS title rejects instances, or withdraws a rejection. |
ErrNotKeyObjectSelection | The document is not a KOS. |
Example
// Print the content tree of a Structured Report.
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/amrshadid/go-dicom/filebase"
"github.com/amrshadid/go-dicom/filereader"
"github.com/amrshadid/go-dicom/sr"
)
func show(item *sr.ContentItem, depth int) {
line := strings.Repeat(" ", depth) + item.RelationshipType + " " + item.ValueType
if item.ConceptName != nil {
line += " " + item.ConceptName.Meaning
}
switch item.ValueType {
case sr.ValueTypeText:
line += fmt.Sprintf(": %q", item.Text)
case sr.ValueTypeCode:
line += ": " + item.Code.Meaning
case sr.ValueTypeNum:
line += ": " + item.Measurement.Value
if item.Measurement.Units != nil {
line += " " + item.Measurement.Units.Value
}
}
if item.ReferencedContentItem != nil {
line += fmt.Sprintf(" (by reference to %v)", item.ReferencedContentItem)
}
fmt.Println(line)
for _, c := range item.Children {
show(c, depth+1)
}
}
func main() {
f, err := os.Open(os.Args[1])
if err != nil {
log.Fatal(err)
}
defer f.Close()
df, err := filereader.ReadDICOMFile(filebase.NewFileReader(f))
if err != nil {
log.Fatal(err)
}
root, err := sr.ReadContentTree(df.GetDataset())
if err != nil {
log.Fatal(err)
}
fmt.Println("items:", root.Count())
show(root, 0)
}On pydicom's test-SR.dcm it prints items: 29 and the tree:
CONTAINS NUM Diameter: 3 cm and the rest.
Notes
- A tree read and written back keeps every attribute it was read with,
including those
ContentItemdoes not model, and passes dcmtk's dsrdump; see CONFORMANCE.md §8.3. - What
ReadKeyObjectSelectionreads is in CONFORMANCE.md §8.6.
Note
StructuredReport, Finding, Observation, SRBuilder, SRTemplate,
SRValidator, ReadSRFile and WriteSRFile are an older, flat model of a
report that does not follow the content tree. Use ReadContentTree and
WriteContentTree instead.