Skip to Content
go-dicom(3)
Packages

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), 0x00100010 or 00100010.
  • 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

NameWhat it is for
TagA tag as a uint32, group in the high 16 bits. Prints as (GGGG,EEEE).
NewA tag from group and element.
ParseTagA tag from text: (0010,0010), 0x00100010 or 00100010; 0010,0010 without parentheses is refused.
Tag.GetKeyword, GetName, GetVR, GetVMWhat the dictionary says of a tag.
Tag.IsPrivate, IsPrivateCreator, IsRetired, ExistsQuestions about a tag.
GlobalDictionary, DicomDictionaryThe standard dictionary; GetByKeyword gives a keyword's tag.
TagInfoOne dictionary entry: VR, VM, name, keyword, retired.
Tag.Hex, ToBytes, FromBytesOther forms of a tag.
ItemTag and the delimitersThe item and delimitation tags of PS3.5 7.5.
FindPrivateTagVendor, SearchPrivateTagsThe 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.GetVR of a private element is the standard dictionary's answer, which is usually none; the dataset methods PrivateBlock and GetPrivateValue find 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

dataset · dataelem · uid

On this page