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.
import "github.com/amrshadid/go-dicom/dicomweb" · pkg.go.dev
When to use it
- Search, fetch or upload against a DICOMweb archive (client).
- Put an HTTP face on an archive you already have, or on a dcmstore store that also answers DIMSE (server).
The command line's qido, wado and stow use the client, and
qrscp -web the server.
How it fits together
The server speaks HTTP and leaves storage and matching to the Backend.
*dcmstore.Store is a Backend as it is, so one archive can answer DIMSE and
HTTP alike.
Key types and functions
| Name | What it is for |
|---|---|
NewClient, Client | A client for a base URL such as https://host/dicom-web. |
WithBearerToken, WithBasicAuth, WithHTTPClient | Credentials and transport. |
WithMaxResponseBytes | Bound what a response may hold. |
Client.SearchForStudies, Query | QIDO‑RS; matches, fields, limit and offset. |
Client.SearchEach | The same, one result at a time. |
Client.RetrieveStudy, Client.RetrieveInstance | WADO‑RS instances as data sets. |
Client.RetrieveEach, Client.RetrieveStream | Instances one at a time, without holding all of them. |
Client.RetrieveMetadata, Client.RetrieveFrames, Client.RetrieveRendered | Metadata, frames, and rendered pictures. |
Client.Store, Client.StoreDatasets, StoreResult | STOW‑RS from files or data sets, with what was stored and what failed. |
NewServer, Server, Backend | The server and the archive it serves. |
WithMaxStoreBytes, WithFrameEncoding | Server limits and how frames are sent. |
StatusError, ResponseTooLargeError | HTTP failures and a response past the bound. |
Example
// Serve an archive over DICOMweb, then store, search and retrieve through
// the client. Both ends run in one program.
package main
import (
"context"
"fmt"
"log"
"net"
"net/http"
"os"
"github.com/amrshadid/go-dicom/dcmstore"
"github.com/amrshadid/go-dicom/dicomweb"
)
func main() {
ctx := context.Background()
store, err := dcmstore.Open(os.Args[1]) // the archive directory
if err != nil {
log.Fatal(err)
}
ln, err := net.Listen("tcp", "127.0.0.1:43180")
if err != nil {
log.Fatal(err)
}
mux := http.NewServeMux()
mux.Handle("/dicom-web/", http.StripPrefix("/dicom-web", dicomweb.NewServer(store)))
srv := &http.Server{Handler: mux}
go srv.Serve(ln)
defer srv.Close()
client, err := dicomweb.NewClient("http://127.0.0.1:43180/dicom-web")
if err != nil {
log.Fatal(err)
}
// STOW-RS: send a Part 10 file as it is.
file, err := os.ReadFile(os.Args[2])
if err != nil {
log.Fatal(err)
}
stored, err := client.Store(ctx, "", file)
if err != nil {
log.Fatal(err)
}
fmt.Println("stored:", len(stored.Stored), "failed:", len(stored.Failed))
// QIDO-RS: each result is a data set, as a C-FIND result is.
studies, err := client.SearchForStudies(ctx, dicomweb.Query{
Match: map[string]string{"PatientName": "Compressed*"},
Limit: 10,
})
if err != nil {
log.Fatal(err)
}
for _, s := range studies {
study := s.GetStringByKeyword("StudyInstanceUID")
fmt.Println("study:", s.GetStringByKeyword("PatientName"), study)
// WADO-RS: the instances without their bulk data.
meta, err := client.RetrieveMetadata(ctx, study, "", "")
if err != nil {
log.Fatal(err)
}
for _, m := range meta {
fmt.Println(" instance:", m.GetStringByKeyword("SOPInstanceUID"), m.GetStringByKeyword("Modality"))
}
}
}It serves a dcmstore archive on 127.0.0.1:43180, stores
CT_small.dcm (stored: 1 failed: 0), finds its study and lists its
instance's metadata.
Notes
- The client reads a response up to
DefaultMaxResponseBytesunlessWithMaxResponseBytessays otherwise; the server reads a STOW-RS request up toDefaultMaxStoreBytesunlessWithMaxStoreBytessays otherwise. - The server matches literally; a request for fuzzy matching is answered with a warning.
- Rendered pictures use
Dataset.RenderFrame; see Rendering. - What is served, and with which media types, is in CONFORMANCE.md §4.1.
Caution
The server does not authenticate. It serves whatever the archive holds to whoever reaches it. Wrap it in a handler that decides who may, and serve it over TLS.
See also
dcmstore · network · matching · DICOMweb client · DICOMweb server · TLS and security
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.
encaps
Parses encapsulated Pixel Data (PS3.5 A.4), the item sequence compressed frames are stored in, and groups its fragments into frames.