tag
DICOM tags and the data dictionary: the Tag type, parsing and printing it, and looking up a tag's keyword, name, VR and VM, or a keyword's tag.
import "github.com/amrshadid/go-dicom/tag" · pkg.go.dev
When to use it
- Name an attribute by number:
tag.New(0x0010, 0x0010). - Turn a keyword into a tag or a tag into a keyword, name, VR or VM.
- Parse a tag a user typed:
(0010,0010),0x00100010or00100010. - Ask whether a tag is private, a private creator, retired, or Pixel Data.
dataset has keyword shortcuts (GetStringByKeyword,
KeywordToTag, TagToKeyword) that use this dictionary.
Key types and functions
| Name | What it is for |
|---|---|
Tag | A tag as a uint32, group in the high 16 bits. Prints as (GGGG,EEEE). |
New | A tag from group and element. |
ParseTag | A tag from text: (0010,0010), 0x00100010 or 00100010; 0010,0010 without parentheses is refused. |
Tag.GetKeyword, GetName, GetVR, GetVM | What the dictionary says of a tag. |
Tag.IsPrivate, IsPrivateCreator, IsRetired, Exists | Questions about a tag. |
GlobalDictionary, DicomDictionary | The standard dictionary; GetByKeyword gives a keyword's tag. |
TagInfo | One dictionary entry: VR, VM, name, keyword, retired. |
Tag.Hex, ToBytes, FromBytes | Other forms of a tag. |
ItemTag and the delimiters | The item and delimitation tags of PS3.5 7.5. |
FindPrivateTagVendor, SearchPrivateTags | The private dictionary of vendor tags. |
Example
// Look tags up in the data dictionary, in both directions.
package main
import (
"fmt"
"log"
"github.com/amrshadid/go-dicom/tag"
)
func main() {
t, err := tag.ParseTag("(0010,0010)")
if err != nil {
log.Fatal(err)
}
fmt.Println(t, t.GetKeyword(), t.GetName(), t.GetVR(), t.GetVM())
dict := tag.GlobalDictionary()
rows := dict.GetByKeyword("Rows")
fmt.Println(rows, rows.Hex(), dict.GetVR(rows))
private := tag.New(0x0029, 0x1010)
fmt.Println(private, "private:", private.IsPrivate(), "in dictionary:", private.Exists())
}It prints (0010,0010) PatientName Patient's Name PN 1, (0028,0010) 00280010 US
and (0029,1010) private: true in dictionary: false.
Notes
- The dictionary is built once and shared; lookups are safe from any goroutine.
- A private tag's meaning depends on its private creator.
Tag.GetVRof a private element is the standard dictionary's answer, which is usually none; the dataset methodsPrivateBlockandGetPrivateValuefind elements by creator.
Tip
GetByKeyword returns Tag(0) for an unknown keyword rather than an
error. Check for it, or a typo in a keyword silently names no element.
See also
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).
uid
UIDs: generating new ones, the registry of well-known UIDs (transfer syntaxes, SOP classes and the rest) with their names and keywords, and a few questions about transfer syntaxes.