Skip to content

Conversation

@b4ra0
Copy link

@b4ra0 b4ra0 commented Sep 24, 2025

This pull request updates the Element struct and its related logic to consistently include and use a TagName field, which stores the human-readable name of the DICOM tag. This improves code clarity and ensures the tag's name is always available when working with Element instances.

Enhancements to Element struct and construction:

  • Added a new TagName field to the Element struct to store the tag's human-readable name.
  • Updated all constructors (NewElement, mustNewPrivateElement, and the reader in read.go) to populate the TagName field using tag.Find. If the tag is not found, it defaults to "Unknown".

Improvements to string representation:

  • Modified the Element.String() method to use the new TagName field instead of looking up the tag name each time, improving efficiency and consistency.

Using the example:

dataset, _ := dicom.ParseFile("testdata/1.dcm", nil) // See also: dicom.Parse which has a generic io.Reader API.

// Dataset will nicely print the DICOM dataset data out of the box.
fmt.Println(dataset)

// Dataset is also JSON serializable out of the box.
j, _ := json.Marshal(dataset)
fmt.Println(j)

The new result would be:

{
    "elements": [
        {
            "tag": {
                "Group": 8,
                "Element": 96
            },
            "VR": 0,
            "rawVR": "CS",
            "valueLength": 2,
            "value": [
                "PT"
            ],
            "tagName": "Modality"    
        },
        ...
    ]
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant