Skip to Content
go-dicom(3)
Packages

validate

Checks a data set against the IOD its SOP class requires, with module and attribute tables generated from PS3.3 and PS3.4.

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

When to use it

  • Before sending or archiving instances you created or changed, to catch missing Type 1 and 2 attributes and values outside the enumerated ones.
  • To check what a device sends you.

The command line's validate is built on it.

Key types and functions

NameWhat it is for
DatasetCheck a data set against the IOD of its SOP Class UID.
DatasetAsCheck against the IOD of a SOP class you name.
ReportThe IOD, its PS3.3 section, the edition, and the findings.
Report.Count, Report.Worst, Report.SortSummarize and order the findings.
FindingOne finding: severity, tag, path through sequences, name, module, reference, rule, message.
Severity, NotCheckedError, Warning, and rules that could not be applied.
EditionThe edition of PS3.3 the tables come from.
IODForSOPClass, IODThe modules and their usage for a SOP class.
LookupTable, Table, RowA module or macro table by label.
AttributeType, UsageType 1, 1C, 2, 2C, 3; Mandatory, Conditional, User Option.

Example

// Check a file against the IOD of its SOP class.
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/amrshadid/go-dicom/filebase"
	"github.com/amrshadid/go-dicom/filereader"
	"github.com/amrshadid/go-dicom/validate"
)

func main() {
	f, err := os.Open(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	df, err := filereader.ReadDICOMFile(filebase.NewFileReader(f))
	if err != nil {
		log.Fatal(err)
	}
	report, err := validate.Dataset(df.GetDataset())
	if err != nil {
		log.Fatal(err) // no SOP Class UID, or one without rules here
	}
	report.Sort()
	fmt.Println(report.IOD, "("+report.IODSection+"), PS3.3", report.Edition)
	fmt.Println("errors:", report.Count(validate.Error), "warnings:", report.Count(validate.Warning),
		"not checked:", report.Count(validate.NotChecked))
	for _, f := range report.Findings {
		if f.Severity == validate.Error {
			fmt.Println(f.Severity, f.Path, f.Name, "-", f.Rule, "-", f.Message)
		}
	}
}

On CT_small.dcm it prints CT Image (A.3), PS3.3 2026d and errors: 0 warnings: 0 not checked: 34.

Notes

  • No bulk value's bytes are needed, so a data set read with filereader.ReadOptions{SkipBulkData: true} can be checked.
  • NotChecked findings are conditions PS3.3 states in prose. They say nothing about the instance; they are listed so nothing passes silently.
  • Context groups (PS3.16), rules between attributes, and attributes the IOD does not name are not checked. What is checked, and how much of the conditions, is in CONFORMANCE.md §8.7.

Important

Dataset returns an error, not a report, when the data set has no SOP Class UID or one this package has no tables for. Use DatasetAs with the file's Media Storage SOP Class UID when the data set's own is missing.

See also

dataset · valuerep · anonymize · Validation

On this page