dcmstore
An on-disk store of DICOM instances with an index that answers C-FIND queries, and a network.Handler that serves Verification, Storage and Query/Retrieve from it. Together they are a small archive.
import "github.com/amrshadid/go-dicom/dcmstore" · pkg.go.dev
When to use it
- You need an SCP that receives images and answers C-FIND, C-MOVE and C-GET, without writing the filing, indexing and matching yourself.
- You want a DICOMweb server:
dicomweb.NewServertakes a*Storeas its backend. - You want to file instances by study and series and query them in code.
The command line's qrscp is this package behind network.
Key types and functions
| Name | What it is for |
|---|---|
Open, Store | Open or create an archive directory and load its index. |
Store.Store, Store.Put | File a data set and index it. |
Store.Query | Answer a C‑FIND identifier at its Query/Retrieve Level. |
Store.MatchingInstances, Instance | The instances a query names, as index entries. |
Store.Load, Store.Open | Read an instance back as a data set or as its file. |
Store.Locate | The SOP Instance UIDs under a study, series or instance. |
Store.Remove, Store.Rebuild | Delete one instance; rebuild the index from the files. |
NewHandler, Handler | A network.Handler over a store; OnStored is called after each instance is written. |
SupportedSOPClasses, SupportedTransferSyntaxes | What to give the SCP to accept. |
QueryNegotiation | The extended negotiation the handler supports for C‑FIND. |
QueryLevel, Level | Read Query/Retrieve Level from a query. |
Example
// File instances into an archive directory and query it as a C-FIND would.
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/amrshadid/go-dicom/dataelem"
"github.com/amrshadid/go-dicom/dataset"
"github.com/amrshadid/go-dicom/dcmstore"
"github.com/amrshadid/go-dicom/filebase"
"github.com/amrshadid/go-dicom/filereader"
)
func main() {
ctx := context.Background()
store, err := dcmstore.Open(os.Args[1]) // created if it does not exist
if err != nil {
log.Fatal(err)
}
for _, path := range os.Args[2:] {
f, err := os.Open(path)
if err != nil {
log.Fatal(err)
}
df, err := filereader.ReadDICOMFile(filebase.NewFileReader(f))
f.Close()
if err != nil {
log.Fatal(err)
}
if _, err := store.Store(ctx, df.GetDataset()); err != nil {
log.Fatal(err)
}
}
fmt.Println("instances:", store.Count())
query := dataset.NewDataset()
for _, k := range []struct {
keyword string
vr dataelem.VR
value string
}{
{"QueryRetrieveLevel", dataelem.CS, "STUDY"},
{"ModalitiesInStudy", dataelem.CS, "MR"},
{"PatientName", dataelem.PN, ""},
{"StudyInstanceUID", dataelem.UI, ""},
} {
if err := query.AddByKeyword(k.keyword, k.vr, k.value); err != nil {
log.Fatal(err)
}
}
matches, err := store.Query(ctx, query)
if err != nil {
log.Fatal(err)
}
for _, m := range matches {
fmt.Println(m.GetStringByKeyword("PatientName"), m.GetStringByKeyword("StudyInstanceUID"))
}
}Given a new directory, CT_small.dcm and MR_small.dcm, it prints
instances: 2 and the one study whose modalities include MR.
To serve the same store over the network:
scp := network.NewSCP(network.SCPConfig{AETitle: "ARCHIVE", Port: 11112})
scp.SetHandler(dcmstore.NewHandler(store))
scp.SetSupportedAbstractSyntaxes(dcmstore.SupportedSOPClasses())
if err := scp.ListenAndServe(ctx); err != nil {
log.Fatal(err)
}Notes
- Files sit under
<study>/<series>/<instance>.dcm. Every UID is checked before it becomes part of a path; see fileutil. index.jsonholds the indexed attributes andindex.logthe changes since. A missing or unreadable index is rebuilt from the files atOpen.- Only the keys PS3.4 C.6.1.1 and C.6.2.1 define, and those a DICOMweb search returns, are indexed. A query on any other attribute is not matched on.
- A
Storeis safe for concurrent use within one process. - Matching is matching's, run against the index; what is supported is in CONFORMANCE.md §2.7.
Warning
Nothing locks the directory against a second process. Open each archive directory from one process at a time.
See also
network · matching · dicomweb · Network SCP · Query and retrieve · DICOMweb server
dataset
A data set in memory: the elements of one DICOM object, keyed by tag, with sequences of nested data sets, and the operations that work on the whole object: reading and changing attributes, decoding, rendering and compressing its pixels, transcoding, and the DICOM JSON and XML forms.
dicomweb
DICOMweb (PS3.18) over HTTP: a client for QIDO-RS search, WADO-RS retrieve and STOW-RS store, and a server, an http.Handler, that answers the same services over an archive.