Validation
How go-dicom checks an instance against what its SOP class requires: the IOD tables it uses, what it checks and what it reports as not checked, in Go and with go-dicom validate. It is for anyone who makes DICOM files, or receives them and wants to know whether they are complete.
Overview
The SOP Class UID names the IOD (PS3.4 Table B.5-1), the IOD names its modules
(PS3.3 Annex A), and each module's table names its attributes (PS3.3 Annex C).
Those tables are generated from the standard's DocBook XML, not written by
hand; validate.Edition() says which edition (2026d on this branch).
Every finding has a severity:
| Severity | Meaning |
|---|---|
Error | A rule the instance breaks: a Type 1 attribute absent or empty, a Type 2 attribute absent, a value not among the Enumerated Values, a wrong number of values or items, a conditional attribute absent where its condition holds |
Warning | A value outside the Defined Terms, where PS3.3 allows others |
NotChecked | A rule stated in prose, which was not evaluated. It is reported, never passed in silence |
Validate a data set
f, err := os.Open("rtdose.dcm")
if err != nil {
return err
}
defer f.Close()
df, err := filereader.ReadDICOMFileWithOptions(filebase.NewFileReader(f),
filereader.ReadOptions{SkipBulkData: true})
if err != nil {
return err
}
ds, err := df.GetDatasetWithValuesInFile() // bulk values keep their length, not their bytes
if err != nil {
return err
}
report, err := validate.Dataset(ds)
if err != nil {
return err // no SOP Class UID, or an IOD with no rules
}
fmt.Println(report.IOD, report.IODSection, report.Edition)
for _, finding := range report.Findings {
if finding.Severity == validate.NotChecked {
continue
}
fmt.Println(finding.Severity, finding.Path, finding.Name, finding.Rule, finding.Message)
}
fmt.Println(report.Count(validate.Error), "errors,", report.Count(validate.NotChecked), "not checked; worst:", report.Worst())On pydicom's rtdose.dcm:
RT Dose A.18 2026d
error (0008,1070) Operators' Name Type 2 absent; a Type 2 attribute is required
1 errors, 40 not checked; worst: errorNo bulk value's bytes are needed: a data set read with SkipBulkData and built
with GetDatasetWithValuesInFile is checked as if read whole, the value's
length saying whether it is empty. A plain GetDataset() works too.
Each Finding has the attribute's Tag, its Path through the sequences
above it ((0008,1140)[1] (0008,1155)), its Name, the Module, the
Reference in PS3.3, the Rule (Type 1, Type 2C, Enumerated Values,
Defined Terms, Value Multiplicity, Items, Usage C) and a Message. A
finding about a module has no tag or path. report.Sort() orders the findings
as the command prints them.
validate.DatasetAs(ds, sopClass) checks against another SOP class's IOD, for
a data set whose own SOP Class UID is missing or not trusted (the file meta's
Media Storage SOP Class UID names it too). validate.IODForSOPClass(uid) gives
the IOD and its modules, and validate.LookupTable(label) a module's table,
for a program that wants the rules themselves.
What is checked
- Modules. Every module the IOD makes Mandatory, and every Conditional or User Option module that is present, which is to say one of the attributes only it names is in the data set.
- Types. A Type 1 attribute is present and has a value, a Type 2 attribute is present, and a Type 1C attribute that is present has a value.
- Value multiplicity, as the dictionary gives it (PS3.6).
- Enumerated Values and Defined Terms, where the table lists them, or the section its description names for a specialization: the CT Image module allows Bits Stored of 12 to 16.
- Item counts, where a sequence's description states them ("Only a single Item shall be included", "One or more Items").
- Sequences at any depth, each item against the table of its sequence.
- Overlay groups. Each even group 6000 to 601E is checked on its own against the Overlay Plane module, and what it lacks is reported under its own tag: an overlay with no Overlay Rows is an Error for (6002,0010). Multi-frame Overlay, Overlay Activation and the US overlay subtype apply to the groups that hold one of their attributes. Odd 60xx groups are private.
- Functional groups. For the 29 enhanced IODs with a Functional Group Macros table: each macro the IOD requires is in the shared item or in every frame's, none is in both or where the table forbids it, the per-frame sequence has one item per frame, and each macro is checked as a module is. What is wrong in many frames is one finding saying in how many.
Conditions
PS3.3 states some conditions in fixed sentence forms naming an attribute by its tag, and those are evaluated:
- "Required if Pixel Data Provider URL (0028,7FE0) is not present", "… is present", "… has a Value of YES";
- "Image Type (0008,0008) Value 1 is ORIGINAL or MIXED";
- "… is present and has a Value of X";
- several of these joined by "and", each optionally followed by "May be present otherwise".
An attribute or module whose condition holds and that is absent is an Error; one present where its condition does not hold is an Error too, unless PS3.3 says it may be present otherwise. In 2026d that covers 681 of the 1891 Type 1C and 2C attributes, 25 of the 323 Conditional modules and 48 of the 171 Conditional functional group macros. A condition in a sequence item is evaluated only when it names an attribute of that item's own table.
What is not checked
Important
A clean report means no rule the checker evaluates was broken. It does not mean the instance conforms: prose conditions, context groups and the rules between attributes are not checked.
- Conditions in prose ("Required if contrast media was used"). The module
or attribute is reported as
NotChecked, with the condition as PS3.3 states it. - Context groups (PS3.16): whether a code is from the right CID.
- Rules between attributes (High Bit is Bits Stored minus one).
- Value representation and the form of values, which the
valuereppackage andDataset.Validatecheck, andgo-dicom modifychecks before it writes. - Attributes the IOD does not name.
- SR content trees nested deeper than twelve levels of one table, and the functional groups of Enhanced MR Color Image, whose macros table is not its own; both are reported as not checked.
The checker has not been compared with another validator; its findings were compared with PS3.3 by hand for fifteen files of thirteen IODs (CONFORMANCE.md §8.7).
On the command line
$ go-dicom validate rtdose.dcm
rtdose.dcm: 1.2.840.10008.5.1.4.1.1.481.2, checked as the RT Dose IOD (PS3.3 A.18, 2026d)
error (0008,1070) Operators' Name: Type 2: absent; a Type 2 attribute is required [RT Series; PS3.3 C.8.8.1 (RT Series Module Attributes)]
not checked General Image: Usage C: absent; whether it is required was not checked: Required if dose data contains grid-based doses. [General Image; PS3.3 A.18 Table A.18.3-1]
not checked Image Plane: Usage C: present, and checked; whether it is required was not checked: Required if dose data contains grid-based doses. [Image Plane; PS3.3 A.18 Table A.18.3-1]
…
Error: validate: rtdose.dcm: 1 error(s), 0 warning(s)
$ echo $?
3
$ go-dicom validate examples_overlay.dcm
examples_overlay.dcm: 1.2.840.10008.5.1.4.1.1.4, checked as the MR Image IOD (PS3.3 A.4, 2026d)
warning (0018,0022) Scan Options: Defined Terms: value 1 is "SAT2"; the Defined Terms are PER, RG, CG, PPG, FC, PFF, PFP, SP, FS [MR Image; PS3.3 C.8.3.1 (MR Image Module Attributes)]
…
Error: validate: examples_overlay.dcm: 1 warning(s)
$ echo $?
2The exit status says the worst finding:
| Status | Meaning |
|---|---|
| 0 | No error or warning (findings not checked may be listed) |
| 1 | The file could not be checked: not readable, no SOP Class UID, or an IOD with no rules |
| 2 | Warnings, no error |
| 3 | Errors |
--json prints the report as JSON (file, sopClassUID, iod,
iodSection, edition and findings, each finding with the fields above in
lower case):
$ go-dicom validate --json examples_overlay.dcm
{
"file": "examples_overlay.dcm",
"sopClassUID": "1.2.840.10008.5.1.4.1.1.4",
"iod": "MR Image",
"iodSection": "A.4",
"edition": "2026d",
"findings": [
{
"severity": "warning",
"tag": "(0018,0022)",
"path": "(0018,0022)",
"name": "Scan Options",
"module": "MR Image",
"reference": "PS3.3 C.8.3.1 (MR Image Module Attributes)",
"rule": "Defined Terms",
"message": "value 1 is \"SAT2\"; the Defined Terms are PER, RG, CG, PPG, FC, PFF, PFP, SP, FS"
},
…The summary line goes to standard error, so standard output stays JSON.
Limits and gotchas
- Not checked is not passed. Read the
NotCheckedfindings, or at least count them; for a typical CT there are about thirty. - Only Storage SOP classes with an IOD in the tables can be checked; another SOP class is an error, not an empty report.
- The report is about the IOD, not the encoding. A file that is
truncated or has elements out of order may still validate; those are in the
reader's
Truncated,OverrunandTagOrderViolations(Reading and writing). - Pixel data is checked for presence and length, not decoded.
See also
- Reading and writing: reading with
SkipBulkData - Structured reports: the SR content tree
- validate on pkg.go.dev
- CONFORMANCE.md §8.7
De-identification
How go-dicom removes identifying information from DICOM files: the PS3.15 Annex E profiles and what each one changes, per-attribute overrides and templates, UID remapping, recording the method, and text burned into the pixels. It is for anyone preparing data to leave the place it was made, and it says plainly what is not removed.
Structured reports
How go-dicom reads the content tree of a DICOM Structured Report, writes one back, and reads a Key Object Selection document, in Go and with go-dicom sr. It is for anyone who needs what a report says, not only that it is there.