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
| Name | What it is for |
|---|---|
ValidateValue | Check a value against every rule of its VR. |
ValidateVRLength, ValidateRegex, ValidateType | The checks one at a time. |
ValidateUID, MaxUIDLength | A UID: digits and dots, no leading zeros, at most 64 characters. |
ParseDate, Date | DA into a time.Time. |
ParseTime, Time | TM. |
ParseDecimalString, ParseIntegerString | DS and IS. |
GetVRMetadata, VRMetadata | A VR's name, maximum length, padding and kind (numeric, string, binary, date or time). |
IsValidVR, GetAllVRCodes | Known 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
ValidateUIDis stricter thanuid.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 ^.
See also
dataelem · uid · values · validate · Validation