Skip to Content
go-dicom(3)
Packages

multival

Lists of values with a constructor that coerces each element: the shape of a multi-valued attribute (VM > 1) such as ORIGINAL\PRIMARY\AXIAL.

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

When to use it

When you want a backslash-separated value as a list that keeps coercing what you append to it, for example upper-casing CS values. Nothing else in the module uses it; data elements hold their values as strings, byte slices or numbers.

For the values of an element, use GetStringByKeyword and strings.Split on \, or the typed accessors of dataelem and values.

Key types and functions

NameWhat it is for
ConstrainedList, NewA list that passes each value through a constructor.
ParseDICOMStringSplit a \-separated value into a list.
MultiValueToStringJoin a list back with a separator.
GetConstructorForVRThe constructor for a VR name: CS, DS, IS, LO, SH, ST, or plain strings.
CSConstructor, DSConstructor, ISConstructorSingle constructors.
NewCSList, NewDSList, NewISListLists with a constructor set.
StringList, IntList, FloatListTyped lists without a constructor.
DatasetMultiValueA list labelled with a tag and VR.

Example

// Split a backslash-separated value, normalized by VR, and join it again.
package main

import (
	"fmt"
	"log"

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

func main() {
	list, err := multival.ParseDICOMString(`ORIGINAL\PRIMARY\AXIAL`, multival.GetConstructorForVR("CS"))
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("values:", list.Length(), list.Items())
	if err := list.Append("helical"); err != nil {
		log.Fatal(err)
	}
	fmt.Println(multival.MultiValueToString(list, `\`))
}

It prints values: 3 [ORIGINAL PRIMARY AXIAL] and then ORIGINAL\PRIMARY\AXIAL\HELICAL: the CS constructor upper-cased the appended value.

Notes

  • The constructors coerce; they do not validate. For VR rules use valuerep.ValidateValue (valuerep).
  • A ConstrainedList holds interface{} values; read them back with type assertions.

Note

This is a standalone helper. Values read from a file come from dataset and dataelem, not from this package.

See also

dataelem · values · valuerep

On this page