Skip to Content
go-dicom(3)
Packages

valuerep

The value representations of PS3.5 as rules: length, character set and form checks for each VR, UID checks, and parsers for DA, TM, DS and IS.

import "github.com/amrshadid/go-dicom/valuerep" · pkg.go.dev

When to use it

  • Check a value before you put it in an element: an AE title of at most 16 characters, a UID that is dotted decimal without leading zeros.
  • Parse a date, time, decimal string or integer string from text.
  • Look up a VR's name, maximum length and padding.

dataelem and filewriter use it for their own checks, and network to check the UIDs a peer sends.

Key types and functions

NameWhat it is for
ValidateValueCheck a value against every rule of its VR.
ValidateVRLength, ValidateRegex, ValidateTypeThe checks one at a time.
ValidateUID, MaxUIDLengthA UID: digits and dots, no leading zeros, at most 64 characters.
ParseDate, DateDA into a time.Time.
ParseTime, TimeTM.
ParseDecimalString, ParseIntegerStringDS and IS.
GetVRMetadata, VRMetadataA VR's name, maximum length, padding and kind (numeric, string, binary, date or time).
IsValidVR, GetAllVRCodesKnown VR codes.

Example

// Check values against their VR and parse dates, numbers and names.
package main

import (
	"fmt"

	"github.com/amrshadid/go-dicom/valuerep"
)

func main() {
	fmt.Println("AE ok:", valuerep.ValidateValue("AE", "STORESCP"))
	fmt.Println("AE too long:", valuerep.ValidateValue("AE", "A_TITLE_LONGER_THAN_16"))
	fmt.Println("UID:", valuerep.ValidateUID("1.2.840.10008.1.2.1"))

	if d, err := valuerep.ParseDate("20040119"); err == nil {
		fmt.Println("date:", d.Value.Format("2006-01-02"))
	}
	if ds, err := valuerep.ParseDecimalString("-1024.0"); err == nil {
		fmt.Println("DS:", ds.Value)
	}
	md, err := valuerep.GetVRMetadata("LO")
	if err == nil {
		fmt.Println("LO:", md.Name, "max", md.MaxLength)
	}
}

It prints AE ok: <nil>, the length error for the 22-character title, UID: <nil>, date: 2004-01-19, DS: -1024 and LO: Long String max 64.

Notes

  • ValidateUID is stricter than uid.UID.IsValid, which accepts leading zeros and values longer than 64 characters.
  • How character sets apply to text VRs is in CONFORMANCE.md §6.

Warning

ParsePersonName splits on ^ rather than on the = that separates component groups, so its groups are wrong for any name with more than one component. Split PN values yourself, = first and then ^.

Note

For reading values from a file, use the dataset and dataelem accessors; this package is for checking and parsing text.

See also

dataelem · uid · values · validate · Validation

On this page